Skip to content

Commit

Permalink
first upload
Browse files Browse the repository at this point in the history
  • Loading branch information
Blueforcer committed Jun 29, 2024
1 parent 574e0b8 commit d15a770
Show file tree
Hide file tree
Showing 10 changed files with 463 additions and 296 deletions.
9 changes: 6 additions & 3 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ lib_deps =
adafruit/Adafruit SHT31 Library@^2.2.0
plerup/EspSoftwareSerial@^8.1.0
maxgerhardt/ghostl
terrorsl/sMQTTBroker@^0.1.6


[env:ulanzi]
platform = espressif32@6.3.0
Expand All @@ -39,12 +41,12 @@ build_flags =
-DULANZI
-DMQTT_MAX_PACKET_SIZE=8192
-D CORE_DEBUG_LEVEL=0
-D NDEBUG
-Wno-attributes
-Os
-fno-exceptions
lib_deps =
${env.lib_deps}
${env.lib_deps}


[env:awtrix2_upgrade]
platform = espressif32
Expand All @@ -58,4 +60,5 @@ build_flags =
-Os
-fno-exceptions
lib_deps =
${env.lib_deps}
${env.lib_deps}
jonp92/TemplateTango@^1.0.1
63 changes: 42 additions & 21 deletions src/Apps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,21 @@ void BatApp(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state, int16_t x, i
}
#endif

String replacePlaceholders(String text) {
int start = 0;
while ((start = text.indexOf("{{", start)) != -1) {
int end = text.indexOf("}}", start);
if (end == -1) {
break;
}
String placeholder = text.substring(start + 2, end);
String topic = placeholder;
text.replace("{{" + placeholder + "}}", MQTTManager.getValueForTopic(topic));
start = end + 2;
}
return text;
}

