Fermenter display

This commit is contained in:
Patrick Haßel 2025-02-17 20:08:17 +01:00
parent c87c46ce9c
commit c9a379eaae

View File

@ -16,34 +16,50 @@ DS18B20 ds18b20("DS18B20", D4);
DS18B20Sensor input(ds18b20, 0, ""); DS18B20Sensor input(ds18b20, 0, "");
PWMOutput heater(D2, ""); PWMOutput heater(D2, "", 100);
PIDController pid("fermenter", input, heater, UNIT_TEMPERATURE_C, 500, 0.00000002, 0); PIDController pid("fermenter", input, heater, UNIT_TEMPERATURE_C, 500, 0.00000002, 0);
auto displayToggleInterval = 2000UL;
auto display = LedControl(13, 14, 15, 1); auto display = LedControl(13, 14, 15, 1);
void displayDecimal(int *digit, const double value) { void displayPrintf(const char *format, ...) {
const auto integer = static_cast<int>(value); va_list args;
const auto decimal = static_cast<int>((value - integer) * 10) % 10; va_start(args, format);
display.setDigit(0, (*digit)++, decimal, false); char buffer[9];
display.setDigit(0, (*digit)++, integer % 10, true); vsnprintf(buffer, sizeof buffer, format, args);
display.setDigit(0, (*digit)++, integer / 10 % 10, false); int position = 0;
for (char *b = buffer; *b != 0 && b < buffer + sizeof buffer; b++) {
display.setChar(0, position++, *b, false);
}
va_end(args);
} }
void displayLoop() { void displayLoop() {
static unsigned long lastDisplayInit = 0; const auto now = millis();
if (lastDisplayInit == 0 || millis() - lastDisplayInit > 60 * 60 * 1000) {
lastDisplayInit = millis(); static unsigned long lastInit = 0;
if (lastInit == 0 || now - lastInit >= 60 * 60 * 1000) {
lastInit = now;
display.shutdown(0, true); display.shutdown(0, true);
display.shutdown(0, false); display.shutdown(0, false);
display.setIntensity(0, 4); display.setIntensity(0, 4);
display.clearDisplay(0); display.clearDisplay(0);
} }
auto digit = 0;
displayDecimal(&digit, input.getValue()); static auto mode = true;
digit++; static auto lastMode = 0UL;
digit++; if (lastMode == 0 || now - lastMode >= displayToggleInterval) {
displayDecimal(&digit, pid.targetValue); lastMode = now;
mode = !mode;
}
if (mode) {
displayPrintf("%3.0f ", heater.getPercent());
} else {
displayPrintf("%-4.1f%4.1f", input.getValue(), pid.targetValue);
}
} }
void httpStatus(AsyncWebServerRequest *request) { void httpStatus(AsyncWebServerRequest *request) {
@ -111,6 +127,7 @@ void patrixLoop() {
ds18b20.loop(); ds18b20.loop();
input.loop(); input.loop();
pid.loop(); pid.loop();
displayLoop();
} }
#endif #endif