Skip to content

Commit 13ed78b

Browse files
committed
Merge branch '0_15' into blending-styles
2 parents 0275bd1 + cd1ede3 commit 13ed78b

33 files changed

+323
-294
lines changed

usermods/Battery/usermod_v2_Battery.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#include "UMBattery.h"
66
#include "types/UnkownUMBattery.h"
77
#include "types/LionUMBattery.h"
8-
#include "types/LiPoUMBattery.h"
8+
#include "types/LipoUMBattery.h"
99

1010
/*
1111
* Usermod by Maximilian Mewes

usermods/Temperature/usermod_temperature.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ float UsermodTemperature::readDallas() {
113113
#ifdef WLED_DEBUG
114114
if (OneWire::crc8(data,8) != data[8]) {
115115
DEBUG_PRINTLN(F("CRC error reading temperature."));
116-
for (byte i=0; i < 9; i++) DEBUG_PRINTF_P(PSTR("0x%02X "), data[i]);
116+
for (unsigned i=0; i < 9; i++) DEBUG_PRINTF_P(PSTR("0x%02X "), data[i]);
117117
DEBUG_PRINT(F(" => "));
118118
DEBUG_PRINTF_P(PSTR("0x%02X\n"), OneWire::crc8(data,8));
119119
}
@@ -133,7 +133,7 @@ float UsermodTemperature::readDallas() {
133133
break;
134134
}
135135
}
136-
for (byte i=1; i<9; i++) data[0] &= data[i];
136+
for (unsigned i=1; i<9; i++) data[0] &= data[i];
137137
return data[0]==0xFF ? -127.0f : retVal;
138138
}
139139

usermods/mpu6050_imu/usermod_mpu6050_imu.h

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,11 @@ class MPU6050Driver : public Usermod {
8787
int16_t accel_offset[3];
8888
};
8989
config_t config;
90+
bool configDirty = true; // does the configuration need an update?
9091

9192
// MPU control/status vars
9293
bool irqBound = false; // set true if we have bound the IRQ pin
9394
bool dmpReady = false; // set true if DMP init was successful
94-
uint8_t devStatus; // return status after each device operation (0 = success, !0 = error)
9595
uint16_t packetSize; // expected DMP packet size (default is 42 bytes)
9696
uint16_t fifoCount; // count of all bytes currently in FIFO
9797
uint8_t fifoBuffer[64]; // FIFO storage buffer
@@ -157,7 +157,10 @@ class MPU6050Driver : public Usermod {
157157
um_data.u_type[8] = UMT_UINT32;
158158
}
159159

160+
configDirty = false; // we have now accepted the current configuration, success or not
161+
160162
if (!config.enabled) return;
163+
// TODO: notice if these have changed ??
161164
if (i2c_scl<0 || i2c_sda<0) { DEBUG_PRINTLN(F("MPU6050: I2C is no good.")); return; }
162165
// Check the interrupt pin
163166
if (config.interruptPin >= 0) {
@@ -182,7 +185,7 @@ class MPU6050Driver : public Usermod {
182185

183186
// load and configure the DMP
184187
DEBUG_PRINTLN(F("Initializing DMP..."));
185-
devStatus = mpu.dmpInitialize();
188+
auto devStatus = mpu.dmpInitialize();
186189

187190
// set offsets (from config)
188191
mpu.setXGyroOffset(config.gyro_offset[0]);
@@ -241,6 +244,8 @@ class MPU6050Driver : public Usermod {
241244
* loop() is called continuously. Here you can check for events, read sensors, etc.
242245
*/
243246
void loop() {
247+
if (configDirty) setup();
248+
244249
// if programming failed, don't try to do anything
245250
if (!config.enabled || !dmpReady || strip.isUpdating()) return;
246251

@@ -407,8 +412,8 @@ class MPU6050Driver : public Usermod {
407412
irqBound = false;
408413
}
409414

410-
// Just re-init
411-
setup();
415+
// Re-call setup on the next loop()
416+
configDirty = true;
412417
}
413418

414419
return configComplete;

