added the conversion from 24 bit hex colors saved as int or css hex color

This commit is contained in:
emilekm2142 2017-09-16 21:58:00 +02:00
parent 53836b6f9d
commit 24167098ee
2 changed files with 22 additions and 1 deletions

View File

@ -2710,7 +2710,27 @@ uint16_t TFT_eSPI::color565(uint8_t r, uint8_t g, uint8_t b)
{
return ((r & 0xF8) << 8) | ((g & 0xFC) << 3) | (b >> 3);
}
uint16_t TFT_eSPI::color565FromWebHex(const char* color){
if (color[0] == '#') {
//remove first char
String c = String(color);
c = c.substring(1);
char l[9];
for (int i = 0; i<9; i++)
l[i] = '\0';
c.toCharArray(l, 9);
color = l;
}
int colorInt = strtol(color, NULL, 16);
return color565From888(colorInt);
}
uint16_t TFT_eSPI::color565From888(uint16_t color){
int r = (color >> 16) & 255;
int g = (color >> 8) & 255;
int b = (color) & 255;
return color565(r, g, b);
}
/***************************************************************************************
** Function name: invertDisplay

View File

@ -387,7 +387,8 @@ class TFT_eSPI : public Print {
uint16_t fontsLoaded(void),
color565(uint8_t r, uint8_t g, uint8_t b);
uint16_t color565From888(uint16_t color);
uint16_t color565FromWebHex(const char* color);
int16_t drawChar(unsigned int uniCode, int x, int y, int font),
drawChar(unsigned int uniCode, int x, int y),
drawNumber(long long_num,int poX, int poY, int font),