Skip to content

Commit beca852

Browse files
committed
refactor: update clock performance, fix weather and updaet platformio config
1 parent 92b2402 commit beca852

File tree

10 files changed

+224
-91
lines changed

10 files changed

+224
-91
lines changed

include/plugins/BigClockPlugin.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ class BigClockPlugin : public Plugin
99

1010
int previousMinutes;
1111
int previousHour;
12+
std::vector<int> previousHH;
13+
std::vector<int> previousMM;
14+
bool previousLeadingZero;
1215

1316
public:
1417
void setup() override;

include/plugins/ClockPlugin.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ class ClockPlugin : public Plugin
99

1010
int previousMinutes;
1111
int previousHour;
12+
std::vector<int> previousHH;
13+
std::vector<int> previousMM;
1214

1315
public:
1416
void setup() override;

include/plugins/PongClockPlugin.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ class PongClockPlugin : public Plugin
2828
int previousMinutes, previousHour, ballAngle = 0, fadeLength = 0, current_minute = 0,
2929
current_hour = 0;
3030

31+
std::vector<int> previousDigits;
32+
3133
void drawCharacter(int x, int y, std::vector<int> bits, int bitCount, uint8_t brightness = 255);
3234
byte getScreenIndex(byte x, byte y);
3335
void swapXdirection();

include/plugins/TickingClockPlugin.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ class TickingClockPlugin : public Plugin
1010
int previousMinutes;
1111
int previousHour;
1212
int previousSecond;
13+
std::vector<int> previousHH;
14+
std::vector<int> previousMM;
1315

1416
public:
1517
void setup() override;

platformio.ini

Lines changed: 16 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,13 @@
11
; PlatformIO Project Configuration File
22
;
3-
; Build options: build flags, source filter
4-
; Upload options: custom upload port, speed and extra flags
5-
; Library options: dependencies, extra library storages
6-
; Advanced options: extra scripting
7-
;
83
; Please visit documentation for the other options and examples
94
; https://docs.platformio.org/page/projectconf.html
105

116
[platformio]
127
default_envs = esp32dev
13-
lib_compat_mode = strict
148

159
[env]
10+
lib_compat_mode = strict
1611
framework = arduino
1712
lib_deps =
1813
esp32async/ESPAsyncWebServer @ ^3.7.10
@@ -26,19 +21,22 @@ build_flags =
2621
-DELEGANTOTA_USE_ASYNC_WEBSERVER=1
2722
-fexceptions
2823

29-
[env:esp32c3]
24+
; Base configuration for all ESP32 boards
25+
[env:esp32-base]
3026
lib_deps =
3127
${env.lib_deps}
3228
esp32async/AsyncTCP @ ^3.4.9
3329
lib_ignore = RPAsyncTCP
3430
build_flags =
3531
${env.build_flags}
3632
-I$PROJECT_PACKAGES_DIR/framework-arduinoespressif32/libraries/Network/src
37-
# platform = espressif32
3833
platform = https://github.com/pioarduino/platform-espressif32/releases/download/stable/platform-espressif32.zip
39-
board = esp32-c3-devkitm-1
4034
board_build.partitions = partitions-4MB.csv
4135
monitor_filters = esp32_exception_decoder
36+
37+
[env:esp32c3]
38+
extends = env:esp32-base
39+
board = esp32-c3-devkitm-1
4240
;build_flags =
4341
; ${env.build_flags}
4442
; -DARDUINO_USB_CDC_ON_BOOT=1
@@ -51,45 +49,25 @@ monitor_filters = esp32_exception_decoder
5149
; custom_password = ikea-led-wall
5250

5351
[env:ESP32-wemos]
54-
lib_deps =
55-
${env.lib_deps}
56-
esp32async/AsyncTCP @ ^3.4.9
57-
lib_ignore = RPAsyncTCP
58-
build_flags =
59-
${env.build_flags}
60-
-I$PROJECT_PACKAGES_DIR/framework-arduinoespressif32/libraries/Network/src
61-
# platform = espressif32
62-
platform = https://github.com/pioarduino/platform-espressif32/releases/download/stable/platform-espressif32.zip
52+
extends = env:esp32-base
6353
board = wemos_d1_mini32
64-
board_build.partitions = partitions-4MB.csv
65-
monitor_filters = esp32_exception_decoder
6654
; extra_scripts = upload.py
6755
; upload_protocol = custom
6856
; custom_upload_url = http://192.168.178.50
6957
; custom_username = admin
7058
; custom_password = ikea-led-wall
7159

