feat(display): draw hint animation at touch position instead of center
This commit is contained in:
@@ -136,6 +136,7 @@ HoldState DisplayDriverTFT::updateHold(unsigned long holdMs) {
|
|||||||
if (!_holdActive) {
|
if (!_holdActive) {
|
||||||
_holdActive = true;
|
_holdActive = true;
|
||||||
_holdStartMs = millis();
|
_holdStartMs = millis();
|
||||||
|
h.started = true;
|
||||||
}
|
}
|
||||||
uint32_t held = millis() - _holdStartMs;
|
uint32_t held = millis() - _holdStartMs;
|
||||||
h.active = true;
|
h.active = true;
|
||||||
@@ -147,8 +148,8 @@ HoldState DisplayDriverTFT::updateHold(unsigned long holdMs) {
|
|||||||
_tft.fillRect(0, DISPLAY_HEIGHT - 8, barW, 8, TFT_WHITE);
|
_tft.fillRect(0, DISPLAY_HEIGHT - 8, barW, 8, TFT_WHITE);
|
||||||
_tft.fillRect(barW, DISPLAY_HEIGHT - 8, DISPLAY_WIDTH - barW, 8, TFT_DARKGREY);
|
_tft.fillRect(barW, DISPLAY_HEIGHT - 8, DISPLAY_WIDTH - barW, 8, TFT_DARKGREY);
|
||||||
} else {
|
} else {
|
||||||
if (_ // Clear theholdActive) {
|
if (_holdActive) {
|
||||||
progress bar when released
|
// Clear the progress bar when released
|
||||||
_tft.fillRect(0, DISPLAY_HEIGHT - 8, DISPLAY_WIDTH, 8, TFT_DARKGREY);
|
_tft.fillRect(0, DISPLAY_HEIGHT - 8, DISPLAY_WIDTH, 8, TFT_DARKGREY);
|
||||||
}
|
}
|
||||||
_holdActive = false;
|
_holdActive = false;
|
||||||
@@ -156,9 +157,10 @@ HoldState DisplayDriverTFT::updateHold(unsigned long holdMs) {
|
|||||||
return h;
|
return h;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DisplayDriverTFT::updateHint() {
|
void DisplayDriverTFT::updateHint(int x, int y) {
|
||||||
float t = (millis() % 2000) / 2000.0f;
|
float t = (millis() % 2000) / 2000.0f;
|
||||||
uint8_t v = (uint8_t)(30.0f + 30.0f * sinf(t * 2 * PI));
|
uint8_t v = (uint8_t)(30.0f + 30.0f * sinf(t * 2 * PI));
|
||||||
uint16_t col = _tft.color565(v, v, v);
|
uint16_t col = _tft.color565(v, v, v);
|
||||||
_tft.drawRect(DISPLAY_WIDTH / 2 - 40, DISPLAY_HEIGHT / 2 + 20, 80, 40, col);
|
// Draw at touch position instead of center
|
||||||
|
_tft.drawRect(x - 40, y - 20, 80, 40, col);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ public:
|
|||||||
TouchEvent readTouch() override;
|
TouchEvent readTouch() override;
|
||||||
int dashboardTouch(int x, int y) override;
|
int dashboardTouch(int x, int y) override;
|
||||||
HoldState updateHold(unsigned long holdMs) override;
|
HoldState updateHold(unsigned long holdMs) override;
|
||||||
void updateHint() override;
|
void updateHint(int x, int y) override;
|
||||||
int width() override { return DISPLAY_WIDTH; }
|
int width() override { return DISPLAY_WIDTH; }
|
||||||
int height() override { return DISPLAY_HEIGHT; }
|
int height() override { return DISPLAY_HEIGHT; }
|
||||||
|
|
||||||
|
|||||||
@@ -28,18 +28,32 @@ void loop() {
|
|||||||
|
|
||||||
// ── Touch handling ──
|
// ── Touch handling ──
|
||||||
const ScreenState& st = logic.getScreenState();
|
const ScreenState& st = logic.getScreenState();
|
||||||
|
static int holdStartX = -1;
|
||||||
|
static int holdStartY = -1;
|
||||||
|
|
||||||
if (st.deviceState == DeviceState::ALERTING) {
|
if (st.deviceState == DeviceState::ALERTING) {
|
||||||
HoldState h = display.updateHold(HOLD_TO_SILENCE_MS);
|
HoldState h = display.updateHold(HOLD_TO_SILENCE_MS);
|
||||||
if (h.completed) {
|
if (h.completed) {
|
||||||
logic.silenceAlert();
|
logic.silenceAlert();
|
||||||
|
holdStartX = -1;
|
||||||
|
holdStartY = -1;
|
||||||
}
|
}
|
||||||
if (!h.active) {
|
if (h.started) {
|
||||||
display.updateHint();
|
TouchEvent t = display.readTouch();
|
||||||
|
holdStartX = t.x;
|
||||||
|
holdStartY = t.y;
|
||||||
|
}
|
||||||
|
if (!h.active && holdStartX >= 0) {
|
||||||
|
display.updateHint(holdStartX, holdStartY);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
holdStartX = -1;
|
||||||
|
holdStartY = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (st.screen == ScreenID::DASHBOARD) {
|
||||||
TouchEvent evt = display.readTouch();
|
TouchEvent evt = display.readTouch();
|
||||||
if (evt.pressed && st.screen == ScreenID::DASHBOARD) {
|
if (evt.pressed) {
|
||||||
int tile = display.dashboardTouch(evt.x, evt.y);
|
int tile = display.dashboardTouch(evt.x, evt.y);
|
||||||
if (tile >= 0) Serial.printf("[DASH] Tile %d tapped\n", tile);
|
if (tile >= 0) Serial.printf("[DASH] Tile %d tapped\n", tile);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -108,6 +108,7 @@ HoldState DisplayDriverGFX::updateHold(unsigned long holdMs) {
|
|||||||
|
|
||||||
if(!_isHolding) {
|
if(!_isHolding) {
|
||||||
_isHolding = true;
|
_isHolding = true;
|
||||||
|
state.started = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
state.active = true;
|
state.active = true;
|
||||||
@@ -234,7 +235,7 @@ void DisplayDriverGFX::drawDashboard(const ScreenState& state) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DisplayDriverGFX::updateHint() {
|
void DisplayDriverGFX::updateHint(int x, int y) {
|
||||||
if(!_gfx)
|
if(!_gfx)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -249,5 +250,6 @@ void DisplayDriverGFX::updateHint() {
|
|||||||
uint8_t v = static_cast<uint8_t>(30.0f + 30.0f * sinf(t * 2 * 3.14159f));
|
uint8_t v = static_cast<uint8_t>(30.0f + 30.0f * sinf(t * 2 * 3.14159f));
|
||||||
uint16_t col = ((v >> 3) << 11) | ((v >> 2) << 5) | (v >> 3);
|
uint16_t col = ((v >> 3) << 11) | ((v >> 2) << 5) | (v >> 3);
|
||||||
|
|
||||||
_gfx->drawCircle(DISP_W / 2, DISP_H / 2, 50, col);
|
// Draw at touch position instead of center
|
||||||
|
_gfx->drawCircle(x, y, 50, col);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ public:
|
|||||||
TouchEvent readTouch() override;
|
TouchEvent readTouch() override;
|
||||||
int dashboardTouch(int x, int y) override;
|
int dashboardTouch(int x, int y) override;
|
||||||
HoldState updateHold(unsigned long holdMs) override;
|
HoldState updateHold(unsigned long holdMs) override;
|
||||||
void updateHint() override;
|
void updateHint(int x, int y) override;
|
||||||
|
|
||||||
int width() override;
|
int width() override;
|
||||||
int height() override;
|
int height() override;
|
||||||
|
|||||||
@@ -28,15 +28,32 @@ void loop() {
|
|||||||
|
|
||||||
const ScreenState& st = logic.getScreenState();
|
const ScreenState& st = logic.getScreenState();
|
||||||
|
|
||||||
|
// Track initial hold position for hint
|
||||||
|
static int holdStartX = -1;
|
||||||
|
static int holdStartY = -1;
|
||||||
|
|
||||||
if(st.deviceState == DeviceState::ALERTING) {
|
if(st.deviceState == DeviceState::ALERTING) {
|
||||||
HoldState h = display.updateHold(HOLD_TO_SILENCE_MS);
|
HoldState h = display.updateHold(HOLD_TO_SILENCE_MS);
|
||||||
if(h.completed) {
|
if(h.completed) {
|
||||||
logic.silenceAlert();
|
logic.silenceAlert();
|
||||||
|
holdStartX = -1;
|
||||||
|
holdStartY = -1;
|
||||||
}
|
}
|
||||||
if(!h.active) {
|
if(h.started) {
|
||||||
display.updateHint();
|
// Capture initial touch position
|
||||||
|
holdStartX = evt.x;
|
||||||
|
holdStartY = evt.y;
|
||||||
}
|
}
|
||||||
} else if(evt.pressed) {
|
if(!h.active && holdStartX >= 0) {
|
||||||
|
display.updateHint(holdStartX, holdStartY);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Reset when not alerting
|
||||||
|
holdStartX = -1;
|
||||||
|
holdStartY = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(evt.pressed) {
|
||||||
if(st.screen == ScreenID::OFF) {
|
if(st.screen == ScreenID::OFF) {
|
||||||
// Tap in OFF mode → wake to DASHBOARD
|
// Tap in OFF mode → wake to DASHBOARD
|
||||||
Serial.println("[TOUCH] OFF → DASHBOARD");
|
Serial.println("[TOUCH] OFF → DASHBOARD");
|
||||||
@@ -46,15 +63,12 @@ void loop() {
|
|||||||
int tile = display.dashboardTouch(evt.x, evt.y);
|
int tile = display.dashboardTouch(evt.x, evt.y);
|
||||||
if(tile >= 0) {
|
if(tile >= 0) {
|
||||||
Serial.printf("[DASH] Tile %d tapped\n", tile);
|
Serial.printf("[DASH] Tile %d tapped\n", tile);
|
||||||
// TODO: Handle tile actions
|
|
||||||
}
|
}
|
||||||
} else if(st.screen == ScreenID::ALERT) {
|
} else if(st.screen == ScreenID::ALERT) {
|
||||||
// Tap in ALERT mode → could dismiss or show more info
|
|
||||||
Serial.println("[TOUCH] ALERT tap");
|
Serial.println("[TOUCH] ALERT tap");
|
||||||
// For now, let's make tap do nothing (hold to silence only)
|
|
||||||
// Or: logic.dismissAlert();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(Serial.available()) {
|
if(Serial.available()) {
|
||||||
String cmd = Serial.readStringUntil('\n');
|
String cmd = Serial.readStringUntil('\n');
|
||||||
cmd.trim();
|
cmd.trim();
|
||||||
|
|||||||
@@ -5,17 +5,31 @@
|
|||||||
/// Board sketch creates the concrete driver and passes it in.
|
/// Board sketch creates the concrete driver and passes it in.
|
||||||
class DisplayManager {
|
class DisplayManager {
|
||||||
public:
|
public:
|
||||||
DisplayManager() : _drv(nullptr) {}
|
DisplayManager()
|
||||||
explicit DisplayManager(IDisplayDriver* drv) : _drv(drv) {}
|
: _drv(nullptr) { }
|
||||||
|
explicit DisplayManager(IDisplayDriver* drv)
|
||||||
|
: _drv(drv) { }
|
||||||
void setDriver(IDisplayDriver* drv) { _drv = drv; }
|
void setDriver(IDisplayDriver* drv) { _drv = drv; }
|
||||||
|
|
||||||
void begin() { if (_drv) _drv->begin(); }
|
void begin() {
|
||||||
void setBacklight(bool on) { if (_drv) _drv->setBacklight(on); }
|
if(_drv)
|
||||||
void render(const ScreenState& st) { if (_drv) _drv->render(st); }
|
_drv->begin();
|
||||||
TouchEvent readTouch() { return _drv ? _drv->readTouch() : TouchEvent{}; }
|
}
|
||||||
|
void setBacklight(bool on) {
|
||||||
|
if(_drv)
|
||||||
|
_drv->setBacklight(on);
|
||||||
|
}
|
||||||
|
void render(const ScreenState& st) {
|
||||||
|
if(_drv)
|
||||||
|
_drv->render(st);
|
||||||
|
}
|
||||||
|
TouchEvent readTouch() { return _drv ? _drv->readTouch() : TouchEvent {}; }
|
||||||
int dashboardTouch(int x, int y) { return _drv ? _drv->dashboardTouch(x, y) : -1; }
|
int dashboardTouch(int x, int y) { return _drv ? _drv->dashboardTouch(x, y) : -1; }
|
||||||
HoldState updateHold(unsigned long ms) { return _drv ? _drv->updateHold(ms) : HoldState{}; }
|
HoldState updateHold(unsigned long ms) { return _drv ? _drv->updateHold(ms) : HoldState {}; }
|
||||||
void updateHint() { if (_drv) _drv->updateHint(); }
|
void updateHint(int x, int y) {
|
||||||
|
if(_drv)
|
||||||
|
_drv->updateHint(x, y);
|
||||||
|
}
|
||||||
int width() { return _drv ? _drv->width() : 0; }
|
int width() { return _drv ? _drv->width() : 0; }
|
||||||
int height() { return _drv ? _drv->height() : 0; }
|
int height() { return _drv ? _drv->height() : 0; }
|
||||||
|
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ public:
|
|||||||
|
|
||||||
/// Externally trigger silence (e.g. hold-to-silence gesture).
|
/// Externally trigger silence (e.g. hold-to-silence gesture).
|
||||||
void silenceAlert();
|
void silenceAlert();
|
||||||
|
void setScreen(ScreenID s);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void pollTopics();
|
void pollTopics();
|
||||||
@@ -34,7 +35,6 @@ private:
|
|||||||
void flushStatus(const String& message);
|
void flushStatus(const String& message);
|
||||||
void heartbeat();
|
void heartbeat();
|
||||||
void transition(DeviceState s);
|
void transition(DeviceState s);
|
||||||
void setScreen(ScreenID s);
|
|
||||||
String topicUrl(const char* base);
|
String topicUrl(const char* base);
|
||||||
|
|
||||||
DisplayManager* _display;
|
DisplayManager* _display;
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ struct TouchEvent {
|
|||||||
|
|
||||||
struct HoldState {
|
struct HoldState {
|
||||||
bool active = false;
|
bool active = false;
|
||||||
|
bool started = false;
|
||||||
bool completed = false;
|
bool completed = false;
|
||||||
float progress = 0.0f; // 0.0 – 1.0
|
float progress = 0.0f; // 0.0 – 1.0
|
||||||
};
|
};
|
||||||
@@ -31,7 +32,7 @@ public:
|
|||||||
/// Track a long-press gesture; returns progress/completion.
|
/// Track a long-press gesture; returns progress/completion.
|
||||||
virtual HoldState updateHold(unsigned long holdMs) = 0;
|
virtual HoldState updateHold(unsigned long holdMs) = 0;
|
||||||
/// Idle hint animation (e.g. pulsing ring) while alert is showing.
|
/// Idle hint animation (e.g. pulsing ring) while alert is showing.
|
||||||
virtual void updateHint() = 0;
|
virtual void updateHint(int x, int y) = 0;
|
||||||
|
|
||||||
virtual int width() = 0;
|
virtual int width() = 0;
|
||||||
virtual int height() = 0;
|
virtual int height() = 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user