usermods/usermod_v2_four_line_display_ALT/usermod_v2_four_line_display_ALT.h

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -445,8 +445,8 @@ void FourLineDisplayUsermod::setPowerSave(uint8_t save) {
445445

446446
void FourLineDisplayUsermod::center(String &line, uint8_t width) {
447447
int len = line.length();
448-
if (len<width) for (byte i=(width-len)/2; i>0; i--) line = ' ' + line;
449-
for (byte i=line.length(); i<width; i++) line += ' ';
448+
if (len<width) for (unsigned i=(width-len)/2; i>0; i--) line = ' ' + line;
449+
for (unsigned i=line.length(); i<width; i++) line += ' ';
450450
}
451451

452452
void FourLineDisplayUsermod::draw2x2GlyphIcons() {
@@ -819,28 +819,28 @@ void FourLineDisplayUsermod::showCurrentEffectOrPalette(int inputEffPal, const c
819819
if (overlayUntil == 0) {
820820
lockRedraw = true;
821821
// Find the mode name in JSON
822-
uint8_t printedChars = extractModeName(inputEffPal, qstring, lineBuffer, MAX_JSON_CHARS-1);
822+
unsigned printedChars = extractModeName(inputEffPal, qstring, lineBuffer, MAX_JSON_CHARS-1);
823823
if (lineBuffer[0]=='*' && lineBuffer[1]==' ') {
824824
// remove "* " from dynamic palettes
825-
for (byte i=2; i<=printedChars; i++) lineBuffer[i-2] = lineBuffer[i]; //include '\0'
825+
for (unsigned i=2; i<=printedChars; i++) lineBuffer[i-2] = lineBuffer[i]; //include '\0'
826826
printedChars -= 2;
827827
} else if ((lineBuffer[0]==' ' && lineBuffer[1]>127)) {
828828
// remove note symbol from effect names
829-
for (byte i=5; i<=printedChars; i++) lineBuffer[i-5] = lineBuffer[i]; //include '\0'
829+
for (unsigned i=5; i<=printedChars; i++) lineBuffer[i-5] = lineBuffer[i]; //include '\0'
830830
printedChars -= 5;
831831
}
832832
if (lineHeight == 2) { // use this code for 8 line display
833833
char smallBuffer1[MAX_MODE_LINE_SPACE];
834834
char smallBuffer2[MAX_MODE_LINE_SPACE];
835-
uint8_t smallChars1 = 0;
836-
uint8_t smallChars2 = 0;
835+
unsigned smallChars1 = 0;
836+
unsigned smallChars2 = 0;
837837
if (printedChars < MAX_MODE_LINE_SPACE) { // use big font if the text fits
838838
while (printedChars < (MAX_MODE_LINE_SPACE-1)) lineBuffer[printedChars++]=' ';
839839
lineBuffer[printedChars] = 0;
840840
drawString(1, row*lineHeight, lineBuffer);
841841
} else { // for long names divide the text into 2 lines and print them small
842842
bool spaceHit = false;
843-
for (uint8_t i = 0; i < printedChars; i++) {
843+
for (unsigned i = 0; i < printedChars; i++) {
844844
switch (lineBuffer[i]) {
845845
case ' ':
846846
if (i > 4 && !spaceHit) {
@@ -865,8 +865,8 @@ void FourLineDisplayUsermod::showCurrentEffectOrPalette(int inputEffPal, const c
865865
}
866866
} else { // use this code for 4 ling displays
867867
char smallBuffer3[MAX_MODE_LINE_SPACE+1]; // uses 1x1 icon for mode/palette
868-
uint8_t smallChars3 = 0;
869-
for (uint8_t i = 0; i < MAX_MODE_LINE_SPACE; i++) smallBuffer3[smallChars3++] = (i >= printedChars) ? ' ' : lineBuffer[i];
868+
unsigned smallChars3 = 0;
869+
for (unsigned i = 0; i < MAX_MODE_LINE_SPACE; i++) smallBuffer3[smallChars3++] = (i >= printedChars) ? ' ' : lineBuffer[i];
870870
smallBuffer3[smallChars3] = 0;
871871
drawString(1, row*lineHeight, smallBuffer3, true);
872872
}
@@ -1265,7 +1265,7 @@ void FourLineDisplayUsermod::addToConfig(JsonObject& root) {
12651265
bool FourLineDisplayUsermod::readFromConfig(JsonObject& root) {
12661266
bool needsRedraw = false;
12671267
DisplayType newType = type;
1268-
int8_t oldPin[3]; for (byte i=0; i<3; i++) oldPin[i] = ioPin[i];
1268+
int8_t oldPin[3]; for (unsigned i=0; i<3; i++) oldPin[i] = ioPin[i];
12691269

12701270
JsonObject top = root[FPSTR(_name)];
12711271
if (top.isNull()) {
@@ -1276,7 +1276,7 @@ bool FourLineDisplayUsermod::readFromConfig(JsonObject& root) {
12761276

12771277
enabled = top[FPSTR(_enabled)] | enabled;
12781278
newType = top["type"] | newType;
1279-
for (byte i=0; i<3; i++) ioPin[i] = top["pin"][i] | ioPin[i];
1279+
for (unsigned i=0; i<3; i++) ioPin[i] = top["pin"][i] | ioPin[i];
12801280
flip = top[FPSTR(_flip)] | flip;
12811281
contrast = top[FPSTR(_contrast)] | contrast;
12821282
#ifndef ARDUINO_ARCH_ESP32
@@ -1302,7 +1302,7 @@ bool FourLineDisplayUsermod::readFromConfig(JsonObject& root) {
13021302
DEBUG_PRINTLN(F(" config (re)loaded."));
13031303
// changing parameters from settings page
13041304
bool pinsChanged = false;
1305-
for (byte i=0; i<3; i++) if (ioPin[i] != oldPin[i]) { pinsChanged = true; break; }
1305+
for (unsigned i=0; i<3; i++) if (ioPin[i] != oldPin[i]) { pinsChanged = true; break; }
13061306
if (pinsChanged || type!=newType) {
13071307
bool isSPI = (type == SSD1306_SPI || type == SSD1306_SPI64 || type == SSD1309_SPI64);
13081308
bool newSPI = (newType == SSD1306_SPI || newType == SSD1306_SPI64 || newType == SSD1309_SPI64);

usermods/usermod_v2_rotary_encoder_ui_ALT/usermod_v2_rotary_encoder_ui_ALT.h

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ void RotaryEncoderUIUsermod::sortModesAndPalettes() {
416416

417417
byte *RotaryEncoderUIUsermod::re_initIndexArray(int numModes) {
418418
byte *indexes = (byte *)malloc(sizeof(byte) * numModes);
419-
for (byte i = 0; i < numModes; i++) {
419+
for (unsigned i = 0; i < numModes; i++) {
420420
indexes[i] = i;
421421
}
422422
return indexes;
@@ -700,7 +700,7 @@ void RotaryEncoderUIUsermod::findCurrentEffectAndPalette() {
700700

701701
effectPaletteIndex = 0;
702702
DEBUG_PRINTLN(effectPalette);
703-
for (uint8_t i = 0; i < strip.getPaletteCount()+strip.customPalettes.size(); i++) {
703+
for (unsigned i = 0; i < strip.getPaletteCount()+strip.customPalettes.size(); i++) {
704704
if (palettes_alpha_indexes[i] == effectPalette) {
705705
effectPaletteIndex = i;
706706
DEBUG_PRINTLN(F("Found palette."));
@@ -764,7 +764,7 @@ void RotaryEncoderUIUsermod::changeEffect(bool increase) {
764764
effectCurrent = modes_alpha_indexes[effectCurrentIndex];
765765
stateChanged = true;
766766
if (applyToAll) {
767-
for (byte i=0; i<strip.getSegmentsNum(); i++) {
767+
for (unsigned i=0; i<strip.getSegmentsNum(); i++) {
768768
Segment& seg = strip.getSegment(i);
769769
if (!seg.isActive()) continue;
770770
seg.setMode(effectCurrent);
@@ -792,7 +792,7 @@ void RotaryEncoderUIUsermod::changeEffectSpeed(bool increase) {
792792
effectSpeed = max(min((increase ? effectSpeed+fadeAmount : effectSpeed-fadeAmount), 255), 0);
793793
stateChanged = true;
794794
if (applyToAll) {
795-
for (byte i=0; i<strip.getSegmentsNum(); i++) {
795+
for (unsigned i=0; i<strip.getSegmentsNum(); i++) {
796796
Segment& seg = strip.getSegment(i);
797797
if (!seg.isActive()) continue;
798798
seg.speed = effectSpeed;
@@ -820,7 +820,7 @@ void RotaryEncoderUIUsermod::changeEffectIntensity(bool increase) {
820820
effectIntensity = max(min((increase ? effectIntensity+fadeAmount : effectIntensity-fadeAmount), 255), 0);
821821
stateChanged = true;
822822
if (applyToAll) {
823-
for (byte i=0; i<strip.getSegmentsNum(); i++) {
823+
for (unsigned i=0; i<strip.getSegmentsNum(); i++) {
824824
Segment& seg = strip.getSegment(i);
825825
if (!seg.isActive()) continue;
826826
seg.intensity = effectIntensity;
@@ -855,7 +855,7 @@ void RotaryEncoderUIUsermod::changeCustom(uint8_t par, bool increase) {
855855
case 2: val = sid.custom2 = max(min((increase ? sid.custom2+fadeAmount : sid.custom2-fadeAmount), 255), 0); break;
856856
default: val = sid.custom1 = max(min((increase ? sid.custom1+fadeAmount : sid.custom1-fadeAmount), 255), 0); break;
857857
}
858-
for (byte i=0; i<strip.getSegmentsNum(); i++) {
858+
for (unsigned i=0; i<strip.getSegmentsNum(); i++) {
859859
Segment& seg = strip.getSegment(i);
860860
if (!seg.isActive() || i == id) continue;
861861
switch (par) {
@@ -894,7 +894,7 @@ void RotaryEncoderUIUsermod::changePalette(bool increase) {
894894
effectPalette = palettes_alpha_indexes[effectPaletteIndex];
895895
stateChanged = true;
896896
if (applyToAll) {
897-
for (byte i=0; i<strip.getSegmentsNum(); i++) {
897+
for (unsigned i=0; i<strip.getSegmentsNum(); i++) {
898898
Segment& seg = strip.getSegment(i);
899899
if (!seg.isActive()) continue;
900900
seg.setPalette(effectPalette);
@@ -923,7 +923,7 @@ void RotaryEncoderUIUsermod::changeHue(bool increase){
923923
colorHStoRGB(currentHue1*256, currentSat1, col);
924924
stateChanged = true;
925925
if (applyToAll) {
926-
for (byte i=0; i<strip.getSegmentsNum(); i++) {
926+
for (unsigned i=0; i<strip.getSegmentsNum(); i++) {
927927
Segment& seg = strip.getSegment(i);
928928
if (!seg.isActive()) continue;
929929
seg.colors[0] = RGBW32(col[0], col[1], col[2], col[3]);
@@ -952,7 +952,7 @@ void RotaryEncoderUIUsermod::changeSat(bool increase){
952952
currentSat1 = max(min((increase ? currentSat1+fadeAmount : currentSat1-fadeAmount), 255), 0);
953953
colorHStoRGB(currentHue1*256, currentSat1, col);
954954
if (applyToAll) {
955-
for (byte i=0; i<strip.getSegmentsNum(); i++) {
955+
for (unsigned i=0; i<strip.getSegmentsNum(); i++) {
956956
Segment& seg = strip.getSegment(i);
957957
if (!seg.isActive()) continue;
958958
seg.colors[0] = RGBW32(col[0], col[1], col[2], col[3]);
@@ -1012,7 +1012,7 @@ void RotaryEncoderUIUsermod::changeCCT(bool increase){
10121012
#endif
10131013
currentCCT = max(min((increase ? currentCCT+fadeAmount : currentCCT-fadeAmount), 255), 0);
10141014
// if (applyToAll) {
1015-
for (byte i=0; i<strip.getSegmentsNum(); i++) {
1015+
for (unsigned i=0; i<strip.getSegmentsNum(); i++) {
10161016
Segment& seg = strip.getSegment(i);
10171017
if (!seg.isActive()) continue;
10181018
seg.setCCT(currentCCT);

wled00/FX.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2367,7 +2367,7 @@ uint16_t mode_meteor() {
23672367
}
23682368

23692369
// draw meteor
2370-
for (int j = 0; j < meteorSize; j++) {
2370+
for (unsigned j = 0; j < meteorSize; j++) {
23712371
int index = (in + j) % SEGLEN;
23722372
int idx = 255;
23732373
int i = trail[index] = max;

wled00/FX_fcn.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1294,8 +1294,9 @@ void WS2812FX::finalizeInit(void) {
12941294
const unsigned defDataPins[] = {DATA_PINS};
12951295
const unsigned defCounts[] = {PIXEL_COUNTS};
12961296
const unsigned defNumPins = ((sizeof defDataPins) / (sizeof defDataPins[0]));
1297-
const unsigned defNumCounts = ((sizeof defCounts) / (sizeof defCounts[0]));
1298-
const unsigned defNumBusses = defNumPins > defNumCounts && defNumCounts > 1 && defNumPins%defNumCounts == 0 ? defNumCounts : defNumPins;
1297+
const unsigned defNumCounts = ((sizeof defCounts) / (sizeof defCounts[0]));
1298+
// if number of pins is divisible by counts, use number of counts to determine number of buses, otherwise use pins
1299+
const unsigned defNumBusses = defNumPins > defNumCounts && defNumPins%defNumCounts == 0 ? defNumCounts : defNumPins;
12991300
const unsigned pinsPerBus = defNumPins / defNumBusses;
13001301
unsigned prevLen = 0;
13011302
for (unsigned i = 0; i < defNumBusses && i < WLED_MAX_BUSSES+WLED_MIN_VIRTUAL_BUSSES; i++) {
@@ -1308,6 +1309,7 @@ void WS2812FX::finalizeInit(void) {
13081309
while (pinManager.isPinAllocated(defPin[0]) && defPin[0] < WLED_NUM_PINS) defPin[0]++;
13091310
}
13101311
unsigned start = prevLen;
1312+
// if we have less counts than pins and they do not align, use last known count to set current count
13111313
unsigned count = defCounts[(i < defNumCounts) ? i : defNumCounts -1];
13121314
prevLen += count;
13131315
BusConfig defCfg = BusConfig(DEFAULT_LED_TYPE, defPin, start, count, DEFAULT_LED_COLOR_ORDER, false, 0, RGBW_MODE_MANUAL_ONLY, 0, useGlobalLedBuffer);

wled00/NodeStruct.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ struct NodeStruct
3434

3535
NodeStruct() : age(0), nodeType(0), build(0)
3636
{
37-
for (uint8_t i = 0; i < 4; ++i) { ip[i] = 0; }
37+
for (unsigned i = 0; i < 4; ++i) { ip[i] = 0; }
3838
}
3939
};
4040
typedef std::map<uint8_t, NodeStruct> NodesMap;

wled00/alexa.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ void alexaInit()
2525
// names are identical as the preset names, switching off can be done by switching off any of them
2626
if (alexaNumPresets) {
2727
String name = "";
28-
for (byte presetIndex = 1; presetIndex <= alexaNumPresets; presetIndex++)
28+
for (unsigned presetIndex = 1; presetIndex <= alexaNumPresets; presetIndex++)
2929
{
3030
if (!getPresetName(presetIndex, name)) break; // no more presets
3131
EspalexaDevice* dev = new EspalexaDevice(name.c_str(), onAlexaChange, EspalexaDeviceType::extendedcolor);
@@ -64,7 +64,7 @@ void onAlexaChange(EspalexaDevice* dev)
6464
} else // switch-on behavior for preset devices
6565
{
6666
// turn off other preset devices
67-
for (byte i = 1; i < espalexa.getDeviceCount(); i++)
67+
for (unsigned i = 1; i < espalexa.getDeviceCount(); i++)
6868
{
6969
if (i == dev->getId()) continue;
7070
espalexa.getDevice(i)->setValue(0); // turn off other presets
@@ -87,7 +87,7 @@ void onAlexaChange(EspalexaDevice* dev)
8787
applyPreset(macroAlexaOff, CALL_MODE_ALEXA);
8888
// below for loop stops Alexa from complaining if macroAlexaOff does not actually turn off
8989
}
90-
for (byte i = 0; i < espalexa.getDeviceCount(); i++)
90+
for (unsigned i = 0; i < espalexa.getDeviceCount(); i++)
9191
{
9292
espalexa.getDevice(i)->setValue(0);
9393
}

0 commit comments

Comments
 (0)