Merge branch 'master' into merge-master
This commit is contained in:
commit
d4ea30e081
@ -22,12 +22,12 @@
|
||||
|
||||
// 10 bits
|
||||
#ifndef USERMOD_SN_PHOTORESISTOR_ADC_PRECISION
|
||||
#define USERMOD_SN_PHOTORESISTOR_ADC_PRECISION 1024.0
|
||||
#define USERMOD_SN_PHOTORESISTOR_ADC_PRECISION 1024.0f
|
||||
#endif
|
||||
|
||||
// resistor size 10K hms
|
||||
#ifndef USERMOD_SN_PHOTORESISTOR_RESISTOR_VALUE
|
||||
#define USERMOD_SN_PHOTORESISTOR_RESISTOR_VALUE 10000.0
|
||||
#define USERMOD_SN_PHOTORESISTOR_RESISTOR_VALUE 10000.0f
|
||||
#endif
|
||||
|
||||
// only report if differance grater than offset value
|
||||
|
@ -21,10 +21,10 @@
|
||||
#ifndef USERMOD_BATTERY_ADC_PRECISION
|
||||
#ifdef ARDUINO_ARCH_ESP32
|
||||
// 12 bits
|
||||
#define USERMOD_BATTERY_ADC_PRECISION 4095.0
|
||||
#define USERMOD_BATTERY_ADC_PRECISION 4095.0f
|
||||
#else
|
||||
// 10 bits
|
||||
#define USERMOD_BATTERY_ADC_PRECISION 1024.0
|
||||
#define USERMOD_BATTERY_ADC_PRECISION 1024.0f
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@ -39,11 +39,11 @@
|
||||
// https://batterybro.com/blogs/18650-wholesale-battery-reviews/18852515-when-to-recycle-18650-batteries-and-how-to-start-a-collection-center-in-your-vape-shop
|
||||
// Discharge voltage: 2.5 volt + .1 for personal safety
|
||||
#ifndef USERMOD_BATTERY_MIN_VOLTAGE
|
||||
#define USERMOD_BATTERY_MIN_VOLTAGE 2.6
|
||||
#define USERMOD_BATTERY_MIN_VOLTAGE 2.6f
|
||||
#endif
|
||||
|
||||
#ifndef USERMOD_BATTERY_MAX_VOLTAGE
|
||||
#define USERMOD_BATTERY_MAX_VOLTAGE 4.2
|
||||
#define USERMOD_BATTERY_MAX_VOLTAGE 4.2f
|
||||
#endif
|
||||
|
||||
class UsermodBatteryBasic : public Usermod
|
||||
|
@ -272,7 +272,7 @@ class MultiRelay : public Usermod {
|
||||
|
||||
void publishHomeAssistantAutodiscovery() {
|
||||
for (uint8_t i = 0; i < MULTI_RELAY_MAX_RELAYS; i++) {
|
||||
char uid[16], json_str[1024], buf[128];
|
||||
char uid[24], json_str[1024], buf[128];
|
||||
size_t payload_size;
|
||||
sprintf_P(uid, PSTR("%s_sw%d"), escapedMac.c_str(), i);
|
||||
|
||||
|
@ -81,7 +81,6 @@
|
||||
#define SEGLEN _virtualSegmentLength
|
||||
#define SEGACT SEGMENT.stop
|
||||
#define SPEED_FORMULA_L 5U + (50U*(255U - SEGMENT.speed))/SEGLEN
|
||||
#define RESET_RUNTIME memset(_segment_runtimes, 0, sizeof(_segment_runtimes))
|
||||
|
||||
// some common colors
|
||||
#define RED (uint32_t)0xFF0000
|
||||
@ -410,8 +409,9 @@ class WS2812FX {
|
||||
* Flags that before the next effect is calculated,
|
||||
* the internal segment state should be reset.
|
||||
* Call resetIfRequired before calling the next effect function.
|
||||
* Safe to call from interrupts and network requests.
|
||||
*/
|
||||
inline void reset() { _requiresReset = true; }
|
||||
inline void markForReset() { _requiresReset = true; }
|
||||
private:
|
||||
uint16_t _dataLen = 0;
|
||||
bool _requiresReset = false;
|
||||
|
@ -67,7 +67,12 @@
|
||||
//do not call this method from system context (network callback)
|
||||
void WS2812FX::finalizeInit(void)
|
||||
{
|
||||
RESET_RUNTIME;
|
||||
//reset segment runtimes
|
||||
for (uint8_t i = 0; i < MAX_NUM_SEGMENTS; i++) {
|
||||
_segment_runtimes[i].markForReset();
|
||||
_segment_runtimes[i].resetIfRequired();
|
||||
}
|
||||
|
||||
_hasWhiteChannel = _isOffRefreshRequired = false;
|
||||
|
||||
//if busses failed to load, add default (fresh install, FS issue, ...)
|
||||
@ -373,7 +378,7 @@ void WS2812FX::setMode(uint8_t segid, uint8_t m) {
|
||||
|
||||
if (_segments[segid].mode != m)
|
||||
{
|
||||
_segment_runtimes[segid].reset();
|
||||
_segment_runtimes[segid].markForReset();
|
||||
_segments[segid].mode = m;
|
||||
}
|
||||
}
|
||||
@ -643,12 +648,12 @@ void WS2812FX::setSegment(uint8_t n, uint16_t i1, uint16_t i2, uint8_t grouping,
|
||||
seg.spacing = spacing;
|
||||
}
|
||||
if (offset < UINT16_MAX) seg.offset = offset;
|
||||
_segment_runtimes[n].reset();
|
||||
_segment_runtimes[n].markForReset();
|
||||
}
|
||||
|
||||
void WS2812FX::restartRuntime() {
|
||||
for (uint8_t i = 0; i < MAX_NUM_SEGMENTS; i++) {
|
||||
_segment_runtimes[i].reset();
|
||||
_segment_runtimes[i].markForReset();
|
||||
}
|
||||
}
|
||||
|
||||
@ -679,9 +684,9 @@ void WS2812FX::resetSegments() {
|
||||
_segments[i].cct = 127;
|
||||
_segments[i].speed = DEFAULT_SPEED;
|
||||
_segments[i].intensity = DEFAULT_INTENSITY;
|
||||
_segment_runtimes[i].reset();
|
||||
_segment_runtimes[i].markForReset();
|
||||
}
|
||||
_segment_runtimes[0].reset();
|
||||
_segment_runtimes[0].markForReset();
|
||||
}
|
||||
|
||||
void WS2812FX::makeAutoSegments() {
|
||||
|
@ -72,21 +72,23 @@ void doublePressAction(uint8_t b)
|
||||
bool isButtonPressed(uint8_t i)
|
||||
{
|
||||
if (btnPin[i]<0) return false;
|
||||
uint8_t pin = btnPin[i];
|
||||
|
||||
switch (buttonType[i]) {
|
||||
case BTN_TYPE_NONE:
|
||||
case BTN_TYPE_RESERVED:
|
||||
break;
|
||||
case BTN_TYPE_PUSH:
|
||||
case BTN_TYPE_SWITCH:
|
||||
if (digitalRead(btnPin[i]) == LOW) return true;
|
||||
if (digitalRead(pin) == LOW) return true;
|
||||
break;
|
||||
case BTN_TYPE_PUSH_ACT_HIGH:
|
||||
case BTN_TYPE_PIR_SENSOR:
|
||||
if (digitalRead(btnPin[i]) == HIGH) return true;
|
||||
if (digitalRead(pin) == HIGH) return true;
|
||||
break;
|
||||
case BTN_TYPE_TOUCH:
|
||||
#if defined(ARDUINO_ARCH_ESP32) && !defined(CONFIG_IDF_TARGET_ESP32C3)
|
||||
if (touchRead(btnPin[i]) <= touchThreshold) return true;
|
||||
if (touchRead(pin) <= touchThreshold) return true;
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
|
@ -254,6 +254,7 @@ void decodeIR(uint32_t code)
|
||||
}
|
||||
lastValidCode = 0; irTimesRepeated = 0;
|
||||
//if (decodeIRCustom(code)) return;
|
||||
lastRepeatableAction = ACTION_NONE;
|
||||
if (irEnabled == 8) { // any remote configurable with ir.json file
|
||||
decodeIRJson(code);
|
||||
colorUpdated(CALL_MODE_BUTTON);
|
||||
@ -302,7 +303,6 @@ void applyRepeatActions()
|
||||
case ACTION_INTENSITY_DOWN : changeEffectIntensity(lastRepeatableValue); colorUpdated(CALL_MODE_BUTTON); return;
|
||||
default: break;
|
||||
}
|
||||
|
||||
if (lastValidCode == IR40_WPLUS) {
|
||||
relativeChangeWhite(10);
|
||||
colorUpdated(CALL_MODE_BUTTON);
|
||||
|
@ -77,37 +77,41 @@ float asin_t(float x) {
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
//https://stackoverflow.com/a/42542593
|
||||
#define A 0.0776509570923569
|
||||
#define B -0.287434475393028
|
||||
#define C ((HALF_PI/2) - A - B)
|
||||
|
||||
//polynominal factors for approximation between 1 and 5
|
||||
#define C0 0.089494f
|
||||
#define C1 0.974207f
|
||||
#define C2 -0.326175f
|
||||
#define C3 0.05375f
|
||||
#define C4 -0.003445f
|
||||
|
||||
// declare a template with no implementation, and only one specialization
|
||||
// this allows hiding the constants, while ensuring ODR causes optimizations
|
||||
// to still apply. (Fixes issues with conflicting 3rd party #define's)
|
||||
template <typename T> T atan_t(T x);
|
||||
template<>
|
||||
float atan_t(float x) {
|
||||
bool neg = (x < 0);
|
||||
//For A/B/C, see https://stackoverflow.com/a/42542593
|
||||
static const double A { 0.0776509570923569 };
|
||||
static const double B { -0.287434475393028 };
|
||||
static const double C { ((HALF_PI/2) - A - B) };
|
||||
// polynominal factors for approximation between 1 and 5
|
||||
static const float C0 { 0.089494f };
|
||||
static const float C1 { 0.974207f };
|
||||
static const float C2 { -0.326175f };
|
||||
static const float C3 { 0.05375f };
|
||||
static const float C4 { -0.003445f };
|
||||
|
||||
#ifdef WLED_DEBUG_MATH
|
||||
float xinput = x;
|
||||
#endif
|
||||
bool neg = (x < 0);
|
||||
x = std::abs(x);
|
||||
float res;
|
||||
if (x > 5.0f) { //atan(x) converges to pi/2 - (1/x) for large values
|
||||
if (x > 5.0f) { // atan(x) converges to pi/2 - (1/x) for large values
|
||||
res = HALF_PI - (1.0f/x);
|
||||
}
|
||||
else if (x > 1.0f) { //1 < x < 5
|
||||
} else if (x > 1.0f) { //1 < x < 5
|
||||
float xx = x * x;
|
||||
res = (C4*xx*xx)+(C3*xx*x)+(C2*xx)+(C1*x)+C0;
|
||||
} else { //this approximation is only for x <= 1
|
||||
} else { // this approximation is only for x <= 1
|
||||
float xx = x * x;
|
||||
res = ((A*xx + B)*xx + C)*x;
|
||||
}
|
||||
if (neg) res = -res;
|
||||
if (neg) {
|
||||
res = -res;
|
||||
}
|
||||
#ifdef WLED_DEBUG_MATH
|
||||
Serial.printf("atan: %f,%f,%f,(%f)\n",xinput,res,atan(xinput),res-atan(xinput));
|
||||
#endif
|
||||
|
@ -46,8 +46,6 @@ void handleSerial()
|
||||
static byte red = 0x00;
|
||||
static byte green = 0x00;
|
||||
|
||||
uint16_t nBytes = 0;
|
||||
|
||||
while (Serial.available() > 0)
|
||||
{
|
||||
yield();
|
||||
|
Loading…
Reference in New Issue
Block a user