Skip to content

Commit

Permalink
Removed color convertion libary
Browse files Browse the repository at this point in the history
  • Loading branch information
foorschtbar committed Oct 7, 2024
1 parent 09f0fca commit b96b63a
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 16 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,10 @@ Thanks to these great people for supporting this project.

<!-- ** WORK IN PROGRESS ** -->

### 2.5.2 (2024-10-05)
### 2.5.2 (2024-10-07)

- (foorschtbar) Fixed ESP32 Battery Pin Definition
- (foorschtbar) Removed color convertion libary

### 2.5.1 (2024-04-07)

Expand Down
1 change: 0 additions & 1 deletion platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ lib_deps =
bblanchon/ArduinoJson@5.13.4
beegee-tokyo/DHT sensor library for ESPx@1.19.0
claws/BH1750@1.3.0
ColorConverter=https://github.com/luisllamasbinaburo/Arduino-ColorConverter.git#v2.0.0
fastled/FastLED@3.7.0
knolleary/PubSubClient@2.8.0
LightDependentResistor=https://github.com/QuentinCG/Arduino-Light-Dependent-Resistor-Library.git#1.4.0
Expand Down
19 changes: 7 additions & 12 deletions src/PixelIt.ino
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
#include <DHTesp.h>
#include <DFPlayerMini_Fast.h>
#include <SoftwareSerial.h>
#include "ColorConverterLib.h"
#include <TimeLib.h>
#include <ArduinoJson.h>
#include <ArduinoHttpClient.h>
Expand Down Expand Up @@ -506,11 +505,7 @@ void SaveConfig()
json["matrixTempCorrection"] = matrixTempCorrection;
json["ntpServer"] = ntpServer;
json["clockTimeZone"] = clockTimeZone;

String clockColorHex;
ColorConverter::RgbToHex(clockColorR, clockColorG, clockColorB, clockColorHex);
json["clockColor"] = "#" + clockColorHex;

json["clockColor"] = "#" + RGBtoHEX(clockColorR, clockColorG, clockColorB);
json["clockSwitchAktiv"] = clockSwitchAktiv;
json["clockSwitchSec"] = clockSwitchSec;
json["clock24Hours"] = clock24Hours;
Expand Down Expand Up @@ -692,7 +687,7 @@ void SetConfigVariables(JsonObject &json)

if (json.containsKey("clockColor"))
{
ColorConverter::HexToRgb(json["clockColor"].as<String>(), clockColorR, clockColorG, clockColorB);
HEXtoRGB(json["clockColor"].as<String>(), clockColorR, clockColorG, clockColorB);
}

if (json.containsKey("clockSwitchAktiv"))
Expand Down Expand Up @@ -1545,7 +1540,7 @@ void CreateFrames(JsonObject &json, int forceDuration)
uint8_t b = 255;
if (json["switchAnimation"]["hexColor"].as<char *>() != NULL)
{
ColorConverter::HexToRgb(json["switchAnimation"]["hexColor"].as<char *>(), r, g, b);
HEXtoRGB(json["switchAnimation"]["hexColor"].as<char *>(), r, g, b);
}
else if (json["switchAnimation"]["color"]["r"].as<char *>() != NULL)
{
Expand Down Expand Up @@ -1628,7 +1623,7 @@ void CreateFrames(JsonObject &json, int forceDuration)
else if (json["clock"]["hexColor"].as<char *>() != NULL)
{
logMessage += F("hexColor, ");
ColorConverter::HexToRgb(json["clock"]["hexColor"].as<char *>(), clockColorR, clockColorG, clockColorB);
HEXtoRGB(json["clock"]["hexColor"].as<char *>(), clockColorR, clockColorG, clockColorB);
}
if (logMessage.endsWith(", "))
{
Expand All @@ -1651,7 +1646,7 @@ void CreateFrames(JsonObject &json, int forceDuration)
uint8_t r, g, b;
if (json["bar"]["hexColor"].as<char *>() != NULL)
{
ColorConverter::HexToRgb(json["bar"]["hexColor"].as<char *>(), r, g, b);
HEXtoRGB(json["bar"]["hexColor"].as<char *>(), r, g, b);
}
else
{
Expand All @@ -1671,7 +1666,7 @@ void CreateFrames(JsonObject &json, int forceDuration)
uint8_t r, g, b;
if (x["hexColor"].as<char *>() != NULL)
{
ColorConverter::HexToRgb(x["hexColor"].as<char *>(), r, g, b);
HEXtoRGB(x["hexColor"].as<char *>(), r, g, b);
}
else
{
Expand Down Expand Up @@ -1797,7 +1792,7 @@ void CreateFrames(JsonObject &json, int forceDuration)
uint8_t r, g, b;
if (json["text"]["hexColor"].as<char *>() != NULL)
{
ColorConverter::HexToRgb(json["text"]["hexColor"].as<char *>(), r, g, b);
HEXtoRGB(json["text"]["hexColor"].as<char *>(), r, g, b);
}
else
{
Expand Down
44 changes: 42 additions & 2 deletions src/Tools.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ byte Utf8ToAscii(byte ascii)
case 0XE29885: // Star ★
result = 0xE3;
break;
case 0xF09F9384: // File 📄
case 0xF09F9384: // File 📄
result = 0xE4;
break;
case 0xE299A5: // Heart ♥
Expand All @@ -136,7 +136,7 @@ byte Utf8ToAscii(byte ascii)
break;
case 0xF09F9381: // Folder 📁
result = 0xE9;
break;
break;
}

// Legal UTF-8 Byte Sequences
Expand Down Expand Up @@ -251,4 +251,44 @@ int GetRSSIasQuality(int rssi)
float CelsiusToFahrenheit(float celsius)
{
return (celsius * 9 / 5) + 32;
}

// RGBtoHEX
String RGBtoHEX(int r, int g, int b)
{
String rs = String(r, HEX);
String gs = String(g, HEX);
String bs = String(b, HEX);

if (rs.length() == 1)
rs = "0" + rs;
if (gs.length() == 1)
gs = "0" + gs;
if (bs.length() == 1)
bs = "0" + bs;

return rs + gs + bs;
}

// HEXtoRGB
void HEXtoRGB(String hex, uint8_t &r, uint8_t &g, uint8_t &b)
{
// Remove # if it exists
hex.replace("#", "");
// trim to 6 characters
hex = hex.substring(0, 6);
// check of the string is a valid hex color
// regex: ^#?([a-f0-9]{6}|[a-f0-9]{3})$
if (hex.length() == 6)
{
r = strtol(hex.substring(0, 2).c_str(), nullptr, 16);
g = strtol(hex.substring(2, 4).c_str(), nullptr, 16);
b = strtol(hex.substring(4, 6).c_str(), nullptr, 16);
}
else
{
r = 0;
g = 0;
b = 0;
}
}

0 comments on commit b96b63a

Please sign in to comment.