feat(board): use additional button for APOTA

This commit is contained in:
Paula Scharf 2025-07-17 16:15:10 +02:00
parent cdf606af5f
commit 439bbb8391

View file

@ -72,45 +72,29 @@ void initVariant(void) {
.loop_count = 0 .loop_count = 0
}; };
uint8_t pixel[3] = { 0x10, 0x00, 0x00 }; // green
blinkLED(pixel, led_chan, ws2812_encoder, tx_config);
// define button pin // define button pin
pinMode(0, INPUT_PULLUP); pinMode(47, INPUT_PULLUP);
// keep button pressed
unsigned long pressStartTime = 0;
bool buttonPressed = false;
// Wait 3.5 seconds for the button to be pressed
unsigned long startTime = millis();
// Check if button is pressed // Check if button is pressed
while (millis() - startTime < 3500) { if (digitalRead(47) == LOW) {
if (digitalRead(0) == LOW) { // When the button is pressed and then released, boot into the OTA1 partition
if (!buttonPressed) { const esp_partition_t *ota1_partition = esp_partition_find_first(ESP_PARTITION_TYPE_APP, ESP_PARTITION_SUBTYPE_APP_OTA_1, NULL);
// The button was pressed
buttonPressed = true;
}
} else if (buttonPressed) {
// When the button is pressed and then released, boot into the OTA1 partition
const esp_partition_t *ota1_partition = esp_partition_find_first(ESP_PARTITION_TYPE_APP, ESP_PARTITION_SUBTYPE_APP_OTA_1, NULL);
if (ota1_partition) { if (ota1_partition) {
esp_err_t err = esp_ota_set_boot_partition(ota1_partition); esp_err_t err = esp_ota_set_boot_partition(ota1_partition);
if (err == ESP_OK) { if (err == ESP_OK) {
uint8_t pixel[3] = { 0x00, 0x00, 0x10 }; // blue uint8_t pixel[3] = { 0x00, 0x00, 0x10 }; // blue
blinkLED(pixel, led_chan, ws2812_encoder, tx_config); blinkLED(pixel, led_chan, ws2812_encoder, tx_config);
esp_restart(); // restart, to boot OTA1 partition esp_restart(); // restart, to boot OTA1 partition
} else { } else {
uint8_t pixel[3] = { 0x00, 0x10, 0x00 }; // red uint8_t pixel[3] = { 0x00, 0x10, 0x00 }; // red
blinkLED(pixel, led_chan, ws2812_encoder, tx_config); blinkLED(pixel, led_chan, ws2812_encoder, tx_config);
ESP_LOGE("OTA", "Error setting OTA1 partition: %s", esp_err_to_name(err)); ESP_LOGE("OTA", "Error setting OTA1 partition: %s", esp_err_to_name(err));
}
} }
// Abort after releasing the button
break;
} }
} else {
uint8_t pixel[3] = { 0x10, 0x00, 0x00 }; // green
blinkLED(pixel, led_chan, ws2812_encoder, tx_config);
} }
} }
} }