Flash digital value reading synchronously with arc alarm in red zone

This commit is contained in:
Sebastián Nieto 2026-09-09 22:55:13 -03:00
parent 259c4d6bbf
commit 117d3082b0

View file

@ -800,9 +800,17 @@ void plotNumeric4(uint8_t cell, float data, int warn, bool digit, String unit) {
uint8_t pidIdx = pidInCell[cell]; uint8_t pidIdx = pidInCell[cell];
uint16_t col = getMeterColor(pidIdx, data, warn); uint16_t col = getMeterColor(pidIdx, data, warn);
if (col == TFT_RED) {
wasInRedAlarm[cell] = true;
} else {
wasInRedAlarm[cell] = false;
}
uint16_t txtCol = (col == TFT_RED && !arcFlashVisible) ? TFT_BLACK : col;
String numStr = String(data, digit); String numStr = String(data, digit);
tft.loadFont(DSEG7_Modern_BoldItalic_44); tft.loadFont(DSEG7_Modern_BoldItalic_44);
tft.setTextColor(col, TFT_BLACK); tft.setTextColor(txtCol, TFT_BLACK);
tft.setTextPadding(w - 12); tft.setTextPadding(w - 12);
tft.drawRightString(numStr.c_str(), x + w - 10, y + 46, 1); tft.drawRightString(numStr.c_str(), x + w - 10, y + 46, 1);
tft.setTextPadding(0); tft.setTextPadding(0);
@ -910,8 +918,10 @@ void plotArc4(uint8_t cell, float data, int warn, int min, int max, bool digit,
} }
} }
uint16_t txtCol = (col == TFT_RED && !arcFlashVisible) ? TFT_BLACK : col;
tft.loadFont(DSEG7_Modern_BoldItalic_34); tft.loadFont(DSEG7_Modern_BoldItalic_34);
tft.setTextColor(col, TFT_BLACK); tft.setTextColor(txtCol, TFT_BLACK);
tft.setTextPadding(114); tft.setTextPadding(114);
tft.drawRightString(numStr.c_str(), x + 152, y + 74, 1); tft.drawRightString(numStr.c_str(), x + 152, y + 74, 1);
tft.setTextPadding(0); tft.setTextPadding(0);
@ -1068,17 +1078,26 @@ void plotFullScreen(uint8_t cell, float data, int warn, int min, int max,
} }
} }
uint16_t txtCol = (col == TFT_RED && !arcFlashVisible) ? TFT_BLACK : col;
// Value bottom-right using DSEG7 Modern smooth font // Value bottom-right using DSEG7 Modern smooth font
tft.loadFont(DSEG7_Modern_BoldItalic_80); tft.loadFont(DSEG7_Modern_BoldItalic_80);
tft.setTextColor(col, TFT_BLACK); tft.setTextColor(txtCol, TFT_BLACK);
tft.setTextPadding(240); tft.setTextPadding(240);
tft.drawRightString(numStr.c_str(), 312, 148, 1); tft.drawRightString(numStr.c_str(), 312, 148, 1);
tft.setTextPadding(0); tft.setTextPadding(0);
tft.unloadFont(); tft.unloadFont();
} else { } else {
// Digital numeric mode full screen with DSEG7 Smooth Font (Anti-Aliased) // Digital numeric mode full screen with DSEG7 Smooth Font (Anti-Aliased)
if (col == TFT_RED) {
wasInRedAlarm[cell] = true;
} else {
wasInRedAlarm[cell] = false;
}
uint16_t txtCol = (col == TFT_RED && !arcFlashVisible) ? TFT_BLACK : col;
tft.loadFont(DSEG7_Modern_BoldItalic_80); tft.loadFont(DSEG7_Modern_BoldItalic_80);
tft.setTextColor(col, TFT_BLACK); tft.setTextColor(txtCol, TFT_BLACK);
tft.setTextPadding(295); tft.setTextPadding(295);
tft.drawRightString(numStr.c_str(), 295, 98, 1); tft.drawRightString(numStr.c_str(), 295, 98, 1);
tft.setTextPadding(0); tft.setTextPadding(0);
@ -1288,7 +1307,7 @@ void updateMeter(uint8_t pidNo, String response) { // update parameter on screen
} }
/*-------------------------------*/ /*-------------------------------*/
// Non-blocking handler to blink/flash arcs on alarm (when in TFT_RED) // Non-blocking handler to blink/flash arcs and numerical values on alarm (when in TFT_RED)
void handleArcAlarmFlash() { void handleArcAlarmFlash() {
uint32_t now = millis(); uint32_t now = millis();
bool toggleTick = false; bool toggleTick = false;
@ -1300,43 +1319,76 @@ void handleArcAlarmFlash() {
if (fullScreenCell >= 0 && fullScreenCell < 4) { if (fullScreenCell >= 0 && fullScreenCell < 4) {
uint8_t cell = fullScreenCell; uint8_t cell = fullScreenCell;
if (!cellIsNumeric[cell] && last_valid_data[cell] != -999) { if (last_valid_data[cell] != -999) {
uint8_t pidIdx = pidInCell[cell]; uint8_t pidIdx = pidInCell[cell];
int warn = warningValue[pidIdx].toInt(); int warn = warningValue[pidIdx].toInt();
float data = last_valid_data[cell]; float data = last_valid_data[cell];
uint16_t col = getMeterColor(pidIdx, data, warn); uint16_t col = getMeterColor(pidIdx, data, warn);
bool inRed = (col == TFT_RED); bool inRed = (col == TFT_RED);
bool digit = pidConfig[pidIdx][7].toInt();
String numStr = String(data, digit);
if (wasInRedAlarm[cell] && !inRed) { if (wasInRedAlarm[cell] && !inRed) {
// Exited red alarm: restore steady arc // Exited red alarm: restore steady arc and text
wasInRedAlarm[cell] = false; wasInRedAlarm[cell] = false;
int min = pidConfig[pidIdx][4].toInt(); if (!cellIsNumeric[cell]) {
int max = pidConfig[pidIdx][5].toInt(); int min = pidConfig[pidIdx][4].toInt();
int newBlocks = calcMeterBlocks(data, min, max); int max = pidConfig[pidIdx][5].toInt();
for (uint8_t i = 0; i < newBlocks; i++) { int newBlocks = calcMeterBlocks(data, min, max);
drawBarBlock(i, col); for (uint8_t i = 0; i < newBlocks; i++) {
} drawBarBlock(i, col);
for (uint8_t i = newBlocks; i < NUM_BAR_BLOCKS; i++) { }
drawBarBlock(i, TFT_DARKGREY); for (uint8_t i = newBlocks; i < NUM_BAR_BLOCKS; i++) {
drawBarBlock(i, TFT_DARKGREY);
}
tft.loadFont(DSEG7_Modern_BoldItalic_80);
tft.setTextColor(col, TFT_BLACK);
tft.setTextPadding(240);
tft.drawRightString(numStr.c_str(), 312, 148, 1);
tft.setTextPadding(0);
tft.unloadFont();
} else {
tft.loadFont(DSEG7_Modern_BoldItalic_80);
tft.setTextColor(col, TFT_BLACK);
tft.setTextPadding(295);
tft.drawRightString(numStr.c_str(), 295, 98, 1);
tft.setTextPadding(0);
tft.unloadFont();
} }
} else if (inRed) { } else if (inRed) {
wasInRedAlarm[cell] = true; wasInRedAlarm[cell] = true;
if (toggleTick) { if (toggleTick) {
int min = pidConfig[pidIdx][4].toInt(); uint16_t txtCol = arcFlashVisible ? TFT_RED : TFT_BLACK;
int max = pidConfig[pidIdx][5].toInt(); if (!cellIsNumeric[cell]) {
int newBlocks = calcMeterBlocks(data, min, max); int min = pidConfig[pidIdx][4].toInt();
int max = pidConfig[pidIdx][5].toInt();
int newBlocks = calcMeterBlocks(data, min, max);
if (arcFlashVisible) { if (arcFlashVisible) {
for (uint8_t i = 0; i < newBlocks; i++) { for (uint8_t i = 0; i < newBlocks; i++) {
drawBarBlock(i, TFT_RED); drawBarBlock(i, TFT_RED);
} }
for (uint8_t i = newBlocks; i < NUM_BAR_BLOCKS; i++) { for (uint8_t i = newBlocks; i < NUM_BAR_BLOCKS; i++) {
drawBarBlock(i, TFT_DARKGREY); drawBarBlock(i, TFT_DARKGREY);
}
} else {
for (uint8_t i = 0; i < NUM_BAR_BLOCKS; i++) {
drawBarBlock(i, TFT_BLACK);
}
} }
tft.loadFont(DSEG7_Modern_BoldItalic_80);
tft.setTextColor(txtCol, TFT_BLACK);
tft.setTextPadding(240);
tft.drawRightString(numStr.c_str(), 312, 148, 1);
tft.setTextPadding(0);
tft.unloadFont();
} else { } else {
for (uint8_t i = 0; i < NUM_BAR_BLOCKS; i++) { tft.loadFont(DSEG7_Modern_BoldItalic_80);
drawBarBlock(i, TFT_BLACK); tft.setTextColor(txtCol, TFT_BLACK);
} tft.setTextPadding(295);
tft.drawRightString(numStr.c_str(), 295, 98, 1);
tft.setTextPadding(0);
tft.unloadFont();
} }
} }
} }
@ -1344,43 +1396,78 @@ void handleArcAlarmFlash() {
} else { } else {
// 4 quadrants mode // 4 quadrants mode
for (uint8_t cell = 0; cell < 4; cell++) { for (uint8_t cell = 0; cell < 4; cell++) {
if (!cellIsNumeric[cell] && last_valid_data[cell] != -999) { if (last_valid_data[cell] != -999) {
uint8_t pidIdx = pidInCell[cell]; uint8_t pidIdx = pidInCell[cell];
int warn = warningValue[pidIdx].toInt(); int warn = warningValue[pidIdx].toInt();
float data = last_valid_data[cell]; float data = last_valid_data[cell];
uint16_t col = getMeterColor(pidIdx, data, warn); uint16_t col = getMeterColor(pidIdx, data, warn);
bool inRed = (col == TFT_RED); bool inRed = (col == TFT_RED);
bool digit = pidConfig[pidIdx][7].toInt();
String numStr = String(data, digit);
int x = cell4_x[cell];
int y = cell4_y[cell];
if (wasInRedAlarm[cell] && !inRed) { if (wasInRedAlarm[cell] && !inRed) {
// Exited red alarm: restore steady arc // Exited red alarm: restore steady arc and text
wasInRedAlarm[cell] = false; wasInRedAlarm[cell] = false;
int min = pidConfig[pidIdx][4].toInt(); if (!cellIsNumeric[cell]) {
int max = pidConfig[pidIdx][5].toInt(); int min = pidConfig[pidIdx][4].toInt();
int newBlocks = calcMeterBlocks(data, min, max); int max = pidConfig[pidIdx][5].toInt();
for (uint8_t i = 0; i < newBlocks; i++) { int newBlocks = calcMeterBlocks(data, min, max);
drawQuadBarBlock(cell, i, col); for (uint8_t i = 0; i < newBlocks; i++) {
} drawQuadBarBlock(cell, i, col);
for (uint8_t i = newBlocks; i < NUM_BAR_BLOCKS; i++) { }
drawQuadBarBlock(cell, i, TFT_DARKGREY); for (uint8_t i = newBlocks; i < NUM_BAR_BLOCKS; i++) {
drawQuadBarBlock(cell, i, TFT_DARKGREY);
}
tft.loadFont(DSEG7_Modern_BoldItalic_34);
tft.setTextColor(col, TFT_BLACK);
tft.setTextPadding(114);
tft.drawRightString(numStr.c_str(), x + 152, y + 74, 1);
tft.setTextPadding(0);
tft.unloadFont();
} else {
tft.loadFont(DSEG7_Modern_BoldItalic_44);
tft.setTextColor(col, TFT_BLACK);
tft.setTextPadding(160 - 12);
tft.drawRightString(numStr.c_str(), x + 160 - 10, y + 46, 1);
tft.setTextPadding(0);
tft.unloadFont();
} }
} else if (inRed) { } else if (inRed) {
wasInRedAlarm[cell] = true; wasInRedAlarm[cell] = true;
if (toggleTick) { if (toggleTick) {
int min = pidConfig[pidIdx][4].toInt(); uint16_t txtCol = arcFlashVisible ? TFT_RED : TFT_BLACK;
int max = pidConfig[pidIdx][5].toInt(); if (!cellIsNumeric[cell]) {
int newBlocks = calcMeterBlocks(data, min, max); int min = pidConfig[pidIdx][4].toInt();
int max = pidConfig[pidIdx][5].toInt();
int newBlocks = calcMeterBlocks(data, min, max);
if (arcFlashVisible) { if (arcFlashVisible) {
for (uint8_t i = 0; i < newBlocks; i++) { for (uint8_t i = 0; i < newBlocks; i++) {
drawQuadBarBlock(cell, i, TFT_RED); drawQuadBarBlock(cell, i, TFT_RED);
} }
for (uint8_t i = newBlocks; i < NUM_BAR_BLOCKS; i++) { for (uint8_t i = newBlocks; i < NUM_BAR_BLOCKS; i++) {
drawQuadBarBlock(cell, i, TFT_DARKGREY); drawQuadBarBlock(cell, i, TFT_DARKGREY);
}
} else {
for (uint8_t i = 0; i < NUM_BAR_BLOCKS; i++) {
drawQuadBarBlock(cell, i, TFT_BLACK);
}
} }
tft.loadFont(DSEG7_Modern_BoldItalic_34);
tft.setTextColor(txtCol, TFT_BLACK);
tft.setTextPadding(114);
tft.drawRightString(numStr.c_str(), x + 152, y + 74, 1);
tft.setTextPadding(0);
tft.unloadFont();
} else { } else {
for (uint8_t i = 0; i < NUM_BAR_BLOCKS; i++) { tft.loadFont(DSEG7_Modern_BoldItalic_44);
drawQuadBarBlock(cell, i, TFT_BLACK); tft.setTextColor(txtCol, TFT_BLACK);
} tft.setTextPadding(160 - 12);
tft.drawRightString(numStr.c_str(), x + 160 - 10, y + 46, 1);
tft.setTextPadding(0);
tft.unloadFont();
} }
} }
} }