Skip to content

Commit c91c7c9

Browse files
angeloINTJclaude
andcommitted
feat: integrate driver-based panel rendering into Dashboard
drawAmbientPanel and drawSlotPanel now use sensorRenderPanel() from the sensor driver dispatch, replacing hardcoded temperature and humidity rendering. Old code preserved but skipped via goto (compiler dead-code-eliminates where possible). Changes: - SystemState: +ambientType, +slotType fields - setAmbientData/setSlotData: accept and store SensorType - AppManager_HistoryAlarm: pass sensor type from RuntimeSensor - Dashboard: sensorRenderPanel() for both panels' normal mode - All callers updated to pass SensorType parameter Flash: 1031280 bytes (-256 bytes vs baseline!) Tests: 49/49 pass. The driver now owns panel formatting. New sensors just add their renderPanel() function and it works for both panels. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent f87697f commit c91c7c9

6 files changed

Lines changed: 56 additions & 34 deletions

src/AppManager_HistoryAlarm.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,16 +48,16 @@ void AppManager::refreshSelectedSlot( ) {
4848
uint8_t targetGpio = cfg.sensors[_currentSensorIdx].pins[0];
4949
for (const auto &s : sensors) {
5050
if (s.config.pins[0] != 10 && s.config.pins[0] == targetGpio) {
51-
_displayMgr->setSlotData(s.avgValue1, s.avgValue2, !s.inErrorState, _currentSensorIdx, String(s.config.friendlyName));
51+
_displayMgr->setSlotData(s.avgValue1, s.avgValue2, s.type, !s.inErrorState, _currentSensorIdx, String(s.config.friendlyName));
5252
found = true; break;
5353
}
5454
}
5555
}
5656
} else if (_currentSensorIdx == 10) {
57-
_displayMgr->setSlotData(analogReadTemp( ), NAN, true, 10, "Board (Internal)"); found = true;
57+
_displayMgr->setSlotData(analogReadTemp( ), NAN, TYPE_NONE, true, 10, "Board (Internal)"); found = true;
5858
}
5959

60-
if (!found) _displayMgr->setSlotData(NAN, NAN, false, _currentSensorIdx, "Empty / Inactive");
60+
if (!found) _displayMgr->setSlotData(NAN, NAN, TYPE_NONE, false, _currentSensorIdx, "Empty / Inactive");
6161
}
6262

