2019-06-09 15:46:41 -05:00
|
|
|
#include <stdlib.h>
|
2019-06-09 16:05:06 -05:00
|
|
|
#include <string.h>
|
2019-06-09 15:46:41 -05:00
|
|
|
|
2019-06-09 14:03:56 -05:00
|
|
|
#include <hexagram/cluster.h>
|
|
|
|
|
2019-06-09 17:26:57 -05:00
|
|
|
void hexagram_cluster_resize(hexagram_cluster *cluster,
|
|
|
|
double width,
|
|
|
|
double height) {
|
2019-06-09 17:05:18 -05:00
|
|
|
/*
|
|
|
|
* Ensure correct cluster aspect ratio
|
|
|
|
*/
|
|
|
|
if (width / height > 32.0 / 15.0) {
|
|
|
|
width = height * (32.0 / 15.0);
|
|
|
|
} else {
|
|
|
|
height = width * (15.0 / 32.0);
|
|
|
|
}
|
|
|
|
|
2019-06-09 15:46:41 -05:00
|
|
|
hexagram_tacho_init(&cluster->tacho,
|
|
|
|
width * 0.2,
|
|
|
|
height * 0.5,
|
|
|
|
height * 0.4,
|
|
|
|
6500.0);
|
|
|
|
|
|
|
|
hexagram_speedo_init(&cluster->speedo,
|
|
|
|
width * 0.8,
|
|
|
|
height * 0.5,
|
|
|
|
height * 0.4);
|
|
|
|
|
|
|
|
hexagram_thermo_init(&cluster->thermo,
|
|
|
|
width * 0.43,
|
|
|
|
height * 0.76,
|
|
|
|
height * 0.13,
|
2019-06-28 18:10:01 -05:00
|
|
|
230.0);
|
2019-06-09 15:46:41 -05:00
|
|
|
|
|
|
|
hexagram_fuel_init(&cluster->fuel,
|
|
|
|
width * 0.57,
|
|
|
|
height * 0.76,
|
|
|
|
height * 0.13,
|
2019-06-28 18:10:01 -05:00
|
|
|
0.14);
|
2019-06-09 15:46:41 -05:00
|
|
|
|
|
|
|
hexagram_mfd_init(&cluster->mfd,
|
|
|
|
width * 0.42,
|
|
|
|
height * 0.10,
|
|
|
|
width * 0.16,
|
|
|
|
height * 0.50);
|
|
|
|
|
|
|
|
cluster->width = width;
|
|
|
|
cluster->height = height;
|
2019-06-09 17:26:57 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void hexagram_cluster_init(hexagram_cluster *cluster,
|
|
|
|
double width,
|
|
|
|
double height) {
|
|
|
|
hexagram_cluster_resize(cluster, width, height);
|
2019-06-09 15:46:41 -05:00
|
|
|
|
2019-06-09 16:05:06 -05:00
|
|
|
memset(&cluster->state, '\0', sizeof(cluster->state));
|
2019-06-09 17:26:57 -05:00
|
|
|
}
|
|
|
|
|
2019-06-13 16:55:51 -05:00
|
|
|
hexagram_cluster *hexagram_cluster_new(double width,
|
|
|
|
double height) {
|
2019-06-09 17:26:57 -05:00
|
|
|
hexagram_cluster *cluster;
|
|
|
|
|
|
|
|
if ((cluster = malloc(sizeof(*cluster))) == NULL) {
|
|
|
|
goto error_malloc_cluster;
|
|
|
|
}
|
|
|
|
|
|
|
|
hexagram_cluster_init(cluster, width, height);
|
2019-06-09 16:05:06 -05:00
|
|
|
|
2019-06-09 15:46:41 -05:00
|
|
|
return cluster;
|
|
|
|
|
|
|
|
error_malloc_cluster:
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2019-06-13 16:54:55 -05:00
|
|
|
int hexagram_cluster_update(hexagram_cluster *cluster,
|
|
|
|
struct can_frame *frame) {
|
|
|
|
switch (frame->can_id) {
|
|
|
|
case 0x280: {
|
|
|
|
cluster->state.rpm = 0.25 *
|
|
|
|
(double)(frame->data[2] | (frame->data[3] << 8));
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2019-06-13 23:43:17 -05:00
|
|
|
case 0x288: {
|
2019-06-13 23:53:47 -05:00
|
|
|
cluster->state.temp = 0.75 * (double)(frame->data[1] - 48);
|
2019-06-13 16:54:55 -05:00
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2019-06-13 23:43:17 -05:00
|
|
|
case 0x320: {
|
2019-06-14 01:33:21 -05:00
|
|
|
cluster->state.fuel = (double)(frame->data[2] & 0xf) / 15.0;
|
2019-06-13 16:54:55 -05:00
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
case 0x5a0: {
|
|
|
|
cluster->state.rps = 0.001 * (double)(frame->data[1]
|
|
|
|
| (frame->data[2] << 8));
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-06-09 15:46:41 -05:00
|
|
|
void hexagram_cluster_draw_bg(hexagram_cluster *cluster,
|
|
|
|
cairo_t *cr) {
|
2019-06-09 14:03:56 -05:00
|
|
|
/*
|
|
|
|
* Paint canvas black
|
|
|
|
*/
|
|
|
|
cairo_set_source_rgb(cr, 0, 0, 0);
|
|
|
|
cairo_paint(cr);
|
|
|
|
|
2019-06-09 15:46:41 -05:00
|
|
|
hexagram_tacho_draw_face(&cluster->tacho, cr);
|
|
|
|
hexagram_speedo_draw_face(&cluster->speedo, cr);
|
|
|
|
hexagram_thermo_draw_face(&cluster->thermo, cr);
|
|
|
|
hexagram_fuel_draw_face(&cluster->fuel, cr);
|
|
|
|
hexagram_mfd_draw(&cluster->mfd, cr);
|
2019-06-09 14:03:56 -05:00
|
|
|
}
|
|
|
|
|
2019-06-09 15:46:41 -05:00
|
|
|
void hexagram_cluster_draw_fg(hexagram_cluster *cluster,
|
2019-06-09 16:05:06 -05:00
|
|
|
cairo_t *cr) {
|
2019-06-09 16:26:40 -05:00
|
|
|
hexagram_tacho_draw_needle(&cluster->tacho, cr,
|
|
|
|
cluster->state.rpm);
|
2019-06-09 15:46:41 -05:00
|
|
|
|
|
|
|
hexagram_speedo_draw_needle(&cluster->speedo, cr,
|
2019-06-14 01:11:08 -05:00
|
|
|
cluster->state.rps);
|
2019-06-09 14:03:56 -05:00
|
|
|
|
2019-06-09 15:46:41 -05:00
|
|
|
hexagram_thermo_draw_needle(&cluster->thermo, cr,
|
2019-06-09 16:05:06 -05:00
|
|
|
cluster->state.temp);
|
2019-06-09 14:03:56 -05:00
|
|
|
|
2019-06-09 15:46:41 -05:00
|
|
|
hexagram_fuel_draw_needle(&cluster->fuel, cr,
|
2019-06-09 16:05:06 -05:00
|
|
|
cluster->state.fuel);
|
2019-06-09 14:03:56 -05:00
|
|
|
}
|