Bugfixes.
- multi-relay brightness check - temperature no reading delay - analog button fix & noise reduction - IR removed custom
This commit is contained in:
parent
6760744249
commit
1ba70706c2
@ -17,11 +17,6 @@
|
||||
#define USERMOD_DALLASTEMPERATURE_MEASUREMENT_INTERVAL 60000
|
||||
#endif
|
||||
|
||||
// how many seconds after boot to take first measurement, 20 seconds
|
||||
#ifndef USERMOD_DALLASTEMPERATURE_FIRST_MEASUREMENT_AT
|
||||
#define USERMOD_DALLASTEMPERATURE_FIRST_MEASUREMENT_AT 20000
|
||||
#endif
|
||||
|
||||
class UsermodTemperature : public Usermod {
|
||||
|
||||
private:
|
||||
@ -34,7 +29,7 @@ class UsermodTemperature : public Usermod {
|
||||
bool degC = true;
|
||||
unsigned long readingInterval = USERMOD_DALLASTEMPERATURE_MEASUREMENT_INTERVAL;
|
||||
// set last reading as "40 sec before boot", so first reading is taken after 20 sec
|
||||
unsigned long lastMeasurement = UINT32_MAX - (USERMOD_DALLASTEMPERATURE_MEASUREMENT_INTERVAL - USERMOD_DALLASTEMPERATURE_FIRST_MEASUREMENT_AT);
|
||||
unsigned long lastMeasurement = UINT32_MAX - USERMOD_DALLASTEMPERATURE_MEASUREMENT_INTERVAL;
|
||||
// last time requestTemperatures was called
|
||||
// used to determine when we can read the sensors temperature
|
||||
// we have to wait at least 93.75 ms after requestTemperatures() is called
|
||||
@ -42,10 +37,6 @@ class UsermodTemperature : public Usermod {
|
||||
float temperature = -100; // default to -100, DS18B20 only goes down to -50C
|
||||
// indicates requestTemperatures has been called but the sensor measurement is not complete
|
||||
bool waitingForConversion = false;
|
||||
// flag to indicate we have finished the first readTemperature call
|
||||
// allows this library to report to the user how long until the first
|
||||
// measurement
|
||||
bool readTemperatureComplete = false;
|
||||
// flag set at startup if DS18B20 sensor not found, avoids trying to keep getting
|
||||
// temperature if flashed to a board without a sensor attached
|
||||
bool disabled = false;
|
||||
@ -67,7 +58,7 @@ class UsermodTemperature : public Usermod {
|
||||
for (i=2; i < 8; i++) oneWire->read(); // read unused bytes
|
||||
result = (data[1]<<8) | data[0];
|
||||
result >>= 4; // 9-bit precision accurate to 1°C (/16)
|
||||
if (data[1]&0x80) result |= 0xF000; // fix negative value
|
||||
if (data[1]&0x80) result |= 0x8000; // fix negative value
|
||||
//if (data[0]&0x08) ++result;
|
||||
oneWire->reset();
|
||||
oneWire->write(0xCC); // skip ROM
|
||||
@ -86,7 +77,6 @@ class UsermodTemperature : public Usermod {
|
||||
temperature = readDallas();
|
||||
lastMeasurement = millis();
|
||||
waitingForConversion = false;
|
||||
readTemperatureComplete = true;
|
||||
DEBUG_PRINTF("Read temperature %2.1f.\n", temperature);
|
||||
}
|
||||
|
||||
@ -197,14 +187,6 @@ class UsermodTemperature : public Usermod {
|
||||
JsonArray temp = user.createNestedArray(FPSTR(_name));
|
||||
//temp.add(F("Loaded."));
|
||||
|
||||
if (!readTemperatureComplete) {
|
||||
// if we haven't read the sensor yet, let the user know
|
||||
// that we are still waiting for the first measurement
|
||||
temp.add((USERMOD_DALLASTEMPERATURE_FIRST_MEASUREMENT_AT - millis()) / 1000);
|
||||
temp.add(F(" sec until read"));
|
||||
return;
|
||||
}
|
||||
|
||||
if (temperature <= -100) {
|
||||
temp.add(0);
|
||||
temp.add(F(" Sensor Error!"));
|
||||
|
@ -35,7 +35,7 @@ class MultiRelay : public Usermod {
|
||||
// switch timer start time
|
||||
uint32_t _switchTimerStart = 0;
|
||||
// old brightness
|
||||
uint8_t _oldBrightness = 0;
|
||||
bool _oldBrightness = 0;
|
||||
|
||||
// usermod enabled
|
||||
bool enabled = false; // needs to be configured (no default config)
|
||||
@ -265,7 +265,7 @@ class MultiRelay : public Usermod {
|
||||
_relay[i].active = false;
|
||||
}
|
||||
}
|
||||
_oldBrightness = bri;
|
||||
_oldBrightness = (bool)bri;
|
||||
initDone = true;
|
||||
}
|
||||
|
||||
@ -288,8 +288,8 @@ class MultiRelay : public Usermod {
|
||||
lastUpdate = millis();
|
||||
|
||||
//set relay when LEDs turn on
|
||||
if (_oldBrightness != bri) {
|
||||
_oldBrightness = bri;
|
||||
if (_oldBrightness != (bool)bri) {
|
||||
_oldBrightness = (bool)bri;
|
||||
_switchTimerStart = millis();
|
||||
for (uint8_t i=0; i<MULTI_RELAY_MAX_RELAYS; i++) {
|
||||
if (_relay[i].pin>=0) _relay[i].active = true;
|
||||
|
@ -41,7 +41,6 @@ bool isButtonPressed(uint8_t i)
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
void handleSwitch(uint8_t b)
|
||||
{
|
||||
if (buttonPressedBefore[b] != isButtonPressed(b)) {
|
||||
@ -67,52 +66,63 @@ void handleSwitch(uint8_t b)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void handleAnalog(uint8_t b)
|
||||
{
|
||||
static uint8_t oldRead[WLED_MAX_BUTTONS];
|
||||
#ifdef ESP8266
|
||||
uint8_t aRead = analogRead(A0) >> 2; // convert 10bit read to 8bit
|
||||
uint16_t aRead = analogRead(A0) >> 5; // convert 10bit read to 5bit (remove noise)
|
||||
#else
|
||||
uint8_t aRead = analogRead(btnPin[b]) >> 4; // convert 12bit read to 8bit
|
||||
uint16_t aRead = analogRead(btnPin[b]) >> 7; // convert 12bit read to 5bit (remove noise)
|
||||
#endif
|
||||
|
||||
if (oldRead[b] == aRead) return; // no change in reading
|
||||
oldRead[b] = aRead;
|
||||
|
||||
// if no macro for "short press" and "long press" is defined use brightness control
|
||||
if (!macroButton[b] && !macroLongPress[b]) {
|
||||
// if "double press" macro is 250 or greater use global brightness
|
||||
if (macroDoublePress[b]>=250) {
|
||||
if (macroDoublePress[b] >= 250) {
|
||||
// if change in analog read was detected change global brightness
|
||||
if (aRead == 0)
|
||||
toggleOnOff();
|
||||
else
|
||||
bri = aRead;
|
||||
if (aRead == 0) {
|
||||
briLast = bri;
|
||||
bri = 0;
|
||||
} else{
|
||||
bri = aRead << 3;
|
||||
}
|
||||
} else {
|
||||
// otherwise use "double press" for segment selection
|
||||
//uint8_t mainSeg = strip.getMainSegmentId();
|
||||
WS2812FX::Segment& seg = strip.getSegment(macroDoublePress[b]);
|
||||
if (aRead == 0) {
|
||||
seg.setOption(SEG_OPTION_ON, 0, macroDoublePress[b]); // off
|
||||
seg.setOption(SEG_OPTION_ON, 0); // off
|
||||
} else {
|
||||
seg.setOpacity(aRead, macroDoublePress[b]);
|
||||
seg.setOption(SEG_OPTION_ON, 1, macroDoublePress[b]);
|
||||
seg.setOpacity(aRead << 3, macroDoublePress[b]);
|
||||
seg.setOption(SEG_OPTION_ON, 1);
|
||||
}
|
||||
// this will notify clients of update (websockets,mqtt,etc)
|
||||
//call for notifier -> 0: init 1: direct change 2: button 3: notification 4: nightlight 5: other (No notification)
|
||||
// 6: fx changed 7: hue 8: preset cycle 9: blynk 10: alexa
|
||||
updateInterfaces(NOTIFIER_CALL_MODE_BUTTON);
|
||||
}
|
||||
} else {
|
||||
//TODO:
|
||||
// we can either trigger a preset depending on the level (between short and long entries)
|
||||
// or use it for RGBW direct control
|
||||
}
|
||||
//call for notifier -> 0: init 1: direct change 2: button 3: notification 4: nightlight 5: other (No notification)
|
||||
// 6: fx changed 7: hue 8: preset cycle 9: blynk 10: alexa
|
||||
colorUpdated(NOTIFIER_CALL_MODE_BUTTON);
|
||||
}
|
||||
|
||||
void handleButton()
|
||||
{
|
||||
static unsigned long lastRead = 0UL;
|
||||
|
||||
for (uint8_t b=0; b<WLED_MAX_BUTTONS; b++) {
|
||||
if (btnPin[b]<0 || buttonType[b] == BTN_TYPE_NONE) continue;
|
||||
|
||||
if (buttonType[b] == BTN_TYPE_ANALOG) { // 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();
|
||||
handleAnalog(b); continue;
|
||||
}
|
||||
|
||||
|
@ -75,7 +75,7 @@ void sendHuePoll();
|
||||
void onHueData(void* arg, AsyncClient* client, void *data, size_t len);
|
||||
|
||||
//ir.cpp
|
||||
bool decodeIRCustom(uint32_t code);
|
||||
//bool decodeIRCustom(uint32_t code);
|
||||
void applyRepeatActions();
|
||||
void relativeChange(byte* property, int8_t amount, byte lowerBoundary = 0, byte higherBoundary = 0xFF);
|
||||
void changeEffectSpeed(int8_t amount);
|
||||
|
@ -77,6 +77,9 @@ void presetFallback(int8_t presetID, int8_t effectID, int8_t paletteID)
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* This is no longer needed due to JSON IR mod
|
||||
*
|
||||
//Add what your custom IR codes should trigger here. Guide: https://github.com/Aircoookie/WLED/wiki/Infrared-Control
|
||||
//IR codes themselves can be defined directly after "case" or in "ir_codes.h"
|
||||
bool decodeIRCustom(uint32_t code)
|
||||
@ -92,6 +95,7 @@ bool decodeIRCustom(uint32_t code)
|
||||
if (code != IRCUSTOM_MACRO1) colorUpdated(NOTIFIER_CALL_MODE_BUTTON); //don't update color again if we apply macro, it already does it
|
||||
return true;
|
||||
}
|
||||
*/
|
||||
|
||||
void relativeChange(byte* property, int8_t amount, byte lowerBoundary, byte higherBoundary)
|
||||
{
|
||||
@ -160,30 +164,27 @@ void decodeIR(uint32_t code)
|
||||
return;
|
||||
}
|
||||
lastValidCode = 0; irTimesRepeated = 0;
|
||||
if (decodeIRCustom(code)) return;
|
||||
// if (decodeIRCustom(code)) return;
|
||||
if (code > 0xFFFFFF) return; //invalid code
|
||||
//else if (code > 0xF70000 && code < 0xF80000) decodeIR24(code); //is in 24-key remote range
|
||||
//else if (code > 0xFF0000) {
|
||||
switch (irEnabled) {
|
||||
case 1:
|
||||
if (code > 0xF80000) {
|
||||
decodeIR24OLD(code); // white 24-key remote (old) - it sends 0xFF0000 values
|
||||
decodeIR24OLD(code); // white 24-key remote (old) - it sends 0xFF0000 values
|
||||
} else {
|
||||
decodeIR24(code); //is in 24-key remote range
|
||||
decodeIR24(code); //is in 24-key remote range
|
||||
}
|
||||
break;
|
||||
case 2: decodeIR24CT(code); break; // white 24-key remote with CW, WW, CT+ and CT- keys
|
||||
case 3: decodeIR40(code); break; // blue 40-key remote with 25%, 50%, 75% and 100% keys
|
||||
case 4: decodeIR44(code); break; // white 44-key remote with color-up/down keys and DIY1 to 6 keys
|
||||
case 5: decodeIR21(code); break; // white 21-key remote
|
||||
case 6: decodeIR6(code); break; // black 6-key learning remote defaults: "CH" controls brightness,
|
||||
// "VOL +" controls effect, "VOL -" controls colour/palette, "MUTE"
|
||||
// sets bright plain white
|
||||
case 2: decodeIR24CT(code); break; // white 24-key remote with CW, WW, CT+ and CT- keys
|
||||
case 3: decodeIR40(code); break; // blue 40-key remote with 25%, 50%, 75% and 100% keys
|
||||
case 4: decodeIR44(code); break; // white 44-key remote with color-up/down keys and DIY1 to 6 keys
|
||||
case 5: decodeIR21(code); break; // white 21-key remote
|
||||
case 6: decodeIR6(code); break; // black 6-key learning remote defaults: "CH" controls brightness,
|
||||
// "VOL +" controls effect, "VOL -" controls colour/palette, "MUTE"
|
||||
// sets bright plain white
|
||||
case 7: decodeIR9(code); break;
|
||||
case 8: decodeIRJson(code); break; // any remote configurable with ir.json file
|
||||
case 8: decodeIRJson(code); break; // any remote configurable with ir.json file
|
||||
default: return;
|
||||
}
|
||||
//}
|
||||
|
||||
if (nightlightActive && bri == 0) nightlightActive = false;
|
||||
colorUpdated(NOTIFIER_CALL_MODE_BUTTON); //for notifier, IR is considered a button input
|
||||
@ -569,7 +570,7 @@ void decodeIRJson(uint32_t code)
|
||||
JsonObject fdo;
|
||||
JsonObject jsonCmdObj;
|
||||
|
||||
sprintf_P(objKey, PSTR("\"0x%X\":"), code);
|
||||
sprintf_P(objKey, PSTR("\"0x%lX\":"), code);
|
||||
|
||||
errorFlag = readObjectFromFile("/ir.json", objKey, &irDoc) ? ERR_NONE : ERR_FS_PLOAD;
|
||||
fdo = irDoc.as<JsonObject>();
|
||||
@ -642,9 +643,7 @@ void handleIR()
|
||||
{
|
||||
if (results.value != 0) // only print results if anything is received ( != 0 )
|
||||
{
|
||||
Serial.print("IR recv\r\n0x");
|
||||
Serial.println((uint32_t)results.value, HEX);
|
||||
Serial.println();
|
||||
DEBUG_PRINTF("IR recv: 0x%lX\n", (uint32_t)results.value);
|
||||
}
|
||||
decodeIR(results.value);
|
||||
irrecv->resume();
|
||||
|
@ -648,7 +648,6 @@ bool handleSet(AsyncWebServerRequest *request, const String& req, bool apply)
|
||||
nightlightActive = false; //always disable nightlight when toggling
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
//set hue
|
||||
|
@ -8,7 +8,7 @@
|
||||
*/
|
||||
|
||||
// version code in format yymmddb (b = daily build)
|
||||
#define VERSION 2105231
|
||||
#define VERSION 2105251
|
||||
|
||||
//uncomment this if you have a "my_config.h" file you'd like to use
|
||||
//#define WLED_USE_MY_CONFIG
|
||||
|
Loading…
Reference in New Issue
Block a user