mirror of
https://github.com/justLV/onju-v2
synced 2026-04-21 15:47:55 +00:00
Move touch polling to FreeRTOS task (fix long press during playback)
Long-press detection was in loop() which blocks during TCP audio handling. Moved to dedicated touchTask on Core 1 that polls every 20ms regardless of what loop() is doing.
This commit is contained in:
parent
9dc9abf753
commit
daeaba9bf8
1 changed files with 23 additions and 17 deletions
|
|
@ -326,6 +326,7 @@ void setup()
|
|||
|
||||
xTaskCreatePinnedToCore(micTask, "MicTask", 4096, NULL, 1, NULL, 1);
|
||||
xTaskCreatePinnedToCore(updateLedTask, "updateLedTask", 2048, NULL, 2, NULL, 1);
|
||||
xTaskCreatePinnedToCore(touchTask, "TouchTask", 2048, NULL, 2, NULL, 1);
|
||||
}
|
||||
|
||||
void loop()
|
||||
|
|
@ -408,23 +409,6 @@ void loop()
|
|||
}
|
||||
}
|
||||
|
||||
// Long-press detection: ISR records touch-start, we poll for release
|
||||
if (centerTouchActive) {
|
||||
uint16_t touchVal = touchRead(T_C);
|
||||
unsigned long elapsed = millis() - touchStartTimeCenter;
|
||||
|
||||
if (touchVal > 1800) { // Finger released
|
||||
centerTouchActive = false;
|
||||
lastTouchTimeCenter = millis();
|
||||
|
||||
if (elapsed >= LONG_PRESS_MS) {
|
||||
handleLongPress();
|
||||
} else {
|
||||
handleShortPress();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
WiFiClient client = tcpServer.available();
|
||||
if (client)
|
||||
{
|
||||
|
|
@ -1025,6 +1009,28 @@ void setLed(uint8_t r, uint8_t g, uint8_t b, uint8_t level, uint8_t fade)
|
|||
}
|
||||
|
||||
// volume currently implemented as header from server
|
||||
void touchTask(void *parameter)
|
||||
{
|
||||
while (1) {
|
||||
if (centerTouchActive) {
|
||||
uint16_t touchVal = touchRead(T_C);
|
||||
unsigned long elapsed = millis() - touchStartTimeCenter;
|
||||
|
||||
if (touchVal > 1800) { // Finger released
|
||||
centerTouchActive = false;
|
||||
lastTouchTimeCenter = millis();
|
||||
|
||||
if (elapsed >= LONG_PRESS_MS) {
|
||||
handleLongPress();
|
||||
} else {
|
||||
handleShortPress();
|
||||
}
|
||||
}
|
||||
}
|
||||
vTaskDelay(pdMS_TO_TICKS(20)); // Poll every 20ms
|
||||
}
|
||||
}
|
||||
|
||||
void gotTouch1()
|
||||
{
|
||||
unsigned long currentTime = millis();
|
||||
|
|
|
|||
Loading…
Reference in a new issue