Skip to content

Commit

Permalink
v0.40
Browse files Browse the repository at this point in the history
- fixes a bug in text lengths calculations with spaces
- adds the onscreen menu option to disable or enable internal apps

Many options are moved from webinterface to onscreen menu the last few versions. if you running awtrix light for some versions now, it could be necessary to delete your config.json and restart in order to cleanup your webinterface.

closes #14
  • Loading branch information
Blueforcer committed Mar 26, 2023
1 parent a4ffeb7 commit e66713f
Show file tree
Hide file tree
Showing 17 changed files with 2,723 additions and 2,703 deletions.
Binary file modified docs/flasher/firmware/firmware.bin
Binary file not shown.
2 changes: 1 addition & 1 deletion docs/flasher/firmware/manifest.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "AWTRIX Light",
"version": "0.39",
"version": "0.40",
"home_assistant_domain": "AwtrixLight",
"funding_url": "https://blueforcer.de",
"new_install_prompt_erase": true,
Expand Down
1 change: 1 addition & 0 deletions docs/onscreen.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@ Hold down the middle button for 2s to exit the current menu and to save your set
| `DATE` | Allows selection of date format. |
| `WEEKDAY` | Allows selection of start of week. |
| `TEMP` | Allows selection of temperature system (°C or °F). |
| `APPS` | Allows to enable or disable internal apps |
| `UPDATE` | Check and download new firmware if available. |

52 changes: 28 additions & 24 deletions lib/MatrixUI/MatrixDisplayUi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,38 +185,42 @@ int8_t MatrixDisplayUi::update()
void MatrixDisplayUi::tick()
{
this->state.ticksSinceLastStateSwitch++;
switch (this->state.frameState)

if (this->AppCount > 0)
{
case IN_TRANSITION:
if (this->state.ticksSinceLastStateSwitch >= this->ticksPerTransition)
{
this->state.frameState = FIXED;
this->state.currentFrame = getnextAppNumber();
this->state.ticksSinceLastStateSwitch = 0;
this->nextAppNumber = -1;
}
break;
case FIXED:
// Revert manuelControll
if (this->state.manuelControll)
{
this->state.frameTransitionDirection = this->lastTransitionDirection;
this->state.manuelControll = false;
}
if (this->state.ticksSinceLastStateSwitch >= this->ticksPerFrame)
switch (this->state.frameState)
{
if (this->setAutoTransition)
case IN_TRANSITION:
if (this->state.ticksSinceLastStateSwitch >= this->ticksPerTransition)
{

this->state.frameState = IN_TRANSITION;
this->state.frameState = FIXED;
this->state.currentFrame = getnextAppNumber();
this->state.ticksSinceLastStateSwitch = 0;
this->nextAppNumber = -1;
}
break;
case FIXED:
// Revert manuelControll
if (this->state.manuelControll)
{
this->state.frameTransitionDirection = this->lastTransitionDirection;
this->state.manuelControll = false;
}
this->state.ticksSinceLastStateSwitch = 0;
if (this->state.ticksSinceLastStateSwitch >= this->ticksPerFrame)
{
if (this->setAutoTransition)
{
this->state.frameState = IN_TRANSITION;
}
this->state.ticksSinceLastStateSwitch = 0;
}
break;
}
break;
}

this->matrix->clear();
this->drawApp();
if (this->AppCount > 0)
this->drawApp();
this->drawOverlays();
this->matrix->show();
}
Expand Down
75 changes: 50 additions & 25 deletions src/DisplayManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@ void DisplayManager_::drawJPG(uint16_t x, uint16_t y, fs::File jpgFile)
TJpgDec.drawFsJpg(x, y, jpgFile);
}

void DisplayManager_::drawBMP(int16_t x, int16_t y, const uint16_t bitmap[], int16_t w, int16_t h)
{
matrix.drawRGBBitmap(y, x, bitmap, w, h);
}

