Skip to content

Commit

Permalink
- add gamemode
Browse files Browse the repository at this point in the history
- add ne timemodes
- fix bargraph
  • Loading branch information
Blueforcer committed Jan 4, 2025
1 parent 4a1ad2f commit fdf656d
Show file tree
Hide file tree
Showing 21 changed files with 1,153 additions and 287 deletions.
12 changes: 12 additions & 0 deletions diagram.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"version": 1,
"author": "Uri Shaked",
"editor": "wokwi",
"parts": [
{ "type": "wokwi-esp32-devkit-v1", "id": "esp", "top": -78.19, "left": 44.14, "attrs": {} }
],
"connections": [
[ "esp:TX0", "$serialMonitor:RX", "", [] ],
[ "esp:RX0", "$serialMonitor:TX", "", [] ]
]
}
1 change: 1 addition & 0 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ framework = arduino
board_build.f_cpu = 240000000L
upload_speed = 921600
monitor_speed = 115200
target_firm = env.ElfToHex(join("$BUILD_DIR", "${PROGNAME}"), target_elf)
monitor_filters = esp32_exception_decoder
lib_deps =
bblanchon/ArduinoJson@^6.20.0
Expand Down
160 changes: 137 additions & 23 deletions src/Apps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,26 @@
#include "Overlays.h"
#include "timer.h"

const uint8_t bigdigits_mask[12][7] = {
{132, 48, 48, 48, 48, 48, 132}, // 0
{204, 140, 204, 204, 204, 204, 0}, // 1
{132, 48, 240, 196, 156, 48, 0}, // 2
{132, 48, 240, 196, 240, 48, 132}, // 3
{228, 196, 132, 36, 0, 228, 192}, // 4
{0, 60, 4, 240, 240, 48, 132}, // 5
{196, 156, 60, 4, 48, 48, 132}, // 6
{0, 48, 240, 228, 204, 204, 204}, // 7
{132, 48, 48, 132, 48, 48, 132}, // 8
{132, 48, 48, 128, 240, 228, 140}, // 9
{252, 204, 204, 252, 204, 204, 252}, // :
{252, 252, 252, 252, 252, 252, 252} // ; (blank)
};

uint32_t COLOR_HOUR_ON = 0xFF0000; // Rot
uint32_t COLOR_MINUTE_ON = 0x00FF00; // Grün
uint32_t COLOR_SECOND_ON = 0x0000FF; // Blau
uint32_t COLOR_OFF = 0xFFFFFF; // Weiß

uint16_t nativeAppsCount;

