mirror of
https://github.com/esphome/esphome.git
synced 2025-11-19 00:05:43 +00:00
Tuya rgb support (#2278)
Co-authored-by: Oxan van Leeuwen <oxan@oxanvanleeuwen.nl> Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com>
This commit is contained in:
@@ -270,6 +270,39 @@ optional<int> parse_int(const std::string &str) {
|
||||
return {};
|
||||
return value;
|
||||
}
|
||||
|
||||
optional<int> parse_hex(const char chr) {
|
||||
int out = chr;
|
||||
if (out >= '0' && out <= '9')
|
||||
return (out - '0');
|
||||
if (out >= 'A' && out <= 'F')
|
||||
return (10 + (out - 'A'));
|
||||
if (out >= 'a' && out <= 'f')
|
||||
return (10 + (out - 'a'));
|
||||
return {};
|
||||
}
|
||||
|
||||
optional<int> parse_hex(const std::string &str, size_t start, size_t length) {
|
||||
if (str.length() < start) {
|
||||
return {};
|
||||
}
|
||||
size_t end = start + length;
|
||||
if (str.length() < end) {
|
||||
return {};
|
||||
}
|
||||
int out = 0;
|
||||
for (size_t i = start; i < end; i++) {
|
||||
char chr = str[i];
|
||||
auto digit = parse_hex(chr);
|
||||
if (!digit.has_value()) {
|
||||
ESP_LOGW(TAG, "Can't convert '%s' to number, invalid character %c!", str.substr(start, length).c_str(), chr);
|
||||
return {};
|
||||
}
|
||||
out = (out << 4) | *digit;
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
uint32_t fnv1_hash(const std::string &str) {
|
||||
uint32_t hash = 2166136261UL;
|
||||
for (char c : str) {
|
||||
|
||||
Reference in New Issue
Block a user