Skip to content

Commit

Permalink
Fixes to feature update for Internal Temperature usermod
Browse files Browse the repository at this point in the history
Applied various fixes as advised by @blazoncek

Thankyou for the advice!

- Updated float: 95.0 > 95.0f

- Updated type: const > constexpr

- Comments clarified

- Preset setting: `-1` > `0`
  • Loading branch information
adamsthws committed Jun 27, 2024
1 parent f825cab commit bc4a613
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 16 deletions.
9 changes: 2 additions & 7 deletions usermods/Internal_Temperature_v2/readme.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
# Internal Temperature Usermod

![Screenshot of WLED info page](assets/screenshot-info.png =700x)

<p align="left">
<img width="700" src="assets/screenshot-info.png">
</p>

<p align="left">
<img width="700" src="assets/screenshot-settings.png">
</p>
![Screenshot of WLED usermod settings page](assets/screenshot-settings.png =700x)

## Features
- &nbsp;🌡️&nbsp; Adds the internal temperature readout of the chip to the `Info` tab
Expand Down
17 changes: 8 additions & 9 deletions usermods/Internal_Temperature_v2/usermod_internal_temperature.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ class InternalTemperatureUsermod : public Usermod
{

private:
static const unsigned long minLoopInterval = 1000; // minimum allowable interval (ms)
static constexpr unsigned long minLoopInterval = 1000; // minimum allowable interval (ms)
unsigned long loopInterval = 10000;
unsigned long lastTime = 0;
bool isEnabled = false;
float temperature = 0;
int presetToActivate = -1; // Preset to activate when temp goes above threshold (-1 = disabled)
float activationThreshold = 95.0; // Temperature threshold to trigger high-temperature actions
int presetToActivate = 0; // Preset to activate when temp goes above threshold (0 = disabled)
float activationThreshold = 95.0f; // Temperature threshold to trigger high-temperature actions
float resetMargin = 2.0; // Margin below the activation threshold (Prevents frequent toggling when close to threshold)
bool isAboveThreshold = false; // Flag to track if the high temperature preset is currently active

Expand All @@ -33,7 +33,6 @@ class InternalTemperatureUsermod : public Usermod
public:
void setup()
{
setSafeLoopInterval(loopInterval); // Initialize with a safe loop interval
}

void loop()
Expand Down Expand Up @@ -62,8 +61,8 @@ class InternalTemperatureUsermod : public Usermod
isAboveThreshold = true;
}
// Activate the 'over-threshold' preset if it's not already active
if (presetToActivate != -1 && currentPreset != presetToActivate) {
saveTemporaryPreset(); // Save the current preset to allow re-activation later
if (presetToActivate != 0 && currentPreset != presetToActivate) {
saveTemporaryPreset(); // Save current state to a temporary preset to allow re-activation later
applyPreset(presetToActivate);
}
}
Expand All @@ -75,7 +74,7 @@ class InternalTemperatureUsermod : public Usermod
}
// Revert back to the original preset
if (currentPreset == presetToActivate){
applyTemporaryPreset(); // Restore the previously stored active preset
applyTemporaryPreset(); // Restore the previous state which was stored to the temporary preset
}
}

Expand Down Expand Up @@ -129,8 +128,8 @@ class InternalTemperatureUsermod : public Usermod
oappend(SET_F("addInfo('Internal Temperature:Loop Interval', 1, 'ms');"));
// Display '°C' next to the 'Activation Threshold' setting
oappend(SET_F("addInfo('Internal Temperature:Activation Threshold', 1, '°C');"));
// Display '-1 = Disabled' next to the 'Preset To Activate' setting
oappend(SET_F("addInfo('Internal Temperature:Preset To Activate', 1, '-1 = disabled');"));
// Display '0 = Disabled' next to the 'Preset To Activate' setting
oappend(SET_F("addInfo('Internal Temperature:Preset To Activate', 1, '0 = unused');"));
}

bool readFromConfig(JsonObject &root)
Expand Down

0 comments on commit bc4a613

Please sign in to comment.