80 lines
2.1 KiB
Plaintext
80 lines
2.1 KiB
Plaintext
|
//
|
||
|
// FILE: ClockServer.h
|
||
|
// VERSION: 0.1
|
||
|
// PURPOSE: FREMO Clock Server
|
||
|
//
|
||
|
//
|
||
|
|
||
|
#ifndef _ClockServerLoaded
|
||
|
#define _ClockServerLoaded
|
||
|
|
||
|
#include <Arduino.h>
|
||
|
#include <DjDebug.h>
|
||
|
#include <DjConfig.h>
|
||
|
#include <DjFastclockScanner.h>
|
||
|
#include <Ticker.h>
|
||
|
#include <WiFiUDP.h>
|
||
|
|
||
|
#define MAX_CLOCK_CHANGE_CALLBACKS 5
|
||
|
|
||
|
typedef void (*ClockChangeCallback)(int h, int m, int s);
|
||
|
|
||
|
enum class ClockServerStatus {
|
||
|
ServerNotStarted,
|
||
|
CollectingExistingClocks,
|
||
|
StartingServer,
|
||
|
WaitForAutoActivate,
|
||
|
ServerStarted
|
||
|
};
|
||
|
|
||
|
class ClockServer
|
||
|
{
|
||
|
public:
|
||
|
ClockServer(Debug& _debug, Config& _config):debug(_debug), config(_config), fastclockScanner(_debug) {};
|
||
|
void activateClock();
|
||
|
void deactivateClock();
|
||
|
void setSpeed(float newSpeed);
|
||
|
void begin();
|
||
|
void loop();
|
||
|
static void clockTick();
|
||
|
static void setText(String newText) { text = String(newText); }
|
||
|
void sendFastclockMessage();
|
||
|
static String const getClockString() {
|
||
|
String output = String(clockHours) + ":" + String(clockMinutes) + ":" + String(clockSeconds);
|
||
|
return output;
|
||
|
}
|
||
|
static int const getHours() { return clockHours; }
|
||
|
static int const getMinutes() { return clockMinutes; }
|
||
|
static int const getSeconds() { return clockSeconds; }
|
||
|
static int const getWeekday() { return weekday; }
|
||
|
static String const getName() { return name; }
|
||
|
static float const getSpeed() { return clockSpeed; }
|
||
|
static String const getText() { return text; }
|
||
|
static boolean const isActive() { return active; }
|
||
|
|
||
|
|
||
|
private:
|
||
|
Debug& debug;
|
||
|
Config& config;
|
||
|
FastclockScanner fastclockScanner;
|
||
|
Ticker clockTrigger;
|
||
|
static float clockSpeed;
|
||
|
static String name;
|
||
|
static String text;
|
||
|
static boolean active;
|
||
|
static String clockString;
|
||
|
static String weekdayName;
|
||
|
static int clockHours;
|
||
|
static int clockMinutes;
|
||
|
static int clockSeconds;
|
||
|
static int weekday;
|
||
|
static IPAddress ipMulticast;
|
||
|
static int clientListenPort;
|
||
|
static ClockServerStatus serverStatus;
|
||
|
static uint32_t nextServerStatusTime;
|
||
|
static int sendClockUpdateEvery_ms;
|
||
|
static int autoActivateAfter_ms;
|
||
|
};
|
||
|
|
||
|
#endif
|