Skip to content

Commit 9057681

Browse files
committed
feat(board): use additional button for APOTA
1 parent baa84cf commit 9057681

File tree

1 file changed

+17
-33
lines changed

1 file changed

+17
-33
lines changed

variants/sensebox_eye/variant.cpp

Lines changed: 17 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -72,45 +72,29 @@ void initVariant(void) {
7272
.loop_count = 0
7373
};
7474

75-
uint8_t pixel[3] = { 0x10, 0x00, 0x00 }; // green
76-
blinkLED(pixel, led_chan, ws2812_encoder, tx_config);
77-
7875
// define button pin
79-
pinMode(0, INPUT_PULLUP);
80-
81-
// keep button pressed
82-
unsigned long pressStartTime = 0;
83-
bool buttonPressed = false;
84-
85-
// Wait 3.5 seconds for the button to be pressed
86-
unsigned long startTime = millis();
76+
pinMode(47, INPUT_PULLUP);
8777

8878
// Check if button is pressed
89-
while (millis() - startTime < 3500) {
90-
if (digitalRead(0) == LOW) {
91-
if (!buttonPressed) {
92-
// The button was pressed
93-
buttonPressed = true;
94-
}
95-
} else if (buttonPressed) {
96-
// When the button is pressed and then released, boot into the OTA1 partition
97-
const esp_partition_t *ota1_partition = esp_partition_find_first(ESP_PARTITION_TYPE_APP, ESP_PARTITION_SUBTYPE_APP_OTA_1, NULL);
79+
if (digitalRead(47) == LOW) {
80+
// When the button is pressed and then released, boot into the OTA1 partition
81+
const esp_partition_t *ota1_partition = esp_partition_find_first(ESP_PARTITION_TYPE_APP, ESP_PARTITION_SUBTYPE_APP_OTA_1, NULL);
9882

99-
if (ota1_partition) {
100-
esp_err_t err = esp_ota_set_boot_partition(ota1_partition);
101-
if (err == ESP_OK) {
102-
uint8_t pixel[3] = { 0x00, 0x00, 0x10 }; // blue
103-
blinkLED(pixel, led_chan, ws2812_encoder, tx_config);
104-
esp_restart(); // restart, to boot OTA1 partition
105-
} else {
106-
uint8_t pixel[3] = { 0x00, 0x10, 0x00 }; // red
107-
blinkLED(pixel, led_chan, ws2812_encoder, tx_config);
108-
ESP_LOGE("OTA", "Error setting OTA1 partition: %s", esp_err_to_name(err));
109-
}
83+
if (ota1_partition) {
84+
esp_err_t err = esp_ota_set_boot_partition(ota1_partition);
85+
if (err == ESP_OK) {
86+
uint8_t pixel[3] = { 0x00, 0x00, 0x10 }; // blue
87+
blinkLED(pixel, led_chan, ws2812_encoder, tx_config);
88+
esp_restart(); // restart, to boot OTA1 partition
89+
} else {
90+
uint8_t pixel[3] = { 0x00, 0x10, 0x00 }; // red
91+
blinkLED(pixel, led_chan, ws2812_encoder, tx_config);
92+
ESP_LOGE("OTA", "Error setting OTA1 partition: %s", esp_err_to_name(err));
11093
}
111-
// Abort after releasing the button
112-
break;
11394
}
95+
} else {
96+
uint8_t pixel[3] = { 0x10, 0x00, 0x00 }; // green
97+
blinkLED(pixel, led_chan, ws2812_encoder, tx_config);
11498
}
11599
}
116100
}

0 commit comments

Comments
 (0)