feat: streamline alarm menu to pure tactile ON/OFF toggles with clean save & exit button
This commit is contained in:
parent
a5aa2fbc32
commit
3b868f38dc
1 changed files with 31 additions and 103 deletions
|
|
@ -49,13 +49,8 @@ const String parameterList[4][2] = {
|
||||||
{"Velocidad", " km/h"}
|
{"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() {
|
void warningMenu() {
|
||||||
tft.fillScreen(TFT_BLACK);
|
tft.fillScreen(TFT_BLACK);
|
||||||
|
|
@ -63,108 +58,56 @@ void warningMenu() {
|
||||||
tft.setTextColor(TFT_BLACK);
|
tft.setTextColor(TFT_BLACK);
|
||||||
tft.drawCentreString("[--- Ajuste de Alarmas ---]", 159, 0, 4);
|
tft.drawCentreString("[--- Ajuste de Alarmas ---]", 159, 0, 4);
|
||||||
|
|
||||||
int8_t selIndex = 0;
|
auto drawAllRows = [&]() {
|
||||||
|
|
||||||
auto drawAllRows = [&](int8_t sel) {
|
|
||||||
for (uint8_t i = 0; i < 4; i++) {
|
for (uint8_t i = 0; i < 4; i++) {
|
||||||
int y = 32 + i * 40;
|
int y = 34 + i * 39;
|
||||||
uint16_t bg = (i == sel) ? 0x0011 : TFT_BLACK;
|
tft.fillRoundRect(8, y, 304, 36, 5, 0x18E3);
|
||||||
tft.fillRect(0, y, 320, 38, bg);
|
|
||||||
if (i == sel) {
|
|
||||||
tft.drawRect(1, y, 318, 38, TFT_CYAN);
|
|
||||||
}
|
|
||||||
|
|
||||||
tft.setTextColor(i == sel ? TFT_YELLOW : TFT_WHITE, bg);
|
tft.setTextColor(alarmEnabled[i] ? TFT_WHITE : 0x8410, 0x18E3);
|
||||||
tft.drawString(parameterList[i][0], 8, y + 7, 4);
|
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;
|
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.setTextColor(TFT_WHITE, badgeCol);
|
||||||
tft.drawCentreString(alarmEnabled[i] ? "ON" : "OFF", 171, y + 11, 2);
|
tft.drawCentreString(alarmEnabled[i] ? "ON" : "OFF", 262, y + 6, 4);
|
||||||
|
|
||||||
// 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);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
auto drawBottomButtons = []() {
|
drawAllRows();
|
||||||
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);
|
|
||||||
|
|
||||||
|
// Bottom action button: [ GUARDAR Y SALIR ]
|
||||||
|
tft.fillRoundRect(25, 194, 270, 38, 5, 0x02EC); // Rich Ocean Blue
|
||||||
tft.setTextColor(TFT_WHITE);
|
tft.setTextColor(TFT_WHITE);
|
||||||
tft.drawCentreString("^", 31, 204, 4);
|
tft.drawCentreString("GUARDAR Y SALIR", 160, 201, 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();
|
|
||||||
delay(200);
|
delay(200);
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
autoDim();
|
autoDim();
|
||||||
uint16_t tx = 0, ty = 0;
|
uint16_t tx = 0, ty = 0;
|
||||||
if (getTouch(&tx, &ty)) {
|
if (getTouch(&tx, &ty)) {
|
||||||
// Direct touch on rows
|
// 1. Direct touch on any parameter row to toggle ON/OFF
|
||||||
if (ty >= 32 && ty < 192) {
|
if (ty >= 32 && ty < 190) {
|
||||||
int8_t row = (ty - 32) / 40;
|
int8_t row = (ty - 34) / 39;
|
||||||
if (row >= 0 && row < 4) {
|
if (row >= 0 && row < 4) {
|
||||||
if (tx >= 140 && tx <= 205) {
|
|
||||||
// Tapped ON/OFF badge directly
|
|
||||||
alarmEnabled[row] = !alarmEnabled[row];
|
alarmEnabled[row] = !alarmEnabled[row];
|
||||||
selIndex = row;
|
drawAllRows();
|
||||||
drawAllRows(selIndex);
|
casioBeep(4096, 25);
|
||||||
clickSound();
|
|
||||||
} else {
|
|
||||||
// Selected row
|
|
||||||
selIndex = row;
|
|
||||||
drawAllRows(selIndex);
|
|
||||||
clickSound();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
while (isScreenPressed()) { delay(10); yield(); }
|
while (isScreenPressed()) { delay(10); yield(); }
|
||||||
delay(60);
|
delay(50);
|
||||||
}
|
}
|
||||||
// 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(); }
|
while (isScreenPressed()) { delay(10); yield(); }
|
||||||
delay(60);
|
|
||||||
}
|
|
||||||
// Top bar touch -> SAVE & EXIT
|
|
||||||
else if (ty < 30) {
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else if (digitalRead(SELECTOR_PIN) == LOW) {
|
} else if (digitalRead(SELECTOR_PIN) == LOW) {
|
||||||
|
|
@ -173,21 +116,6 @@ void warningMenu() {
|
||||||
}
|
}
|
||||||
yield();
|
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// -------------------------------------------------------------
|
// -------------------------------------------------------------
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue