forked from Aircoookie/WLED
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lx_parser.cpp
71 lines (61 loc) · 1.85 KB
/
lx_parser.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include "wled.h"
#ifdef WLED_ENABLE_LOXONE
/*
* Parser for Loxone formats
*/
bool parseLx(int lxValue, byte* rgbw)
{
DEBUG_PRINT(F("LX: Lox = "));
DEBUG_PRINTLN(lxValue);
bool ok = false;
float lxRed = 0, lxGreen = 0, lxBlue = 0;
if (lxValue < 200000000) {
// Loxone RGB
ok = true;
lxRed = round((lxValue % 1000) * 2.55);
lxGreen = round(((lxValue / 1000) % 1000) * 2.55);
lxBlue = round(((lxValue / 1000000) % 1000) * 2.55);
} else if ((lxValue >= 200000000) && (lxValue <= 201006500)) {
// Loxone Lumitech
ok = true;
float tmpBri = floor((lxValue - 200000000) / 10000); ;
uint16_t ct = (lxValue - 200000000) - (((uint8_t)tmpBri) * 10000);
tmpBri *= 2.55f;
tmpBri = constrain(tmpBri, 0, 255);
colorKtoRGB(ct, rgbw);
lxRed = rgbw[0]; lxGreen = rgbw[1]; lxBlue = rgbw[2];
lxRed *= (tmpBri/255);
lxGreen *= (tmpBri/255);
lxBlue *= (tmpBri/255);
}
if (ok) {
rgbw[0] = (uint8_t) constrain(lxRed, 0, 255);
rgbw[1] = (uint8_t) constrain(lxGreen, 0, 255);
rgbw[2] = (uint8_t) constrain(lxBlue, 0, 255);
rgbw[3] = 0;
return true;
}
return false;
}
void parseLxJson(int lxValue, byte segId, bool secondary)
{
if (secondary) {
DEBUG_PRINT(F("LY: Lox secondary = "));
} else {
DEBUG_PRINT(F("LX: Lox primary = "));
}
DEBUG_PRINTLN(lxValue);
byte rgbw[] = {0,0,0,0};
if (parseLx(lxValue, rgbw)) {
if (bri == 0) {
DEBUG_PRINTLN(F("LX: turn on"));
toggleOnOff();
}
bri = 255;
nightlightActive = false; //always disable nightlight when toggling
DEBUG_PRINT(F("LX: segment "));
DEBUG_PRINTLN(segId);
strip.getSegment(segId).setColor(secondary, RGBW32(rgbw[0], rgbw[1], rgbw[2], rgbw[3])); // legacy values handled as well in json.cpp by stateUpdated()
}
}
#endif