void ShowCustomApp(String name, FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state, int16_t x, int16_t y, GifPlayer *gifPlayer)
{
// Abort if notifyFlag is set
Expand Down Expand Up @@ -355,19 +370,20 @@ void ShowCustomApp(String name, FastLED_NeoMatrix *matrix, MatrixDisplayUiState

bool hasIcon = ca->icon || ca->jpegDataSize > 0;

// Calculate text and available width
uint16_t textWidth = 0;
if (!ca->fragments.empty())
{
for (const auto &fragment : ca->fragments)
{
textWidth += getTextWidth(fragment.c_str(), ca->textCase);
}
}
else
uint16_t textWidth = 0;
if (!ca->fragments.empty())
{
for (const auto &fragment : ca->fragments)
{
textWidth = getTextWidth(ca->text.c_str(), ca->textCase);
String replacedFragment = replacePlaceholders(fragment);
textWidth += getTextWidth(replacedFragment.c_str(), ca->textCase);
}
}
else
{
String replacedText = replacePlaceholders(ca->text);
textWidth = getTextWidth(replacedText.c_str(), ca->textCase);
}

uint16_t availableWidth = (hasIcon) ? 24 : 32;

Expand Down Expand Up @@ -531,6 +547,8 @@ void ShowCustomApp(String name, FastLED_NeoMatrix *matrix, MatrixDisplayUiState
textX = hasIcon ? 9 : 0;
}

String text =replacePlaceholders(ca->text);

if (noScrolling)
{
ca->repeat = -1; // Disable repeat if text is too short for scrolling
Expand All @@ -540,25 +558,27 @@ void ShowCustomApp(String name, FastLED_NeoMatrix *matrix, MatrixDisplayUiState
int16_t fragmentX = textX + ca->textOffset;
for (size_t i = 0; i < ca->fragments.size(); ++i)
{
String text =replacePlaceholders(ca->fragments[i]);
DisplayManager.setTextColor(TextEffect(ca->colors[i], ca->fade, ca->blink));
DisplayManager.printText(x + fragmentX, y + 6, ca->fragments[i].c_str(), false, ca->textCase);
fragmentX += getTextWidth(ca->fragments[i].c_str(), ca->textCase);
DisplayManager.printText(x + fragmentX, y + 6, text.c_str(), false, ca->textCase);
fragmentX += getTextWidth(text.c_str(), ca->textCase);
}
}
else
{
String text =replacePlaceholders(ca->text);
if (ca->rainbow)
{
DisplayManager.HSVtext(x + textX + ca->textOffset, 6 + y, ca->text.c_str(), false, ca->textCase);
DisplayManager.HSVtext(x + textX + ca->textOffset, 6 + y, text.c_str(), false, ca->textCase);
}
else if (ca->gradient[0] > -1 && ca->gradient[1] > -1)
{
DisplayManager.GradientText(x + textX + ca->textOffset, 6 + y, ca->text.c_str(), ca->gradient[0], ca->gradient[1], false, ca->textCase);
DisplayManager.GradientText(x + textX + ca->textOffset, 6 + y, text.c_str(), ca->gradient[0], ca->gradient[1], false, ca->textCase);
}
else
{
DisplayManager.setTextColor(TextEffect(ca->color, ca->fade, ca->blink));
DisplayManager.printText(x + textX + ca->textOffset, y + 6, ca->text.c_str(), false, ca->textCase);
DisplayManager.printText(x + textX + ca->textOffset, y + 6, text.c_str(), false, ca->textCase);
}
}
}
Expand All @@ -569,25 +589,26 @@ void ShowCustomApp(String name, FastLED_NeoMatrix *matrix, MatrixDisplayUiState
int16_t fragmentX = ca->scrollposition + ca->textOffset;
for (size_t i = 0; i < ca->fragments.size(); ++i)
{
String text =replacePlaceholders(ca->fragments[i]);
DisplayManager.setTextColor(TextEffect(ca->colors[i], ca->fade, ca->blink));
DisplayManager.printText(x + fragmentX, y + 6, ca->fragments[i].c_str(), false, ca->textCase);
fragmentX += getTextWidth(ca->fragments[i].c_str(), ca->textCase);
DisplayManager.printText(x + fragmentX, y + 6, text.c_str(), false, ca->textCase);
fragmentX += getTextWidth(text.c_str(), ca->textCase);
}
}
else
{
if (ca->rainbow)
{
DisplayManager.HSVtext(x + ca->scrollposition + ca->textOffset, 6 + y, ca->text.c_str(), false, ca->textCase);
DisplayManager.HSVtext(x + ca->scrollposition + ca->textOffset, 6 + y, text.c_str(), false, ca->textCase);
}
else if (ca->gradient[0] > -1 && ca->gradient[1] > -1)
{
DisplayManager.GradientText(x + ca->scrollposition + ca->textOffset, 6 + y, ca->text.c_str(), ca->gradient[0], ca->gradient[1], false, ca->textCase);
DisplayManager.GradientText(x + ca->scrollposition + ca->textOffset, 6 + y, text.c_str(), ca->gradient[0], ca->gradient[1], false, ca->textCase);
}
else
{
DisplayManager.setTextColor(TextEffect(ca->color, ca->fade, ca->blink));
DisplayManager.printText(x + ca->scrollposition + ca->textOffset, 6 + y, ca->text.c_str(), false, ca->textCase);
DisplayManager.printText(x + ca->scrollposition + ca->textOffset, 6 + y, text.c_str(), false, ca->textCase);
}
}
}
Expand Down
71 changes: 49 additions & 22 deletions src/DisplayManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,26 @@ bool DisplayManager_::parseCustomPage(const String &name, const char *json, bool
return true;
}

// Function to subscribe to MQTT topics based on placeholders in text
void subscribeToPlaceholders(String text)
{
int start = 0;
while ((start = text.indexOf("{{", start)) != -1)
{
int end = text.indexOf("}}", start);
if (end == -1)
{
break;
}
String placeholder = text.substring(start + 2, end);
String topic = placeholder;

MQTTManager.subscribe(topic.c_str());

start = end + 2;
}
}

bool DisplayManager_::generateCustomPage(const String &name, JsonObject doc, bool preventSave)
{
CustomApp customApp;
Expand Down Expand Up @@ -683,6 +703,13 @@ bool DisplayManager_::generateCustomPage(const String &name, JsonObject doc, boo

customApp.colors.clear();
customApp.fragments.clear();

if (doc.containsKey("text"))
{
String text = doc["text"];
subscribeToPlaceholders(utf8ascii(text));
}

if (doc.containsKey("text") && doc["text"].is<JsonArray>())
{
JsonArray textArray = doc["text"].as<JsonArray>();
Expand Down Expand Up @@ -1949,26 +1976,28 @@ String CRGBtoHex(CRGB color)
return String(buf);
}

String getOverlayName() {
switch(GLOBAL_OVERLAY) {
case DRIZZLE:
return "drizzle";
case RAIN:
return "rain";
case SNOW:
return "snow";
case STORM:
return "storm";
case THUNDER:
return "thunder";
case FROST:
return "frost";
case NONE:
return "clear";
default:
Serial.println(F("Invalid effect."));
return "invalid"; // Oder einen leeren String oder einen Fehlerwert zurückgeben
}
String getOverlayName()
{
switch (GLOBAL_OVERLAY)
{
case DRIZZLE:
return "drizzle";
case RAIN:
return "rain";
case SNOW:
return "snow";
case STORM:
return "storm";
case THUNDER:
return "thunder";
case FROST:
return "frost";
case NONE:
return "clear";
default:
Serial.println(F("Invalid effect."));
return "invalid"; // Oder einen leeren String oder einen Fehlerwert zurückgeben
}
}

String DisplayManager_::getSettings()
Expand Down Expand Up @@ -2018,8 +2047,6 @@ String DisplayManager_::getSettings()
return serializeJson(doc, jsonString), jsonString;
}



void DisplayManager_::setNewSettings(const char *json)
{
if (DEBUG_MODE)
Expand Down
26 changes: 26 additions & 0 deletions src/Functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,35 @@ byte utf8ascii(byte ascii)
break;

case 0xC3:
// polish
if (ascii == 0xB3) return 0x6F;
if (ascii == 0x93) return 0x4F;

return (ascii | 0xC0); // - 34;
break;

case 0xC4:
// polish
if (ascii == 0x85) return 0x61;
if (ascii == 0x84) return 0x41;
if (ascii == 0x87) return 0x63;
if (ascii == 0x86) return 0x43;
if (ascii == 0x99) return 0x65;
if (ascii == 0x98) return 0x45;

case 0xC5:
// polish
if (ascii == 0x82) return 0x6C;
if (ascii == 0x81) return 0x4C;
if (ascii == 0x84) return 0x6E;
if (ascii == 0x83) return 0x4E;
if (ascii == 0x9A) return 0x53;
if (ascii == 0xBC) return 0x7A;
if (ascii == 0xBB) return 0x5A;
if (ascii == 0xBA) return 0x7A;
if (ascii == 0xB9) return 0x5A;
if (ascii == 0x9B) return 0x73;

case 0x82:
if (ascii == 0xAC)
// return (0xEA);
Expand Down
15 changes: 11 additions & 4 deletions src/Globals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,12 @@ void loadDevSettings()
MIN_BRIGHTNESS = doc["min_brightness"];
}

if (doc.containsKey("mqtt_broker"))
{
MQTT_BROKER = doc["mqtt_broker"].as<bool>();
;
}

if (doc.containsKey("max_brightness"))
{
MAX_BRIGHTNESS = doc["max_brightness"];
Expand Down Expand Up @@ -161,7 +167,7 @@ void loadDevSettings()
HOSTNAME = doc["hostname"].as<String>();
}

if (doc.containsKey("buzzer_volume"))
if (doc.containsKey("buzzer_volume"))
{
BUZ_VOL = doc["buzzer_volume"].as<bool>();
}
Expand Down Expand Up @@ -338,7 +344,7 @@ IPAddress gateway;
IPAddress subnet;
IPAddress primaryDNS;
IPAddress secondaryDNS;
const char *VERSION = "0.96";
const char *VERSION = "0.97B2";

String MQTT_HOST = "";
uint16_t MQTT_PORT = 1883;
Expand Down Expand Up @@ -436,7 +442,7 @@ uint32_t HUM_COLOR = 0;
bool ARTNET_MODE;
bool MOODLIGHT_MODE;
long STATS_INTERVAL = 10000;
bool DEBUG_MODE = false;
bool DEBUG_MODE = true;
uint8_t MIN_BRIGHTNESS = 2;
uint8_t MAX_BRIGHTNESS = 160;
double movementFactor = 0.5;
Expand All @@ -452,4 +458,5 @@ uint32_t AP_TIMEOUT = 15;
int WEB_PORT = 80;
OverlayEffect GLOBAL_OVERLAY = NONE;
String HOSTNAME = "";
bool BUZ_VOL = false;
bool BUZ_VOL = false;
bool MQTT_BROKER = false;
1 change: 1 addition & 0 deletions src/Globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,4 +148,5 @@ extern OverlayEffect GLOBAL_OVERLAY;
extern String HOSTNAME;
extern int WEB_PORT;
extern bool BUZ_VOL;
extern bool MQTT_BROKER;
#endif // Globals_H
Loading

0 comments on commit d15a770

Please sign in to comment.