7260
[env:esp32dev]
73-
lib_deps =
74-
${env.lib_deps}
75-
esp32async/AsyncTCP @ ^3.4.9
76-
lib_ignore = RPAsyncTCP
77-
build_flags =
78-
${env.build_flags}
79-
-I$PROJECT_PACKAGES_DIR/framework-arduinoespressif32/libraries/Network/src
80-
# platform = espressif32
81-
platform = https://github.com/pioarduino/platform-espressif32/releases/download/stable/platform-espressif32.zip
61+
extends = env:esp32-base
8262
board = esp32dev
83-
board_build.partitions = partitions-4MB.csv
84-
monitor_filters = esp32_exception_decoder
8563
; extra_scripts = upload.py
8664
; upload_protocol = custom
8765
; custom_upload_url = http://192.168.178.50
8866
; custom_username = admin
8967
; custom_password = ikea-led-wall
9068

91-
[env:nodemcuv2]
92-
board = nodemcuv2
69+
; Base configuration for all ESP8266 boards
70+
[env:esp8266-base]
9371
platform = espressif8266
9472
lib_deps =
9573
${env.lib_deps}
@@ -99,13 +77,10 @@ monitor_filters = esp8266_exception_decoder
9977
build_unflags = -fno-exceptions
10078
board_build.f_cpu = 80000000L
10179

80+
[env:nodemcuv2]
81+
extends = env:esp8266-base
82+
board = nodemcuv2
83+
10284
[env:d1_mini_pro-ota]
85+
extends = env:esp8266-base
10386
board = d1_mini_pro
104-
platform = espressif8266
105-
lib_deps =
106-
${env.lib_deps}
107-
vshymanskyy/Preferences @ ^2.1.0
108-
lib_ignore = RPAsyncTCP, AsyncTCP
109-
monitor_filters = esp8266_exception_decoder
110-
build_unflags = -fno-exceptions
111-
board_build.f_cpu = 80000000L

src/plugins/BigClockPlugin.cpp

Lines changed: 53 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ void BigClockPlugin::setup()
1212

1313
previousMinutes = -1;
1414
previousHour = -1;
15+
previousHH.clear();
16+
previousMM.clear();
17+
previousLeadingZero = false;
1518
}
1619

1720
void BigClockPlugin::loop()
@@ -23,21 +26,64 @@ void BigClockPlugin::loop()
2326
std::vector<int> hh = {(timeinfo.tm_hour - timeinfo.tm_hour % 10) / 10, timeinfo.tm_hour % 10};
2427
std::vector<int> mm = {(timeinfo.tm_min - timeinfo.tm_min % 10) / 10, timeinfo.tm_min % 10};
2528
bool leadingZero = (hh.at(0) == 0);
26-
Screen.clear();
27-
if (leadingZero)
29+
30+
bool layoutChanged = (previousHH.empty() || previousLeadingZero != leadingZero);
31+
32+
if (layoutChanged)
2833
{
29-
hh.erase(hh.begin());
30-
Screen.drawBigNumbers(COLS / 2, 0, hh);
31-
Screen.drawBigNumbers(0, ROWS / 2, mm);
34+
35+
Screen.clear();
36+
if (leadingZero)
37+
{
38+
hh.erase(hh.begin());
39+
Screen.drawBigNumbers(COLS / 2, 0, hh);
40+
Screen.drawBigNumbers(0, ROWS / 2, mm);
41+
}
42+
else
43+
{
44+
Screen.drawBigNumbers(0, 0, hh);
45+
Screen.drawBigNumbers(0, ROWS / 2, mm);
46+
}
3247
}
3348
else
3449
{
35-
Screen.drawBigNumbers(0, 0, hh);
36-
Screen.drawBigNumbers(0, ROWS / 2, mm);
50+
51+
std::vector<int> displayHH = hh;
52+
if (leadingZero)
53+
{
54+
displayHH.erase(displayHH.begin());
55+
}
56+
57+
if (displayHH != previousHH)
58+
{
59+
int startX = leadingZero ? COLS / 2 : 0;
60+
Screen.drawBigNumbers(startX, 0, displayHH);
61+
}
62+
63+
if (mm != previousMM)
64+
{
65+
Screen.drawBigNumbers(0, ROWS / 2, mm);
66+
}
67+
68+
previousHH = displayHH;
69+
previousMM = mm;
70+
}
71+
72+
if (layoutChanged)
73+
{
74+
75+
std::vector<int> displayHH = hh;
76+
if (leadingZero)
77+
{
78+
displayHH.erase(displayHH.begin());
79+
}
80+
previousHH = displayHH;
81+
previousMM = mm;
3782
}
3883

3984
previousMinutes = timeinfo.tm_min;
4085
previousHour = timeinfo.tm_hour;
86+
previousLeadingZero = leadingZero;
4187
}
4288
}
4389
}

src/plugins/ClockPlugin.cpp

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ void ClockPlugin::setup()
1212

1313
previousMinutes = -1;
1414
previousHour = -1;
15+
previousHH.clear();
16+
previousMM.clear();
1517
}
1618

