feat: implement 3-tier dynamic RPM color (Green 800-3500, Yellow 3500-5000, Red 5000-6000 RPM)
This commit is contained in:
parent
6342a0ecfc
commit
a0624a0227
1 changed files with 26 additions and 10 deletions
|
|
@ -689,6 +689,19 @@ inline void drawQuadrantDividers() {
|
|||
tft.fillRect(0, 119, 320, 2, QUAD_DIV_COLOR);
|
||||
}
|
||||
|
||||
// Determine display color for meter:
|
||||
// RPM (PID 1): VERDE (< 3500), AMARILLO (3500-5000), ROJO (5000-6000)
|
||||
// Otros instrumentos: VERDE / ROJO (según umbral de advertencia)
|
||||
inline uint16_t getMeterColor(uint8_t pidIdx, float data, int warn) {
|
||||
if (pidIdx == 1) { // 1 = RPM (PID 010C)
|
||||
if (data >= 5000.0f) return TFT_RED;
|
||||
if (data >= 3500.0f) return TFT_YELLOW;
|
||||
return TFT_GREEN;
|
||||
}
|
||||
if (warn > 0 && data >= (float)warn) return TFT_RED;
|
||||
return TFT_GREEN;
|
||||
}
|
||||
|
||||
// 4-quadrant Numeric Meter (160x120 px)
|
||||
void numericMeter4(uint8_t cell, uint8_t pid, bool redrawHeader = true) {
|
||||
int w = 160;
|
||||
|
|
@ -725,8 +738,8 @@ void plotNumeric4(uint8_t cell, float data, int warn, bool digit, String unit) {
|
|||
int x = cell4_x[cell];
|
||||
int y = cell4_y[cell];
|
||||
int w = 160;
|
||||
bool isWarn = (warn > 0 && data >= warn);
|
||||
uint16_t col = isWarn ? TFT_RED : TFT_GREEN;
|
||||
uint8_t pidIdx = pidInCell[cell];
|
||||
uint16_t col = getMeterColor(pidIdx, data, warn);
|
||||
|
||||
String numStr = String(data, digit);
|
||||
tft.loadFont(DSEG7_Modern_BoldItalic_44);
|
||||
|
|
@ -785,8 +798,10 @@ void plotArc4(uint8_t cell, float data, int warn, int min, int max, bool digit,
|
|||
data = min;
|
||||
if (data > max)
|
||||
data = max;
|
||||
bool isWarn = (warn > 0 && data >= warn);
|
||||
uint16_t col = isWarn ? TFT_RED : TFT_GREEN;
|
||||
|
||||
uint8_t pidIdx = pidInCell[cell];
|
||||
uint16_t col = getMeterColor(pidIdx, data, warn);
|
||||
uint16_t oldCol = (old_data[cell] < min) ? 0 : getMeterColor(pidIdx, old_data[cell], warn);
|
||||
|
||||
String numStr = String(data, digit);
|
||||
|
||||
|
|
@ -802,8 +817,8 @@ void plotArc4(uint8_t cell, float data, int warn, int min, int max, bool digit,
|
|||
if (oldBlocks > NUM_BAR_BLOCKS)
|
||||
oldBlocks = NUM_BAR_BLOCKS;
|
||||
|
||||
bool wasWarn = (warn > 0 && old_data[cell] >= warn);
|
||||
if (isWarn != wasWarn || old_data[cell] < min) {
|
||||
bool colorChanged = (col != oldCol);
|
||||
if (colorChanged || old_data[cell] < min) {
|
||||
for (uint8_t i = 0; i < newBlocks; i++) {
|
||||
drawQuadBarBlock(cell, i, col);
|
||||
}
|
||||
|
|
@ -925,8 +940,9 @@ void plotFullScreen(uint8_t cell, float data, int warn, int min, int max,
|
|||
data = min;
|
||||
if (data > max)
|
||||
data = max;
|
||||
bool isWarn = (warn > 0 && data >= warn);
|
||||
uint16_t col = isWarn ? TFT_RED : TFT_GREEN;
|
||||
uint8_t pidIdx = pidInCell[cell];
|
||||
uint16_t col = getMeterColor(pidIdx, data, warn);
|
||||
uint16_t oldCol = (old_data[cell] < min) ? 0 : getMeterColor(pidIdx, old_data[cell], warn);
|
||||
|
||||
String numStr = String(data, digit);
|
||||
|
||||
|
|
@ -943,8 +959,8 @@ void plotFullScreen(uint8_t cell, float data, int warn, int min, int max,
|
|||
if (oldBlocks > NUM_BAR_BLOCKS)
|
||||
oldBlocks = NUM_BAR_BLOCKS;
|
||||
|
||||
bool wasWarn = (warn > 0 && old_data[cell] >= warn);
|
||||
if (isWarn != wasWarn || old_data[cell] < min) {
|
||||
bool colorChanged = (col != oldCol);
|
||||
if (colorChanged || old_data[cell] < min) {
|
||||
for (uint8_t i = 0; i < newBlocks; i++) {
|
||||
drawBarBlock(i, col);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue