Skip to content

Commit ba67ca7

Browse files
committed
V0.81
- Adds 2 status pixels: Red pixel fades at 0,0 when AWTRIX losts the wifi connection. Yellow pixel fades at 0,7 when AWTRIX looses the MQTT connection. - Downgrade ArduinoESP32 framework back to 2.0.9. because 2.0.11 costs 30kb!!! of heap. see espressif/arduino-esp32#8482 - Fixes a bug where "repeat" doesnt work in customapps - Fixes a bug where mqtt /doupdate doesnt work
1 parent 0b5796a commit ba67ca7

9 files changed

+67
-57
lines changed

platformio.ini

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99
; https://docs.platformio.org/page/projectconf.html
1010

1111
[env:ulanzi]
12-
platform = https://github.com/platformio/platform-espressif32.git
12+
platform = espressif32
13+
platform_packages =
14+
framework-arduinoespressif32 @ https://github.com/espressif/arduino-esp32.git#2.0.9
1315
board = esp32dev
1416
upload_speed = 921600
1517
framework = arduino
@@ -27,7 +29,9 @@ lib_deps =
2729
knolleary/PubSubClient@^2.8
2830

2931
[env:awtrix2_upgrade]
30-
platform = https://github.com/platformio/platform-espressif32.git
32+
platform = espressif32
33+
platform_packages =
34+
framework-arduinoespressif32 @ https://github.com/espressif/arduino-esp32.git#2.0.9
3135
board = wemos_d1_mini32
3236
upload_speed = 921600
3337
board_build.f_cpu = 240000000L

src/Apps.h

Lines changed: 41 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
#include <ArduinoJson.h>
1818
#include "effects.h"
1919

20-
2120
tm timeInfo;
2221
uint16_t nativeAppsCount;
2322

@@ -336,6 +335,26 @@ void TempApp(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state, int16_t x,
336335
}
337336
}
338337

