Update usermod internal temperature

Enabled the storing the currently active preset or playlist for it to be restored later
This commit is contained in:
Adam Matthews 2024-07-01 00:22:52 +01:00
parent 3815516022
commit 78e7312adf

View File

@ -11,6 +11,8 @@ private:
unsigned long lastTime = 0; unsigned long lastTime = 0;
bool isEnabled = false; bool isEnabled = false;
float temperature = 0.0f; float temperature = 0.0f;
uint8_t previousPlaylist = 0; // Stores the playlist that was active before high-temperature activation
uint8_t previousPreset = 0; // Stores the preset that was active before high-temperature activation
uint8_t presetToActivate = 0; // Preset to activate when temp goes above threshold (0 = disabled) uint8_t presetToActivate = 0; // Preset to activate when temp goes above threshold (0 = disabled)
float activationThreshold = 95.0f; // Temperature threshold to trigger high-temperature actions float activationThreshold = 95.0f; // Temperature threshold to trigger high-temperature actions
float resetMargin = 2.0f; // Margin below the activation threshold (Prevents frequent toggling when close to threshold) float resetMargin = 2.0f; // Margin below the activation threshold (Prevents frequent toggling when close to threshold)
@ -49,15 +51,26 @@ public:
temperature = roundf(temperatureRead() * 10) / 10; temperature = roundf(temperatureRead() * 10) / 10;
#endif #endif
// Check if temperature has gone above the threshold // Check if temperature has exceeded the activation threshold
if (temperature >= activationThreshold) { if (temperature >= activationThreshold) {
// Update the state flag if not already set // Update the state flag if not already set
if (!isAboveThreshold){ if (!isAboveThreshold) {
isAboveThreshold = true; isAboveThreshold = true;
} }
// Activate the 'over-threshold' preset if it's not already active // Check if a 'high temperature' preset is configured and it's not already active
if (presetToActivate != 0 && currentPreset != presetToActivate) { if (presetToActivate != 0 && currentPreset != presetToActivate) {
saveTemporaryPreset(); // Save current state to a temporary preset to allow re-activation later // If a playlist is active, store it for reactivation later
if (currentPlaylist > 0) {
previousPlaylist = currentPlaylist;
}
// If a preset is active, store it for reactivation later
else if (currentPreset > 0) {
previousPreset = currentPreset;
// If no playlist or preset is active, save current state for reactivation later
} else {
saveTemporaryPreset();
}
// Activate the 'high temperature' preset
applyPreset(presetToActivate); applyPreset(presetToActivate);
} }
} }
@ -67,9 +80,25 @@ public:
if (isAboveThreshold){ if (isAboveThreshold){
isAboveThreshold = false; isAboveThreshold = false;
} }
// Revert back to the original preset // Check if the 'high temperature' preset is active
if (currentPreset == presetToActivate){ if (currentPreset == presetToActivate) {
applyTemporaryPreset(); // Restore the previous state which was stored to the temporary preset // Check if a previous playlist was stored
if (previousPlaylist > 0) {
// Reactivate the stored playlist
applyPreset(previousPlaylist);
// Clear the stored playlist
previousPlaylist = 0;
}
// Check if a previous preset was stored
else if (previousPreset > 0) {
// Reactivate the stored preset
applyPreset(previousPreset);
// Clear the stored preset
previousPreset = 0;
// If no previous playlist or preset was stored, revert to the stored state
} else {
applyTemporaryPreset();
}
} }
} }