From 3b868f38dc842f5f1a2d2b6b2ae8486f29ea7e4a Mon Sep 17 00:00:00 2001 From: Sebastian Nieto Date: Wed, 9 Sep 2026 23:36:16 -0300 Subject: [PATCH] feat: streamline alarm menu to pure tactile ON/OFF toggles with clean save & exit button --- sketch/obd2_gauge/config.h | 134 +++++++++---------------------------- 1 file changed, 31 insertions(+), 103 deletions(-) diff --git a/sketch/obd2_gauge/config.h b/sketch/obd2_gauge/config.h index b1131b8..c2fb7ee 100644 --- a/sketch/obd2_gauge/config.h +++ b/sketch/obd2_gauge/config.h @@ -49,13 +49,8 @@ const String parameterList[4][2] = { {"Velocidad", " km/h"} }; -// Increments/limits for each PID warning setting -const float pidWarnStepFloat[4] = { 1.0f, 100.0f, 0.1f, 5.0f }; -const float pidWarnMin[4] = { 60.0f, 1500.0f, 12.0f, 40.0f }; -const float pidWarnMax[4] = { 125.0f, 6000.0f, 16.0f, 160.0f }; - // ------------------------------------------------------------- -// Sub-screen 0: Ajuste de Alarmas (Umbrales y Activacion ON/OFF) +// Sub-screen 0: Ajuste de Alarmas (Activación Tactil ON/OFF) // ------------------------------------------------------------- void warningMenu() { tft.fillScreen(TFT_BLACK); @@ -63,108 +58,56 @@ void warningMenu() { tft.setTextColor(TFT_BLACK); tft.drawCentreString("[--- Ajuste de Alarmas ---]", 159, 0, 4); - int8_t selIndex = 0; - - auto drawAllRows = [&](int8_t sel) { + auto drawAllRows = [&]() { for (uint8_t i = 0; i < 4; i++) { - int y = 32 + i * 40; - uint16_t bg = (i == sel) ? 0x0011 : TFT_BLACK; - tft.fillRect(0, y, 320, 38, bg); - if (i == sel) { - tft.drawRect(1, y, 318, 38, TFT_CYAN); - } + int y = 34 + i * 39; + tft.fillRoundRect(8, y, 304, 36, 5, 0x18E3); - tft.setTextColor(i == sel ? TFT_YELLOW : TFT_WHITE, bg); - tft.drawString(parameterList[i][0], 8, y + 7, 4); + tft.setTextColor(alarmEnabled[i] ? TFT_WHITE : 0x8410, 0x18E3); + tft.drawString(parameterList[i][0], 22, y + 6, 4); - // ON / OFF toggle badge + // Large tactile ON / OFF badge uint16_t badgeCol = alarmEnabled[i] ? TFT_GREEN : 0x8000; - tft.fillRoundRect(145, y + 5, 52, 28, 4, badgeCol); + tft.fillRoundRect(220, y + 4, 84, 28, 5, badgeCol); + tft.drawRoundRect(220, y + 4, 84, 28, 5, TFT_WHITE); tft.setTextColor(TFT_WHITE, badgeCol); - tft.drawCentreString(alarmEnabled[i] ? "ON" : "OFF", 171, y + 11, 2); - - // Value & Unit - tft.setTextColor(alarmEnabled[i] ? (i == sel ? TFT_WHITE : TFT_CYAN) : 0x632C, bg); - String valStr = warningValue[i] + parameterList[i][1]; - tft.drawRightString(valStr.c_str(), 312, y + 7, 4); + tft.drawCentreString(alarmEnabled[i] ? "ON" : "OFF", 262, y + 6, 4); } }; - auto drawBottomButtons = []() { - tft.fillRoundRect(4, 196, 54, 38, 4, TFT_NAVY); - tft.fillRoundRect(62, 196, 54, 38, 4, TFT_NAVY); - tft.fillRoundRect(120, 196, 64, 38, 4, 0x03E0); // Greenish - tft.fillRoundRect(188, 196, 58, 38, 4, TFT_NAVY); - tft.fillRoundRect(250, 196, 66, 38, 4, TFT_NAVY); + drawAllRows(); - tft.setTextColor(TFT_WHITE); - tft.drawCentreString("^", 31, 204, 4); - tft.drawCentreString("v", 89, 204, 4); - tft.drawCentreString("ON/OFF", 152, 208, 2); - tft.drawCentreString("-", 217, 198, 6); - tft.drawCentreString("+", 283, 198, 6); - }; - - drawAllRows(selIndex); - drawBottomButtons(); + // Bottom action button: [ GUARDAR Y SALIR ] + tft.fillRoundRect(25, 194, 270, 38, 5, 0x02EC); // Rich Ocean Blue + tft.setTextColor(TFT_WHITE); + tft.drawCentreString("GUARDAR Y SALIR", 160, 201, 4); delay(200); while (true) { autoDim(); uint16_t tx = 0, ty = 0; if (getTouch(&tx, &ty)) { - // Direct touch on rows - if (ty >= 32 && ty < 192) { - int8_t row = (ty - 32) / 40; + // 1. Direct touch on any parameter row to toggle ON/OFF + if (ty >= 32 && ty < 190) { + int8_t row = (ty - 34) / 39; if (row >= 0 && row < 4) { - if (tx >= 140 && tx <= 205) { - // Tapped ON/OFF badge directly - alarmEnabled[row] = !alarmEnabled[row]; - selIndex = row; - drawAllRows(selIndex); - clickSound(); - } else { - // Selected row - selIndex = row; - drawAllRows(selIndex); - clickSound(); - } + alarmEnabled[row] = !alarmEnabled[row]; + drawAllRows(); + casioBeep(4096, 25); + while (isScreenPressed()) { delay(10); yield(); } + delay(50); } - while (isScreenPressed()) { delay(10); yield(); } - delay(60); } - // Bottom buttons - else if (ty >= 194 && ty <= 238) { - if (tx < 60) { // PREV - selIndex = (selIndex <= 0) ? 3 : (selIndex - 1); - drawAllRows(selIndex); - clickSound(); - } else if (tx >= 60 && tx < 118) { // NEXT - selIndex = (selIndex >= 3) ? 0 : (selIndex + 1); - drawAllRows(selIndex); - clickSound(); - } else if (tx >= 118 && tx < 186) { // ON/OFF TOGGLE - alarmEnabled[selIndex] = !alarmEnabled[selIndex]; - drawAllRows(selIndex); - clickSound(); - } else if (tx >= 186 && tx < 248) { // DECREASE (-) - float val = warningValue[selIndex].toFloat() - pidWarnStepFloat[selIndex]; - if (val < pidWarnMin[selIndex]) val = pidWarnMin[selIndex]; - warningValue[selIndex] = (selIndex == 2) ? String(val, 1) : String((int)(val + 0.5f)); - drawAllRows(selIndex); - clickSound(); - } else if (tx >= 248) { // INCREASE (+) - float val = warningValue[selIndex].toFloat() + pidWarnStepFloat[selIndex]; - if (val > pidWarnMax[selIndex]) val = pidWarnMax[selIndex]; - warningValue[selIndex] = (selIndex == 2) ? String(val, 1) : String((int)(val + 0.5f)); - drawAllRows(selIndex); - clickSound(); + // 2. Bottom button [ GUARDAR Y SALIR ] or top bar + else if ((ty >= 190 && ty <= 238 && tx >= 20 && tx <= 300) || ty < 30) { + casioBeep(4096, 25); + pref.begin("setting", false); + for (uint8_t i = 0; i < 4; i++) { + String almKey = "alm_" + String(i); + pref.putBool(almKey.c_str(), alarmEnabled[i]); } + pref.end(); while (isScreenPressed()) { delay(10); yield(); } - delay(60); - } - // Top bar touch -> SAVE & EXIT - else if (ty < 30) { break; } } else if (digitalRead(SELECTOR_PIN) == LOW) { @@ -173,21 +116,6 @@ void warningMenu() { } yield(); } - - // Save changes to Preferences - tft.fillRect(0, 80, 320, 80, TFT_NAVY); - tft.drawRect(0, 80, 320, 80, TFT_WHITE); - tft.setTextColor(TFT_WHITE, TFT_NAVY); - tft.drawCentreString("Alarmas Guardadas.", 160, 105, 4); - casioBeep(4096, 30); - pref.begin("setting", false); - for (uint8_t i = 0; i < 4; i++) { - pref.putString(pidConfig[i][0].c_str(), warningValue[i]); - String almKey = "alm_" + String(i); - pref.putBool(almKey.c_str(), alarmEnabled[i]); - } - pref.end(); - delay(500); } // -------------------------------------------------------------