|
1 |
| -/* |
2 |
| - * The MIT License (MIT) |
3 |
| - * |
4 |
| - * Copyright (c) 2021 Ha Thach (tinyusb.org) for Adafruit Industries |
5 |
| - * |
6 |
| - * Permission is hereby granted, free of charge, to any person obtaining a copy |
7 |
| - * of this software and associated documentation files (the "Software"), to deal |
8 |
| - * in the Software without restriction, including without limitation the rights |
9 |
| - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
10 |
| - * copies of the Software, and to permit persons to whom the Software is |
11 |
| - * furnished to do so, subject to the following conditions: |
12 |
| - * |
13 |
| - * The above copyright notice and this permission notice shall be included in |
14 |
| - * all copies or substantial portions of the Software. |
15 |
| - * |
16 |
| - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
17 |
| - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
18 |
| - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
19 |
| - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
20 |
| - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
21 |
| - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
22 |
| - * THE SOFTWARE. |
23 |
| - */ |
24 |
| - |
25 | 1 | #include "esp32-hal-gpio.h"
|
26 | 2 | #include "pins_arduino.h"
|
| 3 | +#include "esp_partition.h" |
| 4 | +#include "esp_system.h" |
| 5 | +#include "esp_ota_ops.h" |
| 6 | +#include "esp_log.h" |
| 7 | + |
| 8 | +// Globale Variable zur Kommunikation mit dem Hauptprogramm |
| 9 | +bool buttonWasPressed = false; |
27 | 10 |
|
28 | 11 | extern "C" {
|
29 | 12 |
|
30 | 13 | // Initialize variant/board, called before setup()
|
31 | 14 | void initVariant(void) {
|
32 |
| - //enable IO Pins by default |
33 |
| - pinMode(IO_ENABLE, OUTPUT); |
34 |
| - digitalWrite(IO_ENABLE, LOW); |
| 15 | + // Initialisiere Pins wie vorher |
| 16 | + pinMode(IO_ENABLE, OUTPUT); |
| 17 | + digitalWrite(IO_ENABLE, LOW); |
| 18 | + |
| 19 | + pinMode(PIN_NEOPIXEL, OUTPUT); |
| 20 | + digitalWrite(PIN_NEOPIXEL, LOW); |
| 21 | + |
| 22 | + pinMode(PIN_XB1_ENABLE, OUTPUT); |
| 23 | + digitalWrite(PIN_XB1_ENABLE, LOW); |
| 24 | + |
| 25 | + pinMode(PIN_UART_ENABLE, OUTPUT); |
| 26 | + digitalWrite(PIN_UART_ENABLE, LOW); |
35 | 27 |
|
36 |
| - //reset RGB |
37 |
| - pinMode(PIN_RGB_LED, OUTPUT); |
38 |
| - digitalWrite(PIN_RGB_LED, LOW); |
| 28 | + pinMode(PD_ENABLE, OUTPUT); |
| 29 | + digitalWrite(PD_ENABLE, HIGH); |
39 | 30 |
|
40 |
| - //enable XBEE by default |
41 |
| - pinMode(PIN_XB1_ENABLE, OUTPUT); |
42 |
| - digitalWrite(PIN_XB1_ENABLE, LOW); |
| 31 | + // Neuen Button-Pin definieren (z.B. GPIO 0 als Beispiel) |
| 32 | + const int PIN_BUTTON = 0; |
| 33 | + pinMode(PIN_BUTTON, INPUT_PULLUP); |
43 | 34 |
|
44 |
| - //enable UART by default |
45 |
| - pinMode(PIN_UART_ENABLE, OUTPUT); |
46 |
| - digitalWrite(PIN_UART_ENABLE, LOW); |
| 35 | + // Button gedrückt halten |
| 36 | + unsigned long pressStartTime = 0; |
| 37 | + bool buttonPressed = false; |
47 | 38 |
|
48 |
| - //enable PD-Sensor by default |
49 |
| - pinMode(PD_ENABLE, OUTPUT); |
50 |
| - digitalWrite(PD_ENABLE, HIGH); |
| 39 | + // Warten auf Button-Eingabe für 5 Sekunden |
| 40 | + unsigned long startTime = millis(); |
| 41 | + |
| 42 | + // Überprüfen, ob der Button gedrückt wird |
| 43 | + while (millis() - startTime < 5000) { |
| 44 | + if (digitalRead(PIN_BUTTON) == LOW) { |
| 45 | + if (!buttonPressed) { |
| 46 | + // Der Button wurde gerade gedrückt |
| 47 | + buttonPressed = true; |
| 48 | + } |
| 49 | + } else if (buttonPressed) { |
| 50 | + // Wenn der Button gedrückt und dann losgelassen wird, in OTA1-Partition booten |
| 51 | + const esp_partition_t* ota1_partition = esp_partition_find_first( |
| 52 | + ESP_PARTITION_TYPE_APP, ESP_PARTITION_SUBTYPE_APP_OTA_1, NULL); |
| 53 | + |
| 54 | + if (ota1_partition) { |
| 55 | + esp_err_t err = esp_ota_set_boot_partition(ota1_partition); |
| 56 | + if (err == ESP_OK) { |
| 57 | + esp_restart(); // Neustarten, um die OTA1-Partition zu booten |
| 58 | + } else { |
| 59 | + // Fehler beim Setzen der Boot-Partition |
| 60 | + ESP_LOGE("OTA", "Fehler beim Setzen der OTA1-Partition: %s", esp_err_to_name(err)); |
| 61 | + } |
| 62 | + } |
| 63 | + // Nach dem Loslassen des Buttons abbrechen |
| 64 | + break; |
| 65 | + } |
| 66 | + } |
51 | 67 | }
|
| 68 | + |
52 | 69 | }
|
0 commit comments