Мелкие доработки стилей веб-интерфейса
[esp-clock.git] / Clock.h
1 #pragma once
2 #include <ESP8266WiFi.h>
3 #include <Printable.h>
4 #include <LittleFS.h>
5 #include <RTClib.h>
6
7 // net.cpp
8
9 extern bool isNetConnected;
10
11 void setupNet(bool AP = false);
12 void tickNet();
13
14 // time.cpp
15
16 extern bool isTimeSet;
17 extern time_t now;
18 extern time_t last_sync;
19
20 extern int hh;
21 extern int mi;
22 extern int ss;
23
24 extern int dw;
25
26 extern int dd;
27 extern int mm;
28 extern int yy;
29
30 void registerTimeHandler(const char* handlerName, const char handlerType, std::function<void()> timeHandler);
31 void unregisterTimeHandler(const char* handlerName);
32 void registerTimeHandler(const __FlashStringHelper* handlerName, const char handlerType, std::function<void()> timeHandler);
33 void unregisterTimeHandler(const __FlashStringHelper* handlerName);
34 void setupHandlers();
35
36 void setupTime();
37 void tickTime();
38
39 bool isNight();
40
41 // config.cpp
42
43 char* copystr(const char* s);
44 char* copystr(const __FlashStringHelper* s);
45
46 union ValueType {
47   bool boolValue;
48   int intValue;
49   double floatValue;
50   char *charValue;
51 };
52
53 class ConfigParameter: public Printable {
54   public:
55     
56     ConfigParameter(const char *id, const char* value);
57     ConfigParameter(const char *id, int value);
58     ConfigParameter(const char *id, double value);
59     ConfigParameter(const char *id, bool value);
60     ConfigParameter(const __FlashStringHelper* id, const char* value);
61     ConfigParameter(const __FlashStringHelper* id, int value);
62     ConfigParameter(const __FlashStringHelper* id, double value);
63     ConfigParameter(const __FlashStringHelper* id, bool value);
64     ~ConfigParameter();
65     
66     const char *getID() const;
67     char  getType() const;
68     const bool getBoolValue() const;
69     const int getIntValue() const ;
70     const double getFloatValue() const;
71     const char *getCharValue() const;
72     
73     void  setValue(const bool value);
74     void  setValue(const int value);
75     void  setValue(const double value);
76     void  setValue(const char *value);
77
78     virtual size_t printTo(Print& p) const;
79   
80   protected:
81     void init(const char *id, char type);
82     void init(const __FlashStringHelper *id, char type);
83     
84   private:
85     const char *_id;
86     char  _type; // _B_oolean, _I_nt, double _F_loat, _S_tring
87     ValueType _value;
88 };
89
90 class Config: public Printable {
91   public:
92
93     Config();
94     ~Config();
95
96     ConfigParameter* getParameter(int i);
97     int   getParametersCount() const;
98
99     void   setValue(const char *id, const char *value);
100     void   setValue(const char *id, int value);
101     void   setValue(const char *id, double value);
102     void   setValue(const char *id, bool value);
103     int    getIntValue(const char *id) const;
104     double getFloatValue(const char *id) const;
105     bool   getBoolValue(const char *id) const;
106     const char* getCharValue(const char *id) const;
107
108     void   setValue(const __FlashStringHelper* id, const char *value);
109     void   setValue(const __FlashStringHelper* id, int value);
110     void   setValue(const __FlashStringHelper* id, double value);
111     void   setValue(const __FlashStringHelper* id, bool value);
112     int    getIntValue(const __FlashStringHelper* id) const;
113     double getFloatValue(const __FlashStringHelper* id) const ;
114     bool   getBoolValue(const __FlashStringHelper* id) const;
115     const char* getCharValue(const __FlashStringHelper* id) const;
116
117     ConfigParameter* getParam(const char *id) const;
118     ConfigParameter* getParam(const __FlashStringHelper* id) const;
119
120     virtual size_t printTo(Print& p) const;
121
122     void readFrom(Stream& s);
123     void dumpJson(Stream& s) const;
124
125     void clear();
126
127     unsigned long getTimestamp();
128     void resetTimestamp();
129
130   protected:
131     void init();
132     void addParameter(ConfigParameter* p);
133
134   private:
135     int         _paramsCount;
136     int         _max_params;
137     unsigned long _timestamp;
138     ConfigParameter** _params;
139   
140 };
141
142 extern Config cfg;
143 void setupConfig();
144 void saveConfig(bool force = false);
145 void reboot();
146 void reset();
147
148 // hardware.cpp
149
150 extern bool isRTCEnabled;
151 extern RTC_DS3231 RTC;
152
153 void setupHardware();
154 void tickHardware();
155
156 void beep(int tone, int length, int beep_ms = 60000, int silent_ms = 0);
157
158 // panel.cpp
159
160 #define mDefault 0
161 #define mTime 1
162 #define mDate 2
163 #define mWeather 3
164 #define mBarrier 4
165 #define mMessage 5
166 #define mLast 6
167
168 extern int screenMode;
169 extern int screenModeRequested;
170
171 void setupPanel();
172 void tickPanel();
173
174 void utf8rus(const char* source, char* target, int maxLen = 255);
175
176 void message(const char* str, int priority=10);
177 void message(const __FlashStringHelper*  str, int priority=10);
178 void messageModal(const char* str);
179 void messageModal(const __FlashStringHelper*  str);
180 void scroll(const char* str, bool force = false);
181 void setPanelBrightness();
182
183 // alarm.cpp
184
185 void setupAlarm();
186
187 // weather.cpp
188
189 extern char weatherData[256];
190
191 void setupWeatherRequest();
192
193 // web.cpp
194
195 extern bool isApEnabled;
196
197 void setupWeb();
198 void tickWeb();
199 void reportChange(const __FlashStringHelper* name);
200 void reportMessage(const __FlashStringHelper* msg);
201 void sendWeather();