Skip to content

Commit

Permalink
v0.35
Browse files Browse the repository at this point in the history
- moves transistion time and app time setting into onscreen-menu
- Text starts to scroll on the left side instead from right
- allows to switch to a page by name via mqtt
- custompages doesnt need to have integers as an id anymore, you can also use strings now.

closes #7
closes #4
  • Loading branch information
Blueforcer committed Mar 23, 2023
1 parent ec613ec commit 7b5a4d3
Show file tree
Hide file tree
Showing 14 changed files with 324 additions and 190 deletions.
52 changes: 52 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{
"files.associations": {
"array": "cpp",
"atomic": "cpp",
"*.tcc": "cpp",
"cctype": "cpp",
"clocale": "cpp",
"cmath": "cpp",
"cstdarg": "cpp",
"cstddef": "cpp",
"cstdint": "cpp",
"cstdio": "cpp",
"cstdlib": "cpp",
"cstring": "cpp",
"ctime": "cpp",
"cwchar": "cpp",
"cwctype": "cpp",
"deque": "cpp",
"unordered_map": "cpp",
"unordered_set": "cpp",
"vector": "cpp",
"exception": "cpp",
"algorithm": "cpp",
"functional": "cpp",
"iterator": "cpp",
"map": "cpp",
"memory": "cpp",
"memory_resource": "cpp",
"numeric": "cpp",
"optional": "cpp",
"random": "cpp",
"string": "cpp",
"string_view": "cpp",
"system_error": "cpp",
"tuple": "cpp",
"type_traits": "cpp",
"utility": "cpp",
"fstream": "cpp",
"initializer_list": "cpp",
"iomanip": "cpp",
"iosfwd": "cpp",
"istream": "cpp",
"limits": "cpp",
"new": "cpp",
"ostream": "cpp",
"sstream": "cpp",
"stdexcept": "cpp",
"streambuf": "cpp",
"cinttypes": "cpp",
"typeinfo": "cpp"
}
}
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.33",
"version": "0.35",
"home_assistant_domain": "AwtrixLight",
"funding_url": "https://blueforcer.de",
"new_install_prompt_erase": true,
Expand Down
11 changes: 6 additions & 5 deletions lib/MatrixUI/MatrixDisplayUi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
* Copyright (c) 2016 by Daniel Eichhorn
* Copyright (c) 2016 by Fabrice Weinberg
* Copyright (c) 2023 by Stephan Muehl (Blueforcer)
* Note: This old lib for SSD1306 displays has been extremly
* modified for AWTRIX Light and has nothing to do with the original purposes.
* Note: This old lib for SSD1306 displays has been extremly
* modified for AWTRIX Light and has nothing to do with the original purposes.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -89,7 +89,7 @@ void MatrixDisplayUi::setAppAnimation(AnimationDirection dir)
this->frameAnimationDirection = dir;
}

void MatrixDisplayUi::setApps(const std::vector<std::pair<uint16_t, AppCallback>> &appPairs)
void MatrixDisplayUi::setApps(const std::vector<std::pair<String, AppCallback>> &appPairs)
{
delete[] AppFunctions;
AppCount = appPairs.size();
Expand Down Expand Up @@ -262,8 +262,9 @@ void MatrixDisplayUi::drawApp()
y *= dir;
x1 *= dir;
y1 *= dir;
bool FirstFrame = progress < 0.1;
bool LastFrame = progress > 0.9;
Serial.println(progress);
bool FirstFrame = progress < 0.2;
bool LastFrame = progress > 0.8;
this->matrix->drawRect(x, y, x1, y1, matrix->Color(0, 0, 0));
(this->AppFunctions[this->state.currentFrame])(this->matrix, &this->state, x, y, FirstFrame, LastFrame);
(this->AppFunctions[this->getnextAppNumber()])(this->matrix, &this->state, x1, y1, FirstFrame, LastFrame);
Expand Down
2 changes: 1 addition & 1 deletion lib/MatrixUI/MatrixDisplayUi.h
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ class MatrixDisplayUi
/**
* Add frame drawing functions
*/
void setApps(const std::vector<std::pair<uint16_t, AppCallback>> &appPairs);
void setApps(const std::vector<std::pair<String, AppCallback>> &appPairs);

// Overlay

Expand Down
138 changes: 50 additions & 88 deletions src/DisplayManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ void DisplayManager_::drawJPG(uint16_t x, uint16_t y, fs::File jpgFile)
void DisplayManager_::setSettings()
{
ui.setTargetFPS(MATRIX_FPS);
ui.setTimePerApp(TIME_PER_FRAME);
ui.setTimePerApp(TIME_PER_APP);
ui.setTimePerTransition(TIME_PER_TRANSITION);
}

Expand Down Expand Up @@ -128,11 +128,11 @@ bool jpg_output(int16_t x, int16_t y, uint16_t w, uint16_t h, uint16_t *bitmap)
return 0;
}

