diff --git a/firmware/config/engines/honda.cpp b/firmware/config/engines/honda.cpp index de0dca1280..0082a6e365 100644 --- a/firmware/config/engines/honda.cpp +++ b/firmware/config/engines/honda.cpp @@ -28,6 +28,9 @@ ppsSensor : setTimeout(timeout) speedSensor = Sensor.new("VehicleSpeed") speedSensor : setTimeout(timeout) +canTimer = Timer.new() +canTimer : reset() + hexstr = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, "A", "B", "C", "D", "E", "F" } function getTwoBytesMSB(data, offset, factor) @@ -39,6 +42,9 @@ function getTwoBytesLSB(data, offset, factor) end function onPOWERTRAIN_DATA(bus, id, dlc, data) + canTimer : reset() +-- print('onPOWERTRAIN_DATA ' ..arrayToString(data)) + ppsValue = data[1] * 100.0 / 255 ppsSensor : set(ppsValue) @@ -48,6 +54,7 @@ function onPOWERTRAIN_DATA(bus, id, dlc, data) end function onCAR_SPEED(bus, id, dlc, data) + canTimer : reset() speedKph = getTwoBytesLSB(data, 1, 0.01) print('onCAR_SPEED ' .. speedKph) speedSensor : set(speedKph) @@ -58,6 +65,12 @@ end canRxAdd(1, 0x17C, onPOWERTRAIN_DATA) canRxAdd(1, 0x309, onCAR_SPEED) + +function onTick() + if canTimer : getElapsedSeconds() > 20 then + mcu_standby() + end +end )", efi::size(config->luaScript)); #endif // HW_SMALL_CAN_BOARD } diff --git a/firmware/controllers/lua/examples/honda-bcm.txt b/firmware/controllers/lua/examples/honda-bcm.txt index 4fee34413a..7aa71d7b56 100644 --- a/firmware/controllers/lua/examples/honda-bcm.txt +++ b/firmware/controllers/lua/examples/honda-bcm.txt @@ -12,6 +12,9 @@ ppsSensor : setTimeout(timeout) speedSensor = Sensor.new("VehicleSpeed") speedSensor : setTimeout(timeout) +canTimer = Timer.new() +canTimer : reset() + hexstr = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, "A", "B", "C", "D", "E", "F" } function toHexString(num) @@ -47,6 +50,7 @@ function getTwoBytesLSB(data, offset, factor) end function onPOWERTRAIN_DATA(bus, id, dlc, data) + canTimer : reset() -- print('onPOWERTRAIN_DATA ' ..arrayToString(data)) ppsValue = data[1] * 100.0 / 255 @@ -58,6 +62,7 @@ function onPOWERTRAIN_DATA(bus, id, dlc, data) end function onCAR_SPEED(bus, id, dlc, data) + canTimer : reset() speedKph = getTwoBytesLSB(data, 1, 0.01) print('onCAR_SPEED ' .. speedKph) speedSensor : set(speedKph) @@ -67,4 +72,10 @@ function onCAR_SPEED(bus, id, dlc, data) end canRxAdd(1, 0x17C, onPOWERTRAIN_DATA) -canRxAdd(1, 0x309, onCAR_SPEED) \ No newline at end of file +canRxAdd(1, 0x309, onCAR_SPEED) + +function onTick() + if canTimer : getElapsedSeconds() > 20 then + mcu_standby() + end +end