338+
uint16_t fadeColor(uint16_t color, uint32_t interval)
339+
{
340+
float phase = (sin(2 * PI * millis() / float(interval)) + 1) * 0.5;
341+
uint8_t r = ((color >> 11) & 0x1F) * phase;
342+
uint8_t g = ((color >> 5) & 0x3F) * phase;
343+
uint8_t b = (color & 0x1F) * phase;
344+
return (r << 11) | (g << 5) | b;
345+
}
346+
347+
void StatusOverlay(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state, GifPlayer *gifPlayer)
348+
{
349+
if (!WiFi.isConnected()){
350+
matrix->drawPixel(0,0,fadeColor(matrix->Color(255,0,0),2000));
351+
}
352+
if (!MQTTManager.isConnected()){
353+
matrix->drawPixel(0,7,fadeColor(matrix->Color(255,255,0),2000));
354+
}
355+
}
356+
357+
339358
void HumApp(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state, int16_t x, int16_t y, GifPlayer *gifPlayer)
340359
{
341360
if (notifyFlag)
@@ -377,7 +396,7 @@ void BatApp(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state, int16_t x, i
377396
}
378397
#endif
379398

380-
void MenuApp(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state, GifPlayer *gifPlayer)
399+
void MenuOverlay(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state, GifPlayer *gifPlayer)
381400
{
382401
if (!MenuManager.inMenu)
383402
return;
@@ -421,27 +440,27 @@ void ShowCustomApp(String name, FastLED_NeoMatrix *matrix, MatrixDisplayUiState
421440
CURRENT_APP = ca->name;
422441
currentCustomApp = name;
423442

424-
if (!ca->icon && ca->iconName.length() > 0)
425-
{
426-
const char* extensions[] = { ".jpg", ".gif" };
427-
bool isGifFlags[] = { false, true };
428-
429-
for (int i = 0; i < 2; i++)
443+
if (!ca->icon && ca->iconName.length() > 0)
430444
{
431-
String filePath = "/ICONS/" + ca->iconName + extensions[i];
432-
if (LittleFS.exists(filePath))
445+
const char *extensions[] = {".jpg", ".gif"};
446+
bool isGifFlags[] = {false, true};
447+
448+
for (int i = 0; i < 2; i++)
433449
{
434-
ca->isGif = isGifFlags[i];
435-
ca->icon = LittleFS.open(filePath);
436-
break; // Exit loop if icon was found
450+
String filePath = "/ICONS/" + ca->iconName + extensions[i];
451+
if (LittleFS.exists(filePath))
452+
{
453+
ca->isGif = isGifFlags[i];
454+
ca->icon = LittleFS.open(filePath);
455+
break; // Exit loop if icon was found
456+
}
437457
}
438458
}
439-
}
440459

441-
bool hasIcon = ca->icon;
460+
bool hasIcon = ca->icon;
442461

443462
// Calculate text and available width
444-
uint16_t textWidth = 0;
463+
uint16_t textWidth = 0;
445464
if (!ca->fragments.empty())
446465
{
447466
for (const auto &fragment : ca->fragments)
@@ -506,7 +525,7 @@ bool hasIcon = ca->icon;
506525
}
507526
else
508527
{
509-
if ((ca->repeat > 0) && (getTextWidth(ca->text.c_str(), ca->textCase) > availableWidth) && (state->appState == FIXED))
528+
if ((ca->repeat > 0) && (textWidth > availableWidth) && (state->appState == FIXED))
510529
{
511530
DisplayManager.setAutoTransition(false);
512531
}
@@ -536,6 +555,9 @@ bool hasIcon = ca->icon;
536555
else if (ca->repeat > 0)
537556
{
538557
++ca->currentRepeat;
558+
if ((ca->currentRepeat = ca->repeat) && (ca->repeat > 0)){
559+
return;
560+
}
539561
}
540562
ca->scrollDelay = 0;
541563
ca->scrollposition = 9 + ca->textOffset;
@@ -664,7 +686,7 @@ bool hasIcon = ca->icon;
664686

665687
static unsigned long lastTime = 0;
666688

667-
void NotifyApp(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state, GifPlayer *gifPlayer)
689+
void NotifyOverlay(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state, GifPlayer *gifPlayer)
668690
{
669691
// Check if notification flag is set
670692
if (notifications.empty())
@@ -1089,6 +1111,6 @@ void CApp20(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state, int16_t x, i
10891111
ShowCustomApp(name, matrix, state, x, y, gifPlayer);
10901112
}
10911113

1092-
OverlayCallback overlays[] = {MenuApp, NotifyApp};
1114+
OverlayCallback overlays[] = {MenuOverlay, NotifyOverlay, StatusOverlay};
10931115
void (*customAppCallbacks[20])(FastLED_NeoMatrix *, MatrixDisplayUiState *, int16_t, int16_t, GifPlayer *) = {CApp1, CApp2, CApp3, CApp4, CApp5, CApp6, CApp7, CApp8, CApp9, CApp10, CApp11, CApp12, CApp13, CApp14, CApp15, CApp16, CApp17, CApp18, CApp19, CApp20};
10941116
#endif

src/DisplayManager.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -577,6 +577,8 @@ bool DisplayManager_::generateCustomPage(const String &name, JsonObject doc, boo
577577
customApp.repeat = -1;
578578
}
579579

580+
Serial.println(customApp.repeat);
581+
580582
doc.clear();
581583
pushCustomApp(name, pos - 1);
582584
customApps[name] = customApp;
@@ -929,7 +931,7 @@ void DisplayManager_::setup()
929931
ui->setTargetFPS(MATRIX_FPS);
930932
ui->setTimePerApp(TIME_PER_APP);
931933
ui->setTimePerTransition(TIME_PER_TRANSITION);
932-
ui->setOverlays(overlays, 2);
934+
ui->setOverlays(overlays, 3);
933935
ui->setBackgroundEffect(BACKGROUND_EFFECT);
934936
setAutoTransition(AUTO_TRANSITION);
935937
ui->init();

src/DisplayManager.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ class DisplayManager_
5151
void previousApp();
5252
void leftButton();
5353
void resetTextColor();
54-
void setArrayBrightness(uint8_t brightness);
5554
void clearMatrix();
5655
void selectButton();
5756
void selectButtonLong();

src/Functions.h

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -8,28 +8,6 @@
88
std::map<char, uint16_t> CharMap = {
99
{32, 2}, {33, 2}, {34, 4}, {35, 4}, {36, 4}, {37, 4}, {38, 4}, {39, 2}, {40, 3}, {41, 3}, {42, 4}, {43, 4}, {44, 3}, {45, 4}, {46, 2}, {47, 4}, {48, 4}, {49, 4}, {50, 4}, {51, 4}, {52, 4}, {53, 4}, {54, 4}, {55, 4}, {56, 4}, {57, 4}, {58, 2}, {59, 3}, {60, 4}, {61, 4}, {62, 4}, {63, 4}, {64, 4}, {65, 4}, {66, 4}, {67, 4}, {68, 4}, {69, 4}, {70, 4}, {71, 4}, {72, 4}, {73, 2}, {74, 4}, {75, 4}, {76, 4}, {77, 6}, {78, 5}, {79, 4}, {80, 4}, {81, 5}, {82, 4}, {83, 4}, {84, 4}, {85, 4}, {86, 4}, {87, 6}, {88, 4}, {89, 4}, {90, 4}, {91, 4}, {92, 4}, {93, 4}, {94, 4}, {95, 4}, {96, 3}, {97, 4}, {98, 4}, {99, 4}, {100, 4}, {101, 4}, {102, 4}, {103, 4}, {104, 4}, {105, 2}, {106, 4}, {107, 4}, {108, 4}, {109, 4}, {110, 4}, {111, 4}, {112, 4}, {113, 4}, {114, 4}, {115, 4}, {116, 4}, {117, 4}, {118, 4}, {119, 4}, {120, 4}, {121, 4}, {122, 4}, {123, 4}, {124, 2}, {125, 4}, {126, 4}, {161, 2}, {162, 4}, {163, 4}, {164, 4}, {165, 4}, {166, 2}, {167, 4}, {168, 4}, {169, 4}, {170, 4}, {171, 3}, {172, 4}, {173, 3}, {174, 4}, {175, 4}, {176, 3}, {177, 4}, {178, 4}, {179, 4}, {180, 3}, {181, 4}, {182, 4}, {183, 4}, {184, 4}, {185, 2}, {186, 4}, {187, 3}, {188, 4}, {189, 4}, {190, 4}, {191, 4}, {192, 4}, {193, 4}, {194, 4}, {195, 4}, {196, 4}, {197, 4}, {198, 4}, {199, 4}, {200, 4}, {201, 4}, {202, 4}, {203, 4}, {204, 4}, {205, 4}, {206, 4}, {207, 4}, {208, 4}, {209, 4}, {210, 4}, {211, 4}, {212, 4}, {213, 4}, {214, 4}, {215, 4}, {216, 4}, {217, 4}, {218, 4}, {219, 4}, {220, 4}, {221, 4}, {222, 4}, {223, 4}, {224, 4}, {225, 4}, {226, 4}, {227, 4}, {228, 4}, {229, 4}, {230, 4}, {231, 4}, {232, 4}, {233, 4}, {234, 4}, {235, 4}, {236, 3}, {237, 3}, {238, 4}, {239, 4}, {240, 4}, {241, 4}, {242, 4}, {243, 4}, {244, 4}, {245, 4}, {246, 4}, {247, 4}, {248, 4}, {249, 4}, {250, 4}, {251, 4}, {252, 4}, {253, 4}, {254, 4}, {255, 4}, {285, 2}, {338, 4}, {339, 4}, {352, 4}, {353, 4}, {376, 4}, {381, 4}, {382, 4}, {3748, 2}, {5024, 2}, {8226, 2}, {8230, 4}, {8364, 4}, {65533, 4}};
1010

11-
//---------------------------------------------------------------
12-
// This is the gamma lookup for mapping 255 brightness levels
13-
// The lookup table would be similar but have slightly shifted
14-
// numbers for different gammas (gamma 2.0, 2.2, 2.5, etc.)
15-
const uint8_t PROGMEM gamma8[] = {
16-
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
17-
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1,
18-
1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2,
19-
2, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5,
20-
5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 9, 9, 9, 10,
21-
10, 10, 11, 11, 11, 12, 12, 13, 13, 13, 14, 14, 15, 15, 16, 16,
22-
17, 17, 18, 18, 19, 19, 20, 20, 21, 21, 22, 22, 23, 24, 24, 25,
23-
25, 26, 27, 27, 28, 29, 29, 30, 31, 32, 32, 33, 34, 35, 35, 36,
24-
37, 38, 39, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 50,
25-
51, 52, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 66, 67, 68,
26-
69, 70, 72, 73, 74, 75, 77, 78, 79, 81, 82, 83, 85, 86, 87, 89,
27-
90, 92, 93, 95, 96, 98, 99,101,102,104,105,107,109,110,112,114,
28-
115,117,119,120,122,124,126,127,129,131,133,135,137,138,140,142,
29-
144,146,148,150,152,154,156,158,160,162,164,167,169,171,173,175,
30-
177,180,182,184,186,189,191,193,196,198,200,203,205,208,210,213,
31-
215,218,220,223,225,228,231,233,236,239,241,244,247,249,252,255 };
32-
3311

3412
CRGB kelvinToRGB(int kelvin) {
3513
float temperature = kelvin / 100.0;
@@ -62,13 +40,6 @@ CRGB kelvinToRGB(int kelvin) {
6240
return CRGB((uint8_t)red, (uint8_t)green, (uint8_t)blue);
6341
}
6442

65-
CRGB applyGammaCorrection(const CRGB& color) {
66-
CRGB correctedColor;
67-
correctedColor.r = pgm_read_byte(&gamma8[color.r]);
68-
correctedColor.g = pgm_read_byte(&gamma8[color.g]);
69-
correctedColor.b = pgm_read_byte(&gamma8[color.b]);
70-
return correctedColor;
71-
}
7243

7344
uint32_t hsvToRgb(uint8_t h, uint8_t s, uint8_t v)
7445
{

src/Globals.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ IPAddress gateway;
266266
IPAddress subnet;
267267
IPAddress primaryDNS;
268268
IPAddress secondaryDNS;
269-
const char *VERSION = "0.80";
269+
const char *VERSION = "0.81";
270270

271271
String MQTT_HOST = "";
272272
uint16_t MQTT_PORT = 1883;

src/MQTTManager.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,16 @@ void onMqttMessage(const char *topic, const uint8_t *payload, uint16_t length)
187187
return;
188188
}
189189

190+
if (strTopic.equals(MQTT_PREFIX + "/doupdate"))
191+
{
192+
if (UpdateManager.checkUpdate(true))
193+
{
194+
UpdateManager.updateFirmware();
195+
}
196+
delete[] payloadCopy;
197+
return;
198+
}
199+
190200
if (strTopic.equals(MQTT_PREFIX + "/apps"))
191201
{
192202
DisplayManager.updateAppVector(payloadCopy);
@@ -362,9 +372,9 @@ void onMqttConnected()
362372
connected = true;
363373
}
364374

365-
bool MQTTManager_::getStatus()
375+
bool MQTTManager_::isConnected()
366376
{
367-
return connected;
377+
return mqtt.isConnected();
368378
}
369379

370380
void connect()

src/MQTTManager.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ class MQTTManager_
2222
void beginPublish(const char *topic, unsigned int plength, boolean retained);
2323
void writePayload(const char *data, const uint16_t length);
2424
void endPublish();
25-
bool getStatus();
25+
bool isConnected();
26+
2627
};
2728
extern MQTTManager_ &MQTTManager;
2829

src/MatrixDisplayUi.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,10 +132,11 @@ class MatrixDisplayUi
132132
void blinkTransition();
133133
void reloadTransition();
134134
void crossfadeTransition();
135-
uint16_t fadeColor(uint16_t color, uint32_t interval);
135+
136136

137137
public:
138138
MatrixDisplayUi(FastLED_NeoMatrix *matrix);
139+
uint16_t fadeColor(uint16_t color, uint32_t interval);
139140
uint8_t AppCount = 0;
140141
/**
141142
* Initialise the display

0 commit comments

Comments
 (0)