Humidistat
Arduino firmware for a humidistat (humidity controller)
Loading...
Searching...
No Matches
ControllerUI.h
Go to the documentation of this file.
1#ifndef HUMIDISTAT_CONTROLLERUI_H
2#define HUMIDISTAT_CONTROLLERUI_H
3
4#include <stdint.h>
5#include <etl/span.h>
6#include <Print.h>
7
8#include CONFIG_HEADER
11#include "asprintf.h"
12
16private:
17 Print &display;
19
20 unsigned long lastPressed = 0;
21
27
28 bool splashDrawn = false;
29 bool infoDrawn = false;
30 bool screenCleared = false;
31
33 virtual void draw() = 0;
35 virtual void drawSplash() = 0;
37 virtual void drawInfo() = 0;
38
40 virtual void clear() = 0;
44 virtual void setCursor(uint8_t col, uint8_t row) = 0;
45
50 virtual bool handleInput(Buttons state, uint16_t pressedFor) = 0;
51
52protected:
53 etl::span<const ThermistorReader, 4> trs;
54
55 unsigned long lastRefreshed = 0;
56
60
65 explicit ControllerUI(Print *display, const ButtonReader *buttonReader, etl::span<const ThermistorReader, 4> trs);
66
71 void blink(uint8_t col, uint8_t row, const char *buf);
72
77 void printNTC(uint8_t col, uint8_t row, uint8_t i);
78
84 static void adjustValue(double delta, double &value, uint8_t min, uint8_t max);
85
91 template <typename... T>
92 void printf(uint8_t col, uint8_t row, const char *fmt, T... args) {
93 char *buf = asprintf(fmt, args...);
94
95 setCursor(col, row);
96 display.print(buf);
97
98 delete buf;
99 }
100
101public:
103 virtual void begin() = 0;
104
106 void update();
107};
108
109#endif //HUMIDISTAT_CONTROLLERUI_H
Buttons
Possible button values.
Definition Buttons.h:5
char * asprintf(const char *fmt, T... args)
Print formatted data to string. Automatically allocates string on the heap. Make sure to delete it im...
Definition asprintf.h:13
Read button state from a voltage ladder-style keypad.
User interface (display and input) for humidistat. Hold references to ButtonReader for keypad input,...
const uint16_t refreshInterval
const double tolerance
Print & display
static void adjustValue(double delta, double &value, uint8_t min, uint8_t max)
In-/de-crement a variable, while clipping it to [min, max].
etl::span< const ThermistorReader, 4 > trs
unsigned long lastRefreshed
Last time display was updated (in millis)
const uint16_t splashDuration
void update()
Update the display and handle input: set Humidistat's setpoint.
const uint16_t inputInterval
virtual void drawSplash()=0
Draw splash screen.
virtual void setCursor(uint8_t col, uint8_t row)=0
Set cursor to coordinates.
const uint16_t infoDuration
virtual void begin()=0
Initialize the display.
void printf(uint8_t col, uint8_t row, const char *fmt, T... args)
Print formatted data to display, at (col, row). Calculates lengths and creates appropriate buffer int...
const uint16_t blinkInterval
virtual bool handleInput(Buttons state, uint16_t pressedFor)=0
Handle input.
const uint16_t buttonDebounceInterval
ControllerUI(Print *display, const ButtonReader *buttonReader, etl::span< const ThermistorReader, 4 > trs)
Constructor.
const ButtonReader & buttonReader
void printNTC(uint8_t col, uint8_t row, uint8_t i)
Print temperature read from thermistors. Handles NaN values as 0.
virtual void drawInfo()=0
Draw info screen.
virtual void draw()=0
Draw main interface (main loop).
unsigned long lastPressed
Last time a keypress event occurred (in millis)
const uint8_t adjustStep
virtual void clear()=0
Clear screen.
void blink(uint8_t col, uint8_t row, const char *buf)
Print blinking text.
const uint16_t refreshInterval
Interval for updating the display (in millis)
Definition config.h:163
const uint16_t blinkInterval
Interval for blinking display elements (in millis)
Definition config.h:154
const double tolerance
Tolerance in difference between process variable and setpoint outside which the setpoint blinks (in p...
Definition config.h:170
const uint16_t buttonDebounceInterval
For debouncing: interval the keypad state must be stable for (in micros)
Definition config.h:148
const uint16_t infoDuration
Duration for which to show the info screen (in millis)
Definition config.h:160
const uint16_t splashDuration
Duration for which to show the splash screen (in millis)
Definition config.h:157
const uint8_t adjustStep
Step size by which to in-/de-crement for coarse adjustment.
Definition config.h:166
const uint16_t inputInterval
Repeat interval for keypress events (in millis)
Definition config.h:151