int WEATHER_CODE;
Expand Down Expand Up @@ -88,6 +108,99 @@ void TimeApp(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state, int16_t x,
return;
CURRENT_APP = "Time";
currentCustomApp = "";
const char *timeformat = getTimeFormat();
if (TIME_MODE == 5)
{

char t[20];
strftime(t, sizeof(t), timeformat, timer_localtime());

static bool BIGTIME_BG_CHECKED = false;
static bool BIGTIME_BG_ISGIF = false;
static File BIGTIME_BG_GIF;
static uint16_t BIGTIME_BG_CURRENTFRAME = 0;
if (!BIGTIME_BG_CHECKED)
{
if (LittleFS.exists("/bigtime.gif"))
{
BIGTIME_BG_GIF = LittleFS.open("/bigtime.gif");
BIGTIME_BG_ISGIF = true;
}

BIGTIME_BG_CHECKED = true;
}

if (BIGTIME_BG_ISGIF)
{
gifPlayer->playGif(0 + x, 0 + y, &BIGTIME_BG_GIF, BIGTIME_BG_CURRENTFRAME);
BIGTIME_BG_CURRENTFRAME = gifPlayer->getFrame();
}
else
{
DisplayManager.drawFilledRect(0 + x, 0 + y, 32, 8, TEXTCOLOR_888);
}

t[2] = (timeformat[2] == ' ' && timer_time() % 2) ? ';' : ':';
t[0] = t[0] == ' ' ? ';' : t[0];
for (int i = 0; i < 5; i++)
{
int xx = i * 7 - (i > 2 ? 2 : 0) - (i == 2);
matrix->drawBitmap(xx + x, y, bigdigits_mask[t[i] - '0'], 6, 7, 0);
}

matrix->drawFastHLine(0 + x, 7 + y, 32, 0);
matrix->drawFastVLine(6 + x, 0 + y, 7, 0);
matrix->drawFastVLine(25 + x, 0 + y, 7, 0);
return;
}
else if (TIME_MODE == 6)
{

struct tm *currentTime = timer_localtime();
int hour = currentTime->tm_hour;
int minute = currentTime->tm_min;
int second = currentTime->tm_sec;

auto drawBit = [&](int bit, int x1, int y1, uint32_t colorOn, uint32_t colorOff)
{
bool isSet = bit;
uint32_t color = isSet ? colorOn : colorOff;
for (int dx = 0; dx < 2; dx++)
{
for (int dy = 0; dy < 2; dy++)
{
matrix->drawPixel(x1 + dx + x, y1 + dy + y, color);
}
}
};

for (int i = 0; i < 6; i++)
{
int bitValue = (hour >> (6 - 1 - i)) & 1;
int x1 = 5 + i * 4;
int y1 = 0;
drawBit(bitValue, x1 + x, y1 + y, COLOR_HOUR_ON, COLOR_OFF);
}

for (int i = 0; i < 6; i++)
{
int bitValue = (minute >> (6 - 1 - i)) & 1;
int x1 = 5 + i * 4;
int y1 = 3;
drawBit(bitValue, x1 + x, y1 + y, COLOR_MINUTE_ON, COLOR_OFF);
}

for (int i = 0; i < 6; i++)
{
int bitValue = (second >> (6 - 1 - i)) & 1;
int x1 = 5 + i * 4;
int y1 = 6;
drawBit(bitValue, x1 + x, y1 + y, COLOR_SECOND_ON, COLOR_OFF);
}

return;
}

if (TIME_COLOR > 0)
{
DisplayManager.setTextColor(TIME_COLOR);
Expand All @@ -97,7 +210,6 @@ void TimeApp(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state, int16_t x,
DisplayManager.getInstance().resetTextColor();
}

const char *timeformat = getTimeFormat();
char t[20];
if (timeformat[2] == ' ')
{
Expand Down Expand Up @@ -131,7 +243,7 @@ void TimeApp(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state, int16_t x,
{
// week days on bottom line
wdPosY = 7;
timePosY = 6 ;
timePosY = 6;
}

// time
Expand Down Expand Up @@ -299,11 +411,14 @@ void BatApp(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state, int16_t x, i
}
#endif

String replacePlaceholders(String text) {
String replacePlaceholders(String text)
{
int start = 0;
while ((start = text.indexOf("{{", start)) != -1) {
while ((start = text.indexOf("{{", start)) != -1)
{
int end = text.indexOf("}}", start);
if (end == -1) {
if (end == -1)
{
break;
}
String placeholder = text.substring(start + 2, end);
Expand Down Expand Up @@ -362,28 +477,27 @@ void ShowCustomApp(String name, FastLED_NeoMatrix *matrix, MatrixDisplayUiState
ca->isGif = isGifFlags[i];
ca->icon = LittleFS.open(filePath);
ca->currentFrame = 0;
break; // Exit loop if icon was found
break;
}
}
// ca->iconSearched = true;
}

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

uint16_t textWidth = 0;
if (!ca->fragments.empty())
{
for (const auto &fragment : ca->fragments)
uint16_t textWidth = 0;
if (!ca->fragments.empty())
{
for (const auto &fragment : ca->fragments)
{
String replacedFragment = replacePlaceholders(fragment);
textWidth += getTextWidth(replacedFragment.c_str(), ca->textCase);
}
}
else
{
String replacedFragment = replacePlaceholders(fragment);
textWidth += getTextWidth(replacedFragment.c_str(), ca->textCase);
String replacedText = replacePlaceholders(ca->text);
textWidth = getTextWidth(replacedText.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 @@ -547,7 +661,7 @@ else
textX = hasIcon ? 9 : 0;
}

String text =replacePlaceholders(ca->text);
String text = replacePlaceholders(ca->text);

if (noScrolling)
{
Expand All @@ -558,15 +672,15 @@ else
int16_t fragmentX = textX + ca->textOffset;
for (size_t i = 0; i < ca->fragments.size(); ++i)
{
String text =replacePlaceholders(ca->fragments[i]);
String text = replacePlaceholders(ca->fragments[i]);
DisplayManager.setTextColor(TextEffect(ca->colors[i], ca->fade, ca->blink));
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);
String text = replacePlaceholders(ca->text);
if (ca->rainbow)
{
DisplayManager.HSVtext(x + textX + ca->textOffset, 6 + y, text.c_str(), false, ca->textCase);
Expand All @@ -589,7 +703,7 @@ else
int16_t fragmentX = ca->scrollposition + ca->textOffset;
for (size_t i = 0; i < ca->fragments.size(); ++i)
{
String text =replacePlaceholders(ca->fragments[i]);
String text = replacePlaceholders(ca->fragments[i]);
DisplayManager.setTextColor(TextEffect(ca->colors[i], ca->fade, ca->blink));
DisplayManager.printText(x + fragmentX, y + 6, text.c_str(), false, ca->textCase);
fragmentX += getTextWidth(text.c_str(), ca->textCase);
Expand Down
2 changes: 2 additions & 0 deletions src/Apps.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

struct CustomApp
{
int bounceDir = 0;
bool hasCustomColor = false;
uint8_t currentFrame = 0;
String iconName;
Expand All @@ -15,6 +16,7 @@ struct CustomApp
int16_t scrollDelay = 0;
byte lifetimeMode = 0;
String text;
bool bounce = false;
uint32_t color;
File icon;
bool isGif;
Expand Down
43 changes: 29 additions & 14 deletions src/DisplayManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#include <AwtrixFont.h>
#include <HTTPClient.h>
#include "base64.hpp"
#include "GameManager.h"
#include "Games/GameManager.h"

unsigned long lastArtnetStatusTime = 0;
const int numberOfChannels = 256 * 3;
Expand Down Expand Up @@ -568,6 +568,10 @@ bool DisplayManager_::generateCustomPage(const String &name, JsonObject doc, boo
auto color = doc["barBC"];
customApp.barBG = getColorFromJsonVariant(color, 0);
}
else
{
customApp.barBG = 0;
}
JsonArray data = doc[key];
int index = 0;
int maximum = 0;
Expand Down Expand Up @@ -635,6 +639,7 @@ bool DisplayManager_::generateCustomPage(const String &name, JsonObject doc, boo
customApp.lifetime = 0;
}

customApp.bounce = doc.containsKey("bounce") ? doc["bounce"].as<bool>() : false;
customApp.iconOffset = doc.containsKey("iconOffset") ? doc["iconOffset"] : 0;
customApp.textOffset = doc.containsKey("textOffset") ? doc["textOffset"] : 0;
customApp.scrollSpeed = doc.containsKey("scrollSpeed") ? doc["scrollSpeed"].as<int>() : -1;
Expand Down Expand Up @@ -709,21 +714,15 @@ 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>();
parseFragmentsText(textArray, customApp.colors, customApp.fragments, customApp.color);
// Der Code zur Zuweisung von customApp.text könnte hier angepasst werden, je nachdem, wie Sie die Textinformationen verwenden möchten.
}
else if (doc.containsKey("text") && doc["text"].is<String>())
else if (doc.containsKey("text"))
{
String text = doc["text"];
String text = doc["text"].as<String>();
subscribeToPlaceholders(utf8ascii(text));
customApp.text = utf8ascii(text);
}
else
Expand Down Expand Up @@ -1216,7 +1215,6 @@ void DisplayManager_::tick()
{
if (GAME_ACTIVE)
{
matrix->clear();
GameManager.tick();
matrix->show();
}
Expand Down Expand Up @@ -1495,15 +1493,18 @@ void DisplayManager_::drawBarChart(int16_t x, int16_t y, const int data[], byte
{
int x1 = x + startX + i * (barWidth + gap);
int barHeight = data[i];
int y1 = (barHeight > 0) ? (8 - barHeight) : 8;

if (barBG > 0)
{
// Draw background bar
drawFilledRect(x1, y, barWidth, 8, barBG);
}

int y1 = (barHeight > 0) ? (8 - barHeight) : 8;
drawFilledRect(x1, y1 + y, barWidth, barHeight, color);
if (barHeight > 0)
{
drawFilledRect(x1, y1 + y, barWidth, barHeight, color);
}
}
}

Expand Down Expand Up @@ -2094,6 +2095,20 @@ void DisplayManager_::setNewSettings(const char *json)
return;
}

if (doc.containsKey("GAMEMODE"))
{
bool gamemode = doc["GAMEMODE"];
GameManager.start(gamemode);
return;
}

if (doc.containsKey("GAME"))
{
int game = doc["GAME"];
GameManager.ChooseGame(game);
return;
}

TIME_MODE = doc.containsKey("TMODE") ? doc["TMODE"].as<int>() : TIME_MODE;
TRANS_EFFECT = doc.containsKey("TEFF") ? doc["TEFF"] : TRANS_EFFECT;
TIME_PER_TRANSITION = doc.containsKey("TSPEED") ? doc["TSPEED"] : TIME_PER_TRANSITION;
Expand Down Expand Up @@ -2575,7 +2590,7 @@ void DisplayManager_::drawLine(int16_t x0, int16_t y0, int16_t x1, int16_t y1, u
}
}

void DisplayManager_::drawRGBBitmap(int16_t x, int16_t y, uint32_t *bitmap, int16_t w, int16_t h)
void DisplayManager_::drawRGBBitmap(int16_t x, int16_t y, const uint32_t *bitmap, int16_t w, int16_t h)
{
for (int16_t i = 0; i < w; i++)
{
Expand Down
2 changes: 1 addition & 1 deletion src/DisplayManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ class DisplayManager_
void drawFilledRect(int16_t x, int16_t y, int16_t w, int16_t h, uint32_t color);
void drawLine(int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint32_t color);
void drawPixel(int16_t x0, int16_t y0, uint32_t color);
void drawRGBBitmap(int16_t x, int16_t y, uint32_t *bitmap, int16_t w, int16_t h);
void drawRGBBitmap(int16_t x, int16_t y, const uint32_t *bitmap, int16_t w, int16_t h);
void drawCircle(int16_t x0, int16_t y0, int16_t r, uint32_t color);
void fillCircle(int16_t x0, int16_t y0, int16_t r, uint32_t color);
void drawFastVLine(int16_t x, int16_t y, int16_t h, uint32_t color);
Expand Down
Loading

0 comments on commit fdf656d

Please sign in to comment.