diff --git a/bin/dash2can.c b/bin/dash2can.c index 6d85991..0b71dd5 100644 --- a/bin/dash2can.c +++ b/bin/dash2can.c @@ -43,11 +43,14 @@ static int ev_handler(struct can_frame *frame, void *ctx) { return hexagram_can_if_write(can_if, frame); } -static hexagram_schedule_slot table[4] = { +#define SCHEDULE_SLOT_COUNT 5 + +static hexagram_schedule_slot table[SCHEDULE_SLOT_COUNT] = { { 16670, { .can_id = 0x280, .can_dlc = 8 }, ev_handler }, { 16670, { .can_id = 0x288, .can_dlc = 8 }, ev_handler }, { 16670, { .can_id = 0x320, .can_dlc = 8 }, ev_handler }, - { 16670, { .can_id = 0x5a0, .can_dlc = 8 }, ev_handler } + { 16670, { .can_id = 0x540, .can_dlc = 8 }, ev_handler }, + { 16670, { .can_id = 0x5a0, .can_dlc = 8 }, ev_handler }, }; static void table_update(hexagram_schedule_slot *table, @@ -62,13 +65,17 @@ static void table_update(hexagram_schedule_slot *table, table[0].frame.data[3] = (engine_rpm & 0xff00) >> 8; table[0].frame.data[2] = engine_rpm & 0x00ff; + /* Current gear */ + printf("Current gear: %x\n", packet->race.gear); + table[3].frame.data[7] = 0xc | (packet->race.gear + 2) << 4; + /* Vehicle speed */ - table[3].frame.data[1] = (speed_rps & 0xff00) >> 8; - table[3].frame.data[2] = speed_rps & 0x00ff; + table[4].frame.data[1] = (speed_rps & 0xff00) >> 8; + table[4].frame.data[2] = speed_rps & 0x00ff; } int hexagram_main_dash2can(int argc, char **argv) { - size_t i, count = 4; + size_t i; int sock; struct sockaddr_in sockaddr; @@ -102,7 +109,7 @@ int hexagram_main_dash2can(int argc, char **argv) { goto error_can_if_open; } - for (i=0; i (ssize_t)sizeof(packet)) { continue; } diff --git a/py/hexagram/app.pyx b/py/hexagram/app.pyx index bc9c3c6..702bd12 100755 --- a/py/hexagram/app.pyx +++ b/py/hexagram/app.pyx @@ -11,6 +11,7 @@ from hexagram.can cimport * from hexagram.window cimport * from hexagram.cluster import Cluster +from hexagram.trans import Gear CLUSTER_RPM_MIN = 1200 CLUSTER_RPM_REDLINE = 6500 @@ -36,6 +37,14 @@ cdef handle_xevents(hexagram_window *window, cluster.draw_fg(fg) hexagram_window_swap_buffer(window) +GEAR_VALUES = { + 0: Gear.P, + 1: Gear.R, + 2: Gear.N, + 3: Gear.D, + 4: Gear.S +} + cdef cluster_update(cluster: Cluster, fg: cairo.Context, hexagram_window *window, @@ -49,6 +58,13 @@ cdef cluster_update(cluster: Cluster, cluster.thermo.value = 0.75 * float(frame.data[1] - 48) elif frame.can_id == 0x320: cluster.fuel.value = frame.data[2] & 0xf + elif frame.can_id == 0x540: + value = ((frame.data[7] & 0xf0) >> 4) - 2 + + if (frame.data[7] & 0xc) == 0xc: + cluster.tacho.gear = Gear(value) + else: + cluster.tacho.gear = GEAR_VALUES[value] elif frame.can_id == 0x5a0: rps = 0.001 * float(frame.data[1] | (frame.data[2] << 8)) kph = (2.00152 * rps * 3600) / 1000.0 diff --git a/py/hexagram/trans.py b/py/hexagram/trans.py index cf67476..81754d2 100644 --- a/py/hexagram/trans.py +++ b/py/hexagram/trans.py @@ -1,6 +1,9 @@ import enum class Gear(enum.Enum): + S = -4 + D = -3 + P = -2 R = -1 N = 0 GEAR_1 = 1 @@ -15,8 +18,9 @@ class Gear(enum.Enum): GEAR_10 = 10 __strings__ = { - -1: 'R', 0: 'N', 1: '1', 2: '2', 3: '3', 4: '4', - 5: '5', 6: '6', 7: '7', 8: '8', 9: '9', 10: '10' + -2: 'P', -1: 'R', 0: 'N', + 1: '1', 2: '2', 3: '3', 4: '4', 5: '5', + 6: '6', 7: '7', 8: '8', 9: '9', 10: '10' } def __str__(self):