Threading/Queues and Display Gif added

This commit is contained in:
2026-10-25 00:05:24 +02:00
parent 893dfd419e
commit 70f77133e6
11 changed files with 244 additions and 110 deletions
+53 -7
View File
@@ -1,13 +1,36 @@
#include "DisplayManager.h"
#include "img/image_cards_hearts_bits.h"
#include "img/image_paint_3_bits.h"
#include "img/tenor.h"
#include <string.h>
DisplayManager::DisplayManager(int8_t cs, int8_t dc, int8_t rst)
: _tft(cs, dc, rst) {}
static void drawAnimationFrame(Adafruit_ST7789& tft, int16_t x, uint8_t frame) {
uint16_t pixels[240];
const uint8_t* bitmap = tenor_frames[frame];
tft.startWrite();
tft.setAddrWindow(x, 0, 240, 240);
for (int16_t y = 0; y < 240; y++) {
for (int16_t byteIndex = 0; byteIndex < 30; byteIndex++) {
uint8_t bits = pgm_read_byte(&bitmap[y * 30 + byteIndex]);
for (uint8_t bit = 0; bit < 8; bit++) {
pixels[byteIndex * 8 + bit] = (bits & (0x80 >> bit)) ? ST77XX_WHITE : ST77XX_BLACK;
}
}
tft.writePixels(pixels, 240);
}
tft.endWrite();
}
void DisplayManager::begin() {
_tft.init(240, 320);
_tft.setRotation(1);
clear();
drawFaceScreen();
}
void DisplayManager::clear() {
@@ -33,20 +56,35 @@ void DisplayManager::toggleState() {
}
void DisplayManager::update() {
// Put any periodic animations here (e.g., blinking face frames)
if (_currentState != STATE_FACE) return;
unsigned long now = millis();
if (_showingText) {
if (now - _textShownAt < 2000) return;
drawFaceScreen();
}
if (now - _lastScreenUpdate < 71) return;
_lastScreenUpdate = now;
int16_t x = (_tft.width() - 240) / 2;
drawAnimationFrame(_tft, x, _animationFrame);
_tft.drawBitmap(x + 105, 14, image_cards_hearts_bits, 30, 32, 0xE8EC);
_animationFrame = (_animationFrame + 1) % 8;
}
// --- DESIGNED VIA LOPAKA.APP ---
void DisplayManager::drawFaceScreen() {
_showingText = false;
_animationFrame = 0;
clear();
// Example layout elements generated/inspired by Lopaka:
_tft.setTextColor(ST77XX_CYAN);
_tft.setTextSize(3);
_tft.setCursor(90, 100);
_tft.print("^ _ ^"); // Simple default face
int16_t x = (_tft.width() - 240) / 2;
_tft.drawBitmap(x, 0, image_paint_3_bits, 240, 240, ST77XX_WHITE);
_tft.drawBitmap(x + 105, 14, image_cards_hearts_bits, 30, 32, 0xE8EC);
}
void DisplayManager::drawMenuScreen() {
_showingText = false;
clear();
// Example Menu/Stats UI layout adapted from Lopaka export
@@ -69,8 +107,16 @@ void DisplayManager::drawMenuScreen() {
}
void DisplayManager::drawCenteredText(const char* text, uint16_t color) {
if (_currentState != STATE_FACE) return; // Only override face text if we are on face screen
if (_currentState != STATE_FACE || text == nullptr) return;
if (strcmp(text, _lastText) == 0) return;
size_t textLength = strlen(text);
if (textLength >= sizeof(_lastText)) textLength = sizeof(_lastText) - 1;
memcpy(_lastText, text, textLength);
_lastText[textLength] = '\0';
_showingText = true;
_textShownAt = millis();
clear();
_tft.setTextSize(2);
_tft.setTextColor(color);