Skip to content

Commit 4875f5e

Browse files
committed
BTNPIN can now be disabled by setting to -1 (fixes wled#1237)
Added HEX color receiving to JSON API Moved Kelvin color receiving in JSON API
1 parent e19ab9a commit 4875f5e

File tree

8 files changed

+69
-30
lines changed

8 files changed

+69
-30
lines changed

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@
22

33
### Development versions after the 0.10.2 release
44

5+
#### Build 2011200
6+
7+
- Added HEX color receiving to JSON API with `"col":["RRGGBBWW"]` format
8+
- Moved Kelvin color receiving in JSON API from `"col":[[val]]` to `"col":[val]` format
9+
_Notice:_ This is technically a breaking change. Since no release was made since the introduction and the Kelvin property was not previously documented in the wiki,
10+
impact should be minimal.
11+
- BTNPIN can now be disabled by setting to -1 (fixes #1237)
12+
513
#### Build 2011180
614

715
- Platformio.ini updates and streamlining (PR #1266)
@@ -42,6 +50,7 @@
4250
- More explanatory error messages in UI
4351
- Improved candle brightness
4452
- Return remaining nightlight time `nl.rem` in JSON API (PR #1302)
53+
- UI sends timestamp with every command, allowing for timed presets without using NTP
4554
- Added gamma calculation (yet unused)
4655
- Added LED type definitions to const.h (yet unused)
4756
- Added nicer 404 page
@@ -89,6 +98,7 @@
8998

9099
- Added Loxone parser (PR #1185)
91100
- Added support for kelvin input via `K=` HTTP and `"col":[[val]]` JSON API calls
101+
_Notice:_ `"col":[[val]]` removed in build 2011200, use `"col":[val]`
92102
- Added supplementary UDP socket (#1205)
93103
- TMP2.net receivable by default
94104
- UDP sockets accept HTTP and JSON API commands

wled00/button.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ void shortPressAction()
1717

1818
bool isButtonPressed()
1919
{
20-
#ifdef BTNPIN
20+
#if defined(BTNPIN) && BTNPIN > -1
2121
if (digitalRead(BTNPIN) == LOW) return true;
2222
#endif
2323
#ifdef TOUCHPIN
@@ -29,7 +29,7 @@ bool isButtonPressed()
2929

3030
void handleButton()
3131
{
32-
#if defined(BTNPIN) || defined(TOUCHPIN)
32+
#if (defined(BTNPIN) && BTNPIN > -1) || defined(TOUCHPIN)
3333
if (!buttonEnabled) return;
3434

3535
if (isButtonPressed()) //pressed

wled00/colors.cpp

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ void colorRGBtoXY(byte* rgb, float* xy) //rgb to coordinates (https://www.develo
177177
}
178178
#endif // WLED_DISABLE_HUESYNC
179179

180-
180+
//RRGGBB / WWRRGGBB order for hex
181181
void colorFromDecOrHexString(byte* rgb, char* in)
182182
{
183183
if (in[0] == 0) return;
@@ -198,6 +198,27 @@ void colorFromDecOrHexString(byte* rgb, char* in)
198198
rgb[2] = c & 0xFF;
199199
}
200200

201+
//contrary to the colorFromDecOrHexString() function, this uses the more standard RRGGBB / RRGGBBWW order
202+
bool colorFromHexString(byte* rgb, const char* in) {
203+
if (in == nullptr) return false;
204+
size_t inputSize = strnlen(in, 9);
205+
if (inputSize != 6 && inputSize != 8) return false;
206+
207+
uint32_t c = strtoul(in, NULL, 16);
208+
209+
if (inputSize == 6) {
210+
rgb[0] = (c >> 16) & 0xFF;
211+
rgb[1] = (c >> 8) & 0xFF;
212+
rgb[2] = c & 0xFF;
213+
} else {
214+
rgb[0] = (c >> 24) & 0xFF;
215+
rgb[1] = (c >> 16) & 0xFF;
216+
rgb[2] = (c >> 8) & 0xFF;
217+
rgb[3] = c & 0xFF;
218+
}
219+
return true;
220+
}
221+
201222
float minf (float v, float w)
202223
{
203224
if (w > v) return v;

wled00/fcn_declare.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ void colorXYtoRGB(float x, float y, byte* rgb); // only defined if huesync disab
4343
void colorRGBtoXY(byte* rgb, float* xy); // only defined if huesync disabled TODO
4444

4545
void colorFromDecOrHexString(byte* rgb, char* in);
46+
bool colorFromHexString(byte* rgb, const char* in);
4647
void colorRGBtoRGBW(byte* rgb); //rgb to rgbw (http://codewelt.com/rgbw). (RGBW_MODE_LEGACY)
4748

4849
//dmx.cpp

wled00/json.cpp

Lines changed: 31 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -36,29 +36,38 @@ void deserializeSegment(JsonObject elem, byte it)
3636
{
3737
for (uint8_t i = 0; i < 3; i++)
3838
{
39+
int rgbw[] = {0,0,0,0};
40+
bool colValid = false;
3941
JsonArray colX = colarr[i];
40-
if (colX.isNull()) break;
41-
byte sz = colX.size();
42-
if (sz > 0 && sz < 5)
43-
{
44-
int rgbw[] = {0,0,0,0};
45-
byte cp = copyArray(colX, rgbw);
46-
47-
if (cp == 1) {
48-
if (rgbw[0] == 0) seg.colors[i] = 0;
49-
else {
50-
byte ctrgb[] = {0,0,0,0};
51-
colorKtoRGB(rgbw[0], ctrgb);
52-
for (uint8_t c = 0; c < 3; c++) rgbw[c] = ctrgb[c];
53-
}
54-
}
55-
if (id == strip.getMainSegmentId() && i < 2) //temporary, to make transition work on main segment
56-
{
57-
if (i == 0) {col[0] = rgbw[0]; col[1] = rgbw[1]; col[2] = rgbw[2]; col[3] = rgbw[3];}
58-
if (i == 1) {colSec[0] = rgbw[0]; colSec[1] = rgbw[1]; colSec[2] = rgbw[2]; colSec[3] = rgbw[3];}
59-
} else {
60-
seg.colors[i] = ((rgbw[3] << 24) | ((rgbw[0]&0xFF) << 16) | ((rgbw[1]&0xFF) << 8) | ((rgbw[2]&0xFF)));
42+
if (colX.isNull()) {
43+
byte brgbw[] = {0,0,0,0};
44+
const char* hexCol = colarr[i];
45+
if (hexCol == nullptr) { //Kelvin color temperature (or invalid), e.g 2400
46+
int kelvin = colarr[i] | -1;
47+
if (kelvin < 0) continue;
48+
if (kelvin == 0) seg.colors[i] = 0;
49+
if (kelvin > 0) colorKtoRGB(kelvin, brgbw);
50+
colValid = true;
51+
} else { //HEX string, e.g. "FFAA00"
52+
colValid = colorFromHexString(brgbw, hexCol);
6153
}
54+
for (uint8_t c = 0; c < 4; c++) rgbw[c] = brgbw[c];
55+
} else { //Array of ints (RGB or RGBW color), e.g. [255,160,0]
56+
byte sz = colX.size();
57+
if (sz == 0) continue; //do nothing on empty array
58+
59+
byte cp = copyArray(colX, rgbw, 4);
60+
if (cp == 1 && rgbw[0] == 0) seg.colors[i] = 0;
61+
colValid = true;
62+
}
63+
64+
if (!colValid) continue;
65+
if (id == strip.getMainSegmentId() && i < 2) //temporary, to make transition work on main segment
66+
{
67+
if (i == 0) {col[0] = rgbw[0]; col[1] = rgbw[1]; col[2] = rgbw[2]; col[3] = rgbw[3];}
68+
if (i == 1) {colSec[0] = rgbw[0]; colSec[1] = rgbw[1]; colSec[2] = rgbw[2]; colSec[3] = rgbw[3];}
69+
} else { //normal case, apply directly to segment (=> no transition!)
70+
seg.colors[i] = ((rgbw[3] << 24) | ((rgbw[0]&0xFF) << 16) | ((rgbw[1]&0xFF) << 8) | ((rgbw[2]&0xFF)));
6271
}
6372
}
6473
}
@@ -179,7 +188,7 @@ bool deserializeState(JsonObject root)
179188
JsonObject nl = root["nl"];
180189
nightlightActive = nl["on"] | nightlightActive;
181190
nightlightDelayMins = nl[F("dur")] | nightlightDelayMins;
182-
nightlightMode = nl[F("fade")] | nightlightMode; //deprecated
191+
nightlightMode = nl[F("fade")] | nightlightMode; //deprecated, remove for v0.12.0
183192
nightlightMode = nl[F("mode")] | nightlightMode;
184193
nightlightTargetBri = nl[F("tbri")] | nightlightTargetBri;
185194

wled00/wled.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ void WLED::beginStrip()
317317
strip.setBrightness(0);
318318
strip.setShowCallback(handleOverlayDraw);
319319

320-
#ifdef BTNPIN
320+
#if defined(BTNPIN) && BTNPIN > -1
321321
pinManager.allocatePin(BTNPIN, false);
322322
pinMode(BTNPIN, INPUT_PULLUP);
323323
#endif
@@ -342,7 +342,7 @@ void WLED::beginStrip()
342342
#endif
343343

344344
// disable button if it is "pressed" unintentionally
345-
#if defined(BTNPIN) || defined(TOUCHPIN)
345+
#if (defined(BTNPIN) && BTNPIN > -1) || defined(TOUCHPIN)
346346
if (isButtonPressed())
347347
buttonEnabled = false;
348348
#else

wled00/wled.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*/
99

1010
// version code in format yymmddb (b = daily build)
11-
#define VERSION 2011180
11+
#define VERSION 2011200
1212

1313
//uncomment this if you have a "my_config.h" file you'd like to use
1414
//#define WLED_USE_MY_CONFIG

wled00/wled_server.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,6 @@ void initServer()
9696
});
9797
server.addHandler(handler);
9898

99-
//*******DEPRECATED*******
10099
server.on("/version", HTTP_GET, [](AsyncWebServerRequest *request){
101100
request->send(200, "text/plain", (String)VERSION);
102101
});
@@ -108,7 +107,6 @@ void initServer()
108107
server.on("/freeheap", HTTP_GET, [](AsyncWebServerRequest *request){
109108
request->send(200, "text/plain", (String)ESP.getFreeHeap());
110109
});
111-
//*******END*******/
112110

113111
server.on("/u", HTTP_GET, [](AsyncWebServerRequest *request){
114112
request->send_P(200, "text/html", PAGE_usermod);

0 commit comments

Comments
 (0)