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:
18 static bool IsReady();
19 static int GetYear();
20 static int GetMonth();
21 static int GetDay();
22 static int GetDayOfWeek(); // 1 - Sunday, 2 - Monday
23 static enum DayOfWeek GetHvacDayOfWeek(); // 0 - Sunday, 1 - Monday as enum
24 static int GetHour();
25 static int GetQuarter(); // 0 - 0..14 min, 1 - 15..29 min, 2 - 30..44 min, 3
26 // - 45..59 min
27 static int GetMin();
28 static int GetSec();
29 static time_t GetTimeStamp();
30
31 static Clock* GetInstance();
32
33 Clock();
34 virtual ~Clock();
35
36 virtual bool isReady();
37 virtual int getYear();
38 virtual int getMonth();
39 virtual int getDay();
40 virtual int getDayOfWeek();
41 virtual enum DayOfWeek getHvacDayOfWeek();
42 virtual int getHour();
43 virtual int getQuarter();
44 virtual int getMin();
45 virtual int getSec();
46 virtual time_t getTimeStamp();
47
48 void onTimer() override;
49 bool iterateConnected() override;
50 void onLoadConfig(SuplaDeviceClass *sdc) override;
51 void onDeviceConfigChange(uint64_t fieldBit) override;
52
53 virtual void parseLocaltimeFromServer(TSDC_UserLocalTimeResult *result);
54
55 void setUseAutomaticTimeSyncRemoteConfig(bool value);
56 void printCurrentTime(const char *prefix = nullptr);
57
58 void setAutomaticTimeSync(bool value) { automaticTimeSync = value; }
59
60 protected:
61 void setSystemTime(time_t newTime);
62 time_t localtime = {};
63 uint32_t lastServerUpdate = 0;
64 uint32_t lastMillis = 0;
65 bool isClockReady = false;
66 bool automaticTimeSync = true;
67 bool useAutomaticTimeSyncRemoteConfig = true;
68};
69
70}; // namespace Supla
71
72#endif // SRC_SUPLA_CLOCK_CLOCK_H_
Definition SuplaDevice.h:167
Definition clock.h:16
bool iterateConnected() override
Method called on each SuplaDevice iteration when device is connected and registered to Supla server o...
Definition clock.cpp:220
void onTimer() override
Method called on timer interupt.
Definition clock.cpp:204
void onLoadConfig(SuplaDeviceClass *sdc) override
First method called on element in SuplaDevice.begin().
Definition clock.cpp:237
void onDeviceConfigChange(uint64_t fieldBit) override
Method called when device config is changed.
Definition clock.cpp:261
Base class for all elements of SuplaDevice.
Definition element.h:27
Definition proto.h:2642