void DisplayManager_::applyAllSettings()
{
ui.setTargetFPS(MATRIX_FPS);
Expand Down Expand Up @@ -219,21 +224,18 @@ void pushCustomFrame(String name, int position)

void removeCustomFrame(const String &name)
{
// Suchen Sie nach dem Element, das dem Namen entspricht
auto it = std::find_if(Apps.begin(), Apps.end(), [&name](const std::pair<String, AppCallback> &appPair)
{ return appPair.first == name; });

// Wenn das Element gefunden wurde, entfernen Sie es aus dem Vektor
if (it != Apps.end())
{
Apps.erase(it);
ui.setApps(Apps); // Aktualisieren Sie die Frames
ui.setApps(Apps);
}
}

void DisplayManager_::generateCustomPage(String name, String payload)
{

if (payload == "" && customFrames.count(name))
{
customFrames.erase(customFrames.find(name));
Expand Down Expand Up @@ -261,7 +263,6 @@ void DisplayManager_::generateCustomPage(String name, String payload)
customFrame.pushIcon = doc.containsKey("pushIcon") ? doc["pushIcon"] : 0;
customFrame.name = name;
customFrame.text = utf8ascii(doc["text"].as<String>());

customFrame.color = doc.containsKey("color") ? doc["color"].is<String>() ? hexToRgb565(doc["color"]) : doc["color"].is<JsonArray>() ? hexToRgb565(doc["color"].as<String>())
: TEXTCOLOR_565
: TEXTCOLOR_565;
Expand Down Expand Up @@ -342,25 +343,49 @@ void DisplayManager_::generateNotification(String payload)
}
}

void DisplayManager_::loadApps()
{
Apps.clear();
Apps.push_back(std::make_pair("time", TimeFrame));
if (SHOW_DATE)
Apps.push_back(std::make_pair("date", DateFrame));
if (SHOW_TEMP)
Apps.push_back(std::make_pair("temp", TempFrame));
if (SHOW_HUM)
Apps.push_back(std::make_pair("hum", HumFrame));
if (SHOW_BATTERY)
Apps.push_back(std::make_pair("bat", BatFrame));
// if (SHOW_WEATHER)
// Apps.push_back(std::make_pair(5, WeatherFrame));
nativeAppsCount = Apps.size();
ui.setApps(Apps); // Add frames
if (AUTO_TRANSITION && nativeAppsCount == 1)
void DisplayManager_::loadNativeApps()
{
// Define a helper function to check and update an app
auto updateApp = [&](const String &name, AppCallback callback, bool show, size_t position)
{
auto it = std::find_if(Apps.begin(), Apps.end(), [&](const std::pair<String, AppCallback> &app)
{ return app.first == name; });
if (it != Apps.end())
{
if (!show)
{
Apps.erase(it);
}
}
else
{
if (show)
{
Apps.insert(Apps.begin() + position, std::make_pair(name, callback));
}
}
};

// Update the "time" app at position 0
updateApp("time", TimeFrame, SHOW_TIME, 0);

// Update the "date" app at position 1
updateApp("date", DateFrame, SHOW_DATE, 1);

// Update the "temp" app at position 2
updateApp("temp", TempFrame, SHOW_TEMP, 2);

// Update the "hum" app at position 3
updateApp("hum", HumFrame, SHOW_HUM, 3);

// Update the "bat" app at position 4
updateApp("bat", BatFrame, SHOW_BAT, 4);

ui.setApps(Apps);
if (AUTO_TRANSITION && Apps.size() == 1)
{
setAutoTransition(false);
StartAppUpdater();
}
}

void DisplayManager_::setup()
Expand Down Expand Up @@ -545,8 +570,8 @@ void DisplayManager_::drawProgressBar(int cur, int total)

void DisplayManager_::drawMenuIndicator(int cur, int total)
{
int menuItemWidth = 2;
int totalWidth = total * menuItemWidth + (total - 2);
int menuItemWidth = 1;
int totalWidth = total * menuItemWidth + (total - 1);
int leftMargin = (MATRIX_WIDTH - totalWidth) / 2;
int pixelSpacing = 1;
for (int i = 0; i < total; i++)
Expand Down
3 changes: 2 additions & 1 deletion src/DisplayManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class DisplayManager_
void rightButton();
void dismissNotify();
void HSVtext(int16_t, int16_t, const char *, bool);
void loadApps();
void loadNativeApps();
void nextApp();
void previousApp();
void leftButton();
Expand All @@ -55,6 +55,7 @@ class DisplayManager_
void drawJPG(uint16_t x, uint16_t y, fs::File jpgFile);
void drawProgressBar(int cur, int total);
void drawMenuIndicator(int cur, int total);
void drawBMP(int16_t x, int16_t y, const uint16_t bitmap[], int16_t w, int16_t h);
};

extern DisplayManager_ &DisplayManager;
Expand Down
5 changes: 2 additions & 3 deletions src/Frames.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ void TimeFrame(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state, int16_t x
timeInfo = localtime(&now);
char t[20];
strftime(t, sizeof(t), TIME_FORMAT.c_str(), localtime(&now));
DisplayManager.printText(0 + x, 6 + y, t, true, true);
DisplayManager.printText(0 + x, 6 + y, t, true, false);

if (!SHOW_WEEKDAY)
return;
Expand Down Expand Up @@ -184,7 +184,7 @@ void HumFrame(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state, int16_t x,
return;
CURRENT_APP = "Humidity";
DisplayManager.getInstance().resetTextColor();
matrix->drawRGBBitmap(x, y + 1, get_icon(2075), 8, 8);
matrix->drawRGBBitmap(x, y + 1, get_icon(2075), 8,8);
matrix->setCursor(14 + x, 6 + y);
int humidity = CURRENT_HUM; // Temperatur ohne Nachkommastellen
matrix->print(humidity); // Ausgabe der Temperatur
Expand Down Expand Up @@ -214,7 +214,6 @@ void MenuFrame(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state)
void AlarmFrame(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state)
{
if (ALARM_ACTIVE)

{
matrix->fillScreen(matrix->Color(255, 0, 0));
CURRENT_APP = "Alarm";
Expand Down
5 changes: 3 additions & 2 deletions src/Functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include <Globals.h>

std::map<char, uint16_t> CharMap = {
{32, 3}, {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, 4}, {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}};
{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, 4}, {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}};

uint32_t hsvToRgb(uint8_t h, uint8_t s, uint8_t v)
{
Expand All @@ -24,7 +24,8 @@ uint16_t hexToRgb565(String hexValue)
uint8_t r = strtol(hexValue.substring(0, 2).c_str(), NULL, 16);
uint8_t g = strtol(hexValue.substring(2, 4).c_str(), NULL, 16);
uint8_t b = strtol(hexValue.substring(4, 6).c_str(), NULL, 16);
if ((errno == ERANGE) || (r > 255) || (g > 255) || (b > 255)) {
if ((errno == ERANGE) || (r > 255) || (g > 255) || (b > 255))
{
return 0xFFFF;
}
uint16_t color = ((r >> 3) << 11) | ((g >> 2) << 5) | (b >> 3);
Expand Down
21 changes: 10 additions & 11 deletions src/GifPlayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ class GifPlayer
long lastFrameTime;
bool firstFrameDone;
int newframeDelay;
int lastFrame[8 * 8];
bool lastFrameDrawn = false;
int lastFrame[8 * 8];
bool lastFrameDrawn = false;
unsigned long nextFrameTime = 0;
#define GIFHDRTAGNORM "GIF87a"
#define GIFHDRTAGNORM "GIF87a"
#define GIFHDRTAGNORM1 "GIF89a"
#define GIFHDRSIZE 6
FastLED_NeoMatrix *mtx;
Expand Down Expand Up @@ -528,6 +528,7 @@ class GifPlayer
}
}
needNewFrame = false;
lastFrameTime = millis();
}

public:
Expand Down Expand Up @@ -595,15 +596,12 @@ class GifPlayer
if (!file)
return 0;

unsigned long now = millis();

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

lastFrameTime = now;
lastFrameDrawn = false;

offsetX = x;
Expand All @@ -614,8 +612,9 @@ class GifPlayer
byte b = readByte();
if (b == 0x2c)
{
unsigned int fdelay = parseTableBasedImage();
return fdelay;
Serial.println("Parse");
parseTableBasedImage();
return 0;
}
else if (b == 0x21)
{
Expand All @@ -641,12 +640,12 @@ class GifPlayer
else
{
done = true;
backUpStream(1);
file.seek(0);
Serial.println("Finished");
parseGifHeader();
parseLogicalScreenDescriptor();
parseGlobalColorTable();
drawFrame(offsetX, offsetY);
drawFrame(offsetX,offsetY);
return ERROR_FINISHED;
}
}
Expand Down
16 changes: 14 additions & 2 deletions src/Globals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ void loadSettings()
DATE_FORMAT = Settings.getString("DFORMAT", "%d.%m.%y");
START_ON_MONDAY = Settings.getBool("SOM", true);
IS_CELSIUS = Settings.getBool("CEL", true);
SHOW_TIME = Settings.getBool("TIM", true);
SHOW_DATE = Settings.getBool("DAT", true);
SHOW_TEMP = Settings.getBool("TEMP", true);
SHOW_HUM = Settings.getBool("HUM", true);
SHOW_BAT = Settings.getBool("BAT", true);
Settings.end();
}

Expand All @@ -34,6 +39,12 @@ void saveSettings()
Settings.putString("DFORMAT", DATE_FORMAT);
Settings.putBool("SOM", START_ON_MONDAY);
Settings.putBool("CEL", IS_CELSIUS);

Settings.putBool("TIM", SHOW_TIME);
Settings.putBool("DAT", SHOW_DATE);
Settings.putBool("TEMP", SHOW_TEMP);
Settings.putBool("HUM", SHOW_HUM);
Settings.putBool("BAT", SHOW_BAT);
Settings.end();
}

Expand All @@ -42,7 +53,7 @@ IPAddress gateway;
IPAddress subnet;
IPAddress primaryDNS;
IPAddress secondaryDNS;
const char *VERSION = "0.39";
const char *VERSION = "0.40";
String MQTT_HOST = "";
uint16_t MQTT_PORT = 1883;
String MQTT_USER;
Expand All @@ -51,9 +62,10 @@ String MQTT_PREFIX = "AwtrixLight";
String CITY = "Berlin,de";
bool IO_BROKER = false;
bool NET_STATIC = false;
bool SHOW_TIME = true;
bool SHOW_DATE = true;
bool SHOW_WEATHER = true;
bool SHOW_BATTERY = true;
bool SHOW_BAT = true;
bool SHOW_TEMP = true;
bool SHOW_HUM = true;
bool SHOW_SECONDS = true;
Expand Down
3 changes: 2 additions & 1 deletion src/Globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ extern String MQTT_PREFIX;
extern String CITY;
extern bool IO_BROKER;
extern bool NET_STATIC;
extern bool SHOW_TIME;
extern bool SHOW_DATE;
extern bool SHOW_WEATHER;
extern bool SHOW_BATTERY;
extern bool SHOW_BAT;
extern bool SHOW_TEMP;
extern bool SHOW_HUM;
extern bool SHOW_SECONDS;
Expand Down
Loading

0 comments on commit e66713f

Please sign in to comment.