diff --git a/examples/cluster.c b/examples/cluster.c index 1e3b7c1..4e800a2 100644 --- a/examples/cluster.c +++ b/examples/cluster.c @@ -8,60 +8,12 @@ #include #include -#include -#include -#include -#include -#include -#include - -typedef struct _hexagram_cluster_state { - double rpm, rps, temp, fuel; -} hexagram_cluster_state; +#include static hexagram_cluster_state state = { 0, 0, 0, 0 }; -static void cluster_draw_bg(cairo_t *cr, - double width, - double height) { - /* - * Paint canvas black - */ - cairo_set_source_rgb(cr, 0, 0, 0); - cairo_paint(cr); - - hexagram_tacho_draw_face(cr, - width * 0.2, - height * 0.5, - height * 0.4, - 6500); - - hexagram_speedo_draw_face(cr, - width * 0.8, - height * 0.5, - height * 0.4); - - hexagram_thermo_draw_face(cr, - width * 0.43, - height * 0.76, - height * 0.13, - 240.0); - - hexagram_fuel_draw_face(cr, - width * 0.57, - height * 0.76, - height * 0.13, - 0.125); - - hexagram_mfd_draw(cr, - width * 0.42, - height * 0.1, - width * 0.16, - height * 0.5); -} - static void cluster_update(struct can_frame *frame) { switch (frame->can_id) { case 0x280: { @@ -92,36 +44,6 @@ static void cluster_update(struct can_frame *frame) { } } -static void cluster_draw(cairo_t *cr, - double x, - double y, - double width, - double height) { - hexagram_tacho_draw_needle(cr, - x + width * 0.2, - y + height * 0.5, - height * 0.4, - state.rpm); - - hexagram_speedo_draw_needle(cr, - width * 0.8, - height * 0.5, - height * 0.4, - (2.032 * state.rps * 3600) / 1000.0); - - hexagram_thermo_draw_needle(cr, - width * 0.43, - height * 0.76, - height * 0.13, - state.temp); - - hexagram_fuel_draw_needle(cr, - width * 0.57, - height * 0.76, - height * 0.13, - state.fuel); -} - static int usage(int argc, char **argv, const char *message, ...) { if (message) { va_list args; @@ -180,7 +102,7 @@ int main(int argc, char **argv) { /* * Draw the background layer */ - cluster_draw_bg(bg, width, height); + hexagram_cluster_draw_bg(bg, width, height); /* * Present the background layer @@ -214,7 +136,7 @@ int main(int argc, char **argv) { case MapNotify: case Expose: hexagram_window_refresh_bg(window); - cluster_draw(fg, 0, 0, width, height); + hexagram_cluster_draw_fg(&state, fg, 0, 0, width, height); hexagram_window_swap_buffer(window); break; @@ -249,7 +171,7 @@ int main(int argc, char **argv) { if (now.tv_sec - last.tv_sec || now.tv_usec - last.tv_usec > 16666) { hexagram_window_refresh_bg(window); - cluster_draw(fg, 0, 0, width, height); + hexagram_cluster_draw_fg(&state, fg, 0, 0, width, height); hexagram_window_swap_buffer(window); (void)memcpy(&last, &now, sizeof(now)); diff --git a/include/hexagram/cluster.h b/include/hexagram/cluster.h new file mode 100644 index 0000000..7fac712 --- /dev/null +++ b/include/hexagram/cluster.h @@ -0,0 +1,21 @@ +#ifndef _HEXAGRAM_CLUSTER_H +#define _HEXAGRAM_CLUSTER_H + +#include + +typedef struct _hexagram_cluster_state { + double rpm, rps, temp, fuel; +} hexagram_cluster_state; + +void hexagram_cluster_draw_bg(cairo_t *cr, + double width, + double height); + +void hexagram_cluster_draw_fg(hexagram_cluster_state *state, + cairo_t *cr, + double x, + double y, + double width, + double height); + +#endif /* _HEXAGRAM_CLUSTER_H */ diff --git a/src/Makefile b/src/Makefile index 4082c9f..64d0d42 100644 --- a/src/Makefile +++ b/src/Makefile @@ -8,12 +8,14 @@ CFLAGS += -fPIC -I$(INCLUDE_PATH) $(shell pkg-config --cflags cairo x11) LDFLAGS = $(shell pkg-config --libs cairo x11) -lXext HEADERS = dict.h hash.h can.h capture.h pcapng.h module.h window.h \ - gauge.h tacho.h speedo.h thermo.h fuel.h mfd.h sim.h + gauge.h tacho.h speedo.h thermo.h fuel.h mfd.h cluster.h \ + sim.h HEADERS_LOCAL = util.h OBJS = dict.o hash.o can.o capture.o pcapng.o module.o window.o \ - gauge.o tacho.o speedo.o thermo.o fuel.o mfd.o sim.o + gauge.o tacho.o speedo.o thermo.o fuel.o mfd.o cluster.o \ + sim.o VERSION_MAJOR = 0 VERSION_MINOR = 0.1 diff --git a/src/cluster.c b/src/cluster.c new file mode 100644 index 0000000..5e1ff4c --- /dev/null +++ b/src/cluster.c @@ -0,0 +1,76 @@ +#include +#include +#include +#include +#include +#include + +void hexagram_cluster_draw_bg(cairo_t *cr, + double width, + double height) { + /* + * Paint canvas black + */ + cairo_set_source_rgb(cr, 0, 0, 0); + cairo_paint(cr); + + hexagram_tacho_draw_face(cr, + width * 0.2, + height * 0.5, + height * 0.4, + 6500); + + hexagram_speedo_draw_face(cr, + width * 0.8, + height * 0.5, + height * 0.4); + + hexagram_thermo_draw_face(cr, + width * 0.43, + height * 0.76, + height * 0.13, + 240.0); + + hexagram_fuel_draw_face(cr, + width * 0.57, + height * 0.76, + height * 0.13, + 0.125); + + hexagram_mfd_draw(cr, + width * 0.42, + height * 0.1, + width * 0.16, + height * 0.5); +} + +void hexagram_cluster_draw_fg(hexagram_cluster_state *state, + cairo_t *cr, + double x, + double y, + double width, + double height) { + hexagram_tacho_draw_needle(cr, + x + width * 0.2, + y + height * 0.5, + height * 0.4, + state->rpm); + + hexagram_speedo_draw_needle(cr, + width * 0.8, + height * 0.5, + height * 0.4, + (2.032 * state->rps * 3600) / 1000.0); + + hexagram_thermo_draw_needle(cr, + width * 0.43, + height * 0.76, + height * 0.13, + state->temp); + + hexagram_fuel_draw_needle(cr, + width * 0.57, + height * 0.76, + height * 0.13, + state->fuel); +}