mirror of
https://github.com/wled/WLED.git
synced 2025-07-17 15:56:31 +00:00
Bugfix:
- rewrite error-prone use of shifting - allow -1 for analog pin on ESP8266
This commit is contained in:
parent
62cb8358cc
commit
3bb9d220bb
@ -70,10 +70,12 @@ void handleAnalog(uint8_t b)
|
|||||||
{
|
{
|
||||||
static uint8_t oldRead[WLED_MAX_BUTTONS];
|
static uint8_t oldRead[WLED_MAX_BUTTONS];
|
||||||
#ifdef ESP8266
|
#ifdef ESP8266
|
||||||
uint16_t aRead = analogRead(A0) >> 4; // convert 10bit read to 6bit (remove noise/reduce range & frequency of UI updates)
|
uint16_t aRead = analogRead(A0) >> 2; // convert 10bit read to 8bit
|
||||||
#else
|
#else
|
||||||
uint16_t aRead = analogRead(btnPin[b]) >> 6; // convert 12bit read to 6bit (remove noise/reduce range & frequency of UI updates)
|
uint16_t aRead = analogRead(btnPin[b]) >> 4; // convert 12bit read to 8bit
|
||||||
#endif
|
#endif
|
||||||
|
// remove noise & reduce frequency of UI updates
|
||||||
|
aRead &= 0xFC;
|
||||||
|
|
||||||
if (oldRead[b] == aRead) return; // no change in reading
|
if (oldRead[b] == aRead) return; // no change in reading
|
||||||
oldRead[b] = aRead;
|
oldRead[b] = aRead;
|
||||||
@ -87,11 +89,11 @@ void handleAnalog(uint8_t b)
|
|||||||
briLast = bri;
|
briLast = bri;
|
||||||
bri = 0;
|
bri = 0;
|
||||||
} else{
|
} else{
|
||||||
bri = aRead << 2;
|
bri = aRead;
|
||||||
}
|
}
|
||||||
} else if (macroDoublePress[b] == 249) {
|
} else if (macroDoublePress[b] == 249) {
|
||||||
// effect speed
|
// effect speed
|
||||||
effectSpeed = aRead << 2;
|
effectSpeed = aRead;
|
||||||
effectChanged = true;
|
effectChanged = true;
|
||||||
for (uint8_t i = 0; i < strip.getMaxSegments(); i++) {
|
for (uint8_t i = 0; i < strip.getMaxSegments(); i++) {
|
||||||
WS2812FX::Segment& seg = strip.getSegment(i);
|
WS2812FX::Segment& seg = strip.getSegment(i);
|
||||||
@ -100,7 +102,7 @@ void handleAnalog(uint8_t b)
|
|||||||
}
|
}
|
||||||
} else if (macroDoublePress[b] == 248) {
|
} else if (macroDoublePress[b] == 248) {
|
||||||
// effect intensity
|
// effect intensity
|
||||||
effectIntensity = aRead << 2;
|
effectIntensity = aRead;
|
||||||
effectChanged = true;
|
effectChanged = true;
|
||||||
for (uint8_t i = 0; i < strip.getMaxSegments(); i++) {
|
for (uint8_t i = 0; i < strip.getMaxSegments(); i++) {
|
||||||
WS2812FX::Segment& seg = strip.getSegment(i);
|
WS2812FX::Segment& seg = strip.getSegment(i);
|
||||||
@ -109,7 +111,7 @@ void handleAnalog(uint8_t b)
|
|||||||
}
|
}
|
||||||
} else if (macroDoublePress[b] == 247) {
|
} else if (macroDoublePress[b] == 247) {
|
||||||
// selected palette
|
// selected palette
|
||||||
effectPalette = map(aRead, 0, 63, 0, strip.getPaletteCount()-1);
|
effectPalette = map(aRead, 0, 252, 0, strip.getPaletteCount()-1);
|
||||||
effectChanged = true;
|
effectChanged = true;
|
||||||
for (uint8_t i = 0; i < strip.getMaxSegments(); i++) {
|
for (uint8_t i = 0; i < strip.getMaxSegments(); i++) {
|
||||||
WS2812FX::Segment& seg = strip.getSegment(i);
|
WS2812FX::Segment& seg = strip.getSegment(i);
|
||||||
@ -123,7 +125,7 @@ void handleAnalog(uint8_t b)
|
|||||||
if (aRead == 0) {
|
if (aRead == 0) {
|
||||||
seg.setOption(SEG_OPTION_ON, 0); // off
|
seg.setOption(SEG_OPTION_ON, 0); // off
|
||||||
} else {
|
} else {
|
||||||
seg.setOpacity(aRead << 3, macroDoublePress[b]);
|
seg.setOpacity(aRead, macroDoublePress[b]);
|
||||||
seg.setOption(SEG_OPTION_ON, 1);
|
seg.setOption(SEG_OPTION_ON, 1);
|
||||||
}
|
}
|
||||||
// this will notify clients of update (websockets,mqtt,etc)
|
// this will notify clients of update (websockets,mqtt,etc)
|
||||||
@ -146,7 +148,11 @@ void handleButton()
|
|||||||
static unsigned long lastRead = 0UL;
|
static unsigned long lastRead = 0UL;
|
||||||
|
|
||||||
for (uint8_t b=0; b<WLED_MAX_BUTTONS; b++) {
|
for (uint8_t b=0; b<WLED_MAX_BUTTONS; b++) {
|
||||||
|
#ifdef ESP8266
|
||||||
|
if ((btnPin[b]<0 && buttonType[b] != BTN_TYPE_ANALOG) || buttonType[b] == BTN_TYPE_NONE) continue;
|
||||||
|
#else
|
||||||
if (btnPin[b]<0 || buttonType[b] == BTN_TYPE_NONE) continue;
|
if (btnPin[b]<0 || buttonType[b] == BTN_TYPE_NONE) continue;
|
||||||
|
#endif
|
||||||
|
|
||||||
if (buttonType[b] == BTN_TYPE_ANALOG && millis() - lastRead > 250) { // button is not a button but a potentiometer
|
if (buttonType[b] == BTN_TYPE_ANALOG && millis() - lastRead > 250) { // button is not a button but a potentiometer
|
||||||
if (b+1 == WLED_MAX_BUTTONS) lastRead = millis();
|
if (b+1 == WLED_MAX_BUTTONS) lastRead = millis();
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
// version code in format yymmddb (b = daily build)
|
// version code in format yymmddb (b = daily build)
|
||||||
#define VERSION 2105271
|
#define VERSION 2105281
|
||||||
|
|
||||||
//uncomment this if you have a "my_config.h" file you'd like to use
|
//uncomment this if you have a "my_config.h" file you'd like to use
|
||||||
//#define WLED_USE_MY_CONFIG
|
//#define WLED_USE_MY_CONFIG
|
||||||
|
Loading…
x
Reference in New Issue
Block a user