77 lines
1.6 KiB
C
77 lines
1.6 KiB
C
|
#include <stdio.h>
|
||
|
#include <stdlib.h>
|
||
|
#include <string.h>
|
||
|
#include <stdarg.h>
|
||
|
#include <inttypes.h>
|
||
|
|
||
|
#include <ncurses.h>
|
||
|
|
||
|
#include <hexagram/can.h>
|
||
|
|
||
|
static int usage(int argc, char **argv, const char *message, ...) {
|
||
|
if (message) {
|
||
|
va_list args;
|
||
|
|
||
|
va_start(args, message);
|
||
|
vfprintf(stderr, message, args);
|
||
|
va_end(args);
|
||
|
}
|
||
|
|
||
|
fprintf(stderr, "usage: %s canif\n", argv[0]);
|
||
|
|
||
|
return 1;
|
||
|
}
|
||
|
|
||
|
int main(int argc, char **argv) {
|
||
|
WINDOW *win;
|
||
|
hexagram_can_if *can_if;
|
||
|
struct can_frame frame;
|
||
|
uint8_t last_gear = 0;
|
||
|
|
||
|
if (argc != 2) {
|
||
|
return usage(argc, argv, NULL);
|
||
|
}
|
||
|
|
||
|
if ((can_if = hexagram_can_if_open(argv[1])) == NULL) {
|
||
|
perror("hexagram_can_if_open()");
|
||
|
|
||
|
goto error_can_if_open;
|
||
|
}
|
||
|
|
||
|
initscr();
|
||
|
|
||
|
win = newwin(LINES, COLS, 0, 0);
|
||
|
|
||
|
while (hexagram_can_if_read(can_if, &frame) >= 0) {
|
||
|
char lever_states[16] = " PRNDS ";
|
||
|
char manual_gears[16] = " 123456 ";
|
||
|
|
||
|
if (frame.can_id == 0x280) {
|
||
|
|
||
|
} else if (frame.can_id == 0x540) {
|
||
|
if (frame.data[7] != last_gear) {
|
||
|
wmove(win, 0, 0);
|
||
|
|
||
|
if ((frame.data[7] & 0xc) == 0xc) {
|
||
|
wprintw(win, " %c\n",
|
||
|
manual_gears[(frame.data[7] & 0xf0) >> 4]);
|
||
|
} else {
|
||
|
wprintw(win, "%c \n",
|
||
|
lever_states[(frame.data[7] & 0xf0) >> 4]);
|
||
|
}
|
||
|
|
||
|
wrefresh(win);
|
||
|
|
||
|
last_gear = frame.data[7];
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
hexagram_can_if_close(can_if);
|
||
|
|
||
|
return 0;
|
||
|
|
||
|
error_can_if_open:
|
||
|
return 1;
|
||
|
}
|