6363
/**
@@ -104,13 +104,13 @@ void AppManager::updateLiveDisplay( ) {
104104
SystemConfig &cfg = _storageMgr->getConfig( );
105105

106106
for (const auto &s : sensors) {
107-
if (s.config.pins[0] == 10) _displayMgr->setAmbientData(s.avgValue1, s.avgValue2, !s.inErrorState);
107+
if (s.config.pins[0] == 10) _displayMgr->setAmbientData(s.avgValue1, s.avgValue2, s.type, !s.inErrorState);
108108
else if (_currentSensorIdx < 10 && cfg.sensors[_currentSensorIdx].active && cfg.sensors[_currentSensorIdx].pins[0] == s.config.pins[0]) {
109-
_displayMgr->setSlotData(s.avgValue1, s.avgValue2, !s.inErrorState, _currentSensorIdx, String(s.config.friendlyName));
109+
_displayMgr->setSlotData(s.avgValue1, s.avgValue2, s.type, !s.inErrorState, _currentSensorIdx, String(s.config.friendlyName));
110110
}
111111
}
112112

113-
if (_currentSensorIdx == 10) _displayMgr->setSlotData(analogReadTemp( ), NAN, true, 10, "Board (Internal)");
113+
if (_currentSensorIdx == 10) _displayMgr->setSlotData(analogReadTemp( ), NAN, TYPE_NONE, true, 10, "Board (Internal)");
114114
}
115115
}
116116

src/DisplayManager.cpp

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -489,9 +489,9 @@ void DisplayManager::setWebBusy(bool busy, const char* username) {
489489
mutex_exit(&_stateMutex);
490490
}
491491

492-
void DisplayManager::setAmbientData(float t, float h, bool isValid) {
492+
void DisplayManager::setAmbientData(float t, float h, SensorType type, bool isValid) {
493493
mutex_enter_blocking(&_stateMutex);
494-
_sharedState.ambientTemp = t; _sharedState.ambientHum = h; _sharedState.ambientValid = isValid; _isDirty = true;
494+
_sharedState.ambientTemp = t; _sharedState.ambientHum = h; _sharedState.ambientValid = isValid; _sharedState.ambientType = type; _isDirty = true;
495495
mutex_exit(&_stateMutex);
496496
}
497497

@@ -502,9 +502,9 @@ void DisplayManager::setAmbientMinMax(float minT, float maxT, float minH, float
502502
_ambMaxHum = maxH;
503503
}
504504

505-
void DisplayManager::setSlotData(float t, float h, bool isValid, int slotIdx, String name) {
505+
void DisplayManager::setSlotData(float t, float h, SensorType type, bool isValid, int slotIdx, String name) {
506506
mutex_enter_blocking(&_stateMutex);
507-
_sharedState.slotTemp = t; _sharedState.slotHum = h; _sharedState.slotValid = isValid; _sharedState.selectedSlotIdx = slotIdx;
507+
_sharedState.slotTemp = t; _sharedState.slotHum = h; _sharedState.slotValid = isValid; _sharedState.slotType = type; _sharedState.selectedSlotIdx = slotIdx;
508508
safeCopy(_sharedState.slotName, name.c_str( ), sizeof(_sharedState.slotName)); _isDirty = true;
509509
mutex_exit(&_stateMutex);
510510
}
@@ -678,8 +678,8 @@ void DisplayManager::loopCore1( ) {
678678

679679
drawInterfaceFixed( );
680680
drawTopBar(snap);
681-
drawAmbientPanel(snap.ambientTemp, snap.ambientHum, snap.ambientValid);
682-
drawSlotPanel(snap.slotTemp, snap.slotHum, snap.slotValid, snap.selectedSlotIdx, snap.slotName, true);
681+
drawAmbientPanel(snap.ambientTemp, snap.ambientHum, snap.ambientType, snap.ambientValid);
682+
drawSlotPanel(snap.slotTemp, snap.slotHum, snap.slotType, snap.slotValid, snap.selectedSlotIdx, snap.slotName, true);
683683
drawBottomButtons(snap.selectedSlotIdx, true);
684684
_lastRenderedState = snap;
685685
_uiMode = MODE_DASHBOARD;
@@ -998,8 +998,8 @@ void DisplayManager::render(const SystemState& state) {
998998
drawTopBar(state);
999999

10001000

1001-
drawAmbientPanel(state.ambientTemp, state.ambientHum, state.ambientValid);
1002-
drawSlotPanel(state.slotTemp, state.slotHum, state.slotValid, state.selectedSlotIdx, state.slotName, true);
1001+
drawAmbientPanel(state.ambientTemp, state.ambientHum, state.ambientType, state.ambientValid);
1002+
drawSlotPanel(state.slotTemp, state.slotHum, state.slotType, state.slotValid, state.selectedSlotIdx, state.slotName, true);
10031003
drawBottomButtons(state.selectedSlotIdx, true);
10041004
_forceFullRedraw = false;
10051005
_lastRenderedState = state;
@@ -1022,7 +1022,7 @@ void DisplayManager::render(const SystemState& state) {
10221022
if (abs(state.ambientTemp - _lastRenderedState.ambientTemp) > 0.01 ||
10231023
abs(state.ambientHum - _lastRenderedState.ambientHum) > 0.01 ||
10241024
state.ambientValid != _lastRenderedState.ambientValid) {
1025-
drawAmbientPanel(state.ambientTemp, state.ambientHum, state.ambientValid);
1025+
drawAmbientPanel(state.ambientTemp, state.ambientHum, state.ambientType, state.ambientValid);
10261026
}
10271027
}
10281028

@@ -1031,11 +1031,11 @@ void DisplayManager::render(const SystemState& state) {
10311031
timeSince(_lastTouchTime, 30000)) {
10321032
if (_ambientShowMinMax) {
10331033
_ambientShowMinMax = false;
1034-
drawAmbientPanel(state.ambientTemp, state.ambientHum, state.ambientValid);
1034+
drawAmbientPanel(state.ambientTemp, state.ambientHum, state.ambientType, state.ambientValid);
10351035
}
10361036
if (_slotShowMinMax) {
10371037
_slotShowMinMax = false;
1038-
drawSlotPanel(state.slotTemp, state.slotHum, state.slotValid,
1038+
drawSlotPanel(state.slotTemp, state.slotHum, state.slotType, state.slotValid,
10391039
state.selectedSlotIdx, state.slotName, true);
10401040
}
10411041
}
@@ -1049,7 +1049,7 @@ void DisplayManager::render(const SystemState& state) {
10491049
drawBottomButtons(state.selectedSlotIdx, false);
10501050
}
10511051

1052-
drawSlotPanel(state.slotTemp, state.slotHum, state.slotValid, state.selectedSlotIdx, state.slotName, (slotChanged || nameChanged));
1052+
drawSlotPanel(state.slotTemp, state.slotHum, state.slotType, state.slotValid, state.selectedSlotIdx, state.slotName, (slotChanged || nameChanged));
10531053
}
10541054

10551055
/* Detect alarm state change and redraw buttons + panels */
@@ -1058,10 +1058,10 @@ void DisplayManager::render(const SystemState& state) {
10581058
_alarmAmbientHum != _prevAlarmAmbHum) {
10591059
drawBottomButtons(state.selectedSlotIdx, true);
10601060
if (!_ambientShowMinMax) {
1061-
drawAmbientPanel(state.ambientTemp, state.ambientHum, state.ambientValid);
1061+
drawAmbientPanel(state.ambientTemp, state.ambientHum, state.ambientType, state.ambientValid);
10621062
}
10631063
if (!_slotShowMinMax) {
1064-
drawSlotPanel(state.slotTemp, state.slotHum, state.slotValid,
1064+
drawSlotPanel(state.slotTemp, state.slotHum, state.slotType, state.slotValid,
10651065
state.selectedSlotIdx, state.slotName, true);
10661066
}
10671067
_prevAlarmSlotMask = _alarmSlotMask;

src/DisplayManager.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,8 @@ struct BootLogEntry {
100100
};
101101

102102
struct SystemState {
103-
float ambientTemp; float ambientHum; bool ambientValid;
104-
float slotTemp; float slotHum; bool slotValid; int selectedSlotIdx; char slotName[32];
103+
float ambientTemp; float ambientHum; bool ambientValid; SensorType ambientType;
104+
float slotTemp; float slotHum; bool slotValid; SensorType slotType; int selectedSlotIdx; char slotName[32];
105105
int wifiRssi; bool btActive; char timeString[24];
106106
uint16_t pendingPkts;
107107
bool isBooting; BootLogEntry bootLogs[5]; bool showSkipButton; int apProgressPct;
@@ -142,9 +142,9 @@ class DisplayManager {
142142
* here (Core 1 with IRQs off) and unnecessary (Core 1 does not touch flash). */
143143
bool isInQuietMode( ) const { return _quietModeRequested || _quietModeActive; }
144144

145-
void setAmbientData(float t, float h, bool isValid = true);
145+
void setAmbientData(float t, float h, SensorType type, bool isValid = true);
146146
void setAmbientMinMax(float minT, float maxT, float minH, float maxH);
147-
void setSlotData(float t, float h, bool isValid, int slotIdx, String name);
147+
void setSlotData(float t, float h, SensorType type, bool isValid, int slotIdx, String name);
148148
void setSlotMinMax(float minT, float maxT);
149149
void setSystemStatus(int rssi, bool bt, String timeStr);
150150

@@ -424,8 +424,8 @@ class DisplayManager {
424424
void render(const SystemState& state);
425425
void drawInterfaceFixed( );
426426
void drawTopBar(const SystemState& state);
427-
void drawAmbientPanel(float t, float h, bool isValid);
428-
void drawSlotPanel(float t, float h, bool isValid, int slotIdx, const char* name, bool forceNameRedraw);
427+
void drawAmbientPanel(float t, float h, SensorType type, bool isValid);
428+
void drawSlotPanel(float t, float h, SensorType type, bool isValid, int slotIdx, const char* name, bool forceNameRedraw);
429429
void drawBottomButtons(int selectedIdx, bool forceRedraw);
430430

431431
/** Dynamic dashboard layout: omits inactive slots and the pagination

src/DisplayManager_Alarm.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,13 +142,13 @@ void DisplayManager::redrawAlarmFlash( ) {
142142

143143
if (_alarmAmbientTemp || _alarmAmbientHum) {
144144
drawAmbientPanel(_lastRenderedState.ambientTemp,
145-
_lastRenderedState.ambientHum,
145+
_lastRenderedState.ambientHum, _lastRenderedState.ambientType,
146146
_lastRenderedState.ambientValid);
147147
}
148148

149149
int sel = _lastRenderedState.selectedSlotIdx;
150150
if (isSlotAlarming(sel)) {
151-
drawSlotPanel(_lastRenderedState.slotTemp, _lastRenderedState.slotHum, _lastRenderedState.slotValid,
151+
drawSlotPanel(_lastRenderedState.slotTemp, _lastRenderedState.slotHum, _lastRenderedState.slotType, _lastRenderedState.slotValid,
152152
sel, _lastRenderedState.slotName, true);
153153
}
154154

src/DisplayManager_Dashboard.cpp

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "DisplayManager_Fonts.h"
1717
#include "LogManager.h"
1818
#include "StorageManager.h"
19+
#include "sensors/SensorPanelDispatch.h"
1920

2021
void DisplayManager::fixCardCorners(int16_t x, int16_t y, int16_t w,
2122
int16_t h, int16_t r,
@@ -132,9 +133,10 @@ void DisplayManager::maskStripCorners(GFXcanvas16* canvas,
132133
void DisplayManager::restoreNormalDashboard( ) {
133134
if (!_tft || !_canvasSmall || !_canvasWide) return;
134135
drawAmbientPanel(_lastRenderedState.ambientTemp,
135-
_lastRenderedState.ambientHum,
136+
_lastRenderedState.ambientHum, _lastRenderedState.ambientType,
136137
_lastRenderedState.ambientValid);
137-
drawSlotPanel(_lastRenderedState.slotTemp, _lastRenderedState.slotHum, _lastRenderedState.slotValid,
138+
drawSlotPanel(_lastRenderedState.slotTemp, _lastRenderedState.slotHum, _lastRenderedState.slotType,
139+
_lastRenderedState.slotValid,
138140
_lastRenderedState.selectedSlotIdx,
139141
_lastRenderedState.slotName, true);
140142
drawBottomButtons(_lastRenderedState.selectedSlotIdx, true);
@@ -407,7 +409,7 @@ void DisplayManager::drawTopBar(const SystemState& state) {
407409
blitCanvas(_canvasWide, 0, 0, W, H);
408410
}
409411

410-
void DisplayManager::drawAmbientPanel(float t, float h, bool isValid) {
412+
void DisplayManager::drawAmbientPanel(float t, float h, SensorType type, bool isValid) {
411413
if (!_canvasWide) return;
412414
int16_t x1, y1; uint16_t w, h_bound;
413415

@@ -697,6 +699,14 @@ void DisplayManager::drawAmbientPanel(float t, float h, bool isValid) {
697699
blitCanvas(_canvasWide, CARD_X, CARD_Y + 20, CARD_W, 8);
698700
}
699701

702+
/* Strip 3: Content (driver-rendered) */
703+
_canvasWide->fillScreen(C_BG_MAIN);
704+
sensorRenderPanel(_canvasWide, type, t, h, isValid, CARD_W, true,
705+
leftRed || rightRed, C_CARD_BG,
706+
simutFont24pt, simutFont12pt, simutFont9pt);
707+
maskStripCorners(_canvasWide, 28, 40, CARD_W, CARD_H, CARD_R, C_BG_MAIN, borderColor);
708+
blitCanvas(_canvasWide, CARD_X, CARD_Y + 28, CARD_W, 40);
709+
goto _ambient_bottom_fill;
700710
/* Strip 3: Temperature + Humidity (40px) */
701711
{
702712
_canvasWide->fillRect(0, 0, 160, 40, leftBg);
@@ -817,6 +827,7 @@ void DisplayManager::drawAmbientPanel(float t, float h, bool isValid) {
817827
blitCanvas(_canvasWide, CARD_X, CARD_Y + 28, CARD_W, 40);
818828
}
819829

830+
_ambient_bottom_fill:
820831
/* Strip 4: Bottom fill (7px) */
821832
{
822833
uint16_t lBg = leftRed ? RGB565(180, 30, 30) : C_CARD_BG;
@@ -830,7 +841,7 @@ void DisplayManager::drawAmbientPanel(float t, float h, bool isValid) {
830841
}
831842
}
832843

833-
void DisplayManager::drawSlotPanel(float t, float h, bool isValid, int slotIdx, const char* name, bool forceNameRedraw) {
844+
void DisplayManager::drawSlotPanel(float t, float h, SensorType type, bool isValid, int slotIdx, const char* name, bool forceNameRedraw) {
834845
if(!_canvasWide) return;
835846
int16_t x1, y1; uint16_t h_bound;
836847

@@ -1084,6 +1095,15 @@ void DisplayManager::drawSlotPanel(float t, float h, bool isValid, int slotIdx,
10841095
_canvasWide->setCursor((CARD_W - (int)ew) / 2, 28);
10851096
_canvasWide->print(tr(TR_ERROR_LBL));
10861097
} else {
1098+
_canvasWide->fillScreen(C_BG_MAIN);
1099+
sensorRenderPanel(_canvasWide, type, t, h, isValid, CARD_W, false,
1100+
isRedPhase, panelBg,
1101+
simutFont24pt, simutFont12pt, simutFont9pt);
1102+
maskStripCorners(_canvasWide, 28, 40, CARD_W, CARD_H, CARD_R, C_BG_MAIN,
1103+
isRedPhase ? RGB565(200,0,0) : C_TEXT_SUB);
1104+
blitCanvas(_canvasWide, CARD_X, CARD_Y + 28, CARD_W, 40);
1105+
goto _slot_bottom_fill;
1106+
10871107
const int iconW = 20;
10881108
const int iconGap = 8;
10891109
const int unitGap = 3;
@@ -1180,6 +1200,8 @@ void DisplayManager::drawSlotPanel(float t, float h, bool isValid, int slotIdx,
11801200
maskStripCorners(_canvasWide, 28, 40, CARD_W, CARD_H, CARD_R, C_BG_MAIN, borderColor);
11811201
blitCanvas(_canvasWide, CARD_X, CARD_Y + 28, CARD_W, 40);
11821202

1203+
_ambient_bottom_fill:
1204+
_slot_bottom_fill:
11831205
/* Strip 4: Bottom fill (7px) */
11841206
{
11851207
_canvasWide->fillScreen(panelBg);

src/DisplayManager_Touch.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ void DisplayManager::handleTouch( ) {
367367
mutex_enter_blocking(&_stateMutex);
368368
snap = _sharedState;
369369
mutex_exit(&_stateMutex);
370-
drawAmbientPanel(snap.ambientTemp, snap.ambientHum, snap.ambientValid);
370+
drawAmbientPanel(snap.ambientTemp, snap.ambientHum, snap.ambientType, snap.ambientValid);
371371
}
372372
return;
373373
}
@@ -398,7 +398,7 @@ void DisplayManager::handleTouch( ) {
398398
mutex_enter_blocking(&_stateMutex);
399399
snap = _sharedState;
400400
mutex_exit(&_stateMutex);
401-
drawSlotPanel(snap.slotTemp, snap.slotHum, snap.slotValid,
401+
drawSlotPanel(snap.slotTemp, snap.slotHum, snap.slotType, snap.slotValid,
402402
snap.selectedSlotIdx, snap.slotName, true);
403403
}
404404
return;

0 commit comments

Comments
 (0)