supla-device
Loading...
Searching...
No Matches
clock.h
1// SPDX-FileCopyrightText: AC SOFTWARE SP. Z O.O.
2// SPDX-License-Identifier: GPL-2.0-or-later
3
4#ifndef SRC_SUPLA_CLOCK_CLOCK_H_
5#define SRC_SUPLA_CLOCK_CLOCK_H_
6
7#include <supla-common/proto.h>
8#include <supla/element.h>
9#include <time.h>
10#include <supla/control/hvac_base.h>
11
12namespace Supla {
13
14const char AutomaticTimeSyncCfgTag[] = "timesync_auto";
15
16class Clock : public Element {
17 public:
23 static bool IsReady();
24
30 static int GetYear();
31
37 static int GetMonth();
38
44 static int GetDay();
45
53 static int GetDayOfWeek();
54
62 static enum DayOfWeek GetHvacDayOfWeek();
63
69 static int GetHour();
70
78 static int GetQuarter();
79
85 static int GetMin();
86
92 static int GetSec();
93
94 static time_t GetTimeStamp();
95 static bool GetLocalTime(struct tm *timeInfo);
96
102 static Clock* GetInstance();
103
104 Clock();
105 virtual ~Clock();
106
107 virtual bool isReady();
108 virtual int getYear();
109 virtual int getMonth();
110 virtual int getDay();
111 virtual int getDayOfWeek();
112 virtual enum DayOfWeek getHvacDayOfWeek();
113 virtual int getHour();
114 virtual int getQuarter();
115 virtual int getMin();
116 virtual int getSec();
117 virtual time_t getTimeStamp();
118 virtual bool getLocalTime(struct tm *timeInfo);
119
120 void onTimer() override;
121 bool iterateConnected() override;
122 void onLoadConfig(SuplaDeviceClass *sdc) override;
123 void onDeviceConfigChange(uint64_t fieldBit) override;
124
125 virtual void parseLocaltimeFromServer(TSDC_UserLocalTimeResult *result);
126
127 void setUseAutomaticTimeSyncRemoteConfig(bool value);
128 void printCurrentTime(const char *prefix = nullptr);
129
130 void setAutomaticTimeSync(bool value) { automaticTimeSync = value; }
131
132 protected:
133 void setSystemTime(time_t newTime);
134 time_t localtime = {};
135 uint32_t lastServerUpdate = 0;
136 uint32_t lastMillis = 0;
137 bool isClockReady = false;
138 bool automaticTimeSync = true;
139 bool useAutomaticTimeSyncRemoteConfig = true;
140};
141
142}; // namespace Supla
143
144#endif // SRC_SUPLA_CLOCK_CLOCK_H_
Definition SuplaDevice.h:167
Definition clock.h:16
static int GetMonth()
Returns month from Clock (if is set and ready).
Definition clock.cpp:36
static enum DayOfWeek GetHvacDayOfWeek()
Returns day of week from Clock to HVAC (if is set and ready).
Definition clock.cpp:57
bool iterateConnected() override
Method called on each SuplaDevice iteration when device is connected and registered to Supla server o...
Definition clock.cpp:238
static Clock * GetInstance()
Returns pointer of Clock.
Definition clock.cpp:103
static int GetHour()
Returns hour from Clock (if is set and ready).
Definition clock.cpp:64
static int GetYear()
Returns year from Clock (if is set and ready).
Definition clock.cpp:29
static int GetDayOfWeek()
Returns day of week from Clock (if is set and ready).
Definition clock.cpp:50
static bool IsReady()
Checks if Clock is set and ready.
Definition clock.cpp:22
void onTimer() override
Method called on timer interupt.
Definition clock.cpp:222
static int GetDay()
Returns day from Clock (if is set and ready).
Definition clock.cpp:43
void onLoadConfig(SuplaDeviceClass *sdc) override
First method called on element in SuplaDevice.begin().
Definition clock.cpp:255
static int GetSec()
Returns seconds from Clock (if is set and ready).
Definition clock.cpp:85
void onDeviceConfigChange(uint64_t fieldBit) override
Method called when device config is changed.
Definition clock.cpp:279
static int GetMin()
Returns minutes from Clock (if is set and ready).
Definition clock.cpp:78
static int GetQuarter()
Returns quarter from Clock (if is set and ready).
Definition clock.cpp:71
Base class for all elements of SuplaDevice.
Definition element.h:30
Definition proto.h:2688