refactor(Style): Add font abstraction and CSS-like styling constants
This commit is contained in:
@@ -1,5 +1,85 @@
|
||||
#include "DisplayDriverTFT.h"
|
||||
|
||||
#include <Arduino.h>
|
||||
#include <KlubhausCore.h>
|
||||
#include <TFT_eSPI.h>
|
||||
|
||||
extern DisplayManager display;
|
||||
|
||||
// ── Fonts ───────────────────────────────────────────────────
|
||||
// TFT_eSPI built-in fonts for 320x240 display (further scaled)
|
||||
// Using FreeFonts for better readability
|
||||
|
||||
void DisplayDriverTFT::setTitleFont() { _tft.setFreeFont(&FreeSansBold12pt7b); }
|
||||
|
||||
void DisplayDriverTFT::setBodyFont() { _tft.setFreeFont(&FreeSans9pt7b); }
|
||||
|
||||
void DisplayDriverTFT::setLabelFont() { _tft.setFreeFont(&FreeSans9pt7b); }
|
||||
|
||||
void DisplayDriverTFT::setDefaultFont() { _tft.setTextFont(2); }
|
||||
|
||||
// ── Test harness ───────────────────────────────────────────────
|
||||
|
||||
// Test harness: parse serial commands to inject synthetic touches
|
||||
// Commands:
|
||||
// TEST:touch x y press - simulate press at (x, y)
|
||||
// TEST:touch x y release - simulate release at (x, y)
|
||||
// TEST:touch clear - clear test mode
|
||||
bool DisplayDriverTFT::parseTestTouch(int* outX, int* outY, bool* outPressed) {
|
||||
if(!Serial.available())
|
||||
return false;
|
||||
|
||||
if(Serial.peek() != 'T') {
|
||||
return false;
|
||||
}
|
||||
|
||||
String cmd = Serial.readStringUntil('\n');
|
||||
cmd.trim();
|
||||
|
||||
if(!cmd.startsWith("TEST:touch"))
|
||||
return false;
|
||||
|
||||
int firstSpace = cmd.indexOf(' ');
|
||||
if(firstSpace < 0)
|
||||
return false;
|
||||
|
||||
String args = cmd.substring(firstSpace + 1);
|
||||
args.trim();
|
||||
|
||||
if(args.equals("clear")) {
|
||||
_testMode = false;
|
||||
Serial.println("[TEST] Test mode cleared");
|
||||
return false;
|
||||
}
|
||||
|
||||
int secondSpace = args.indexOf(' ');
|
||||
if(secondSpace < 0)
|
||||
return false;
|
||||
|
||||
String xStr = args.substring(0, secondSpace);
|
||||
String yState = args.substring(secondSpace + 1);
|
||||
yState.trim();
|
||||
|
||||
int x = xStr.toInt();
|
||||
int y = yState.substring(0, yState.indexOf(' ')).toInt();
|
||||
String state = yState.substring(yState.indexOf(' ') + 1);
|
||||
state.trim();
|
||||
|
||||
bool pressed = state.equals("press");
|
||||
|
||||
Serial.printf("[TEST] Injecting touch: (%d,%d) %s\n", x, y, pressed ? "press" : "release");
|
||||
|
||||
if(outX)
|
||||
*outX = x;
|
||||
if(outY)
|
||||
*outY = y;
|
||||
if(outPressed)
|
||||
*outPressed = pressed;
|
||||
|
||||
_testMode = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
void DisplayDriverTFT::begin() {
|
||||
// Backlight
|
||||
pinMode(PIN_LCD_BL, OUTPUT);
|
||||
@@ -145,6 +225,34 @@ void DisplayDriverTFT::drawDashboard(const ScreenState& st) {
|
||||
|
||||
TouchEvent DisplayDriverTFT::readTouch() {
|
||||
TouchEvent evt;
|
||||
|
||||
// Check for test injection via serial
|
||||
int testX, testY;
|
||||
bool testPressed;
|
||||
if(parseTestTouch(&testX, &testY, &testPressed)) {
|
||||
if(testPressed && !_touchWasPressed) {
|
||||
evt.pressed = true;
|
||||
_touchDownX = testX;
|
||||
_touchDownY = testY;
|
||||
evt.downX = _touchDownX;
|
||||
evt.downY = _touchDownY;
|
||||
} else if(!testPressed && _touchWasPressed) {
|
||||
evt.released = true;
|
||||
evt.downX = _touchDownX;
|
||||
evt.downY = _touchDownY;
|
||||
}
|
||||
|
||||
if(testPressed) {
|
||||
evt.x = testX;
|
||||
evt.y = testY;
|
||||
evt.downX = _touchDownX;
|
||||
evt.downY = _touchDownY;
|
||||
}
|
||||
|
||||
_touchWasPressed = testPressed;
|
||||
return evt;
|
||||
}
|
||||
|
||||
uint16_t tx, ty;
|
||||
uint8_t touched = _tft.getTouch(&tx, &ty, 100);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user