From 6a795710626e42c8feed12c5adb3e9c20af06231 Mon Sep 17 00:00:00 2001 From: rusefi Date: Sat, 14 May 2022 20:18:51 -0400 Subject: [PATCH] some Lua fun --- .../controllers/lua/examples/bmw-idrive.txt | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 firmware/controllers/lua/examples/bmw-idrive.txt diff --git a/firmware/controllers/lua/examples/bmw-idrive.txt b/firmware/controllers/lua/examples/bmw-idrive.txt new file mode 100644 index 0000000000..2cb75da301 --- /dev/null +++ b/firmware/controllers/lua/examples/bmw-idrive.txt @@ -0,0 +1,42 @@ +-- https://rusefi.com/forum/viewtopic.php?f=4&t=2325 +-- tested on 9286699 + + +CAN_BUTTONS = 0x267 + +brighness = 0 + +canRxAdd(0x264) -- rotation, I did not get it to work +canRxAdd(CAN_BUTTONS) -- buttons + +setTickRate(5) -- set tick rate to 5hz + +function onCanRx(bus, id, dlc, data) + id = id % 2048 + -- print('got CAN id=' ..id ..' dlc=' ..dlc) + + if id == CAN_BUTTONS then + -- print('got buttons @4=' ..data[4] ..' @6=' ..data[6]) + + if data[4] == 1 or data[4] == 2 then + print('got hold or release @4=' ..data[4] ..' @6=' ..data[6]) + + if data[6] == 2 and brighness > 0 then + brighness = brighness - 1 + print('brighness ' ..brighness) + end + + if data[6] == 4 and brighness < 15 then + brighness = brighness + 1 + print('brighness ' ..brighness) + end + end + end +end + +function onTick() + -- wake up, need to send once every 1.5 second but we can send more often because why not + txCan(1, 0x563, 0, { 3 }) + txCan(1, 0x202, 0, { brighness * 16 + 0xd }) +end +