diff --git a/sketch/obd2_gauge/obd2_gauge.ino b/sketch/obd2_gauge/obd2_gauge.ino index f454abd..ac198f9 100644 --- a/sketch/obd2_gauge/obd2_gauge.ino +++ b/sketch/obd2_gauge/obd2_gauge.ino @@ -300,6 +300,13 @@ recent_client_addr : {0x00,0x00,0x00,0x00,0x00,0x00} array of bytes[6] while (!foundOBD2) { //not success try scan and connect another OBD2 scanBTdevice(); autoDim(); //auto backlight handle + + if (digitalRead(SELECTOR_PIN) == LOW) { //button pressed + delay(50); + if (digitalRead(SELECTOR_PIN) == LOW) { + configMenu(); + } + } } //Initialize ELM327 @@ -338,11 +345,13 @@ void loop() { updateBacklightFade(); // non-blocking smooth backlight fade handler handleArcAlarmFlash(); // non-blocking arc alarm flash handler (blinks when in TFT_RED) - // SCAN TOUCHSCREEN + // SCAN TOUCHSCREEN & BUTTON // - Single click on a quadrant: toggles between clock (arc) and number // - Double click on a quadrant: puts that instrument in full screen (or exits full screen) + // - Long press (> 1s) on screen OR holding selector button: opens configuration menu uint16_t touchX = 0, touchY = 0; bool isTouched = getTouch(&touchX, &touchY); + bool btnPressed = (digitalRead(SELECTOR_PIN) == LOW); static bool isTouching = false; static uint32_t touchStartTime = 0; @@ -350,19 +359,31 @@ void loop() { static uint8_t clickCount = 0; static uint32_t firstClickTime = 0; static int8_t clickQuadrant = -1; + static bool longPressHandled = false; - if (isTouched) { + if (isTouched || btnPressed) { if (!isTouching) { isTouching = true; touchStartTime = millis(); lastTouchX = touchX; lastTouchY = touchY; + longPressHandled = false; + } else if (!longPressHandled && (millis() - touchStartTime > 1000)) { + // Long press (> 1s) or button hold: Open Config Menu! + longPressHandled = true; + clickCount = 0; + ledcWriteTone(buzzerChannel, 3500); + delay(40); + ledcWriteTone(buzzerChannel, 0); + configMenu(); + if (foundOBD2) initScreen(); + isTouching = false; } } else { - // Touch released + // Touch / button released if (isTouching) { isTouching = false; - if (millis() - touchStartTime >= 30) { + if (!longPressHandled && (millis() - touchStartTime >= 30)) { // Valid tap detected! Determine quadrant int quad = (lastTouchX < 160) ? ((lastTouchY < 120) ? 0 : 2) : ((lastTouchY < 120) ? 1 : 3);