Blynk library for embedded hardware. Works with Arduino, ESP8266, Raspberry Pi, Intel Edison/Galileo, LinkIt ONE, Particle Core/Photon, Energia, ARM mbed, etc. http://www.blynk.cc/
Dependents: Blynk_RBL_BLE_Nano Blynk_MicroBit Blynk_Serial Blynk_RBL_BLE_Nano
WidgetTimeInput.h
00001 /** 00002 * @file WidgetTimeInput.h 00003 * @author Volodymyr Shymanskyy 00004 * @license This project is released under the MIT License (MIT) 00005 * @copyright Copyright (c) 2015 Volodymyr Shymanskyy 00006 * @date Aug 2016 00007 * @brief 00008 * 00009 */ 00010 00011 #ifndef WidgetTimeInput_h 00012 #define WidgetTimeInput_h 00013 00014 #include <Blynk/BlynkApi.h> 00015 #include <utility/BlynkDateTime.h> 00016 #include <utility/BlynkUtility.h> 00017 00018 class TimeInputParam 00019 { 00020 public: 00021 enum TimeMode { 00022 TIME_UNDEFINED, 00023 TIME_SUNSET, 00024 TIME_SUNRISE, 00025 TIME_SPECIFIED 00026 }; 00027 00028 TimeInputParam(const BlynkParam& param) 00029 { 00030 mStartMode = TIME_UNDEFINED; 00031 mStopMode = TIME_UNDEFINED; 00032 mTZ[0] = '\0'; 00033 mWeekdays = -1; // All set 00034 mTZ_Offset = 0; 00035 00036 BlynkParam::iterator it = param.begin(); 00037 if (it >= param.end()) 00038 return; 00039 00040 if (0 == strcmp(it.asStr(), "sr")) { 00041 mStartMode = TIME_SUNRISE; 00042 } else if (0 == strcmp(it.asStr(), "ss")) { 00043 mStartMode = TIME_SUNSET; 00044 } else if (!it.isEmpty()) { 00045 mStart = BlynkTime(it.asLong()); 00046 if (mStart.isValid()) { 00047 mStartMode = TIME_SPECIFIED; 00048 } 00049 } 00050 00051 if (++it >= param.end()) 00052 return; 00053 00054 if (0 == strcmp(it.asStr(), "sr")) { 00055 mStopMode = TIME_SUNRISE; 00056 } else if (0 == strcmp(it.asStr(), "ss")) { 00057 mStopMode = TIME_SUNSET; 00058 } else if (!it.isEmpty()) { 00059 mStop = BlynkTime(it.asLong()); 00060 if (mStop.isValid()) { 00061 mStopMode = TIME_SPECIFIED; 00062 } 00063 } 00064 00065 if (++it >= param.end()) 00066 return; 00067 00068 strncpy(mTZ, it.asStr(), sizeof(mTZ)); 00069 00070 if (++it >= param.end()) 00071 return; 00072 00073 if (!it.isEmpty()) { 00074 mWeekdays = 0; 00075 const char* p = it.asStr(); 00076 00077 while (int c = *p++) { 00078 if (c >= '1' && c <= '7') { 00079 BlynkBitSet(mWeekdays, c - '1'); 00080 } 00081 } 00082 } 00083 00084 if (++it >= param.end()) 00085 return; 00086 00087 mTZ_Offset = it.asLong(); 00088 } 00089 00090 BlynkTime& getStart() { return mStart; } 00091 BlynkTime& getStop() { return mStop; } 00092 00093 TimeMode getStartMode() const { return mStartMode; } 00094 TimeMode getStopMode() const { return mStopMode; } 00095 00096 bool hasStartTime() const { return mStartMode == TIME_SPECIFIED; } 00097 bool isStartSunrise() const { return mStartMode == TIME_SUNRISE; } 00098 bool isStartSunset() const { return mStartMode == TIME_SUNSET; } 00099 int getStartHour() const { return mStart.hour(); } 00100 int getStartMinute() const { return mStart.minute(); } 00101 int getStartSecond() const { return mStart.second(); } 00102 00103 bool hasStopTime() const { return mStopMode == TIME_SPECIFIED; } 00104 bool isStopSunrise() const { return mStopMode == TIME_SUNRISE; } 00105 bool isStopSunset() const { return mStopMode == TIME_SUNSET; } 00106 int getStopHour() const { return mStop.hour(); } 00107 int getStopMinute() const { return mStop.minute(); } 00108 int getStopSecond() const { return mStop.second(); } 00109 00110 const char* getTZ() const { return mTZ; } 00111 int32_t getTZ_Offset() const { return mTZ_Offset; } 00112 00113 bool isWeekdaySelected(int day) const { 00114 return BlynkBitRead(mWeekdays, (day - 1) % 7); 00115 } 00116 00117 private: 00118 BlynkTime mStart; 00119 BlynkTime mStop; 00120 char mTZ[32]; 00121 int32_t mTZ_Offset; 00122 00123 TimeMode mStopMode; 00124 TimeMode mStartMode; 00125 00126 uint8_t mWeekdays; 00127 }; 00128 00129 #endif
Generated on Tue Jul 12 2022 15:11:12 by 1.7.2