Flatten code a little bit
This commit is contained in:
parent
654dfac3d1
commit
86c9e8cdc3
1 changed files with 23 additions and 24 deletions
|
@ -11,7 +11,12 @@
|
||||||
#include <hexagram/cluster.h>
|
#include <hexagram/cluster.h>
|
||||||
|
|
||||||
static void cluster_update(hexagram_cluster *cluster,
|
static void cluster_update(hexagram_cluster *cluster,
|
||||||
struct can_frame *frame) {
|
cairo_t *cr,
|
||||||
|
hexagram_window *window,
|
||||||
|
struct can_frame *frame,
|
||||||
|
struct timeval *last) {
|
||||||
|
struct timeval now;
|
||||||
|
|
||||||
switch (frame->can_id) {
|
switch (frame->can_id) {
|
||||||
case 0x280: {
|
case 0x280: {
|
||||||
cluster->state.rpm = 0.25 *
|
cluster->state.rpm = 0.25 *
|
||||||
|
@ -38,6 +43,20 @@ static void cluster_update(hexagram_cluster *cluster,
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
default: {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
gettimeofday(&now, NULL);
|
||||||
|
|
||||||
|
if (now.tv_sec - last->tv_sec || now.tv_usec - last->tv_usec > 16666) {
|
||||||
|
hexagram_window_refresh_bg(window);
|
||||||
|
hexagram_cluster_draw_fg(cluster, cr);
|
||||||
|
hexagram_window_swap_buffer(window);
|
||||||
|
|
||||||
|
memcpy(last, &now, sizeof(now));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -68,13 +87,13 @@ int main(int argc, char **argv) {
|
||||||
width = 1024,
|
width = 1024,
|
||||||
height = 480;
|
height = 480;
|
||||||
|
|
||||||
|
cairo_t *fg, *bg;
|
||||||
|
|
||||||
struct timeval last = {
|
struct timeval last = {
|
||||||
.tv_sec = 0,
|
.tv_sec = 0,
|
||||||
.tv_usec = 0
|
.tv_usec = 0
|
||||||
};
|
};
|
||||||
|
|
||||||
cairo_t *fg, *bg;
|
|
||||||
|
|
||||||
if (argc != 2) {
|
if (argc != 2) {
|
||||||
return usage(argc, argv, "No CAN interface specified");
|
return usage(argc, argv, "No CAN interface specified");
|
||||||
}
|
}
|
||||||
|
@ -158,27 +177,7 @@ int main(int argc, char **argv) {
|
||||||
|
|
||||||
hexagram_can_if_read(can_if, &frame);
|
hexagram_can_if_read(can_if, &frame);
|
||||||
|
|
||||||
switch (frame.can_id) {
|
cluster_update(cluster, fg, window, &frame, &last);
|
||||||
case 0x280:
|
|
||||||
case 0x288:
|
|
||||||
case 0x320:
|
|
||||||
case 0x5a0: {
|
|
||||||
struct timeval now;
|
|
||||||
|
|
||||||
cluster_update(cluster, &frame);
|
|
||||||
|
|
||||||
(void)gettimeofday(&now, NULL);
|
|
||||||
|
|
||||||
if (now.tv_sec - last.tv_sec
|
|
||||||
|| now.tv_usec - last.tv_usec > 16666) {
|
|
||||||
hexagram_window_refresh_bg(window);
|
|
||||||
hexagram_cluster_draw_fg(cluster, fg);
|
|
||||||
hexagram_window_swap_buffer(window);
|
|
||||||
|
|
||||||
(void)memcpy(&last, &now, sizeof(now));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue