Aquarium Cooling Controller
ESP32 firmware for aquarium cooling fan control, monitoring, telemetry, and fault handling.
Loading...
Searching...
No Matches
oled_status_display.h
Go to the documentation of this file.
1#pragma once
2
8#include <Arduino.h>
9
10#include "fault_policy.h"
11#include "sensor_manager.h"
12
16enum class OledDisplayMode : uint8_t {
17 kDisabled,
18 kBoot,
20 kFault,
21};
22
27 uint8_t sdaPin;
28 uint8_t sclPin;
29 uint8_t width;
30 uint8_t height;
33 uint32_t busFrequencyHz;
34};
35
44 public:
45 explicit OledStatusDisplay(
46 const OledStatusDisplayConfig& config = {
47 32,
48 27,
49 128,
50 32,
51 0x3C,
52 0x3D,
53 400000,
54 });
55
62 bool begin(uint32_t nowMs);
63
72 void update(uint32_t nowMs,
73 const SensorSnapshot& sensorSnapshot,
74 bool faultSnapshotValid,
75 const FaultPolicySnapshot& policySnapshot);
76
82 bool isAvailable() const;
83
89 OledDisplayMode mode() const;
90
96 const char* modeLabel() const;
97
103 const char* primaryText() const;
104
110 const char* secondaryText() const;
111
117 uint8_t address() const;
118
119 private:
120 struct PendingState {
121 OledDisplayMode mode;
122 char primaryText[12];
123 char secondaryText[12];
124 };
125
126 static const uint8_t* glyphForChar(char c);
127 static const char* faultTextForAlarm(AlarmCode alarmCode);
128 static const char* modeLabelFor(OledDisplayMode mode);
129
130 bool detectDisplay();
131 bool initializeController();
132 bool sendCommand(uint8_t command);
133 bool sendCommands(const uint8_t* commands, size_t count);
134 bool sendData(const uint8_t* data, size_t count);
135 bool flushBuffer();
136 void disableDisplay();
137
138 void clearBuffer();
139 void drawPixel(int16_t x, int16_t y);
140 void drawGlyph5x7(int16_t x, int16_t y, char c, uint8_t scale);
141 int16_t textWidth(const char* text, uint8_t scale) const;
142 void drawText(int16_t x, int16_t y, const char* text, uint8_t scale);
143
144 PendingState buildPendingState(const SensorSnapshot& sensorSnapshot,
145 bool faultSnapshotValid,
146 const FaultPolicySnapshot& policySnapshot) const;
147 bool renderState(const PendingState& state);
148 bool stateEquals(const PendingState& lhs, const PendingState& rhs) const;
149 void copyState(PendingState* destination, const PendingState& source) const;
150
152 uint8_t address_;
153 bool available_;
154 bool i2cReady_;
155 PendingState currentState_;
156 uint8_t buffer_[128 * 32 / 8];
157};
Optional OLED renderer with fail-open behavior.
Definition oled_status_display.h:43
uint8_t address() const
Returns the detected I2C address when the display is available.
Definition oled_status_display.cpp:126
const char * secondaryText() const
Returns the secondary visible text used for the current mode.
Definition oled_status_display.cpp:122
void update(uint32_t nowMs, const SensorSnapshot &sensorSnapshot, bool faultSnapshotValid, const FaultPolicySnapshot &policySnapshot)
Updates the visible OLED state from current controller snapshots.
Definition oled_status_display.cpp:83
bool begin(uint32_t nowMs)
Probes and initializes a compatible OLED if one is present.
Definition oled_status_display.cpp:58
bool isAvailable() const
Indicates whether a compatible OLED is currently available.
Definition oled_status_display.cpp:106
OledDisplayMode mode() const
Returns the last rendered or selected display mode.
Definition oled_status_display.cpp:110
const char * modeLabel() const
Returns a short diagnostic label for the current mode.
Definition oled_status_display.cpp:114
const char * primaryText() const
Returns the primary visible text used for the current mode.
Definition oled_status_display.cpp:118
Converts sensor and fan health into alarms, severity, and responses.
AlarmCode
Stable alarm identifiers for telemetry and diagnostics.
Definition fault_policy.h:24
OledDisplayMode
Visible OLED states exposed for diagnostics and rendering decisions.
Definition oled_status_display.h:16
@ kDisabled
No compatible OLED is available or the display path is disabled.
@ kTemperature
The display shows the current water temperature.
@ kBoot
The controller is still in its short startup display state.
@ kFault
The display shows the fault indicator and short fault text.
OneWire temperature sensor discovery, assignment, and sampling.
Complete policy decision for diagnostics and telemetry.
Definition fault_policy.h:64
Configuration for the optional OLED display path.
Definition oled_status_display.h:26
uint8_t height
OLED height in pixels.
Definition oled_status_display.h:30
uint8_t secondaryAddress
Fallback I2C address to probe second.
Definition oled_status_display.h:32
uint8_t width
OLED width in pixels.
Definition oled_status_display.h:29
uint8_t primaryAddress
Preferred I2C address to probe first.
Definition oled_status_display.h:31
uint8_t sdaPin
GPIO used for the I2C SDA line.
Definition oled_status_display.h:27
uint32_t busFrequencyHz
I2C bus speed in hertz.
Definition oled_status_display.h:33
uint8_t sclPin
GPIO used for the I2C SCL line.
Definition oled_status_display.h:28
Complete OneWire bus and sensor state snapshot.
Definition sensor_manager.h:86