Add car-off shutdown detection to LIN_to_IR firmware

This commit is contained in:
2026-05-25 15:40:27 +02:00
parent 77ff8b973b
commit 8d101b3162
3 changed files with 65 additions and 0 deletions
+37
View File
@@ -27,9 +27,45 @@ The Steering Wheel Module (SWM) sends frames on LIN ID `0x20` with the navigatio
| **RIGHT** | `d0 & 0x08` | `4` | `0x800f0421` | Navigate Right |
| **ENTER** | `d1 & 0x08` | `5` | `0x800f0422` | Select / OK |
| **BACK** | `d1 & 0x01` | `6` | `0x800f0423` | Back / Exit |
| **F12 (Shutdown)** | LIN Silent > 5s | `7` | `0x800f046f` | Trigger Shutdown (via MacroDroid) |
*Note: In previous revisions, `ENTER` and `BACK` were reversed. This has been corrected so that pressing `ENTER` maps to `0x800f0422` and `BACK` maps to `0x800f0423`.*
## Car-Off (Shutdown) Detection
To automatically power off the Raspberry Pi when the car is turned off:
1. **Activity Monitor**: The ATtiny monitors LIN bus activity. The Central Electronic Module (CEM) continuously polls the LIN bus when the ignition is on.
2. **Timeout**: If no LIN serial data is received for 5 seconds, the ATtiny assumes the car is off.
3. **Shutdown Signal**: It transitions the car status to "off" and sends the MCE code `0x800f046f` (mapped to `KEY_F12`) 3 times to ensure transmission reliability.
4. **State Protection**: It will not send the shutdown command again until the car is turned back on and LIN traffic resumes (which sets `is_car_on` back to `true`).
## Raspberry Pi Configuration
### 1. Keymap Setup
Remap scancode `0x800f046f` to `KEY_F12` on the Raspberry Pi:
- The custom TOML configuration is saved at `/data/rc-rc6-mce.toml` on the Pi.
- To apply it dynamically:
```bash
/vendor/bin/ir-keytable -w /data/rc-rc6-mce.toml
```
### 2. MacroDroid Persistence & Trigger
Configure two macros in **MacroDroid** to manage keymap loading and shutdown:
- **Macro 1: Load Keymap on Boot**
- **Trigger**: *Device Boot*
- **Action**: *Run Shell Command* (Check **Run as Root**)
```bash
/vendor/bin/ir-keytable -w /data/rc-rc6-mce.toml
```
- **Macro 2: Shutdown on F12**
- **Trigger**: *Media / Key Pressed* -> Select **F12**
- **Action**: *Run Shell Command* (Check **Run as Root**)
```bash
reboot -p
```
## Protocol and Timing
- **Protocol**: RC-6 Mode 6A (MCE).
@@ -46,3 +82,4 @@ The Steering Wheel Module (SWM) sends frames on LIN ID `0x20` with the navigatio
Since SoftwareSerial RX interrupts consume about 1ms per byte, they will disrupt the precise microsecond-level timing of bit-banged IR frames. To avoid this, interrupts are disabled (`noInterrupts()`) during the 37ms window of IR transmission and re-enabled (`interrupts()`) immediately afterward.
2. **Release detection**:
The SWM continuously transmits frames on the LIN bus. If no button frames are detected or a frame with all 0s is received, the current active button resets to idle. A timeout of `200ms` ensures that if the LIN bus goes quiet, button repeats cease immediately.