Skip to content

Commit

Permalink
v0.85
Browse files Browse the repository at this point in the history
- Sends temperature in /stats with given decimal places. closes #302
- Huge improvements in app transitions while using GIFs
- Improves GIF decoders disposal method handling.
- Adds unique ID to stats. closes #297
  • Loading branch information
Blueforcer committed Sep 8, 2023
1 parent 3ecb908 commit 32aa74a
Show file tree
Hide file tree
Showing 12 changed files with 90 additions and 53 deletions.
File renamed without changes.
12 changes: 5 additions & 7 deletions src/esp-fs-webserver.cpp → lib/webserver/esp-fs-webserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ void FSWebServer::run()
if (WiFi.status() != WL_CONNECTED)
{
failedAttempts++;
if (failedAttempts >= 10)
if (failedAttempts >= 60)
{
Serial.println("10 failed attempts to connect. Restarting ESP...");
Serial.println("60 failed attempts to connect. Restarting ESP...");
ESP.restart();
}
}
Expand Down Expand Up @@ -149,7 +149,7 @@ bool FSWebServer::begin(const char *path)

WebServerClass::THandlerFunction FSWebServer::authMiddleware(WebServerClass::THandlerFunction fn)
{
if (authUser.isEmpty())
if (authUser.isEmpty() || m_apmode)
{
return fn;
}
Expand Down Expand Up @@ -948,8 +948,6 @@ void FSWebServer::handleStatus()
if (m_fsOK)
{
uint32_t ip = (WiFi.status() == WL_CONNECTED) ? WiFi.localIP() : WiFi.softAPIP();
String ssid = WiFi.SSID(); // Get the current SSID

json += PSTR("\"true\", \"totalBytes\":\"");
json += totalBytes;
json += PSTR("\", \"usedBytes\":\"");
Expand All @@ -958,8 +956,8 @@ void FSWebServer::handleStatus()
json += WiFi.status() == WL_CONNECTED ? "Station" : "Access Point";
json += PSTR("\", \"ip\":\"");
json += ip;
json += PSTR("\", \"ssid\":\""); // Add SSID here
json += ssid; // Add the actual SSID
json += PSTR("\", \"ssid\":\"");
json += WiFi.SSID();
json += "\"";
}
else
Expand Down
3 changes: 1 addition & 2 deletions src/esp-fs-webserver.h → lib/webserver/esp-fs-webserver.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ class FSWebServer
void onNotFound(WebServerClass::THandlerFunction fn);

void addHandler(const Uri &uri, HTTPMethod method, WebServerClass::THandlerFunction fn);
void WiFiEvent(WiFiEvent_t event, WiFiEventInfo_t info);
void addHandler(const Uri &uri, WebServerClass::THandlerFunction handler);

void setCaptiveWebage(const char *url);
Expand Down Expand Up @@ -310,7 +309,7 @@ class FSWebServer
private:
int failedAttempts = 0;
unsigned long previousMillis = 0;
unsigned long interval = 30000;
unsigned long interval = 10000;
char m_basePath[16];
UpdateServerClass m_httpUpdater;
String authUser;
Expand Down
File renamed without changes.
File renamed without changes.
16 changes: 10 additions & 6 deletions src/Apps.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ String WEATHER_HUM;

struct CustomApp
{
uint32_t currentFrame;
String iconName;
String iconFile;
String drawInstructions;
Expand Down Expand Up @@ -187,7 +188,7 @@ void TimeApp(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state, int16_t x,
if (notifyFlag)
return;
CURRENT_APP = "Time";

currentCustomApp = "";
if (TIME_COLOR > 0)
{
DisplayManager.setTextColor(TIME_COLOR);
Expand Down Expand Up @@ -294,6 +295,7 @@ void DateApp(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state, int16_t x,
if (notifyFlag)
return;
CURRENT_APP = "Date";
currentCustomApp = "";
if (DATE_COLOR > 0)
{
DisplayManager.setTextColor(DATE_COLOR);
Expand Down Expand Up @@ -329,6 +331,7 @@ void TempApp(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state, int16_t x,
if (notifyFlag)
return;
CURRENT_APP = "Temperature";
currentCustomApp = "";
if (TEMP_COLOR > 0)
{
DisplayManager.setTextColor(TEMP_COLOR);
Expand Down Expand Up @@ -383,6 +386,7 @@ void HumApp(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state, int16_t x, i
if (notifyFlag)
return;
CURRENT_APP = "Humidity";
currentCustomApp = "";
if (HUM_COLOR > 0)
{
DisplayManager.setTextColor(HUM_COLOR);
Expand Down Expand Up @@ -431,6 +435,7 @@ void BatApp(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state, int16_t x, i
if (notifyFlag)
return;
CURRENT_APP = "Battery";
currentCustomApp = "";
if (BAT_COLOR > 0)
{
DisplayManager.setTextColor(BAT_COLOR);
Expand Down Expand Up @@ -490,7 +495,7 @@ void ShowCustomApp(String name, FastLED_NeoMatrix *matrix, MatrixDisplayUiState
CURRENT_APP = ca->name;
currentCustomApp = name;

if ((ca->iconName.length() > 0) && !ca->iconSearched)
if ((ca->iconName.length() > 0) && !ca->icon)
{
const char *extensions[] = {".jpg", ".gif"};
bool isGifFlags[] = {false, true};
Expand All @@ -502,12 +507,10 @@ void ShowCustomApp(String name, FastLED_NeoMatrix *matrix, MatrixDisplayUiState
{
ca->isGif = isGifFlags[i];
ca->icon = LittleFS.open(filePath);
ca->iconFile = ca->iconName + extensions[i];
DEBUG_PRINTLN("Icon found: " + filePath);
break; // Exit loop if icon was found
}
}
ca->iconSearched = true;
// ca->iconSearched = true;
}

bool hasIcon = ca->icon;
Expand Down Expand Up @@ -553,7 +556,8 @@ void ShowCustomApp(String name, FastLED_NeoMatrix *matrix, MatrixDisplayUiState
}
if (ca->isGif)
{
iconWidth = gifPlayer->playGif(x + ca->iconPosition + ca->iconOffset, y, &ca->icon);
iconWidth = gifPlayer->playGif(x + ca->iconPosition + ca->iconOffset, y, &ca->icon,ca->currentFrame);
ca->currentFrame = gifPlayer->getFrame();
}
else
{
Expand Down
14 changes: 11 additions & 3 deletions src/DisplayManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1072,6 +1072,7 @@ void ResetCustomApps()
app.currentRepeat = 0;
app.iconSearched = false;
app.icon.close();
app.currentFrame = 0;
}
}
}
Expand Down Expand Up @@ -1501,6 +1502,12 @@ void DisplayManager_::updateAppVector(const char *json)
doc.clear();
}

double roundToDecimalPlaces(double value, int places)
{
double factor = pow(10.0, places);
return round(value * factor) / factor;
}

String DisplayManager_::getStats()
{
StaticJsonDocument<1024> doc;
Expand All @@ -1515,12 +1522,12 @@ String DisplayManager_::getStats()
#endif
doc[LuxKey] = static_cast<int>(CURRENT_LUX);
doc[LDRRawKey] = LDR_RAW;
uint32_t freeHeap = ESP.getFreeHeap();
doc[RamKey] = freeHeap + ESP.getFreePsram();
doc[RamKey] = ESP.getFreeHeap() + ESP.getFreePsram();
doc[BrightnessKey] = BRIGHTNESS;
if (SENSOR_READING)
{
doc[TempKey] = static_cast<uint8_t>(CURRENT_TEMP);
double formattedTemp = roundToDecimalPlaces(CURRENT_TEMP, TEMP_DECIMAL_PLACES);
doc[TempKey] = formattedTemp;
doc[HumKey] = static_cast<uint8_t>(CURRENT_HUM);
}
doc[UpTimeKey] = PeripheryManager.readUptime();
Expand All @@ -1531,6 +1538,7 @@ String DisplayManager_::getStats()
doc[F("indicator2")] = ui->indicator2State;
doc[F("indicator3")] = ui->indicator3State;
doc[F("app")] = CURRENT_APP;
doc[F("uid")] = uniqueID;
String jsonString;
serializeJson(doc, jsonString);
return jsonString;
Expand Down
64 changes: 44 additions & 20 deletions src/GifPlayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,12 @@ class GifPlayer
#define ERROR_FINISHED 5
#define WIDTH 32
#define HEIGHT 8
uint32_t currentFrame;

private:
bool needNewFrame;
long lastFrameTime;
bool firstFrameDone;
int newframeDelay;
CRGB FrameBuffer[HEIGHT][WIDTH];

bool lastFrameDrawn = false;
unsigned long nextFrameTime = 0;
#define GIFHDRTAGNORM "GIF87a"
Expand Down Expand Up @@ -239,7 +238,7 @@ class GifPlayer

if ((prevDisposalMethod != DISPOSAL_NONE) && (prevDisposalMethod != DISPOSAL_LEAVE))
{
mtx->fillRect(offsetX, offsetY, lsdWidth, lsdHeight, 0);
mtx->clear();
}

if (prevDisposalMethod == DISPOSAL_BACKGROUND)
Expand Down Expand Up @@ -296,6 +295,7 @@ class GifPlayer
}
lzw_decode_init(lzwCodeSize, lzwImageData);
decompressAndDisplayFrame();
redrawLastFrame();
transparentColorIndex = NO_TRANSPARENT_INDEX;
disposalMethod = DISPOSAL_NONE;
if (frameDelay < 1)
Expand Down Expand Up @@ -516,24 +516,29 @@ class GifPlayer
}
else
{
FrameBuffer[y][x] = CRGB::Black;
if (disposalMethod == DISPOSAL_BACKGROUND)
{
FrameBuffer[y][x] = CRGB::Black;
}
}
}
}

redrawLastFrame();
needNewFrame = false;
++currentFrame;
lastFrameTime = millis();
}

public:
void
setMatrix(FastLED_NeoMatrix *matrix)
void setMatrix(FastLED_NeoMatrix *matrix)
{
mtx = matrix;
}

int playGif(int x, int y, File *imageFile)
uint32_t getFrame()
{
return currentFrame;
}

int playGif(int x, int y, File *imageFile, uint32_t frame = 0)
{
offsetX = x;
offsetY = y;
Expand All @@ -545,8 +550,9 @@ class GifPlayer
}
else
{
needNewFrame = true;
currentFrame = 0;
file = *imageFile;

memset(FrameBuffer, 0, sizeof(FrameBuffer));
memset(gifPalette, 0, sizeof(gifPalette));
memset(lzwImageData, 0, sizeof(lzwImageData));
Expand All @@ -555,10 +561,24 @@ class GifPlayer
memset(stack, 0, sizeof(stack));
memset(suffix, 0, sizeof(suffix));
memset(prefix, 0, sizeof(prefix));
parseGifHeader();
parseLogicalScreenDescriptor();
parseGlobalColorTable();
drawFrame();
if (frame != 0)
{

parseGifHeader();
parseLogicalScreenDescriptor();
parseGlobalColorTable();
do
{
drawFrame(true);
} while (currentFrame < frame);
}
else
{
parseGifHeader();
parseLogicalScreenDescriptor();
parseGlobalColorTable();
drawFrame();
}
}
return tbiWidth;
}
Expand Down Expand Up @@ -597,12 +617,16 @@ class GifPlayer
}
}

unsigned long drawFrame()
unsigned long drawFrame(bool force = false)
{
redrawLastFrame();
if (millis() - lastFrameTime < newframeDelay)

if (!force)
{
return 0;
if (millis() - lastFrameTime < newframeDelay)
{
redrawLastFrame();
return 0;
}
}

lastFrameDrawn = false;
Expand Down
8 changes: 4 additions & 4 deletions src/Globals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ void loadSettings()
CALENDAR_HEADER_COLOR = Settings.getUInt("CHCOL", 0xFF0000);
CALENDAR_TEXT_COLOR = Settings.getUInt("CTCOL", 0x000000);
CALENDAR_BODY_COLOR = Settings.getUInt("CBCOL", 0xFFFFFF);
TRANS_EFFECT = Settings.getUInt("TEFF", 1);
TRANS_EFFECT = Settings.getUInt("TEFF", 10);
TIME_MODE = Settings.getUInt("TMODE", 1);
TIME_COLOR = Settings.getUInt("TIME_COL", 0);
DATE_COLOR = Settings.getUInt("DATE_COL", 0);
Expand Down Expand Up @@ -297,7 +297,7 @@ IPAddress gateway;
IPAddress subnet;
IPAddress primaryDNS;
IPAddress secondaryDNS;
const char *VERSION = "0.84";
const char *VERSION = "0.85";

String MQTT_HOST = "";
uint16_t MQTT_PORT = 1883;
Expand All @@ -321,7 +321,7 @@ String NET_SN = "255.255.255.0";
String NET_PDNS = "8.8.8.8";
String NET_SDNS = "1.1.1.1";
long TIME_PER_APP = 7000;
uint8_t MATRIX_FPS = 40;
uint8_t MATRIX_FPS = 42;
int TIME_PER_TRANSITION = 400;
String NTP_SERVER = "de.pool.ntp.org";
String NTP_TZ = "CET-1CEST,M3.5.0,M10.5.0/3";
Expand Down Expand Up @@ -396,7 +396,7 @@ uint32_t HUM_COLOR = 0;
bool ARTNET_MODE;
bool MOODLIGHT_MODE;
long STATS_INTERVAL = 10000;
bool DEBUG_MODE = true;
bool DEBUG_MODE = false;
uint8_t MIN_BRIGHTNESS = 2;
uint8_t MAX_BRIGHTNESS = 180;
double movementFactor = 0.5;
Expand Down
10 changes: 5 additions & 5 deletions src/MQTTManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ void MQTTManager_::sendStats()
{
if (mqtt.isConnected())
{
if (HA_DISCOVERY && mqtt.isConnected())
if (HA_DISCOVERY && mqtt.isConnected())
{
char buffer[5];
#ifndef awtrix2_upgrade
Expand Down Expand Up @@ -766,13 +766,13 @@ void MQTTManager_::sendButton(byte btn, bool state)

void MQTTManager_::setIndicatorState(uint8_t indicator, bool state, uint32_t color)
{
if (HA_DISCOVERY && mqtt.isConnected())
if (HA_DISCOVERY && mqtt.isConnected())
{
HALight::RGBColor c;
c.isSet = true;
c.red = (color >> 16) & 0xFF; // Rote Komponente 8-Bit
c.green = (color >> 8) & 0xFF; // Grüne Komponente 8-Bit
c.blue = color & 0xFF;
c.red = (color >> 16) & 0xFF; // Rote Komponente 8-Bit
c.green = (color >> 8) & 0xFF; // Grüne Komponente 8-Bit
c.blue = color & 0xFF;

switch (indicator)
{
Expand Down
Loading

0 comments on commit 32aa74a

Please sign in to comment.