forked from Makuna/NeoPixelBus
AVR needs to use some macros to access PROGMEM
This commit is contained in:
@@ -348,6 +348,11 @@ const HtmlColorName HtmlColor::ColorNames[] PROGMEM = {
|
|||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#ifndef pgm_read_ptr
|
||||||
|
// ESP8266 doesn't define this macro, but it doesn't need it either.
|
||||||
|
#define pgm_read_ptr(addr) (*reinterpret_cast<const void* const *>(addr))
|
||||||
|
#endif
|
||||||
|
|
||||||
bool HtmlColor::Parse(const char* name, size_t namelen)
|
bool HtmlColor::Parse(const char* name, size_t namelen)
|
||||||
{
|
{
|
||||||
if (name[0] == '#')
|
if (name[0] == '#')
|
||||||
@@ -394,10 +399,11 @@ bool HtmlColor::Parse(const char* name, size_t namelen)
|
|||||||
|
|
||||||
for (uint8_t i = 0; i < sizeof(ColorNames)/sizeof(ColorNames[0]); ++i)
|
for (uint8_t i = 0; i < sizeof(ColorNames)/sizeof(ColorNames[0]); ++i)
|
||||||
{
|
{
|
||||||
const HtmlColorName* cn = &ColorNames[i];
|
const HtmlColorName* cptr = &ColorNames[i];
|
||||||
if (strncasecmp_P(name, cn->Name, namelen) == 0 && strlen_P(cn->Name) == namelen)
|
PGM_P cname = (PGM_P)pgm_read_ptr(&cptr->Name);
|
||||||
|
if (strncasecmp_P(name, cname, namelen) == 0 && strlen_P(cname) == namelen)
|
||||||
{
|
{
|
||||||
Color = cn->Color;
|
Color = pgm_read_dword(&cptr->Color);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -413,14 +419,15 @@ size_t HtmlColor::ToString(char* buf, size_t buflen) const
|
|||||||
{
|
{
|
||||||
for (uint8_t i = 0; i < sizeof(ColorNames) / sizeof(ColorNames[0]); ++i)
|
for (uint8_t i = 0; i < sizeof(ColorNames) / sizeof(ColorNames[0]); ++i)
|
||||||
{
|
{
|
||||||
const HtmlColorName* cn = &ColorNames[i];
|
const HtmlColorName* cptr = &ColorNames[i];
|
||||||
if (cn->Color == Color)
|
if (pgm_read_dword(&cptr->Color) == Color)
|
||||||
{
|
{
|
||||||
size_t namelen = strlen_P(cn->Name);
|
PGM_P name = (PGM_P)pgm_read_ptr(&cptr->Name);
|
||||||
|
size_t namelen = strlen_P(name);
|
||||||
if (buflen-- > 0)
|
if (buflen-- > 0)
|
||||||
{
|
{
|
||||||
buflen = min(buflen, namelen);
|
buflen = min(buflen, namelen);
|
||||||
memcpy_P(buf, cn->Name, buflen);
|
memcpy_P(buf, name, buflen);
|
||||||
buf[buflen] = 0;
|
buf[buflen] = 0;
|
||||||
}
|
}
|
||||||
return namelen;
|
return namelen;
|
||||||
|
Reference in New Issue
Block a user