Skip to content

Commit f11f6fc

Browse files
Improve DateStrings, reply on Arduino.h to define PROGMEM, etc
1 parent 98c6ec9 commit f11f6fc

File tree

1 file changed

+11
-15
lines changed

1 file changed

+11
-15
lines changed

DateStrings.cpp

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,18 @@
99
*
1010
*/
1111

12-
#if defined(__AVR__)
13-
#include <avr/pgmspace.h>
14-
#else
15-
// for compatiblity with Arduino Due and Teensy 3.0 and maybe others?
12+
#include <Arduino.h>
13+
14+
// Arduino.h should properly define PROGMEM, PGM_P, strcpy_P, pgm_read_byte, pgm_read_ptr
15+
// But not all platforms define these as they should. If you find a platform needing these
16+
// defined, or if any this becomes unnecessary as platforms improve, please send a pull req.
17+
#if defined(ESP8266)
18+
#undef PROGMEM
1619
#define PROGMEM
17-
#define PGM_P const char *
18-
#define pgm_read_byte(addr) (*(const unsigned char *)(addr))
19-
#define pgm_read_word(addr) (*(const unsigned char **)(addr))
20-
#if defined(ESP8266) || defined(ARDUINO_ARCH_ESP32)
21-
#ifndef strcpy_P
22-
#define strcpy_P(dest, src) strcpy((dest), (src))
23-
#endif
24-
#endif
2520
#endif
26-
#include <string.h> // for strcpy_P or strcpy
21+
2722
#include "TimeLib.h"
23+
2824

2925
// the short strings for each day or month must be exactly dt_SHORT_STR_LEN
3026
#define dt_SHORT_STR_LEN 3 // the length of short strings
@@ -73,7 +69,7 @@ const char dayShortNames_P[] PROGMEM = "ErrSunMonTueWedThuFriSat";
7369

7470
char* monthStr(uint8_t month)
7571
{
76-
strcpy_P(buffer, (PGM_P)pgm_read_word(&(monthNames_P[month])));
72+
strcpy_P(buffer, (PGM_P)pgm_read_ptr(&(monthNames_P[month])));
7773
return buffer;
7874
}
7975

@@ -87,7 +83,7 @@ char* monthShortStr(uint8_t month)
8783

8884
char* dayStr(uint8_t day)
8985
{
90-
strcpy_P(buffer, (PGM_P)pgm_read_word(&(dayNames_P[day])));
86+
strcpy_P(buffer, (PGM_P)pgm_read_ptr(&(dayNames_P[day])));
9187
return buffer;
9288
}
9389

0 commit comments

Comments
 (0)