diff --git a/usermods/Temperature/usermod_temperature.h b/usermods/Temperature/usermod_temperature.h index 5ac992f952..23c5606500 100644 --- a/usermods/Temperature/usermod_temperature.h +++ b/usermods/Temperature/usermod_temperature.h @@ -17,6 +17,8 @@ #define USERMOD_DALLASTEMPERATURE_MEASUREMENT_INTERVAL 60000 #endif +static uint16_t mode_temperature(); + class UsermodTemperature : public Usermod { private: @@ -60,6 +62,7 @@ class UsermodTemperature : public Usermod { static const char _sensor[]; static const char _temperature[]; static const char _Temperature[]; + static const char _data_fx[]; //Dallas sensor quick (& dirty) reading. Credit to - Author: Peter Scargill, August 17th, 2013 float readDallas(); @@ -70,8 +73,13 @@ class UsermodTemperature : public Usermod { void publishHomeAssistantAutodiscovery(); #endif + static UsermodTemperature* _instance; // to overcome nonstatic getTemperatureC() method and avoid usermods.lookup(USERMOD_ID_TEMPERATURE); + public: + UsermodTemperature() { _instance = this; } + static UsermodTemperature *getInstance() { return UsermodTemperature::_instance; } + /* * API calls te enable data exchange between WLED modules */ @@ -234,6 +242,7 @@ void UsermodTemperature::setup() { } temperaturePin = -1; // allocation failed } + if (sensorFound && !initDone) strip.addEffect(255, &mode_temperature, _data_fx); } lastMeasurement = millis() - readingInterval + 10000; initDone = true; @@ -440,6 +449,8 @@ const char *UsermodTemperature::getTemperatureUnit() { return degC ? "°C" : "°F"; } +UsermodTemperature* UsermodTemperature::_instance = nullptr; + // strings to reduce flash memory usage (used more than twice) const char UsermodTemperature::_name[] PROGMEM = "Temperature"; const char UsermodTemperature::_enabled[] PROGMEM = "enabled"; @@ -449,4 +460,14 @@ const char UsermodTemperature::_parasitePin[] PROGMEM = "parasite-pwr-pin"; const char UsermodTemperature::_domoticzIDX[] PROGMEM = "domoticz-idx"; const char UsermodTemperature::_sensor[] PROGMEM = "sensor"; const char UsermodTemperature::_temperature[] PROGMEM = "temperature"; -const char UsermodTemperature::_Temperature[] PROGMEM = "/temperature"; \ No newline at end of file +const char UsermodTemperature::_Temperature[] PROGMEM = "/temperature"; +const char UsermodTemperature::_data_fx[] PROGMEM = "Temperature@Min,Max;;!;01;pal=54"; + +static uint16_t mode_temperature() { + float low = mapf((float)SEGMENT.speed, 0.f, 255.f, -150.f, 149.9f); // default: 0°C, range: -15°C to 15°C + float high = mapf((float)SEGMENT.intensity, 0.f, 255.f, 150.f, 450.f); // default: 30°C, range 15°C to 45°C + float temp = constrain(UsermodTemperature::getInstance()->getTemperatureC()*10.f, low, high); // get a little better resolution + unsigned i = map(temp, (unsigned)low, (unsigned)high, 0, 255); + SEGMENT.fill(SEGMENT.color_from_palette(i, false, false, 255)); + return FRAMETIME; +} diff --git a/usermods/audioreactive/audio_reactive.h b/usermods/audioreactive/audio_reactive.h index 088ac880b8..fde7afded0 100644 --- a/usermods/audioreactive/audio_reactive.h +++ b/usermods/audioreactive/audio_reactive.h @@ -149,7 +149,6 @@ static bool useBandPassFilter = false; // if true, enables a //////////////////// // some prototypes, to ensure consistent interfaces -static float mapf(float x, float in_min, float in_max, float out_min, float out_max); // map function for float static float fftAddAvg(int from, int to); // average of several FFT result bins void FFTcode(void * parameter); // audio processing task: read samples, run FFT, fill GEQ channels from FFT results static void runMicFilter(uint16_t numSamples, float *sampleBuffer); // pre-filtering of raw samples (band-pass) @@ -211,11 +210,6 @@ static ArduinoFFT FFT = ArduinoFFT( vReal, vImag, samplesFFT, SAMP // Helper functions -// float version of map() -static float mapf(float x, float in_min, float in_max, float out_min, float out_max){ - return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min; -} - // compute average of several FFT result bins static float fftAddAvg(int from, int to) { float result = 0.0f; diff --git a/wled00/FX.cpp b/wled00/FX.cpp index 807594e430..0084b09e0f 100644 --- a/wled00/FX.cpp +++ b/wled00/FX.cpp @@ -6483,11 +6483,6 @@ static const char _data_FX_MODE_2DWAVERLY[] PROGMEM = "Waverly@Amplification,Sen #endif // WLED_DISABLE_2D -// float version of map() -static float mapf(float x, float in_min, float in_max, float out_min, float out_max){ - return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min; -} - // Gravity struct requited for GRAV* effects typedef struct Gravity { int topLED; diff --git a/wled00/fcn_declare.h b/wled00/fcn_declare.h index f8399b1ad6..a95064a2a6 100644 --- a/wled00/fcn_declare.h +++ b/wled00/fcn_declare.h @@ -378,6 +378,7 @@ uint16_t crc16(const unsigned char* data_p, size_t length); um_data_t* simulateSound(uint8_t simulationId); void enumerateLedmaps(); uint8_t get_random_wheel_index(uint8_t pos); +float mapf(float x, float in_min, float in_max, float out_min, float out_max); // RAII guard class for the JSON Buffer lock // Modeled after std::lock_guard diff --git a/wled00/util.cpp b/wled00/util.cpp index 2e70564489..99a75bdd30 100644 --- a/wled00/util.cpp +++ b/wled00/util.cpp @@ -612,3 +612,8 @@ uint8_t get_random_wheel_index(uint8_t pos) { } return r; } + +// float version of map() +float mapf(float x, float in_min, float in_max, float out_min, float out_max) { + return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min; +}