void DisplayManager_::printText(int16_t x, int16_t y, const char *text, bool centered)
void DisplayManager_::printText(int16_t x, int16_t y, const char *text, bool centered, bool ignoreUppercase)
{
if (centered)
{
uint16_t textWidth = getTextWidth(text);
uint16_t textWidth = getTextWidth(text, ignoreUppercase);
int16_t textX = ((32 - textWidth) / 2);
matrix.setCursor(textX, y);
}
Expand All @@ -141,7 +141,7 @@ void DisplayManager_::printText(int16_t x, int16_t y, const char *text, bool cen
matrix.setCursor(x, y);
}

if (UPPERCASE_LETTERS)
if (UPPERCASE_LETTERS && !ignoreUppercase)
{
size_t length = strlen(text);
char upperText[length + 1]; // +1 for the null terminator
Expand Down Expand Up @@ -184,64 +184,37 @@ void DisplayManager_::HSVtext(int16_t x, int16_t y, const char *text, bool clear
}
char temp_str[2] = {'\0', '\0'};
temp_str[0] = text[i];
xpos += getTextWidth(temp_str);
xpos += getTextWidth(temp_str, false);
}
hueOffset++;
if (clear)
matrix.show();
}

void pushCustomFrame(uint16_t id)
void pushCustomFrame(String name)
{
if (customFrames.count(id) == 0)

if (customFrames.count(name) == 0)
{
uint16_t newID = nativeAppsCount + id;
switch (id)
++customPagesCount;
void (*customFrames[10])(FastLED_NeoMatrix *, MatrixDisplayUiState *, int16_t, int16_t, bool, bool) = {CFrame1, CFrame2, CFrame3, CFrame4, CFrame5, CFrame6, CFrame7, CFrame8, CFrame9, CFrame10};
if (customFrames[customPagesCount] != NULL)
{
Apps.push_back(std::make_pair(name, customFrames[customPagesCount]));
ui.setApps(Apps); // Add frames
}
else
{
case 1:
Apps.push_back(std::make_pair(newID, CFrame1));
break;
case 2:
Apps.push_back(std::make_pair(newID, CFrame2));
break;
case 3:
Apps.push_back(std::make_pair(newID, CFrame3));
break;
case 4:
Apps.push_back(std::make_pair(newID, CFrame4));
break;
case 5:
Apps.push_back(std::make_pair(newID, CFrame5));
break;
case 6:
Apps.push_back(std::make_pair(newID, CFrame6));
break;
case 7:
Apps.push_back(std::make_pair(newID, CFrame7));
break;
case 8:
Apps.push_back(std::make_pair(newID, CFrame8));
break;
case 9:
Apps.push_back(std::make_pair(newID, CFrame9));
break;
case 10:
Apps.push_back(std::make_pair(newID, CFrame10));
break;
default:
return;
break;
++customPagesCount;
}
ui.setApps(Apps); // Add frames
}
}

void removeCustomFrame(uint16_t id)
void removeCustomFrame(const String &name)
{
id += nativeAppsCount;
// Suchen Sie nach dem Element, das der ID entspricht
auto it = std::find_if(Apps.begin(), Apps.end(), [id](const std::pair<uint16_t, AppCallback> &appPair)
{ return appPair.first == id; });
// 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())
Expand All @@ -251,13 +224,13 @@ void removeCustomFrame(uint16_t id)
}
}

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

if (payload == "" && customFrames.count(id))
if (payload == "" && customFrames.count(name))
{
customFrames.erase(customFrames.find(id));
removeCustomFrame(id);
customFrames.erase(customFrames.find(name));
removeCustomFrame(name);
return;
}

Expand All @@ -268,21 +241,6 @@ void DisplayManager_::generateCustomPage(uint16_t id, String payload)

CustomFrame customFrame;

if (id == 0)
{
if (doc.containsKey("id"))
{
customFrame.id = doc["id"].as<uint8_t>();
}
else
{
return;
}
}

if (id > 10)
return;