1719
void ClockPlugin::loop()
@@ -20,15 +22,32 @@ void ClockPlugin::loop()
2022
{
2123
if (previousHour != timeinfo.tm_hour || previousMinutes != timeinfo.tm_min)
2224
{
23-
Screen.clear();
24-
Screen.drawNumbers(3,
25-
2,
26-
{(timeinfo.tm_hour - timeinfo.tm_hour % 10) / 10, timeinfo.tm_hour % 10});
27-
Screen.drawNumbers(3, 8, {(timeinfo.tm_min - timeinfo.tm_min % 10) / 10, timeinfo.tm_min % 10});
28-
}
25+
std::vector<int> hh = {(timeinfo.tm_hour - timeinfo.tm_hour % 10) / 10, timeinfo.tm_hour % 10};
26+
std::vector<int> mm = {(timeinfo.tm_min - timeinfo.tm_min % 10) / 10, timeinfo.tm_min % 10};
27+
28+
if (previousHH.empty())
29+
{
30+
Screen.clear();
31+
Screen.drawNumbers(3, 2, hh);
32+
Screen.drawNumbers(3, 8, mm);
33+
}
34+
else
35+
{
36+
if (hh != previousHH)
37+
{
38+
Screen.drawNumbers(3, 2, hh);
39+
}
40+
if (mm != previousMM)
41+
{
42+
Screen.drawNumbers(3, 8, mm);
43+
}
44+
}
2945

30-
previousMinutes = timeinfo.tm_min;
31-
previousHour = timeinfo.tm_hour;
46+
previousHH = hh;
47+
previousMM = mm;
48+
previousMinutes = timeinfo.tm_min;
49+
previousHour = timeinfo.tm_hour;
50+
}
3251
}
3352
}
3453

src/plugins/PongClockPlugin.cpp

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -50,18 +50,39 @@ int PongClockPlugin::realRandom(int min, int max)
5050

5151
void PongClockPlugin::drawDigits()
5252
{
53-
drawCharacter(0,
54-
0,
55-
Screen.readBytes(smallNumbers[(current_hour - current_hour % 10) / 10]),
56-
4,
57-
100);
58-
drawCharacter(4, 0, Screen.readBytes(smallNumbers[current_hour % 10]), 4, 100);
59-
drawCharacter(9,
60-
0,
61-
Screen.readBytes(smallNumbers[(current_minute - current_minute % 10) / 10]),
62-
4,
63-
100);
64-
drawCharacter(13, 0, Screen.readBytes(smallNumbers[current_minute % 10]), 4, 100);
53+
std::vector<int> currentDigits = {(current_hour - current_hour % 10) / 10,
54+
current_hour % 10,
55+
(current_minute - current_minute % 10) / 10,
56+
current_minute % 10};
57+
58+
if (previousDigits.empty())
59+
{
60+
drawCharacter(0, 0, Screen.readBytes(smallNumbers[currentDigits[0]]), 4, 100);
61+
drawCharacter(4, 0, Screen.readBytes(smallNumbers[currentDigits[1]]), 4, 100);
62+
drawCharacter(9, 0, Screen.readBytes(smallNumbers[currentDigits[2]]), 4, 100);
63+
drawCharacter(13, 0, Screen.readBytes(smallNumbers[currentDigits[3]]), 4, 100);
64+
}
65+
else
66+
{
67+
if (currentDigits[0] != previousDigits[0])
68+
{
69+
drawCharacter(0, 0, Screen.readBytes(smallNumbers[currentDigits[0]]), 4, 100);
70+
}
71+
if (currentDigits[1] != previousDigits[1])
72+
{
73+
drawCharacter(4, 0, Screen.readBytes(smallNumbers[currentDigits[1]]), 4, 100);
74+
}
75+
if (currentDigits[2] != previousDigits[2])
76+
{
77+
drawCharacter(9, 0, Screen.readBytes(smallNumbers[currentDigits[2]]), 4, 100);
78+
}
79+
if (currentDigits[3] != previousDigits[3])
80+
{
81+
drawCharacter(13, 0, Screen.readBytes(smallNumbers[currentDigits[3]]), 4, 100);
82+
}
83+
}
84+
85+
previousDigits = currentDigits;
6586
}
6687

6788
float PongClockPlugin::degToRad(float deg)
@@ -204,6 +225,7 @@ void PongClockPlugin::reset()
204225
pongPaddleRightTarget = constrain(pong_predict_y(ballX, ballY, ballAngle), X_MAX, 255 - X_MAX);
205226
ballBrightness = 255;
206227
ballBrightnessStep = -1;
228+
previousDigits.clear(); // Clear to force full redraw
207229
drawDigits();
208230
}
209231

0 commit comments

Comments
 (0)