From 7d669b4a91fb6ed18f7065fa304c2d2bc0ac3bb5 Mon Sep 17 00:00:00 2001 From: lurenaud Date: Mon, 25 May 2026 17:49:30 +0200 Subject: [PATCH] Update ATtiny84 firmware to use Volume Up for shutdown, configure KeyMapper, and document automatic boot hotspot --- Arduino/LIN_to_IR/LIN_to_IR.cpp | 4 +-- Arduino/LIN_to_IR/README.md | 64 ++++++++++++++++++++++++--------- Kicad/PCB_AndroidAuto.kicad_pro | 14 +++++--- 3 files changed, 58 insertions(+), 24 deletions(-) diff --git a/Arduino/LIN_to_IR/LIN_to_IR.cpp b/Arduino/LIN_to_IR/LIN_to_IR.cpp index b3fd158..1cba575 100644 --- a/Arduino/LIN_to_IR/LIN_to_IR.cpp +++ b/Arduino/LIN_to_IR/LIN_to_IR.cpp @@ -85,7 +85,7 @@ uint32_t get_mce_code(uint8_t button) { case 4: return 0x800f0421; // RIGHT case 5: return 0x800f0422; // ENTER / OK case 6: return 0x800f0423; // BACK - case 7: return 0x800f046f; // F12 (Shutdown) + case 7: return 0x800f0410; // Volume Up (Shutdown) default: return 0; } } @@ -210,7 +210,7 @@ void loop() { current_button = 0; } - // Car off detection: if no LIN activity for 5 seconds, send F12 to trigger shutdown + // Car off detection: if no LIN activity for 5 seconds, send Volume Up to trigger shutdown if (is_car_on && (millis() - last_lin_activity_time > 5000)) { is_car_on = false; for (int i = 0; i < 3; i++) { diff --git a/Arduino/LIN_to_IR/README.md b/Arduino/LIN_to_IR/README.md index 904403a..5ddd525 100644 --- a/Arduino/LIN_to_IR/README.md +++ b/Arduino/LIN_to_IR/README.md @@ -27,7 +27,7 @@ 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) | +| **Volume Up (Shutdown)** | LIN Silent > 5s | `7` | `0x800f0410` | Trigger Shutdown (via KeyMapper) | *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`.* @@ -36,35 +36,65 @@ The Steering Wheel Module (SWM) sends frames on LIN ID `0x20` with the navigatio 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. +3. **Shutdown Signal**: It transitions the car status to "off" and sends the MCE code `0x800f0410` (mapped to `KEY_VOLUMEUP`) 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: +Remap the MCE remote codes 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: +### 2. KeyMapper Setup +Instead of MacroDroid, **KeyMapper** is used to intercept the `KEY_VOLUMEUP` trigger from the direct-wired IR receiver and execute the shutdown command. -- **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 - ``` +To configure KeyMapper completely via command-line: +- **Enable Accessibility Service**: + ```bash + adb shell settings put secure accessibility_enabled 1 + adb shell settings put secure enabled_accessibility_services io.github.sds100.keymapper/.system.accessibility.MyAccessibilityService + ``` +- **Grant Do Not Disturb Access** (to prevent warnings on volume key mapping): + ```bash + adb shell settings put secure enabled_notification_policy_access_packages io.github.sds100.keymapper + ``` +- **Map Trigger and Action**: + The preconfigured KeyMapper SQLite database is pushed directly to the device. The Volume Up key is mapped to run the command: + ```bash + reboot -p + ``` -- **Macro 2: Shutdown on F12** - - **Trigger**: *Media / Key Pressed* -> Select **F12** - - **Action**: *Run Shell Command* (Check **Run as Root**) - ```bash - reboot -p - ``` +### 3. Wi-Fi Hotspot Auto-start Setup +To enable the Wi-Fi hotspot (`VolvoC70_AndroidAuto` with passphrase `123456789`) automatically at startup: +- A boot shell script `/system/bin/start_hotspot.sh` is defined to wait for boot completion and start the SoftAP. +- A custom Android init service configuration `/system/etc/init/start_hotspot.rc` starts it when `sys.boot_completed` transitions to `1`. + +**Script (`/system/bin/start_hotspot.sh`):** +```sh +#!/system/bin/sh +while [ "$(getprop sys.boot_completed)" != "1" ]; do + sleep 1 +done +sleep 5 +cmd wifi start-softap VolvoC70_AndroidAuto wpa2 123456789 +``` + +**Init Service (`/system/etc/init/start_hotspot.rc`):** +```rc +service start_hotspot /system/bin/sh /system/bin/start_hotspot.sh + class main + user root + group root system wifi + oneshot + disabled + +on property:sys.boot_completed=1 + start start_hotspot +``` ## Protocol and Timing diff --git a/Kicad/PCB_AndroidAuto.kicad_pro b/Kicad/PCB_AndroidAuto.kicad_pro index 461d08a..4d2dc55 100644 --- a/Kicad/PCB_AndroidAuto.kicad_pro +++ b/Kicad/PCB_AndroidAuto.kicad_pro @@ -514,7 +514,6 @@ "priority": 2147483647, "schematic_color": "rgba(0, 0, 0, 0.000)", "track_width": 0.2, - "tuning_profile": "", "via_diameter": 0.6, "via_drill": 0.3, "wire_width": 6 @@ -533,7 +532,6 @@ "priority": 0, "schematic_color": "rgba(0, 0, 0, 0.000)", "track_width": 1.37, - "tuning_profile": "", "via_diameter": 0.6, "via_drill": 0.3, "wire_width": 6 @@ -552,7 +550,6 @@ "priority": 1, "schematic_color": "rgba(0, 0, 0, 0.000)", "track_width": 0.5, - "tuning_profile": "", "via_diameter": 0.8, "via_drill": 0.4, "wire_width": 6 @@ -571,14 +568,13 @@ "priority": 2, "schematic_color": "rgba(0, 0, 0, 0.000)", "track_width": 0.15, - "tuning_profile": "", "via_diameter": 0.5, "via_drill": 0.4, "wire_width": 6 } ], "meta": { - "version": 5 + "version": 4 }, "net_colors": null, "netclass_assignments": null, @@ -599,8 +595,10 @@ "idf": "", "netlist": "", "plot": "", + "pos_files": "", "specctra_dsn": "", "step": "3D/PCB_AndroidAuto.stp", + "svg": "", "vrml": "" }, "page_layout_descr_file": "" @@ -724,8 +722,14 @@ "page_layout_descr_file": "", "plot_directory": "", "reuse_designators": true, + "space_save_all_events": true, "spice_adjust_passive_values": false, + "spice_current_sheet_as_root": false, "spice_external_command": "spice \"%I\"", + "spice_model_current_sheet_as_root": true, + "spice_save_all_currents": false, + "spice_save_all_dissipations": false, + "spice_save_all_voltages": false, "subpart_first_id": 65, "subpart_id_separator": 0, "top_level_sheets": [