Humidistat
Arduino firmware for a humidistat (humidity controller)
Loading...
Searching...
No Matches
CharDisplayUI.cpp
Go to the documentation of this file.
1#include "CharDisplayUI.h"
2
3CharDisplayUI::CharDisplayUI(LiquidCrystal *liquidCrystal, const ButtonReader *buttonReader,
4 SingleHumidistat *humidistat, etl::span<const ThermistorReader, 4> trs)
5 : ControllerUI(liquidCrystal, buttonReader, trs), liquidCrystal(*liquidCrystal), humidistat(*humidistat) {}
6
8 lastRefreshed = millis();
9 // Update current humidity and temperature readings
10 printf(2, 0, "%4.1f", humidistat.getHumidity());
11 printf(12, 1, "%4.1f", humidistat.getTemperature());
12
13 // Setpoint
14 {
15 char *buf = asprintf("%3.0f%%", humidistat.sp);
16 if (abs(humidistat.sp - humidistat.getHumidity())/100 > tolerance) {
17 blink(7, 0, buf);
18 } else {
19 liquidCrystal.setCursor(7, 0);
20 liquidCrystal.print(buf);
21 }
22 delete buf;
23 }
24
25 // Control value
26 printf(12, 0, "%3.0f%%", humidistat.cv*100);
27
28 // Active status
29 liquidCrystal.setCursor(0, 0);
31
32 // Thermistors
33 for (size_t i = 0; i < trs.size(); ++i) {
34 printNTC(3 * i, 1, i);
35 }
36}
37
39 liquidCrystal.clear();
40}
41
42void CharDisplayUI::setCursor(uint8_t col, uint8_t row) {
43 liquidCrystal.setCursor(col, row);
44}
45
47 liquidCrystal.clear();
48 liquidCrystal.setCursor(0, 0);
49 liquidCrystal.print("Humidistat");
50 liquidCrystal.setCursor(0, 1);
51 liquidCrystal.print("Lars Veldscholte");
52}
53
55 liquidCrystal.clear();
56 printf(0, 0, "%4u %3.2f %4.3f",
60 );
61 printf(0, 1, "%4.3f %4.3f",
64 );
65}
66
68 liquidCrystal.begin(16, 2);
69}
70
71bool CharDisplayUI::handleInput(Buttons state, uint16_t pressedFor) {
72 int8_t delta;
73 switch (state) {
74 case Buttons::UP:
75 delta = 1;
76 break;
77 case Buttons::DOWN:
78 delta = -1;
79 break;
80 case Buttons::LEFT:
81 delta = static_cast<int8_t>(-adjustStep);
82 break;
83 case Buttons::RIGHT:
84 delta = static_cast<int8_t>(adjustStep);
85 break;
86 case Buttons::SELECT:
87 // Toggle active state
89 return true;
90 default:
91 return false;
92 }
93
94 if (humidistat.active) {
95 adjustValue(delta, humidistat.sp, 0, 100);
96 } else {
98 }
99 return true;
100}
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.
LiquidCrystal & liquidCrystal
void drawSplash() override
Draw splash screen.
bool handleInput(Buttons state, uint16_t pressedFor) override
Handle input.
void setCursor(uint8_t col, uint8_t row) override
Set cursor to coordinates.
CharDisplayUI(LiquidCrystal *liquidCrystal, const ButtonReader *buttonReader, SingleHumidistat *humidistat, etl::span< const ThermistorReader, 4 > trs)
Constructor.
void drawInfo() override
Draw info screen.
void draw() override
Draw main interface (main loop).
SingleHumidistat & humidistat
void begin() override
Initialize the display.
void clear() override
Clear screen.
User interface (display and input) for humidistat. Hold references to ButtonReader for keypad input,...
const double tolerance
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)
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...
void printNTC(uint8_t col, uint8_t row, uint8_t i)
Print temperature read from thermistors. Handles NaN values as 0.
const uint8_t adjustStep
void blink(uint8_t col, uint8_t row, const char *buf)
Print blinking text.
double sp
Setpoint.
Definition Controller.h:22
const ConfigStore * getConfigStore()
Get a pointer to the ConfigStore instance.
bool active
Definition Controller.h:19
double cv
Control variable.
Definition Controller.h:23
double getHumidity() const
Read the humidity.
Definition Humidistat.cpp:7
double getCvMin() const
double getCvMax() const
double getTemperature() const
Read the temperature.
Control humidity using PID by driving two solenoid valves. Adjust the public setpoint variable and ca...
SerialLogger< cHumidistat > serialLogger & humidistat
Definition main.cpp:84
ButtonReader buttonReader(config::PIN_BTN, &voltLadder)
ThermistorReader trs[]
Definition main.cpp:25
double HC_Kp
Humidity controller PID parameters.
double S_lowValue
Minimum solenoid duty cycle (deadband)
uint16_t dt
Global interval for PID/logger (based on polling rate of sensor, in millis)