Files
Flipdot-display/src/esp32/logic/display_controller.cpp
T

131 lines
2.6 KiB
C++
Raw Normal View History

#include "logic/display_controller.h"
#include "config.h"
#include "logic/schedule.h"
DisplayController::DisplayController(DisplayPower &power, Frames &frames) : _power(power), _frames(frames)
{
}
void DisplayController::setClockEnabled(bool enabled)
{
_clock_enabled = enabled;
}
void DisplayController::setPowerEnabled(bool enabled)
{
_power_enabled = enabled;
}
bool DisplayController::clockEnabled() const
{
return _clock_enabled;
}
bool DisplayController::powerEnabled() const
{
return _power_enabled;
}
2026-10-13 01:34:04 +02:00
void DisplayController::update(uint32_t now, bool time_valid, int hour, int minute, bool wifi_connected)
{
2026-10-13 01:34:04 +02:00
if (wifi_connected)
_wifi_lost = false;
else if (!_wifi_lost)
{
_wifi_lost = true;
_wifi_lost_since = now;
}
bool show_no_wifi = _wifi_lost && now - _wifi_lost_since >= NO_WIFI_SHOW_TIME;
// Switched off elsewhere (power timer, Nano flashing): the Nano lost its frame
if (!_power.isOn())
_screen = Screen::Unknown;
if (_off_timer.expired(now))
{
_power.off();
_screen = Screen::Unknown;
return;
}
if (!_power_enabled)
{
if (_power.isOn())
{
_showBlank();
_off_timer.request(now, CLEAR_BEFORE_OFF_TIME);
}
return;
}
// Keep the boot screen until the time is known
if (!time_valid)
return;
if (!_clock_enabled)
{
// The logo is only shown while the display is on; it never switches the power on
if (_power.isOn())
{
_showLogo();
_off_timer.request(now, POWER_OFF_DELAY);
}
return;
}
switch (scheduleFor(hour, minute))
{
case ScheduleMode::Night:
if (_power.isOn())
{
_showBlank();
_off_timer.request(now, POWER_OFF_DELAY);
}
break;
case ScheduleMode::Clock:
_off_timer.cancel();
if (!_power.isOn())
{
_power.on();
_screen = Screen::Unknown;
}
2026-10-13 01:34:04 +02:00
_showClock(hour, minute, show_no_wifi);
break;
case ScheduleMode::Standby:
// Flipdots keep their image without power, so the last time stays visible
if (_power.isOn())
_off_timer.request(now, POWER_OFF_DELAY);
break;
}
}
2026-10-13 01:34:04 +02:00
void DisplayController::_showClock(int hour, int minute, bool no_wifi)
{
2026-10-13 01:34:04 +02:00
Screen screen = no_wifi ? Screen::NoWifi : Screen::Clock;
if (_screen == screen && _shown_hour == hour && _shown_minute == minute)
return;
2026-10-13 01:34:04 +02:00
if (no_wifi)
_frames.noWifi(hour, minute);
else
_frames.clock(hour, minute);
_screen = screen;
_shown_hour = hour;
_shown_minute = minute;
}
void DisplayController::_showLogo()
{
if (_screen == Screen::Logo)
return;
_frames.logo();
_screen = Screen::Logo;
}
void DisplayController::_showBlank()
{
if (_screen == Screen::Blank)
return;
_frames.blank();
_screen = Screen::Blank;
}