centralized LED Control and ModeSwitching in Lubeapp.cpp
This commit is contained in:
@@ -12,6 +12,7 @@
|
||||
*/
|
||||
|
||||
#include "lubeapp.h"
|
||||
#include "ledcontrol.h"
|
||||
|
||||
uint32_t lubePulseTimestamp = 0;
|
||||
|
||||
@@ -27,6 +28,8 @@ uint32_t lubePulseTimestamp = 0;
|
||||
*/
|
||||
void RunLubeApp(uint32_t add_milimeters)
|
||||
{
|
||||
static tSystem_Status lastSystemStatus = sysStat_Startup;
|
||||
|
||||
// Calculate and update tank percentage
|
||||
globals.TankPercentage = PersistenceData.tankRemain_microL / (LubeConfig.tankCapacity_ml * 10);
|
||||
|
||||
@@ -49,17 +52,31 @@ void RunLubeApp(uint32_t add_milimeters)
|
||||
switch (globals.systemStatus)
|
||||
{
|
||||
case sysStat_Startup:
|
||||
strcpy_P(globals.systemStatustxt, PSTR("Startup"));
|
||||
|
||||
if (lastSystemStatus != globals.systemStatus)
|
||||
{
|
||||
strcpy_P(globals.systemStatustxt, PSTR("Startup"));
|
||||
LEDControl_SetBasic(LED_STARTUP_NORMAL, LED_PATTERN_BLINK);
|
||||
lastSystemStatus = globals.systemStatus;
|
||||
globals.resumeStatus = sysStat_Startup;
|
||||
}
|
||||
|
||||
// Transition to Normal status after startup delay
|
||||
if (millis() > STARTUP_DELAY)
|
||||
{
|
||||
globals.systemStatus = sysStat_Normal;
|
||||
globals.resumeStatus = sysStat_Normal;
|
||||
}
|
||||
break;
|
||||
|
||||
case sysStat_Normal:
|
||||
strcpy_P(globals.systemStatustxt, PSTR("Normal"));
|
||||
if (lastSystemStatus != globals.systemStatus)
|
||||
{
|
||||
strcpy_P(globals.systemStatustxt, PSTR("Normal"));
|
||||
LEDControl_SetBasic(LED_NORMAL_COLOR, LED_PATTERN_ON);
|
||||
lastSystemStatus = globals.systemStatus;
|
||||
globals.resumeStatus = sysStat_Normal;
|
||||
}
|
||||
|
||||
// Trigger lube pulse if traveled distance exceeds the configured limit
|
||||
if (PersistenceData.TravelDistance_highRes_mm / 1000 > LubeConfig.DistancePerLube_Default)
|
||||
{
|
||||
@@ -69,7 +86,14 @@ void RunLubeApp(uint32_t add_milimeters)
|
||||
break;
|
||||
|
||||
case sysStat_Rain:
|
||||
strcpy_P(globals.systemStatustxt, PSTR("Rain"));
|
||||
if (lastSystemStatus != globals.systemStatus)
|
||||
{
|
||||
strcpy_P(globals.systemStatustxt, PSTR("Rain"));
|
||||
LEDControl_SetBasic(LED_RAIN_COLOR, LED_PATTERN_ON);
|
||||
lastSystemStatus = globals.systemStatus;
|
||||
globals.resumeStatus = sysStat_Rain;
|
||||
}
|
||||
|
||||
// Trigger lube pulse if traveled distance exceeds the configured limit in Rain mode
|
||||
if (PersistenceData.TravelDistance_highRes_mm / 1000 > LubeConfig.DistancePerLube_Rain)
|
||||
{
|
||||
@@ -79,7 +103,14 @@ void RunLubeApp(uint32_t add_milimeters)
|
||||
break;
|
||||
|
||||
case sysStat_Purge:
|
||||
strcpy_P(globals.systemStatustxt, PSTR("Purge"));
|
||||
if (lastSystemStatus != globals.systemStatus)
|
||||
{
|
||||
globals.purgePulses = LubeConfig.BleedingPulses;
|
||||
strcpy_P(globals.systemStatustxt, PSTR("Purge"));
|
||||
LEDControl_SetBasic(LED_PURGE_COLOR, LED_PATTERN_BLINK);
|
||||
lastSystemStatus = globals.systemStatus;
|
||||
}
|
||||
|
||||
// Execute lube pulses during the Purge status
|
||||
if (globals.purgePulses > 0)
|
||||
{
|
||||
@@ -99,12 +130,26 @@ void RunLubeApp(uint32_t add_milimeters)
|
||||
break;
|
||||
|
||||
case sysStat_Error:
|
||||
strcpy_P(globals.systemStatustxt, PSTR("Error"));
|
||||
|
||||
if (lastSystemStatus != globals.systemStatus)
|
||||
{
|
||||
strcpy_P(globals.systemStatustxt, PSTR("Error"));
|
||||
LEDControl_SetBasic(LED_ERROR_COLOR, LED_PATTERN_BLINK_FAST);
|
||||
lastSystemStatus = globals.systemStatus;
|
||||
}
|
||||
|
||||
globals.purgePulses = 0;
|
||||
break;
|
||||
|
||||
case sysStat_Shutdown:
|
||||
strcpy_P(globals.systemStatustxt, PSTR("Shutdown"));
|
||||
|
||||
if (lastSystemStatus != globals.systemStatus)
|
||||
{
|
||||
strcpy_P(globals.systemStatustxt, PSTR("Shutdown"));
|
||||
LEDControl_SetBasic(LED_SHUTDOWN_COLOR, LED_PATTERN_BREATH_REVERSE);
|
||||
lastSystemStatus = globals.systemStatus;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
|
Reference in New Issue
Block a user