- Buffer de transicion persistente (sprTrans) de 25KB asignado una sola vez en setup() para evitar fallos de memoria heap contigua - Eliminacion de carga y descarga dinamica de fuentes en renderPage2ToSprite durante las transiciones para evitar fugas de RAM - Timeout de seguridad por hardware de 250ms en waitForTouchRelease() para prevenir bloqueos por ruido en la lamina resistiva - Pantallas 2 y 3: Reloj atomico GPS con DSEG7 de 80pt y Telemetria satelital completa (rumbo, satelites, altitud, coordenadas) - Documentacion de conexion y pines para modulo GPS N32+/U-blox
70 lines
No EOL
1.7 KiB
C
70 lines
No EOL
1.7 KiB
C
#pragma once
|
|
|
|
#include "SoftSPI.h"
|
|
#include "XPT2046_TouchscreenSOFTSPI.h"
|
|
|
|
// Touchscreen pins for Cheap Yellow Display (CYD)
|
|
#define XPT2046_MOSI 32 // T_DIN
|
|
#define XPT2046_MISO 39 // T_OUT
|
|
#define XPT2046_CLK 25 // T_CLK
|
|
#define XPT2046_CS 33 // T_CS
|
|
|
|
extern SoftSPI *tsSoftSpi;
|
|
extern XPT2046_TouchscreenSOFTSPI ts;
|
|
|
|
#define TFT_GREY 0x5AEB
|
|
#define _height 240
|
|
#define _width 320
|
|
|
|
// Get mapped touchscreen coordinates in landscape (320x240)
|
|
bool getTouch(uint16_t *x, uint16_t *y) {
|
|
if (!tsSoftSpi)
|
|
return false;
|
|
|
|
if (ts.touched(tsSoftSpi)) {
|
|
TS_Point p = ts.getPoint(tsSoftSpi);
|
|
|
|
// Filter noise: require valid touch pressure and coordinates within active
|
|
// screen
|
|
if (p.z < 160)
|
|
return false;
|
|
if (p.x < 150 || p.x > 3850 || p.y < 150 || p.y > 3850)
|
|
return false;
|
|
|
|
int16_t tx = map(p.x, 200, 3700, 0, 320);
|
|
int16_t ty = map(p.y, 240, 3800, 0, 240);
|
|
|
|
*x = constrain(tx, 0, 319);
|
|
*y = constrain(ty, 0, 239);
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
// Direct touch check using pressure Z
|
|
inline bool isScreenPressed() {
|
|
if (!tsSoftSpi)
|
|
return false;
|
|
return ts.touched(tsSoftSpi);
|
|
}
|
|
|
|
// Wait until both touchscreen and selector button are completely released with
|
|
// 30ms continuous debounce and 250ms maximum hardware safety timeout
|
|
inline void waitForTouchRelease() {
|
|
uint16_t dummyX, dummyY;
|
|
uint8_t releaseCount = 0;
|
|
uint32_t startWait = millis();
|
|
while (releaseCount < 3 && (millis() - startWait < 250)) {
|
|
if (getTouch(&dummyX, &dummyY) || (digitalRead(SELECTOR_PIN) == LOW)) {
|
|
releaseCount = 0;
|
|
} else {
|
|
releaseCount++;
|
|
}
|
|
delay(10);
|
|
yield();
|
|
}
|
|
}
|
|
|
|
void touch_calibrate() {
|
|
// Calibration placeholder for backward compatibility
|
|
} |