Skip to content

Commit 517a85f

Browse files
authored
Merge pull request wled#1711 from Aircoookie/dev-multipin-select
Multipin select working!
2 parents 849e04a + f3aa8d3 commit 517a85f

File tree

17 files changed

+1387
-1045
lines changed

17 files changed

+1387
-1045
lines changed

CHANGELOG.md

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

33
### Development versions after 0.11.1 release
44

5+
#### Build 2101310
6+
7+
- First alpha configurable multipin
8+
59
#### Build 2101130
610

711
- Added color transitions for all segments and slots and for segment brightness

usermods/Temperature/usermod_temperature.h

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@
55
#include <DallasTemperature.h> //DS18B20
66

77
//Pin defaults for QuinLed Dig-Uno
8+
#ifndef TEMPERATURE_PIN
89
#ifdef ARDUINO_ARCH_ESP32
910
#define TEMPERATURE_PIN 18
1011
#else //ESP8266 boards
1112
#define TEMPERATURE_PIN 14
1213
#endif
14+
#endif
1315

1416
// the frequency to check temperature, 1 minute
1517
#ifndef USERMOD_DALLASTEMPERATURE_MEASUREMENT_INTERVAL
@@ -58,6 +60,7 @@ class UsermodTemperature : public Usermod {
5860
}
5961

