helpers.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. //#ifndef HELPERS_H
  2. //#define HELPERS_H
  3. //
  4. //
  5. //
  6. //static const uint8_t monthDays[]={31,28,31,30,31,30,31,31,30,31,30,31};
  7. //#define LEAP_YEAR(Y) ( ((1970+Y)>0) && !((1970+Y)%4) && ( ((1970+Y)%100) || !((1970+Y)%400) ) )
  8. //
  9. //
  10. //struct strDateTime
  11. //{
  12. // byte hour;
  13. // byte minute;
  14. // byte second;
  15. // int year;
  16. // byte month;
  17. // byte day;
  18. // byte wday;
  19. //
  20. //} ;
  21. //
  22. //
  23. //
  24. ////
  25. //// Summertime calculates the daylight saving for a given date.
  26. ////
  27. //boolean summertime(int year, byte month, byte day, byte hour, byte tzHours)
  28. //// input parameters: "normal time" for year, month, day, hour and tzHours (0=UTC, 1=MEZ)
  29. //{
  30. // if (month<3 || month>10) return false; // keine Sommerzeit in Jan, Feb, Nov, Dez
  31. // if (month>3 && month<10) return true; // Sommerzeit in Apr, Mai, Jun, Jul, Aug, Sep
  32. // if (month==3 && (hour + 24 * day)>=(1 + tzHours + 24*(31 - (5 * year /4 + 4) % 7)) || month==10 && (hour + 24 * day)<(1 + tzHours + 24*(31 - (5 * year /4 + 1) % 7)))
  33. // return true;
  34. // else
  35. // return false;
  36. //}
  37. //
  38. ////
  39. //// Check the Values is between 0-255
  40. ////
  41. //boolean checkRange(String Value)
  42. //{
  43. // if (Value.toInt() < 0 || Value.toInt() > 255)
  44. // {
  45. // return false;
  46. // }
  47. // else
  48. // {
  49. // return true;
  50. // }
  51. //}
  52. //
  53. //
  54. //void WriteStringToEEPROM(int beginaddress, String string)
  55. //{
  56. // char charBuf[string.length()+1];
  57. // string.toCharArray(charBuf, string.length()+1);
  58. // for (int t= 0; t<sizeof(charBuf);t++)
  59. // {
  60. // EEPROM.write(beginaddress + t,charBuf[t]);
  61. // }
  62. //}
  63. //String ReadStringFromEEPROM(int beginaddress)
  64. //{
  65. // byte counter=0;
  66. // char rChar;
  67. // String retString = "";
  68. // while (1)
  69. // {
  70. // rChar = EEPROM.read(beginaddress + counter);
  71. // if (rChar == 0) break;
  72. // if (counter > 31) break;
  73. // counter++;
  74. // retString.concat(rChar);
  75. //
  76. // }
  77. // return retString;
  78. //}
  79. //void EEPROMWritelong(int address, long value)
  80. // {
  81. // byte four = (value & 0xFF);
  82. // byte three = ((value >> 8) & 0xFF);
  83. // byte two = ((value >> 16) & 0xFF);
  84. // byte one = ((value >> 24) & 0xFF);
  85. //
  86. // //Write the 4 bytes into the eeprom memory.
  87. // EEPROM.write(address, four);
  88. // EEPROM.write(address + 1, three);
  89. // EEPROM.write(address + 2, two);
  90. // EEPROM.write(address + 3, one);
  91. // }
  92. //long EEPROMReadlong(long address)
  93. // {
  94. // //Read the 4 bytes from the eeprom memory.
  95. // long four = EEPROM.read(address);
  96. // long three = EEPROM.read(address + 1);
  97. // long two = EEPROM.read(address + 2);
  98. // long one = EEPROM.read(address + 3);
  99. //
  100. // //Return the recomposed long by using bitshift.
  101. // return ((four << 0) & 0xFF) + ((three << 8) & 0xFFFF) + ((two << 16) & 0xFFFFFF) + ((one << 24) & 0xFFFFFFFF);
  102. //}
  103. //
  104. //void ConvertUnixTimeStamp( unsigned long TimeStamp, struct strDateTime* DateTime)
  105. //{
  106. // uint8_t year;
  107. // uint8_t month, monthLength;
  108. // uint32_t time;
  109. // unsigned long days;
  110. // time = (uint32_t)TimeStamp;
  111. // DateTime->second = time % 60;
  112. // time /= 60; // now it is minutes
  113. // DateTime->minute = time % 60;
  114. // time /= 60; // now it is hours
  115. // DateTime->hour = time % 24;
  116. // time /= 24; // now it is days
  117. // DateTime->wday = ((time + 4) % 7) + 1; // Sunday is day 1
  118. //
  119. // year = 0;
  120. // days = 0;
  121. // while((unsigned)(days += (LEAP_YEAR(year) ? 366 : 365)) <= time) {
  122. // year++;
  123. // }
  124. // DateTime->year = year; // year is offset from 1970
  125. //
  126. // days -= LEAP_YEAR(year) ? 366 : 365;
  127. // time -= days; // now it is days in this year, starting at 0
  128. //
  129. // days=0;
  130. // month=0;
  131. // monthLength=0;
  132. // for (month=0; month<12; month++) {
  133. // if (month==1) { // february
  134. // if (LEAP_YEAR(year)) {
  135. // monthLength=29;
  136. // } else {
  137. // monthLength=28;
  138. // }
  139. // } else {
  140. // monthLength = monthDays[month];
  141. // }
  142. //
  143. // if (time >= monthLength) {
  144. // time -= monthLength;
  145. // } else {
  146. // break;
  147. // }
  148. // }
  149. // DateTime->month = month + 1; // jan is month 1
  150. // DateTime->day = time + 1; // day of month
  151. // DateTime->year += 1970;
  152. //
  153. //
  154. //}
  155. //
  156. //
  157. //
  158. //String GetMacAddress()
  159. //{
  160. // uint8_t mac[6];
  161. // char macStr[18] = {0};
  162. // WiFi.macAddress(mac);
  163. // sprintf(macStr, "%02X:%02X:%02X:%02X:%02X:%02X", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
  164. // return String(macStr);
  165. //}
  166. //
  167. //// convert a single hex digit character to its integer value (from https://code.google.com/p/avr-netino/)
  168. //unsigned char h2int(char c)
  169. //{
  170. // if (c >= '0' && c <='9'){
  171. // return((unsigned char)c - '0');
  172. // }
  173. // if (c >= 'a' && c <='f'){
  174. // return((unsigned char)c - 'a' + 10);
  175. // }
  176. // if (c >= 'A' && c <='F'){
  177. // return((unsigned char)c - 'A' + 10);
  178. // }
  179. // return(0);
  180. //}
  181. //
  182. //String urldecode(String input) // (based on https://code.google.com/p/avr-netino/)
  183. //{
  184. // char c;
  185. // String ret = "";
  186. //
  187. // for(byte t=0;t<input.length();t++)
  188. // {
  189. // c = input[t];
  190. // if (c == '+') c = ' ';
  191. // if (c == '%') {
  192. //
  193. //
  194. // t++;
  195. // c = input[t];
  196. // t++;
  197. // c = (h2int(c) << 4) | h2int(input[t]);
  198. // }
  199. //
  200. // ret.concat(c);
  201. // }
  202. // return ret;
  203. //
  204. //}
  205. //
  206. //
  207. //
  208. //
  209. //
  210. //#endif