From 6b63549de2ad9bf9bb86b69d904bf5a8f5630dd1 Mon Sep 17 00:00:00 2001 From: XANTRONIX Development Date: Tue, 9 Jan 2024 22:23:57 -0500 Subject: [PATCH] Ensure correct Forza<>CAN gear encoding/decoding --- bin/dash2can.c | 6 +++++- py/hexagram/app.pyx | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/bin/dash2can.c b/bin/dash2can.c index 2060d15..23e42f6 100644 --- a/bin/dash2can.c +++ b/bin/dash2can.c @@ -66,7 +66,11 @@ static void table_update(hexagram_schedule_slot *table, table[0].frame.data[2] = engine_rpm & 0x00ff; /* Current gear */ - table[3].frame.data[7] = 0xc | (packet->race.gear + 2) << 4; + if (packet->race.gear == 0) { + table[3].frame.data[7] = 0x30; /* Reverse gear */ + } else { + table[3].frame.data[7] = 0xc | (packet->race.gear + 2) << 4; + } /* Vehicle speed */ table[4].frame.data[1] = (speed_rps & 0xff00) >> 8; diff --git a/py/hexagram/app.pyx b/py/hexagram/app.pyx index 702bd12..b35197f 100755 --- a/py/hexagram/app.pyx +++ b/py/hexagram/app.pyx @@ -64,7 +64,7 @@ cdef cluster_update(cluster: Cluster, if (frame.data[7] & 0xc) == 0xc: cluster.tacho.gear = Gear(value) else: - cluster.tacho.gear = GEAR_VALUES[value] + cluster.tacho.gear = GEAR_VALUES.get(value, Gear.D) elif frame.can_id == 0x5a0: rps = 0.001 * float(frame.data[1] | (frame.data[2] << 8)) kph = (2.00152 * rps * 3600) / 1000.0