6062
void getTemperature() {
63+
if (strip.isUpdating()) return;
6164
#ifdef USERMOD_DALLASTEMPERATURE_CELSIUS
6265
temperature = sensor.getTempC(sensorDeviceAddress);
6366
#else
@@ -80,30 +83,28 @@ class UsermodTemperature : public Usermod {
8083
disabled = !sensor.getAddress(sensorDeviceAddress, 0);
8184

8285
if (!disabled) {
83-
DEBUG_PRINTLN("Dallas Temperature found");
86+
DEBUG_PRINTLN(F("Dallas Temperature found"));
8487
// set the resolution for this specific device
8588
sensor.setResolution(sensorDeviceAddress, 9, true);
8689
// do not block waiting for reading
87-
sensor.setWaitForConversion(false);
90+
sensor.setWaitForConversion(false);
91+
// allocate pin & prevent other use
92+
if (!pinManager.allocatePin(TEMPERATURE_PIN,false))
93+
disabled = true;
8894
} else {
89-
DEBUG_PRINTLN("Dallas Temperature not found");
95+
DEBUG_PRINTLN(F("Dallas Temperature not found"));
9096
}
9197
}
9298

9399
void loop() {
94-
if (disabled) {
95-
return;
96-
}
100+
if (disabled || strip.isUpdating()) return;
97101

98102
unsigned long now = millis();
99103

100104
// check to see if we are due for taking a measurement
101105
// lastMeasurement will not be updated until the conversion
102106
// is complete the the reading is finished
103-
if (now - lastMeasurement < USERMOD_DALLASTEMPERATURE_MEASUREMENT_INTERVAL)
104-
{
105-
return;
106-
}
107+
if (now - lastMeasurement < USERMOD_DALLASTEMPERATURE_MEASUREMENT_INTERVAL) return;
107108

108109
// we are due for a measurement, if we are not already waiting
109110
// for a conversion to complete, then make a new request for temps
@@ -125,7 +126,7 @@ class UsermodTemperature : public Usermod {
125126
// dont publish super low temperature as the graph will get messed up
126127
// the DallasTemperature library returns -127C or -196.6F when problem
127128
// reading the sensor
128-
strcat(subuf, "/temperature");
129+
strcat_P(subuf, PSTR("/temperature"));
129130
mqtt->publish(subuf, 0, true, String(temperature).c_str());
130131
} else {
131132
// publish something else to indicate status?
@@ -136,34 +137,32 @@ class UsermodTemperature : public Usermod {
136137

137138
void addToJsonInfo(JsonObject& root) {
138139
// dont add temperature to info if we are disabled
139-
if (disabled) {
140-
return;
141-
}
140+
if (disabled) return;
142141

143-
JsonObject user = root["u"];
144-
if (user.isNull()) user = root.createNestedObject("u");
142+
JsonObject user = root[F("u")];
143+
if (user.isNull()) user = root.createNestedObject(F("u"));
145144

146-
JsonArray temp = user.createNestedArray("Temperature");
145+
JsonArray temp = user.createNestedArray(F("Temperature"));
147146

148147
if (!getTemperatureComplete) {
149148
// if we haven't read the sensor yet, let the user know
150149
// that we are still waiting for the first measurement
151150
temp.add((USERMOD_DALLASTEMPERATURE_FIRST_MEASUREMENT_AT - millis()) / 1000);
152-
temp.add(" sec until read");
151+
temp.add(F(" sec until read"));
153152
return;
154153
}
155154

156155
if (temperature <= -100) {
157156
temp.add(0);
158-
temp.add(" Sensor Error!");
157+
temp.add(F(" Sensor Error!"));
159158
return;
160159
}
161160

162161
temp.add(temperature);
163162
#ifdef USERMOD_DALLASTEMPERATURE_CELSIUS
164-
temp.add("°C");
163+
temp.add(F("°C"));
165164
#else
166-
temp.add("°F");
165+
temp.add(F("°F"));
167166
#endif
168167
}
169168

wled00/FX.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1265,7 +1265,7 @@ uint16_t WS2812FX::police_base(uint32_t color1, uint32_t color2, bool all)
12651265
for (uint16_t i = idexB; i < idexR; i++) setPixelColor(i, color2);
12661266
}
12671267
} else { //regular dot-only mode
1268-
uint8_t size = 1 + SEGMENT.intensity >> 3;
1268+
uint8_t size = 1 + (SEGMENT.intensity >> 3);
12691269
if (size > SEGLEN/2) size = 1+ SEGLEN/2;
12701270
for (uint8_t i=0; i <= size; i++) {
12711271
setPixelColor(idexR+i, color1);

wled00/FX.h

Lines changed: 9 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -29,42 +29,6 @@
2929
#ifndef WS2812FX_h
3030
#define WS2812FX_h
3131

32-
//TEMPORARY DEFINES FOR TESTING - MAKE THESE RUNTIME CONFIGURABLE TOO!
33-
#ifndef LEDPIN
34-
#define LEDPIN 2
35-
#endif
36-
37-
#ifndef BTNPIN
38-
#define BTNPIN 0 //button pin. Needs to have pullup (gpio0 recommended)
39-
#endif
40-
41-
#ifndef TOUCHPIN
42-
//#define TOUCHPIN T0 //touch pin. Behaves the same as button. ESP32 only.
43-
#endif
44-
45-
#ifndef IRPIN
46-
#define IRPIN 4 //infrared pin (-1 to disable) MagicHome: 4, H801 Wifi: 0
47-
#endif
48-
49-
#ifndef RLYPIN
50-
#define RLYPIN 12 //pin for relay, will be set HIGH if LEDs are on (-1 to disable). Also usable for standby leds, triggers,...
51-
#endif
52-
53-
#ifndef AUXPIN
54-
#define AUXPIN -1 //debug auxiliary output pin (-1 to disable)
55-
#endif
56-
57-
#ifndef RLYMDE
58-
#define RLYMDE 1 //mode for relay, 0: LOW if LEDs are on 1: HIGH if LEDs are on
59-
#endif
60-
//END OF TEMP DEFINES
61-
62-
#ifdef ESP32_MULTISTRIP
63-
#include "../usermods/esp32_multistrip/NpbWrapper.h"
64-
#else
65-
#include "bus_manager.h"
66-
#endif
67-
6832
#include "const.h"
6933

7034
#define FASTLED_INTERNAL //remove annoying pragma messages
@@ -616,12 +580,11 @@ class WS2812FX {
616580
ablMilliampsMax = 850;
617581
currentMilliamps = 0;
618582
timebase = 0;
619-
busses = new BusManager();
620583
resetSegments();
621584
}
622585

623586
void
624-
init(bool supportWhite, uint16_t countPixels, bool skipFirst),
587+
finalizeInit(bool supportWhite, uint16_t countPixels, bool skipFirst),
625588
service(void),
626589
blur(uint8_t),
627590
fill(uint32_t),
@@ -661,6 +624,8 @@ class WS2812FX {
661624
paletteFade = 0,
662625
paletteBlend = 0,
663626
milliampsPerLed = 55,
627+
// getStripType(uint8_t strip=0),
628+
// setStripType(uint8_t type, uint8_t strip=0),
664629
getBrightness(void),
665630
getMode(void),
666631
getSpeed(void),
@@ -675,11 +640,17 @@ class WS2812FX {
675640
get_random_wheel_index(uint8_t);
676641

677642
int8_t
643+
// setStripPin(uint8_t strip, int8_t pin),
644+
// getStripPin(uint8_t strip=0),
645+
// setStripPinClk(uint8_t strip, int8_t pin),
646+
// getStripPinClk(uint8_t strip=0),
678647
tristate_square8(uint8_t x, uint8_t pulsewidth, uint8_t attdec);
679648

680649
uint16_t
681650
ablMilliampsMax,
682651
currentMilliamps,
652+
// setStripLen(uint8_t strip, uint16_t len),
653+
// getStripLen(uint8_t strip=0),
683654
triwave16(uint16_t);
684655

685656
uint32_t
@@ -826,8 +797,6 @@ class WS2812FX {
826797
mode_dynamic_smooth(void);
827798

828799
private:
829-
BusManager *busses;
830-
831800
uint32_t crgb_to_col(CRGB fastled);
832801
CRGB col_to_crgb(uint32_t);
833802
CRGBPalette16 currentPalette;

wled00/FX_fcn.cpp

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ const uint16_t customMappingSize = sizeof(customMappingTable)/sizeof(uint16_t);
4949
#endif
5050

5151
//do not call this method from system context (network callback)
52-
void WS2812FX::init(bool supportWhite, uint16_t countPixels, bool skipFirst)
52+
void WS2812FX::finalizeInit(bool supportWhite, uint16_t countPixels, bool skipFirst)
5353
{
5454
if (supportWhite == _useRgbw && countPixels == _length && _skipFirstMode == skipFirst) return;
5555
RESET_RUNTIME;
@@ -62,20 +62,21 @@ void WS2812FX::init(bool supportWhite, uint16_t countPixels, bool skipFirst)
6262
_lengthRaw += LED_SKIP_AMOUNT;
6363
}
6464

65-
uint8_t pins[] = {LEDPIN};
66-
67-
while (!busses->canAllShow()) yield();
68-
busses->removeAll();
69-
busses->add(supportWhite? TYPE_SK6812_RGBW : TYPE_WS2812_RGB, pins, 0, countPixels, COL_ORDER_GRB);
65+
//if busses failed to load, add default (FS issue...)
66+
if (busses.getNumBusses() == 0) {
67+
uint8_t defPin[] = {LEDPIN};
68+
BusConfig defCfg = BusConfig(TYPE_WS2812_RGB, defPin, 0, _lengthRaw, COL_ORDER_GRB);
69+
busses.add(defCfg);
70+
}
7071

7172
_segments[0].start = 0;
7273
_segments[0].stop = _length;
7374

7475
setBrightness(_brightness);
7576

7677
#ifdef ESP8266
77-
for (uint8_t i = 0; i < busses->getNumBusses(); i++) {
78-
Bus* b = busses->getBus(i);
78+
for (uint8_t i = 0; i < busses.getNumBusses(); i++) {
79+
Bus* b = busses.getBus(i);
7980
if ((!IS_DIGITAL(b->getType()) || IS_2PIN(b->getType()))) continue;
8081
uint8_t pins[5];
8182
b->getPins(pins);
@@ -205,12 +206,12 @@ void WS2812FX::setPixelColor(uint16_t i, byte r, byte g, byte b, byte w)
205206
if (indexSet < customMappingSize) indexSet = customMappingTable[indexSet];
206207
#endif
207208
if (indexSetRev >= SEGMENT.start && indexSetRev < SEGMENT.stop) {
208-
busses->setPixelColor(indexSet + skip, col);
209+
busses.setPixelColor(indexSet + skip, col);
209210
if (IS_MIRROR) { //set the corresponding mirrored pixel
210211
if (reverseMode) {
211-
busses->setPixelColor(REV(SEGMENT.start) - indexSet + skip + REV(SEGMENT.stop) + 1, col);
212+
busses.setPixelColor(REV(SEGMENT.start) - indexSet + skip + REV(SEGMENT.stop) + 1, col);
212213
} else {
213-
busses->setPixelColor(SEGMENT.stop - indexSet + skip + SEGMENT.start - 1, col);
214+
busses.setPixelColor(SEGMENT.stop - indexSet + skip + SEGMENT.start - 1, col);
214215
}
215216
}
216217
}
@@ -221,11 +222,11 @@ void WS2812FX::setPixelColor(uint16_t i, byte r, byte g, byte b, byte w)
221222
if (i < customMappingSize) i = customMappingTable[i];
222223
#endif
223224
uint32_t col = ((w << 24) | (r << 16) | (g << 8) | (b));
224-
busses->setPixelColor(i + skip, col);
225+
busses.setPixelColor(i + skip, col);
225226
}
226227
if (skip && i == 0) {
227228
for (uint16_t j = 0; j < skip; j++) {
228-
busses->setPixelColor(j, BLACK);
229+
busses.setPixelColor(j, BLACK);
229230
}
230231
}
231232
}
@@ -276,7 +277,7 @@ void WS2812FX::show(void) {
276277

277278
for (uint16_t i = 0; i < _length; i++) //sum up the usage of each LED
278279
{
279-
RgbwColor c = busses->getPixelColor(i);
280+
RgbwColor c = busses.getPixelColor(i);
280281

281282
if(useWackyWS2815PowerModel)
282283
{
@@ -305,24 +306,24 @@ void WS2812FX::show(void) {
305306
uint16_t scaleI = scale * 255;
306307
uint8_t scaleB = (scaleI > 255) ? 255 : scaleI;
307308
uint8_t newBri = scale8(_brightness, scaleB);
308-
busses->setBrightness(newBri);
309+
busses.setBrightness(newBri);
309310
currentMilliamps = (powerSum0 * newBri) / puPerMilliamp;
310311
} else
311312
{
312313
currentMilliamps = powerSum / puPerMilliamp;
313-
busses->setBrightness(_brightness);
314+
busses.setBrightness(_brightness);
314315
}
315316
currentMilliamps += MA_FOR_ESP; //add power of ESP back to estimate
316317
currentMilliamps += _length; //add standby power back to estimate
317318
} else {
318319
currentMilliamps = 0;
319-
busses->setBrightness(_brightness);
320+
busses.setBrightness(_brightness);
320321
}
321322

322323
// some buses send asynchronously and this method will return before
323324
// all of the data has been sent.
324325
// See https://github.com/Makuna/NeoPixelBus/wiki/ESP32-NeoMethods#neoesp32rmt-methods
325-
busses->show();
326+
busses.show();
326327
_lastShow = millis();
327328
}
328329

@@ -331,7 +332,7 @@ void WS2812FX::show(void) {
331332
* On some hardware (ESP32), strip updates are done asynchronously.
332333
*/
333334
bool WS2812FX::isUpdating() {
334-
return !busses->canAllShow();
335+
return !busses.canAllShow();
335336
}
336337

337338
/**
@@ -492,7 +493,7 @@ uint32_t WS2812FX::getPixelColor(uint16_t i)
492493

493494
if (i >= _lengthRaw) return 0;
494495

495-
return busses->getPixelColor(i);
496+
return busses.getPixelColor(i);
496497
}
497498

498499
WS2812FX::Segment& WS2812FX::getSegment(uint8_t id) {

0 commit comments

Comments
 (0)