(Easter Egg!)
This commit is contained in:
parent
969bde5116
commit
0be93447f5
2 changed files with 40 additions and 14 deletions
|
@ -1,5 +1,6 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdarg.h>
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
|
||||
|
@ -9,7 +10,7 @@
|
|||
#include <hexagram/window.h>
|
||||
|
||||
typedef struct _hexagram_cluster_state {
|
||||
double rpm, rps, temp, level;
|
||||
double rpm, rps, temp, fuel;
|
||||
} hexagram_cluster_state;
|
||||
|
||||
static hexagram_cluster_state state = {
|
||||
|
@ -328,7 +329,7 @@ static void cluster_update(struct can_frame *frame) {
|
|||
}
|
||||
|
||||
case 0x320: {
|
||||
state.level = (double)(frame->data[2]);
|
||||
state.fuel = (double)(frame->data[2] & 0xf) / 16.0;
|
||||
|
||||
break;
|
||||
}
|
||||
|
@ -368,7 +369,22 @@ static void cluster_draw(cairo_t *cr,
|
|||
width * 0.57,
|
||||
height * 0.76,
|
||||
height * 0.11,
|
||||
0.5);
|
||||
state.fuel);
|
||||
}
|
||||
|
||||
static int usage(int argc, char **argv, const char *message, ...) {
|
||||
if (message) {
|
||||
va_list args;
|
||||
|
||||
va_start(args, message);
|
||||
vfprintf(stderr, message, args);
|
||||
fprintf(stderr, "\n");
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
fprintf(stderr, "usage: %s canif\n", argv[0]);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
|
@ -389,11 +405,17 @@ int main(int argc, char **argv) {
|
|||
|
||||
cairo_t *fg, *bg;
|
||||
|
||||
if ((can_if = hexagram_can_if_open("vcan0")) == NULL)
|
||||
exit(1);
|
||||
if (argc != 2) {
|
||||
return usage(argc, argv, "No CAN interface specified");
|
||||
}
|
||||
|
||||
if ((window = hexagram_window_new_x11(NULL, width, height)) == NULL)
|
||||
exit(1);
|
||||
if ((can_if = hexagram_can_if_open(argv[1])) == NULL) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
if ((window = hexagram_window_new_x11(NULL, width, height)) == NULL) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
display = hexagram_window_display(window);
|
||||
|
||||
|
|
|
@ -15,6 +15,7 @@ static int usage(int argc, char **argv, const char *message, ...) {
|
|||
|
||||
va_start(args, message);
|
||||
vfprintf(stderr, message, args);
|
||||
fprintf(stderr, "\n");
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
|
@ -57,17 +58,17 @@ int main(int argc, char **argv) {
|
|||
|
||||
wprintw(win, "%6.1lf RPM", rpm);
|
||||
} else if (frame.can_id == 0x540) {
|
||||
wmove(win, 6, 0);
|
||||
wmove(win, 7, 0);
|
||||
|
||||
if ((frame.data[7] & 0xc) == 0xc) {
|
||||
uint8_t gear = ((frame.data[7] & 0xf0) >> 4) - 2;
|
||||
|
||||
wprintw(win, "1 2 3 4 5 6");
|
||||
|
||||
wmove(win, 7, 0);
|
||||
wmove(win, 8, 0);
|
||||
wprintw(win, " ");
|
||||
|
||||
wmove(win, 7, gear * 2);
|
||||
wmove(win, 8, gear * 2);
|
||||
|
||||
wprintw(win, "_");
|
||||
} else {
|
||||
|
@ -75,10 +76,10 @@ int main(int argc, char **argv) {
|
|||
|
||||
wprintw(win, "P R N D S ");
|
||||
|
||||
wmove(win, 7, 0);
|
||||
wmove(win, 8, 0);
|
||||
wprintw(win, " ");
|
||||
|
||||
wmove(win, 7, pos * 2);
|
||||
wmove(win, 8, pos * 2);
|
||||
|
||||
wprintw(win, "_");
|
||||
}
|
||||
|
@ -104,8 +105,11 @@ int main(int argc, char **argv) {
|
|||
wmove(win, 3, 0);
|
||||
|
||||
wprintw(win, "%6.1lf °C ambient", temp);
|
||||
} else if (frame.can_id == 0x4a0) {
|
||||
} else if (frame.can_id == 0x320) {
|
||||
double fuel = (double)(frame.data[2] & 0xf) / 16.0;
|
||||
|
||||
wmove(win, 5, 0);
|
||||
wprintw(win, "%5.0lf%% Fuel", fuel * 100.0);
|
||||
}
|
||||
|
||||
if (((now.tv_sec * 1000000) + now.tv_usec) - ((last.tv_sec * 1000000) + last.tv_usec) > 100000) {
|
||||
|
|
Loading…
Add table
Reference in a new issue