2026-10-13 00:56:32 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
|
|
|
|
|
|
#include "logic/power_timer.h"
|
2026-10-13 01:52:34 +02:00
|
|
|
#include "logic/settings.h"
|
2026-10-13 00:56:32 +02:00
|
|
|
|
|
|
|
|
// Power for the panels and the Nano (implemented by NanoLink)
|
|
|
|
|
class DisplayPower
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
virtual bool isOn() = 0;
|
|
|
|
|
// Switch on and wait until the Nano is ready
|
|
|
|
|
virtual void on() = 0;
|
|
|
|
|
virtual void off() = 0;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// The screens the display can show (implemented by FlipdotFrames)
|
|
|
|
|
class Frames
|
|
|
|
|
{
|
|
|
|
|
public:
|
2026-10-13 01:52:34 +02:00
|
|
|
virtual void clock(int hour, int minute, bool evening) = 0;
|
2026-10-13 01:34:04 +02:00
|
|
|
// Shown instead of the clock while WiFi is down (the time keeps running without it)
|
|
|
|
|
virtual void noWifi(int hour, int minute) = 0;
|
2026-10-13 01:52:34 +02:00
|
|
|
// The bitmap selected as page
|
|
|
|
|
virtual void page() = 0;
|
|
|
|
|
// The image sent from the web UI's live mode
|
|
|
|
|
virtual void live() = 0;
|
2026-10-15 01:29:01 +02:00
|
|
|
// Left on the dots when the display switches off: blank or the off bitmap
|
|
|
|
|
virtual void off() = 0;
|
2026-10-13 00:56:32 +02:00
|
|
|
};
|
|
|
|
|
|
2026-10-13 01:52:34 +02:00
|
|
|
enum class Page : uint8_t
|
|
|
|
|
{
|
|
|
|
|
Clock, // Pikachu with the time
|
|
|
|
|
Bitmap, // a bitmap (FlipdotFrames holds which one)
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Decides what the display shows and when it is powered, based on the time, the settings,
|
|
|
|
|
// the Home Assistant switches and the web UI. A frame is only sent when it changes. Pure
|
|
|
|
|
// logic, tested in test/test_esp32.
|
2026-10-13 00:56:32 +02:00
|
|
|
class DisplayController
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
DisplayController(DisplayPower &power, Frames &frames);
|
|
|
|
|
|
2026-10-13 01:52:34 +02:00
|
|
|
void setSettings(const ScheduleSettings &schedule, const ClockSettings &clock);
|
2026-10-15 01:29:01 +02:00
|
|
|
// How long the Nano takes to show a frame with the refresh effect (ms, 0 = instant).
|
|
|
|
|
// The power stays on that much longer after the last frame.
|
|
|
|
|
void setEffectTime(uint32_t ms);
|
2026-10-13 01:52:34 +02:00
|
|
|
|
2026-10-15 01:29:01 +02:00
|
|
|
// What is shown during the day. Call pageChanged() when the page or off bitmap
|
|
|
|
|
// itself changed.
|
2026-10-13 01:52:34 +02:00
|
|
|
void setPage(Page page);
|
|
|
|
|
void pageChanged();
|
|
|
|
|
|
|
|
|
|
// Live mode: show Frames::live() now, whatever the time, until stopLive() or
|
|
|
|
|
// LIVE_TIMEOUT after the last showLive()
|
|
|
|
|
void showLive(uint32_t now);
|
|
|
|
|
void stopLive();
|
|
|
|
|
bool liveActive() const;
|
|
|
|
|
|
2026-10-13 00:56:32 +02:00
|
|
|
// Home Assistant "FlipDot Display Power" switch: off clears the display and powers it off
|
|
|
|
|
void setPowerEnabled(bool enabled);
|
|
|
|
|
|
|
|
|
|
bool powerEnabled() const;
|
|
|
|
|
|
|
|
|
|
// Call often (every loop). time_valid is false until the time is synced over NTP.
|
2026-10-13 01:34:04 +02:00
|
|
|
// While WiFi is down for NO_WIFI_SHOW_TIME, "No WiFi" is shown instead of the clock.
|
|
|
|
|
void update(uint32_t now, bool time_valid, int hour, int minute, bool wifi_connected);
|
2026-10-13 00:56:32 +02:00
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
enum class Screen
|
|
|
|
|
{
|
|
|
|
|
Unknown, // nothing sent since the last power on
|
|
|
|
|
Clock,
|
2026-10-13 01:34:04 +02:00
|
|
|
NoWifi,
|
2026-10-13 01:52:34 +02:00
|
|
|
Page,
|
|
|
|
|
Live,
|
2026-10-15 01:29:01 +02:00
|
|
|
Off, // blank or the off bitmap
|
2026-10-13 00:56:32 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
DisplayPower &_power;
|
|
|
|
|
Frames &_frames;
|
|
|
|
|
PowerTimer _off_timer;
|
|
|
|
|
|
2026-10-13 01:52:34 +02:00
|
|
|
ScheduleSettings _schedule;
|
|
|
|
|
ClockSettings _clock;
|
|
|
|
|
Page _page = Page::Clock;
|
2026-10-15 01:29:01 +02:00
|
|
|
uint32_t _effect_time = 0;
|
2026-10-13 01:52:34 +02:00
|
|
|
|
2026-10-13 00:56:32 +02:00
|
|
|
bool _power_enabled = true;
|
|
|
|
|
|
|
|
|
|
Screen _screen = Screen::Unknown;
|
|
|
|
|
int _shown_hour = -1;
|
|
|
|
|
int _shown_minute = -1;
|
2026-10-13 01:52:34 +02:00
|
|
|
bool _shown_evening = false;
|
|
|
|
|
uint32_t _content_revision = 0; // changed page, bitmap or live image
|
|
|
|
|
uint32_t _shown_revision = 0;
|
|
|
|
|
|
|
|
|
|
bool _live = false;
|
|
|
|
|
uint32_t _live_since = 0;
|
2026-10-13 00:56:32 +02:00
|
|
|
|
2026-10-13 01:34:04 +02:00
|
|
|
bool _wifi_lost = false;
|
|
|
|
|
uint32_t _wifi_lost_since = 0;
|
|
|
|
|
|
2026-10-13 01:52:34 +02:00
|
|
|
void _ensureOn();
|
2026-10-13 01:34:04 +02:00
|
|
|
void _showClock(int hour, int minute, bool no_wifi);
|
2026-10-13 01:52:34 +02:00
|
|
|
void _showOnce(Screen screen);
|
2026-10-13 00:56:32 +02:00
|
|
|
};
|