From 0e8a06d24a4e3f88f7f00b5b92edb3d98e9c70ca Mon Sep 17 00:00:00 2001 From: "DESKTOP-PUHFO60\\dsx2016" Date: Tue, 27 Oct 2026 22:06:33 +0800 Subject: [PATCH] Stabilize CYD touch: correct axes, debounce, lower-half zones. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fix raw→UI mapping, 1s action cooldown, and stop noise from auto starting/stopping recordings. Co-authored-by: Cursor --- src/main.cpp | 22 +++++++++++++--------- src/touch.cpp | 9 ++++----- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index e260bea..6ef93c8 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -130,9 +130,9 @@ static void touchscreen_read(lv_indev_t *indev, lv_indev_data_t *data) { was_pressed = false; const uint32_t held = millis() - press_ms; const uint32_t now = millis(); - /* Min hold filters spikes; max ignores long rests; cooldown stops auto-toggle. */ - if (held < 40 || held > 800) return; - if (now - last_action_ms < 900) { + /* Short SoftSPI taps are often <20ms; cooldown stops EMI auto-toggle. */ + if (held > 1200) return; + if (now - last_action_ms < 1000) { Serial.println("Touch ignored (cooldown)"); return; } @@ -354,16 +354,20 @@ static void create_ui(void) { lv_obj_set_style_text_color(hint2, COL_MUTED, 0); lv_obj_align(hint2, LV_ALIGN_BOTTOM_MID, 0, 0); - /* Force layout then capture absolute hit boxes (+pad). */ + /* Lower-half zones with gap in the middle — forgiving but not full-screen. */ lv_obj_update_layout(scr); - lv_obj_get_coords(btn_rec, &hit_rec); - lv_obj_get_coords(btn_play, &hit_play); - hit_rec.x1 -= 8; hit_rec.y1 -= 8; hit_rec.x2 += 8; hit_rec.y2 += 12; - hit_play.x1 -= 8; hit_play.y1 -= 8; hit_play.x2 += 8; hit_play.y2 += 12; + hit_rec.x1 = 0; + hit_rec.x2 = UI_HOR_RES / 2 - 12; + hit_rec.y1 = 110; + hit_rec.y2 = UI_VER_RES - 1; + hit_play.x1 = UI_HOR_RES / 2 + 12; + hit_play.x2 = UI_HOR_RES - 1; + hit_play.y1 = 110; + hit_play.y2 = UI_VER_RES - 1; hit_bl.x1 = 0; hit_bl.y1 = 0; hit_bl.x2 = UI_HOR_RES - 1; - hit_bl.y2 = 28; + hit_bl.y2 = 32; Serial.printf("Hit REC(%d..%d,%d..%d) PLAY(%d..%d,%d..%d)\n", (int)hit_rec.x1, (int)hit_rec.x2, (int)hit_rec.y1, (int)hit_rec.y2, (int)hit_play.x1, (int)hit_play.x2, (int)hit_play.y1, (int)hit_play.y2); diff --git a/src/touch.cpp b/src/touch.cpp index 64f1f0a..b3597eb 100644 --- a/src/touch.cpp +++ b/src/touch.cpp @@ -161,11 +161,10 @@ void touch_read_cb(lv_indev_t * /*indev*/, lv_indev_data_t *data) { s_down_streak = 0; } } else if (p.z >= Z_DOWN && raw_ok) { - if (s_down_streak < 255) s_down_streak++; - /* 2 solid samples — filters 1-poll EMI spikes, still accepts light taps */ - if (s_down_streak >= 2) { - s_down = true; - } + /* Single solid sample OK — SoftSPI taps are often 1 poll wide. + * Cooldown in main.cpp blocks EMI auto-toggle. */ + s_down = true; + s_down_streak = 1; } else { s_down_streak = 0; }