experiments with Pylontech/GroWatt PV tech
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

97 lines
3.1 KiB

  1. /* DateStrings.cpp
  2. * Definitions for date strings for use with the Time library
  3. *
  4. * Updated for Arduino 1.5.7 18 July 2014
  5. *
  6. * No memory is consumed in the sketch if your code does not call any of the string methods
  7. * You can change the text of the strings, make sure the short strings are each exactly 3 characters
  8. * the long strings can be any length up to the constant dt_MAX_STRING_LEN defined in TimeLib.h
  9. *
  10. */
  11. #if defined(__AVR__)
  12. #include <avr/pgmspace.h>
  13. #else
  14. // for compatiblity with Arduino Due and Teensy 3.0 and maybe others?
  15. #define PROGMEM
  16. #define PGM_P const char *
  17. #define pgm_read_byte(addr) (*(const unsigned char *)(addr))
  18. #define pgm_read_word(addr) (*(const unsigned char **)(addr))
  19. #define strcpy_P(dest, src) strcpy((dest), (src))
  20. #endif
  21. #include <string.h> // for strcpy_P or strcpy
  22. #include "TimeLib.h"
  23. // the short strings for each day or month must be exactly dt_SHORT_STR_LEN
  24. #define dt_SHORT_STR_LEN 3 // the length of short strings
  25. static char buffer[dt_MAX_STRING_LEN+1]; // must be big enough for longest string and the terminating null
  26. const char monthStr0[] PROGMEM = "";
  27. const char monthStr1[] PROGMEM = "January";
  28. const char monthStr2[] PROGMEM = "February";
  29. const char monthStr3[] PROGMEM = "March";
  30. const char monthStr4[] PROGMEM = "April";
  31. const char monthStr5[] PROGMEM = "May";
  32. const char monthStr6[] PROGMEM = "June";
  33. const char monthStr7[] PROGMEM = "July";
  34. const char monthStr8[] PROGMEM = "August";
  35. const char monthStr9[] PROGMEM = "September";
  36. const char monthStr10[] PROGMEM = "October";
  37. const char monthStr11[] PROGMEM = "November";
  38. const char monthStr12[] PROGMEM = "December";
  39. const PROGMEM char * const PROGMEM monthNames_P[] =
  40. {
  41. monthStr0,monthStr1,monthStr2,monthStr3,monthStr4,monthStr5,monthStr6,
  42. monthStr7,monthStr8,monthStr9,monthStr10,monthStr11,monthStr12
  43. };
  44. const char monthShortNames_P[] PROGMEM = "ErrJanFebMarAprMayJunJulAugSepOctNovDec";
  45. const char dayStr0[] PROGMEM = "Err";
  46. const char dayStr1[] PROGMEM = "Sunday";
  47. const char dayStr2[] PROGMEM = "Monday";
  48. const char dayStr3[] PROGMEM = "Tuesday";
  49. const char dayStr4[] PROGMEM = "Wednesday";
  50. const char dayStr5[] PROGMEM = "Thursday";
  51. const char dayStr6[] PROGMEM = "Friday";
  52. const char dayStr7[] PROGMEM = "Saturday";
  53. const PROGMEM char * const PROGMEM dayNames_P[] =
  54. {
  55. dayStr0,dayStr1,dayStr2,dayStr3,dayStr4,dayStr5,dayStr6,dayStr7
  56. };
  57. const char dayShortNames_P[] PROGMEM = "ErrSunMonTueWedThuFriSat";
  58. /* functions to return date strings */
  59. char* monthStr(uint8_t month)
  60. {
  61. strcpy_P(buffer, (PGM_P)pgm_read_word(&(monthNames_P[month])));
  62. return buffer;
  63. }
  64. char* monthShortStr(uint8_t month)
  65. {
  66. for (int i=0; i < dt_SHORT_STR_LEN; i++)
  67. buffer[i] = pgm_read_byte(&(monthShortNames_P[i+ (month*dt_SHORT_STR_LEN)]));
  68. buffer[dt_SHORT_STR_LEN] = 0;
  69. return buffer;
  70. }
  71. char* dayStr(uint8_t day)
  72. {
  73. strcpy_P(buffer, (PGM_P)pgm_read_word(&(dayNames_P[day])));
  74. return buffer;
  75. }
  76. char* dayShortStr(uint8_t day)
  77. {
  78. uint8_t index = day*dt_SHORT_STR_LEN;
  79. for (int i=0; i < dt_SHORT_STR_LEN; i++)
  80. buffer[i] = pgm_read_byte(&(dayShortNames_P[index + i]));
  81. buffer[dt_SHORT_STR_LEN] = 0;
  82. return buffer;
  83. }