7
7
#include < Update.h>
8
8
#include < Wire.h>
9
9
#ifdef DISPLAY_ENABLED
10
- #define SCREEN_WIDTH 128
10
+ #define SCREEN_WIDTH 128
11
11
#define SCREEN_HEIGHT 64
12
- #define OLED_RESET -1
12
+ #define OLED_RESET -1
13
13
#include < Adafruit_GFX.h>
14
14
#include < Adafruit_SSD1306.h>
15
15
Adafruit_SSD1306 display (SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
16
16
#include < Adafruit_NeoPixel.h>
17
17
Adafruit_NeoPixel rgb_led_1 = Adafruit_NeoPixel(1 , 1 , NEO_GRB + NEO_KHZ800);
18
18
19
-
20
19
#endif
21
20
#include " esp_partition.h"
22
21
#include " esp_ota_ops.h"
@@ -25,7 +24,6 @@ Adafruit_NeoPixel rgb_led_1 = Adafruit_NeoPixel(1, 1, NEO_GRB + NEO_KHZ800);
25
24
String ssid;
26
25
uint8_t mac[6 ];
27
26
28
-
29
27
// Create an instance of the server
30
28
WebServer server (80 );
31
29
bool displayEnabled;
@@ -36,48 +34,35 @@ volatile bool doublePressDetected = false; // Flag für Doppeldruck
36
34
const unsigned long doublePressInterval = 500 ; // Max. Zeit (in ms) zwischen zwei Drücken für Doppeldruck
37
35
volatile int pressCount = 0 ; // Zählt die Button-Drucke
38
36
39
- const unsigned char epd_bitmap_wifi [] PROGMEM = {
40
- 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
41
- 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x1f , 0x80 , 0x00 , 0x00 , 0x00 , 0x01 ,
42
- 0xff , 0xf0 , 0x00 , 0x00 , 0x00 , 0x07 , 0xff , 0xfc , 0x00 , 0x00 , 0x00 , 0x1f , 0xe0 , 0xff , 0x00 , 0x00 ,
43
- 0x00 , 0x3f , 0x00 , 0x0f , 0x80 , 0x00 , 0x00 , 0x7c , 0x00 , 0x03 , 0xe0 , 0x00 , 0x00 , 0xf0 , 0x00 , 0x01 ,
44
- 0xf0 , 0x00 , 0x01 , 0xe0 , 0x00 , 0x00 , 0x78 , 0x00 , 0x03 , 0xc0 , 0x00 , 0x00 , 0x38 , 0x00 , 0x07 , 0x80 ,
45
- 0x00 , 0x00 , 0x1c , 0x00 , 0x0f , 0x00 , 0x06 , 0x00 , 0x0e , 0x00 , 0x0e , 0x00 , 0x7f , 0xe0 , 0x0e , 0x00 ,
46
- 0x0c , 0x01 , 0xff , 0xf0 , 0x06 , 0x00 , 0x00 , 0x07 , 0xff , 0xfc , 0x02 , 0x00 , 0x00 , 0x0f , 0x80 , 0x3e ,
47
- 0x00 , 0x00 , 0x00 , 0x1f , 0x00 , 0x0f , 0x00 , 0x00 , 0x00 , 0x1c , 0x00 , 0x07 , 0x80 , 0x00 , 0x00 , 0x38 ,
48
- 0x00 , 0x03 , 0xc0 , 0x00 , 0x00 , 0x70 , 0x00 , 0x01 , 0xc0 , 0x00 , 0x00 , 0x70 , 0x00 , 0x00 , 0xc0 , 0x00 ,
49
- 0x00 , 0x20 , 0x00 , 0x00 , 0x40 , 0x00 , 0x00 , 0x00 , 0x1f , 0x80 , 0x00 , 0x00 , 0x00 , 0x00 , 0x7f , 0xc0 ,
50
- 0x00 , 0x00 , 0x00 , 0x00 , 0xff , 0xe0 , 0x00 , 0x00 , 0x00 , 0x01 , 0xe0 , 0xf0 , 0x00 , 0x00 , 0x00 , 0x01 ,
51
- 0xc0 , 0x78 , 0x00 , 0x00 , 0x00 , 0x03 , 0x80 , 0x38 , 0x00 , 0x00 , 0x00 , 0x01 , 0x00 , 0x10 , 0x00 , 0x00 ,
52
- 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
53
- 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
54
- 0x06 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x06 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x04 , 0x00 , 0x00 , 0x00 ,
55
- 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
56
- 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00
37
+ const unsigned char epd_bitmap_wifi[] PROGMEM = {
38
+ 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
39
+ 0x00 , 0x00 , 0x1f , 0x80 , 0x00 , 0x00 , 0x00 , 0x01 , 0xff , 0xf0 , 0x00 , 0x00 , 0x00 , 0x07 , 0xff , 0xfc , 0x00 , 0x00 , 0x00 , 0x1f , 0xe0 , 0xff , 0x00 , 0x00 ,
40
+ 0x00 , 0x3f , 0x00 , 0x0f , 0x80 , 0x00 , 0x00 , 0x7c , 0x00 , 0x03 , 0xe0 , 0x00 , 0x00 , 0xf0 , 0x00 , 0x01 , 0xf0 , 0x00 , 0x01 , 0xe0 , 0x00 , 0x00 , 0x78 , 0x00 ,
41
+ 0x03 , 0xc0 , 0x00 , 0x00 , 0x38 , 0x00 , 0x07 , 0x80 , 0x00 , 0x00 , 0x1c , 0x00 , 0x0f , 0x00 , 0x06 , 0x00 , 0x0e , 0x00 , 0x0e , 0x00 , 0x7f , 0xe0 , 0x0e , 0x00 ,
42
+ 0x0c , 0x01 , 0xff , 0xf0 , 0x06 , 0x00 , 0x00 , 0x07 , 0xff , 0xfc , 0x02 , 0x00 , 0x00 , 0x0f , 0x80 , 0x3e , 0x00 , 0x00 , 0x00 , 0x1f , 0x00 , 0x0f , 0x00 , 0x00 ,
43
+ 0x00 , 0x1c , 0x00 , 0x07 , 0x80 , 0x00 , 0x00 , 0x38 , 0x00 , 0x03 , 0xc0 , 0x00 , 0x00 , 0x70 , 0x00 , 0x01 , 0xc0 , 0x00 , 0x00 , 0x70 , 0x00 , 0x00 , 0xc0 , 0x00 ,
44
+ 0x00 , 0x20 , 0x00 , 0x00 , 0x40 , 0x00 , 0x00 , 0x00 , 0x1f , 0x80 , 0x00 , 0x00 , 0x00 , 0x00 , 0x7f , 0xc0 , 0x00 , 0x00 , 0x00 , 0x00 , 0xff , 0xe0 , 0x00 , 0x00 ,
45
+ 0x00 , 0x01 , 0xe0 , 0xf0 , 0x00 , 0x00 , 0x00 , 0x01 , 0xc0 , 0x78 , 0x00 , 0x00 , 0x00 , 0x03 , 0x80 , 0x38 , 0x00 , 0x00 , 0x00 , 0x01 , 0x00 , 0x10 , 0x00 , 0x00 ,
46
+ 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
47
+ 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x06 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x06 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x04 , 0x00 , 0x00 , 0x00 ,
48
+ 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00
57
49
};
58
50
59
51
// 'checkmark', 44x44px
60
- const unsigned char epd_bitmap_checkmark [] PROGMEM = {
61
- 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
62
- 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
63
- 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
64
- 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
65
- 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x01 , 0x80 , 0x00 , 0x00 , 0x00 ,
66
- 0x00 , 0x03 , 0x80 , 0x00 , 0x00 , 0x00 , 0x00 , 0x07 , 0x80 , 0x00 , 0x00 , 0x00 , 0x00 , 0x0f , 0x00 , 0x00 ,
67
- 0x00 , 0x00 , 0x00 , 0x1e , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x3c , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x78 ,
68
- 0x00 , 0x00 , 0x00 , 0x0e , 0x00 , 0xf0 , 0x00 , 0x00 , 0x00 , 0x0f , 0x01 , 0xe0 , 0x00 , 0x00 , 0x00 , 0x0f ,
69
- 0x83 , 0xc0 , 0x00 , 0x00 , 0x00 , 0x07 , 0xc7 , 0x80 , 0x00 , 0x00 , 0x00 , 0x03 , 0xef , 0x00 , 0x00 , 0x00 ,
70
- 0x00 , 0x01 , 0xfe , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0xfc , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x78 , 0x00 ,
71
- 0x00 , 0x00 , 0x00 , 0x00 , 0x10 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
72
- 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
73
- 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
74
- 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
75
- 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
76
- 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
77
- 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00
52
+ const unsigned char epd_bitmap_checkmark[] PROGMEM = {
53
+ 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
54
+ 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
55
+ 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
56
+ 0x00 , 0x00 , 0x00 , 0x01 , 0x80 , 0x00 , 0x00 , 0x00 , 0x00 , 0x03 , 0x80 , 0x00 , 0x00 , 0x00 , 0x00 , 0x07 , 0x80 , 0x00 , 0x00 , 0x00 , 0x00 , 0x0f , 0x00 , 0x00 ,
57
+ 0x00 , 0x00 , 0x00 , 0x1e , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x3c , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x78 , 0x00 , 0x00 , 0x00 , 0x0e , 0x00 , 0xf0 , 0x00 , 0x00 ,
58
+ 0x00 , 0x0f , 0x01 , 0xe0 , 0x00 , 0x00 , 0x00 , 0x0f , 0x83 , 0xc0 , 0x00 , 0x00 , 0x00 , 0x07 , 0xc7 , 0x80 , 0x00 , 0x00 , 0x00 , 0x03 , 0xef , 0x00 , 0x00 , 0x00 ,
59
+ 0x00 , 0x01 , 0xfe , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0xfc , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x78 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x10 , 0x00 , 0x00 , 0x00 ,
60
+ 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
61
+ 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
62
+ 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
63
+ 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00
78
64
};
79
65
80
-
81
66
void IRAM_ATTR handleButtonPress () {
82
67
unsigned long currentTime = millis (); // Hole aktuelle Zeit
83
68
@@ -96,8 +81,7 @@ void IRAM_ATTR handleButtonPress() {
96
81
97
82
// Funktion zum Wechseln der Boot-Partition auf OTA1
98
83
void setBootPartitionToOTA0 () {
99
- const esp_partition_t * ota0_partition = esp_partition_find_first (
100
- ESP_PARTITION_TYPE_APP, ESP_PARTITION_SUBTYPE_APP_OTA_0, NULL );
84
+ const esp_partition_t *ota0_partition = esp_partition_find_first (ESP_PARTITION_TYPE_APP, ESP_PARTITION_SUBTYPE_APP_OTA_0, NULL );
101
85
102
86
if (ota0_partition) {
103
87
// Setze OTA1 als neue Boot-Partition
@@ -127,20 +111,19 @@ void displayStatusBar(int progress) {
127
111
display.setCursor (22 , 22 );
128
112
display.println (" hochgeladen!" );
129
113
130
- display.fillRect (0 , SCREEN_HEIGHT - 24 , SCREEN_WIDTH- 4 , 8 , BLACK); // Clear status bar area
131
- display.drawRect (0 , SCREEN_HEIGHT - 24 , SCREEN_WIDTH- 4 , 8 , WHITE); // Draw border
132
- int filledWidth = (progress * SCREEN_WIDTH- 4 ) / 100 ; // Calculate progress width
133
- display.fillRect (1 , SCREEN_HEIGHT - 23 , filledWidth- 4 , 6 , WHITE); // Fill progress bar
114
+ display.fillRect (0 , SCREEN_HEIGHT - 24 , SCREEN_WIDTH - 4 , 8 , BLACK); // Clear status bar area
115
+ display.drawRect (0 , SCREEN_HEIGHT - 24 , SCREEN_WIDTH - 4 , 8 , WHITE); // Draw border
116
+ int filledWidth = (progress * SCREEN_WIDTH - 4 ) / 100 ; // Calculate progress width
117
+ display.fillRect (1 , SCREEN_HEIGHT - 23 , filledWidth - 4 , 6 , WHITE); // Fill progress bar
134
118
135
- display.setCursor ((SCREEN_WIDTH/ 2 )- 12 , SCREEN_HEIGHT - 10 );
119
+ display.setCursor ((SCREEN_WIDTH / 2 ) - 12 , SCREEN_HEIGHT - 10 );
136
120
display.setTextSize (1 );
137
121
display.setTextColor (WHITE, BLACK);
138
122
display.print (progress);
139
123
display.println (" %" );
140
124
display.display ();
141
125
}
142
126
143
-
144
127
void displayWelcomeScreen () {
145
128
display.clearDisplay ();
146
129
@@ -157,7 +140,7 @@ void displayWelcomeScreen() {
157
140
158
141
// Display SSID
159
142
display.setCursor (40 , 43 );
160
- display.setTextSize (1 ); // Larger text for SSID
143
+ display.setTextSize (1 ); // Larger text for SSID
161
144
display.print (ssid);
162
145
163
146
display.display ();
@@ -180,15 +163,12 @@ void displaySuccessScreen() {
180
163
display.display ();
181
164
}
182
165
183
- void wipeDisplay (){
184
- display.clearDisplay ();
185
- display.println (" " );
186
- display.display ();
166
+ void wipeDisplay () {
167
+ display.clearDisplay ();
168
+ display.println (" " );
169
+ display.display ();
187
170
}
188
171
189
-
190
-
191
-
192
172
void setupWiFi () {
193
173
WiFi.macAddress (mac);
194
174
char macLastFour[5 ];
@@ -210,18 +190,19 @@ void setupWiFi() {
210
190
void setupOTA () {
211
191
// Handle updating process
212
192
server.on (
213
- " /sketch" , HTTP_POST, []() {
193
+ " /sketch" , HTTP_POST,
194
+ []() {
214
195
server.sendHeader (" Connection" , " close" );
215
196
server.send (200 , " text/plain" , (Update.hasError ()) ? " FAIL" : " OK" );
216
197
ESP.restart ();
217
198
},
218
199
[]() {
219
- HTTPUpload& upload = server.upload ();
200
+ HTTPUpload & upload = server.upload ();
220
201
221
202
if (upload.status == UPLOAD_FILE_START) {
222
203
Serial.setDebugOutput (true );
223
204
size_t fsize = UPDATE_SIZE_UNKNOWN;
224
- if (server.clientContentLength () > 0 ){
205
+ if (server.clientContentLength () > 0 ) {
225
206
fsize = server.clientContentLength ();
226
207
}
227
208
Serial.printf (" Receiving Update: %s, Size: %d\n " , upload.filename .c_str (), fsize);
@@ -236,7 +217,7 @@ void setupOTA() {
236
217
Update.printError (Serial);
237
218
} else {
238
219
int progress = (Update.progress () * 100 ) / Update.size ();
239
- displayStatusBar (progress); // Update progress on status bar
220
+ displayStatusBar (progress); // Update progress on status bar
240
221
}
241
222
} else if (upload.status == UPLOAD_FILE_END) {
242
223
if (Update.end (true )) { // true to set the size to the current progress
@@ -249,7 +230,8 @@ void setupOTA() {
249
230
Serial.setDebugOutput (false );
250
231
}
251
232
yield ();
252
- });
233
+ }
234
+ );
253
235
}
254
236
255
237
void setup () {
@@ -287,14 +269,14 @@ void loop() {
287
269
Serial.println (" Doppeldruck erkannt!" );
288
270
setBootPartitionToOTA0 ();
289
271
#ifdef DISPLAY_ENABLED
290
- display.setCursor (0 ,0 );
272
+ display.setCursor (0 , 0 );
291
273
display.setTextSize (1 );
292
- display.setTextColor (WHITE,BLACK);
274
+ display.setTextColor (WHITE, BLACK);
293
275
display.println (" " );
294
276
display.display ();
295
277
delay (50 );
296
278
#endif
297
279
// Neustart, um von der neuen Partition zu booten
298
280
esp_restart ();
299
281
}
300
- }
282
+ }
0 commit comments