Update ATtiny firmware to trigger GPIO 23 power button on screen open/close, send multiple close serial commands, and update documentation
This commit is contained in:
@@ -142,6 +142,7 @@ bool is_car_on = false;
|
||||
|
||||
// RTI Screen variables
|
||||
bool screen_open = true; // Screen should open at startup
|
||||
uint8_t rti_close_bytes_left = 0;
|
||||
unsigned long last_rti_send_time = 0;
|
||||
uint8_t rti_byte_index = 0;
|
||||
|
||||
@@ -157,6 +158,7 @@ unsigned long power_button_start_time = 0;
|
||||
|
||||
void trigger_power_button() {
|
||||
if (!power_button_active) {
|
||||
digitalWrite(LED_PIN, HIGH); // Turn debug LED ON
|
||||
pinMode(RPI_POWER_PIN, OUTPUT);
|
||||
digitalWrite(RPI_POWER_PIN, LOW);
|
||||
power_button_active = true;
|
||||
@@ -167,10 +169,24 @@ void trigger_power_button() {
|
||||
void update_power_button() {
|
||||
if (power_button_active && (millis() - power_button_start_time >= 150)) {
|
||||
pinMode(RPI_POWER_PIN, INPUT);
|
||||
digitalWrite(LED_PIN, LOW); // Turn debug LED OFF
|
||||
power_button_active = false;
|
||||
}
|
||||
}
|
||||
|
||||
void set_screen_state(bool open) {
|
||||
if (screen_open != open) {
|
||||
screen_open = open;
|
||||
rti_byte_index = 0; // Reset byte index to send new sequence immediately
|
||||
if (!screen_open) {
|
||||
rti_close_bytes_left = 30; // Send the OFF packet (3 bytes) 10 times
|
||||
trigger_power_button();
|
||||
} else {
|
||||
trigger_power_button();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void process_button_state(uint8_t active_button) {
|
||||
unsigned long now = millis();
|
||||
|
||||
@@ -183,8 +199,7 @@ void process_button_state(uint8_t active_button) {
|
||||
button_triggered = true;
|
||||
|
||||
if (current_button == 8) {
|
||||
screen_open = !screen_open;
|
||||
rti_byte_index = 0; // Reset byte index to send new sequence immediately
|
||||
set_screen_state(!screen_open);
|
||||
} else if (current_button == 9) {
|
||||
trigger_power_button();
|
||||
}
|
||||
@@ -305,7 +320,7 @@ void loop() {
|
||||
last_lin_activity_time = millis();
|
||||
if (!is_car_on) {
|
||||
is_car_on = true;
|
||||
screen_open = true; // Automatically open screen when car turns back on
|
||||
set_screen_state(true); // Automatically open screen when car turns back on
|
||||
}
|
||||
b = LINBusSerial.read();
|
||||
n = frame.num_bytes();
|
||||
@@ -332,7 +347,7 @@ void loop() {
|
||||
// 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;
|
||||
screen_open = false; // Close screen when car is off
|
||||
set_screen_state(false); // Close screen when car is off
|
||||
for (int i = 0; i < 3; i++) {
|
||||
send_ir_for_button(7, i & 1);
|
||||
delay(100);
|
||||
@@ -354,8 +369,20 @@ void loop() {
|
||||
rti_write_byte(byte_to_send);
|
||||
rti_byte_index = (rti_byte_index + 1) % 3;
|
||||
} else {
|
||||
// Stay completely silent on serial when screen is closed to let it retract/close
|
||||
rti_byte_index = 0;
|
||||
if (rti_close_bytes_left > 0) {
|
||||
uint8_t byte_to_send = 0;
|
||||
// OFF sequence: 0x4F (OFF), 0x20 (standard brightness), 0x83 (execute)
|
||||
if (rti_byte_index == 0) byte_to_send = 0x4F;
|
||||
else if (rti_byte_index == 1) byte_to_send = 0x20;
|
||||
else byte_to_send = 0x83;
|
||||
|
||||
rti_write_byte(byte_to_send);
|
||||
rti_byte_index = (rti_byte_index + 1) % 3;
|
||||
rti_close_bytes_left--;
|
||||
} else {
|
||||
// Stay completely silent on serial when screen is closed to let it retract/close
|
||||
rti_byte_index = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user