-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWidgetTimeInput.h
executable file
·129 lines (104 loc) · 3.42 KB
/
WidgetTimeInput.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/**
* @file WidgetTimeInput.h
* @author Volodymyr Shymanskyy
* @license This project is released under the MIT License (MIT)
* @copyright Copyright (c) 2015 Volodymyr Shymanskyy
* @date Aug 2016
* @brief
*
*/
#ifndef WidgetTimeInput_h
#define WidgetTimeInput_h
#include "BlynkApi.h"
#include "BlynkDateTime.h"
#include "BlynkUtility.h"
class TimeInputParam
{
public:
enum TimeMode {
TIME_UNDEFINED,
TIME_SUNSET,
TIME_SUNRISE,
TIME_SPECIFIED
};
TimeInputParam(const BlynkParam& param)
{
mStartMode = TIME_UNDEFINED;
mStopMode = TIME_UNDEFINED;
mTZ[0] = '\0';
mWeekdays = -1; // All set
mTZ_Offset = 0;
BlynkParam::iterator it = param.begin();
if (it >= param.end())
return;
if (0 == strcmp(it.asStr(), "sr")) {
mStartMode = TIME_SUNRISE;
} else if (0 == strcmp(it.asStr(), "ss")) {
mStartMode = TIME_SUNSET;
} else if (!it.isEmpty()) {
mStart = BlynkTime(it.asLong());
if (mStart.isValid()) {
mStartMode = TIME_SPECIFIED;
}
}
if (++it >= param.end())
return;
if (0 == strcmp(it.asStr(), "sr")) {
mStopMode = TIME_SUNRISE;
} else if (0 == strcmp(it.asStr(), "ss")) {
mStopMode = TIME_SUNSET;
} else if (!it.isEmpty()) {
mStop = BlynkTime(it.asLong());
if (mStop.isValid()) {
mStopMode = TIME_SPECIFIED;
}
}
if (++it >= param.end())
return;
strncpy(mTZ, it.asStr(), sizeof(mTZ));
if (++it >= param.end())
return;
if (!it.isEmpty()) {
mWeekdays = 0;
const char* p = it.asStr();
while (int c = *p++) {
if (c >= '1' && c <= '7') {
BlynkBitSet(mWeekdays, c - '1');
}
}
}
if (++it >= param.end())
return;
mTZ_Offset = it.asLong();
}
BlynkTime& getStart() { return mStart; }
BlynkTime& getStop() { return mStop; }
TimeMode getStartMode() const { return mStartMode; }
TimeMode getStopMode() const { return mStopMode; }
bool hasStartTime() const { return mStartMode == TIME_SPECIFIED; }
bool isStartSunrise() const { return mStartMode == TIME_SUNRISE; }
bool isStartSunset() const { return mStartMode == TIME_SUNSET; }
int getStartHour() const { return mStart.hour(); }
int getStartMinute() const { return mStart.minute(); }
int getStartSecond() const { return mStart.second(); }
bool hasStopTime() const { return mStopMode == TIME_SPECIFIED; }
bool isStopSunrise() const { return mStopMode == TIME_SUNRISE; }
bool isStopSunset() const { return mStopMode == TIME_SUNSET; }
int getStopHour() const { return mStop.hour(); }
int getStopMinute() const { return mStop.minute(); }
int getStopSecond() const { return mStop.second(); }
const char* getTZ() const { return mTZ; }
uint32_t getTZ_Offset() const { return mTZ_Offset; }
bool isWeekdaySelected(int day) const {
return BlynkBitRead(mWeekdays, (day - 1) % 7);
}
private:
BlynkTime mStart;
BlynkTime mStop;
char mTZ[32];
uint32_t mTZ_Offset;
TimeMode mStopMode;
TimeMode mStartMode;
uint8_t mWeekdays;
};
#endif