refactor(display): extract tile layout logic to library helper class

This commit is contained in:
2026-02-18 11:43:46 -08:00
parent 67613120ad
commit 1961631e2c
11 changed files with 244 additions and 182 deletions

View File

@@ -1,4 +1,7 @@
#include "DisplayDriverTFT.h"
#include <KlubhausCore.h>
extern DisplayManager display;
void DisplayDriverTFT::begin() {
// Backlight
@@ -134,25 +137,19 @@ void DisplayDriverTFT::drawDashboard(const ScreenState& st) {
_tft.setCursor(DISPLAY_WIDTH - 50, 5);
_tft.printf("WiFi:%s", st.wifiSsid.length() > 0 ? "ON" : "OFF");
// Render tiles via DisplayManager (abstracted to library)
// For now, draw directly using our tile implementation
constexpr int cols = 2;
constexpr int rows = 2;
constexpr int tileW = DISPLAY_WIDTH / cols;
constexpr int tileH = (DISPLAY_HEIGHT - 30) / rows;
constexpr int margin = 8;
// Get tile layouts from library helper
int tileCount = display.calculateDashboardLayouts(30, 8);
const TileLayout* layouts = display.getTileLayouts();
const char* tileLabels[] = { "Alert", "Silent", "Status", "Reboot" };
const uint16_t tileColors[] = { 0x0280, 0x0400, 0x0440, 0x0100 };
for(int i = 0; i < 4; i++) {
int col = i % cols;
int row = i / cols;
int x = col * tileW + margin;
int y = 30 + row * tileH + margin;
int w = tileW - 2 * margin;
int h = tileH - 2 * margin;
for(int i = 0; i < tileCount && i < 4; i++) {
const TileLayout& lay = layouts[i];
int x = lay.x;
int y = lay.y;
int w = lay.w;
int h = lay.h;
// Tile background
_tft.fillRoundRect(x, y, w, h, 8, tileColors[i]);
@@ -180,7 +177,6 @@ TouchEvent DisplayDriverTFT::readTouch() {
evt.pressed = true;
evt.x = tx;
evt.y = ty;
Serial.printf("[TOUCH] x=%d, y=%d\n", tx, ty);
}
return evt;
}
@@ -196,22 +192,6 @@ void DisplayDriverTFT::transformTouch(int* x, int* y) {
*y = temp;
}
void DisplayDriverTFT::drawTileAt(int x, int y, int w, int h, const char* label, uint16_t bgColor) {
// Tile background
_tft.fillRoundRect(x, y, w, h, 8, bgColor);
// Tile border
_tft.drawRoundRect(x, y, w, h, 8, TFT_WHITE);
// Tile label
_tft.setTextColor(TFT_WHITE);
_tft.setTextSize(2);
int textLen = strlen(label);
int textW = textLen * 12; // approx width
_tft.setCursor(x + w/2 - textW/2, y + h/2 - 10);
_tft.print(label);
}
HoldState DisplayDriverTFT::updateHold(unsigned long holdMs) {
HoldState h;
TouchEvent t = readTouch();

View File

@@ -14,12 +14,11 @@ public:
uint16_t getRawTouchZ();
HoldState updateHold(unsigned long holdMs) override;
void updateHint(int x, int y, bool active) override;
int width() override { return DISPLAY_WIDTH; }
int height() override { return DISPLAY_HEIGHT; }
int width() override { return _tft.width(); }
int height() override { return _tft.height(); }
// Dashboard tiles - library handles grid math, we just draw
// Dashboard - uses transform for touch coordinate correction
void transformTouch(int* x, int* y) override;
void drawTileAt(int x, int y, int w, int h, const char* label, uint16_t bgColor) override;
private:
void drawBoot(const ScreenState& st);

View File

@@ -24,11 +24,6 @@ void loop() {
// Read touch
TouchEvent evt = display.readTouch();
// Touch debug (useful for new boards)
if(evt.pressed) {
Serial.printf("[TOUCH] pressed: x=%d, y=%d\n", evt.x, evt.y);
}
// State machine tick
logic.update();