Skip to content

Commit 84bb778

Browse files
committed
add toRed, toGreen, & toBlue methods
1 parent 90ac8b3 commit 84bb778

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

src/AdafruitIO_Data.cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,39 @@ unsigned long AdafruitIO_Data::toUnsignedLong()
312312
#endif
313313
}
314314

315+
int AdafruitIO_Data::toRed()
316+
{
317+
if(! _value)
318+
return 0;
319+
320+
char r[] = "0x";
321+
strncat(r, toChar() + 1, 2);
322+
323+
return (int)strtol(r, NULL, 0);
324+
}
325+
326+
int AdafruitIO_Data::toGreen()
327+
{
328+
if(! _value)
329+
return 0;
330+
331+
char g[] = "0x";
332+
strncat(g, toChar() + 3, 2);
333+
334+
return (int)strtol(g, NULL, 0);
335+
}
336+
337+
int AdafruitIO_Data::toBlue()
338+
{
339+
if(! _value)
340+
return 0;
341+
342+
char b[] = "0x";
343+
strncat(b, toChar() + 5, 2);
344+
345+
return (int)strtol(b, NULL, 0);
346+
}
347+
315348
long AdafruitIO_Data::toNeoPixel()
316349
{
317350
if(! _value)

src/AdafruitIO_Data.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ class AdafruitIO_Data {
6262
long toLong();
6363
unsigned long toUnsignedLong();
6464

65+
int toRed();
66+
int toGreen();
67+
int toBlue();
6568
long toNeoPixel();
6669

6770
char* toCSV();

0 commit comments

Comments
 (0)