Public Access
68 lines
1.6 KiB
C++
68 lines
1.6 KiB
C++
#pragma once
|
|||
|
|
|
||
|
|
#include <stdint.h>
|
||
|
|
|
||
|
|
#include "logic/power_timer.h"
|
||
|
|
|
||
|
|
// 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:
|
||
|
|
virtual void clock(int hour, int minute) = 0;
|
||
|
|
virtual void logo() = 0;
|
||
|
|
virtual void blank() = 0;
|
||
|
|
};
|
||
|
|
|
||
|
|
// Decides what the display shows and when it is powered, based on the time and the two
|
||
|
|
// Home Assistant switches. A frame is only sent when it changes. Pure logic, tested in
|
||
|
|
// test/test_esp32.
|
||
|
|
class DisplayController
|
||
|
|
{
|
||
|
|
public:
|
||
|
|
DisplayController(DisplayPower &power, Frames &frames);
|
||
|
|
|
||
|
|
// Home Assistant "FlipDot Display Clock" switch: off shows the logo instead of the clock
|
||
|
|
void setClockEnabled(bool enabled);
|
||
|
|
// Home Assistant "FlipDot Display Power" switch: off clears the display and powers it off
|
||
|
|
void setPowerEnabled(bool enabled);
|
||
|
|
|
||
|
|
bool clockEnabled() const;
|
||
|
|
bool powerEnabled() const;
|
||
|
|
|
||
|
|
// Call often (every loop). time_valid is false until the time is synced over NTP.
|
||
|
|
void update(uint32_t now, bool time_valid, int hour, int minute);
|
||
|
|
|
||
|
|
private:
|
||
|
|
enum class Screen
|
||
|
|
{
|
||
|
|
Unknown, // nothing sent since the last power on
|
||
|
|
Clock,
|
||
|
|
Logo,
|
||
|
|
Blank,
|
||
|
|
};
|
||
|
|
|
||
|
|
DisplayPower &_power;
|
||
|
|
Frames &_frames;
|
||
|
|
PowerTimer _off_timer;
|
||
|
|
|
||
|
|
bool _clock_enabled = true;
|
||
|
|
bool _power_enabled = true;
|
||
|
|
|
||
|
|
Screen _screen = Screen::Unknown;
|
||
|
|
int _shown_hour = -1;
|
||
|
|
int _shown_minute = -1;
|
||
|
|
|
||
|
|
void _showClock(int hour, int minute);
|
||
|
|
void _showLogo();
|
||
|
|
void _showBlank();
|
||
|
|
};
|