Add missing files, split fuel gauge into separate files

This commit is contained in:
XANTRONIX Development 2019-06-09 13:55:54 -05:00
parent 478d1142e5
commit 0326608b17
8 changed files with 273 additions and 74 deletions

View file

@ -12,6 +12,7 @@
#include <hexagram/tacho.h> #include <hexagram/tacho.h>
#include <hexagram/speedo.h> #include <hexagram/speedo.h>
#include <hexagram/thermo.h> #include <hexagram/thermo.h>
#include <hexagram/fuel.h>
typedef struct _hexagram_cluster_state { typedef struct _hexagram_cluster_state {
double rpm, rps, temp, fuel; double rpm, rps, temp, fuel;
@ -21,68 +22,6 @@ static hexagram_cluster_state state = {
0, 0, 0, 0 0, 0, 0, 0
}; };
static void draw_fuel_gauge(cairo_t *cr,
double x,
double y,
double r,
double redline) {
int i;
cairo_set_source_rgb(cr, 1, 1, 1);
cairo_arc(cr, x, y, r, 0, 2*M_PI);
cairo_stroke(cr);
cairo_move_to(cr, x - 0.8 * r, y - 0.1 * r);
cairo_show_text(cr, "0");
cairo_move_to(cr, x - 0.15 * r, y - 0.5 * r);
cairo_show_text(cr, "1/2");
cairo_move_to(cr, x + 0.65 * r, y - 0.1 * r);
cairo_show_text(cr, "1");
/*
* Draw gauge graduations
*/
for (i=0; i<=16; i++) {
if (i <= (16.0 * redline)) {
cairo_set_source_rgb(cr, 1, 0, 0);
} else {
cairo_set_source_rgb(cr, 1, 1, 1);
}
hexagram_gauge_draw_mark(cr, x, y,
((i % 4)? 0.8: 0.7) * r,
0.90 * r,
300 * (M_PI/180),
420 * (M_PI/180),
(double)i / 16.0);
}
}
static void draw_fuel_gauge_needle(cairo_t *cr,
double x,
double y,
double r,
double level) {
if (level > 1.0) {
level = 1.0;
}
/*
* Draw a tiny boi circle
*/
cairo_set_source_rgb(cr, 1, 1, 1);
cairo_arc(cr, x, y, 0.08 * r, 0, 2*M_PI);
cairo_stroke(cr);
hexagram_gauge_draw_needle(cr, x, y, 0.9 * r,
300 * (M_PI/180),
420 * (M_PI/180),
level / 1.0);
}
static void draw_mfd(cairo_t *cr, static void draw_mfd(cairo_t *cr,
double x, double x,
double y, double y,
@ -131,11 +70,11 @@ static void cluster_draw_bg(cairo_t *cr,
height * 0.13, height * 0.13,
240.0); 240.0);
draw_fuel_gauge(cr, hexagram_fuel_draw_face(cr,
width * 0.57, width * 0.57,
height * 0.76, height * 0.76,
height * 0.13, height * 0.13,
0.125); 0.125);
draw_mfd(cr, draw_mfd(cr,
width * 0.42, width * 0.42,
@ -197,11 +136,11 @@ static void cluster_draw(cairo_t *cr,
height * 0.13, height * 0.13,
state.temp); state.temp);
draw_fuel_gauge_needle(cr, hexagram_fuel_draw_needle(cr,
width * 0.57, width * 0.57,
height * 0.76, height * 0.76,
height * 0.13, height * 0.13,
state.fuel); state.fuel);
} }
static int usage(int argc, char **argv, const char *message, ...) { static int usage(int argc, char **argv, const char *message, ...) {

16
include/hexagram/fuel.h Normal file
View file

@ -0,0 +1,16 @@
#ifndef _HEXAGRAM_FUEL_H
#define _HEXAGRAM_FUEL_H
void hexagram_fuel_draw_face(cairo_t *cr,
double x,
double y,
double r,
double redline);
void hexagram_fuel_draw_needle(cairo_t *cr,
double x,
double y,
double r,
double level);
#endif /* _HEXAGRAM_FUEL_H */

17
include/hexagram/speedo.h Normal file
View file

@ -0,0 +1,17 @@
#ifndef _HEXAGRAM_SPEEDO_H
#define _HEXAGRAM_SPEEDO_H
#include <cairo.h>
void hexagram_speedo_draw_face(cairo_t *cr,
double x,
double y,
double r);
void hexagram_speedo_draw_needle(cairo_t *cr,
double x,
double y,
double r,
double kph);
#endif /* _HEXAGRAM_SPEEDO_H */

18
include/hexagram/thermo.h Normal file
View file

@ -0,0 +1,18 @@
#ifndef _HEXAGRAM_THERMO_H
#define _HEXAGRAM_THERMO_H
#include <cairo.h>
void hexagram_thermo_draw_face(cairo_t *cr,
double x,
double y,
double r,
double redline);
void hexagram_thermo_draw_needle(cairo_t *cr,
double x,
double y,
double r,
double temp);
#endif /* _HEXAGRAM_THERMO_H */

View file

@ -8,12 +8,12 @@ CFLAGS += -fPIC -I$(INCLUDE_PATH) $(shell pkg-config --cflags cairo x11)
LDFLAGS = $(shell pkg-config --libs cairo x11) -lXext LDFLAGS = $(shell pkg-config --libs cairo x11) -lXext
HEADERS = dict.h hash.h can.h capture.h pcapng.h module.h window.h \ HEADERS = dict.h hash.h can.h capture.h pcapng.h module.h window.h \
gauge.h tacho.h speedo.h thermo.h sim.h gauge.h tacho.h speedo.h thermo.h fuel.h sim.h
HEADERS_LOCAL = util.h HEADERS_LOCAL = util.h
OBJS = dict.o hash.o can.o capture.o pcapng.o module.o window.o \ OBJS = dict.o hash.o can.o capture.o pcapng.o module.o window.o \
gauge.o tacho.o speedo.o thermo.o sim.o gauge.o tacho.o speedo.o thermo.o fuel.o sim.o
VERSION_MAJOR = 0 VERSION_MAJOR = 0
VERSION_MINOR = 0.1 VERSION_MINOR = 0.1

67
src/fuel.c Normal file
View file

@ -0,0 +1,67 @@
#include <math.h>
#include <hexagram/gauge.h>
#include <hexagram/fuel.h>
void hexagram_fuel_draw_face(cairo_t *cr,
double x,
double y,
double r,
double redline) {
int i;
cairo_set_source_rgb(cr, 1, 1, 1);
cairo_arc(cr, x, y, r, 0, 2*M_PI);
cairo_stroke(cr);
cairo_move_to(cr, x - 0.8 * r, y - 0.1 * r);
cairo_show_text(cr, "0");
cairo_move_to(cr, x - 0.15 * r, y - 0.5 * r);
cairo_show_text(cr, "1/2");
cairo_move_to(cr, x + 0.65 * r, y - 0.1 * r);
cairo_show_text(cr, "1");
/*
* Draw gauge graduations
*/
for (i=0; i<=16; i++) {
if (i <= (16.0 * redline)) {
cairo_set_source_rgb(cr, 1, 0, 0);
} else {
cairo_set_source_rgb(cr, 1, 1, 1);
}
hexagram_gauge_draw_mark(cr, x, y,
((i % 4)? 0.8: 0.7) * r,
0.90 * r,
300 * (M_PI/180),
420 * (M_PI/180),
(double)i / 16.0);
}
}
void hexagram_fuel_draw_needle(cairo_t *cr,
double x,
double y,
double r,
double level) {
if (level > 1.0) {
level = 1.0;
}
/*
* Draw a tiny boi circle
*/
cairo_set_source_rgb(cr, 1, 1, 1);
cairo_arc(cr, x, y, 0.08 * r, 0, 2*M_PI);
cairo_stroke(cr);
hexagram_gauge_draw_needle(cr, x, y, 0.9 * r,
300 * (M_PI/180),
420 * (M_PI/180),
level / 1.0);
}

69
src/speedo.c Normal file
View file

@ -0,0 +1,69 @@
#include <stdio.h>
#include <math.h>
#include <hexagram/gauge.h>
#include <hexagram/speedo.h>
void hexagram_speedo_draw_face(cairo_t *cr,
double x,
double y,
double r) {
int i;
cairo_select_font_face(cr, "Helvetica",
CAIRO_FONT_SLANT_NORMAL,
CAIRO_FONT_WEIGHT_NORMAL);
cairo_set_font_size(cr, r * 0.125);
cairo_set_source_rgb(cr, 1, 1, 1);
cairo_arc(cr, x, y, r, 0, 2*M_PI);
cairo_stroke(cr);
/*
* Draw face numbers
*/
for (i=0; i<=180; i+=20) {
char text[5];
snprintf(text, 4, "%02d", i);
hexagram_gauge_draw_number(cr, x, y,
0.85 * r,
232 * (M_PI/180),
488 * (M_PI/180),
i / 180.0,
text);
}
for (i=0; i<=180; i+=2) {
hexagram_gauge_draw_mark(cr, x, y,
((i % 10)? 0.75: 0.7) * r,
0.8 * r,
232 * (M_PI/180),
488 * (M_PI/180),
i / 180.0);
}
}
void hexagram_speedo_draw_needle(cairo_t *cr,
double x,
double y,
double r,
double kph) {
if (kph > 290) {
kph = 290;
}
/*
* Draw a tiny boi circle
*/
cairo_set_source_rgb(cr, 1, 1, 1);
cairo_arc(cr, x, y, 0.08 * r, 0, 2*M_PI);
cairo_stroke(cr);
hexagram_gauge_draw_needle(cr, x, y, 0.8 * r,
232 * (M_PI/180),
488 * (M_PI/180),
kph / 290);
}

73
src/thermo.c Normal file
View file

@ -0,0 +1,73 @@
#include <math.h>
#include <hexagram/gauge.h>
#include <hexagram/thermo.h>
void hexagram_thermo_draw_face(cairo_t *cr,
double x,
double y,
double r,
double redline) {
int i;
cairo_select_font_face(cr, "Helvetica",
CAIRO_FONT_SLANT_NORMAL,
CAIRO_FONT_WEIGHT_NORMAL);
cairo_set_font_size(cr, r * 0.2);
cairo_set_source_rgb(cr, 1, 1, 1);
cairo_arc(cr, x, y, r, 0, 2*M_PI);
cairo_stroke(cr);
/*
* Draw face numbers
*/
cairo_move_to(cr, x - 0.8 * r, y - 0.1 * r);
cairo_show_text(cr, "120");
cairo_move_to(cr, x - 0.15 * r, y - 0.5 * r);
cairo_show_text(cr, "190");
cairo_move_to(cr, x + 0.5 * r, y - 0.1 * r);
cairo_show_text(cr, "260");
/*
* Draw gauge graduations
*/
for (i=0; i<=140; i+=7) {
if (i + 120 >= redline) {
cairo_set_source_rgb(cr, 1, 0, 0);
}
hexagram_gauge_draw_mark(cr, x, y,
((i % 35)? 0.8: 0.7) * r,
0.90 * r,
300 * (M_PI/180),
420 * (M_PI/180),
i / 140.0);
}
}
void hexagram_thermo_draw_needle(cairo_t *cr,
double x,
double y,
double r,
double temp) {
if (temp > 260) {
temp = 260;
}
/*
* Draw a tiny boi circle
*/
cairo_set_source_rgb(cr, 1, 1, 1);
cairo_arc(cr, x, y, 0.08 * r, 0, 2*M_PI);
cairo_stroke(cr);
hexagram_gauge_draw_needle(cr, x, y, 0.9 * r,
300 * (M_PI/180),
420 * (M_PI/180),
temp / 260);
}