if (doc.containsKey("sound"))
{
customFrame.sound = ("/" + doc["sound"].as<String>() + ".txt");
Expand All @@ -292,27 +250,18 @@ void DisplayManager_::generateCustomPage(uint16_t id, String payload)
customFrame.sound = "";
}

if (doc.containsKey("name"))
{
customFrame.name = doc["name"].as<String>();
}
else
{
customFrame.name = "Custom " + String(id);
}

customFrame.rainbow = doc.containsKey("rainbow") ? doc["rainbow"] : false;
customFrame.pushIcon = doc.containsKey("pushIcon") ? doc["pushIcon"] : 0;
customFrame.id = id;
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;

if (currentCustomFrame != id)
if (currentCustomFrame != name)
{
customFrame.scrollposition = 34;
customFrame.scrollposition = 9;
}

customFrame.repeat = doc.containsKey("repeat") ? doc["repeat"].as<uint8_t>() : -1;
Expand All @@ -333,24 +282,24 @@ void DisplayManager_::generateCustomPage(uint16_t id, String payload)
}
}

pushCustomFrame(id);
customFrames[id] = customFrame;
pushCustomFrame(name);
customFrames[name] = customFrame;
}

void DisplayManager_::generateNotification(String payload)
{
StaticJsonDocument<1024> doc;
deserializeJson(doc, payload);

notify.duration = doc.containsKey("duration") ? doc["duration"].as<int>() * 1000 : TIME_PER_FRAME;
notify.duration = doc.containsKey("duration") ? doc["duration"].as<int>() * 1000 : TIME_PER_APP;
notify.text = utf8ascii(doc["text"].as<String>());
notify.repeat = doc.containsKey("repeat") ? doc["repeat"].as<uint16_t>() : -1;
notify.rainbow = doc.containsKey("rainbow") ? doc["rainbow"].as<bool>() : false;
notify.hold = doc.containsKey("hold") ? doc["hold"].as<bool>() : false;
notify.pushIcon = doc.containsKey("pushIcon") ? doc["pushIcon"] : 0;
notify.flag = true;
notify.startime = millis();
notify.scrollposition = 34;
notify.scrollposition = 9;
notify.iconWasPushed = false;
notify.iconPosition = 0;

Expand Down Expand Up @@ -387,15 +336,15 @@ void DisplayManager_::generateNotification(String payload)
void DisplayManager_::loadApps()
{
Apps.clear();
Apps.push_back(std::make_pair(0, TimeFrame));
Apps.push_back(std::make_pair("time", TimeFrame));
if (SHOW_DATE)
Apps.push_back(std::make_pair(1, DateFrame));
Apps.push_back(std::make_pair("date", DateFrame));
if (SHOW_TEMP)
Apps.push_back(std::make_pair(2, TempFrame));
Apps.push_back(std::make_pair("temp", TempFrame));
if (SHOW_HUM)
Apps.push_back(std::make_pair(3, HumFrame));
Apps.push_back(std::make_pair("hum", HumFrame));
if (SHOW_BATTERY)
Apps.push_back(std::make_pair(4, BatFrame));
Apps.push_back(std::make_pair("bat", BatFrame));
// if (SHOW_WEATHER)
// Apps.push_back(std::make_pair(5, WeatherFrame));
nativeAppsCount = Apps.size();
Expand Down Expand Up @@ -531,3 +480,16 @@ void DisplayManager_::gererateTimer(String Payload)
int interval = difftime(futureTime, now) * 1000;
TimerTicker.attach_ms(interval, timerCallback);
}

void DisplayManager_::switchToApp(String Payload)
{
DynamicJsonDocument doc(512);
DeserializationError error = deserializeJson(doc, Payload);
if (error)
return;
String name = doc["name"].as<String>();
bool fast = doc["fast"] | false;
int index = findAppIndexByName(name);
if (index > -1)
ui.transitionToApp(index);
}
5 changes: 3 additions & 2 deletions src/DisplayManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,10 @@ class DisplayManager_
void setFPS(uint8_t);
void MatrixState(bool);
void generateNotification(String);
void generateCustomPage(uint16_t, String);
void printText(int16_t x, int16_t y, const char *text, bool centered);
void generateCustomPage(String, String);
void printText(int16_t x, int16_t y, const char *text, bool centered, bool ignoreUppercase);
bool setAutoTransition(bool active);
void switchToApp(String Payload);
void drawGIF(uint16_t x, uint16_t y, fs::File gifFile);
void drawJPG(uint16_t x, uint16_t y, fs::File jpgFile);
};
Expand Down
Loading

0 comments on commit 7b5a4d3

Please sign in to comment.