PlatformIO package of the Teensy core framework compatible with GCC 10 & C++20
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

98 Zeilen
3.1KB

  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. #include <Arduino.h>
  12. // Arduino.h should properly define PROGMEM, PGM_P, strcpy_P, pgm_read_byte, pgm_read_ptr
  13. // But not all platforms define these as they should. If you find a platform needing these
  14. // defined, or if any this becomes unnecessary as platforms improve, please send a pull req.
  15. #if defined(ESP8266)
  16. #undef PROGMEM
  17. #define PROGMEM
  18. #endif
  19. #include "TimeLib.h"
  20. // the short strings for each day or month must be exactly dt_SHORT_STR_LEN
  21. #define dt_SHORT_STR_LEN 3 // the length of short strings
  22. static char buffer[dt_MAX_STRING_LEN+1]; // must be big enough for longest string and the terminating null
  23. const char monthStr0[] PROGMEM = "";
  24. const char monthStr1[] PROGMEM = "January";
  25. const char monthStr2[] PROGMEM = "February";
  26. const char monthStr3[] PROGMEM = "March";
  27. const char monthStr4[] PROGMEM = "April";
  28. const char monthStr5[] PROGMEM = "May";
  29. const char monthStr6[] PROGMEM = "June";
  30. const char monthStr7[] PROGMEM = "July";
  31. const char monthStr8[] PROGMEM = "August";
  32. const char monthStr9[] PROGMEM = "September";
  33. const char monthStr10[] PROGMEM = "October";
  34. const char monthStr11[] PROGMEM = "November";
  35. const char monthStr12[] PROGMEM = "December";
  36. const PROGMEM char * const PROGMEM monthNames_P[] =
  37. {
  38. monthStr0,monthStr1,monthStr2,monthStr3,monthStr4,monthStr5,monthStr6,
  39. monthStr7,monthStr8,monthStr9,monthStr10,monthStr11,monthStr12
  40. };
  41. const char monthShortNames_P[] PROGMEM = "ErrJanFebMarAprMayJunJulAugSepOctNovDec";
  42. const char dayStr0[] PROGMEM = "Err";
  43. const char dayStr1[] PROGMEM = "Sunday";
  44. const char dayStr2[] PROGMEM = "Monday";
  45. const char dayStr3[] PROGMEM = "Tuesday";
  46. const char dayStr4[] PROGMEM = "Wednesday";
  47. const char dayStr5[] PROGMEM = "Thursday";
  48. const char dayStr6[] PROGMEM = "Friday";
  49. const char dayStr7[] PROGMEM = "Saturday";
  50. const PROGMEM char * const PROGMEM dayNames_P[] =
  51. {
  52. dayStr0,dayStr1,dayStr2,dayStr3,dayStr4,dayStr5,dayStr6,dayStr7
  53. };
  54. const char dayShortNames_P[] PROGMEM = "ErrSunMonTueWedThuFriSat";
  55. /* functions to return date strings */
  56. char* monthStr(uint8_t month)
  57. {
  58. strcpy_P(buffer, (PGM_P)pgm_read_ptr(&(monthNames_P[month])));
  59. return buffer;
  60. }
  61. char* monthShortStr(uint8_t month)
  62. {
  63. for (int i=0; i < dt_SHORT_STR_LEN; i++)
  64. buffer[i] = pgm_read_byte(&(monthShortNames_P[i+ (month*dt_SHORT_STR_LEN)]));
  65. buffer[dt_SHORT_STR_LEN] = 0;
  66. return buffer;
  67. }
  68. char* dayStr(uint8_t day)
  69. {
  70. strcpy_P(buffer, (PGM_P)pgm_read_ptr(&(dayNames_P[day])));
  71. return buffer;
  72. }
  73. char* dayShortStr(uint8_t day)
  74. {
  75. uint8_t index = day*dt_SHORT_STR_LEN;
  76. for (int i=0; i < dt_SHORT_STR_LEN; i++)
  77. buffer[i] = pgm_read_byte(&(dayShortNames_P[index + i]));
  78. buffer[dt_SHORT_STR_LEN] = 0;
  79. return buffer;
  80. }