Split gauge cluster out of examples/cluster.c
This commit is contained in:
parent
dd66c31137
commit
6689722b31
4 changed files with 105 additions and 84 deletions
|
@ -8,60 +8,12 @@
|
|||
|
||||
#include <hexagram/can.h>
|
||||
#include <hexagram/window.h>
|
||||
#include <hexagram/gauge.h>
|
||||
#include <hexagram/tacho.h>
|
||||
#include <hexagram/speedo.h>
|
||||
#include <hexagram/thermo.h>
|
||||
#include <hexagram/fuel.h>
|
||||
#include <hexagram/mfd.h>
|
||||
|
||||
typedef struct _hexagram_cluster_state {
|
||||
double rpm, rps, temp, fuel;
|
||||
} hexagram_cluster_state;
|
||||
#include <hexagram/cluster.h>
|
||||
|
||||
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));
|
||||
|
|
21
include/hexagram/cluster.h
Normal file
21
include/hexagram/cluster.h
Normal file
|
@ -0,0 +1,21 @@
|
|||
#ifndef _HEXAGRAM_CLUSTER_H
|
||||
#define _HEXAGRAM_CLUSTER_H
|
||||
|
||||
#include <cairo.h>
|
||||
|
||||
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 */
|
|
@ -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
|
||||
|
|
76
src/cluster.c
Normal file
76
src/cluster.c
Normal file
|
@ -0,0 +1,76 @@
|
|||
#include <hexagram/tacho.h>
|
||||
#include <hexagram/speedo.h>
|
||||
#include <hexagram/thermo.h>
|
||||
#include <hexagram/fuel.h>
|
||||
#include <hexagram/mfd.h>
|
||||
#include <hexagram/cluster.h>
|
||||
|
||||
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);
|
||||
}
|
Loading…
Add table
Reference in a new issue