Add car-off shutdown detection to LIN_to_IR firmware
This commit is contained in:
@@ -85,6 +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)
|
||||
default: return 0;
|
||||
}
|
||||
}
|
||||
@@ -105,6 +106,8 @@ unsigned long last_frame_time = 0;
|
||||
uint8_t current_button = 0;
|
||||
uint8_t toggle_bit = 0;
|
||||
unsigned long last_ir_send_time = 0;
|
||||
unsigned long last_lin_activity_time = 0;
|
||||
bool is_car_on = false;
|
||||
|
||||
void process_button_state(uint8_t active_button) {
|
||||
unsigned long now = millis();
|
||||
@@ -179,10 +182,15 @@ void setup() {
|
||||
LINBusSerial.begin(9600);
|
||||
frame = LinFrame();
|
||||
last_frame_time = millis();
|
||||
last_lin_activity_time = millis();
|
||||
}
|
||||
|
||||
void loop() {
|
||||
if (LINBusSerial.available()) {
|
||||
last_lin_activity_time = millis();
|
||||
if (!is_car_on) {
|
||||
is_car_on = true;
|
||||
}
|
||||
b = LINBusSerial.read();
|
||||
n = frame.num_bytes();
|
||||
|
||||
@@ -201,4 +209,13 @@ void loop() {
|
||||
if (millis() - last_frame_time > 200) {
|
||||
current_button = 0;
|
||||
}
|
||||
|
||||
// Car off detection: if no LIN activity for 5 seconds, send F12 to trigger shutdown
|
||||
if (is_car_on && (millis() - last_lin_activity_time > 5000)) {
|
||||
is_car_on = false;
|
||||
for (int i = 0; i < 3; i++) {
|
||||
send_ir_for_button(7, i & 1);
|
||||
delay(100);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user