Restructured Folders
This commit is contained in:
113
Software/src/lubeapp.cpp
Normal file
113
Software/src/lubeapp.cpp
Normal file
@@ -0,0 +1,113 @@
|
||||
#include "lubeapp.h"
|
||||
|
||||
uint32_t lubePulseTimestamp = 0;
|
||||
|
||||
void RunLubeApp(uint32_t add_milimeters)
|
||||
{
|
||||
|
||||
MaintainDTC(DTC_TANK_EMPTY, (PersistenceData.tankRemain_µl < LubeConfig.amountPerDose_µl));
|
||||
|
||||
static tSystem_Status preserverSysStatusError;
|
||||
|
||||
if (getlastDTC(true) < DTC_LAST_DTC)
|
||||
{
|
||||
if (globals.systemStatus != sysStat_Error)
|
||||
preserverSysStatusError = globals.systemStatus;
|
||||
globals.systemStatus = sysStat_Error;
|
||||
}
|
||||
else
|
||||
{
|
||||
globals.systemStatus = preserverSysStatusError;
|
||||
}
|
||||
|
||||
// Add traveled Distance in mm
|
||||
PersistenceData.TravelDistance_highRes_mm += add_milimeters;
|
||||
PersistenceData.odometer_mm += add_milimeters;
|
||||
if (PersistenceData.odometer_mm >= 1000000)
|
||||
{
|
||||
PersistenceData.odometer++;
|
||||
PersistenceData.odometer_mm = 0;
|
||||
}
|
||||
|
||||
switch (globals.systemStatus)
|
||||
{
|
||||
case sysStat_Startup:
|
||||
if (millis() > STARTUP_DELAY)
|
||||
{
|
||||
globals.systemStatus = sysStat_Normal;
|
||||
globals.resumeStatus = sysStat_Normal;
|
||||
}
|
||||
break;
|
||||
|
||||
case sysStat_Normal:
|
||||
if (PersistenceData.TravelDistance_highRes_mm / 1000 > LubeConfig.DistancePerLube_Default)
|
||||
{
|
||||
LubePulse();
|
||||
PersistenceData.TravelDistance_highRes_mm = 0;
|
||||
}
|
||||
break;
|
||||
|
||||
case sysStat_Rain:
|
||||
if (PersistenceData.TravelDistance_highRes_mm / 1000 > LubeConfig.DistancePerLube_Rain)
|
||||
{
|
||||
LubePulse();
|
||||
PersistenceData.TravelDistance_highRes_mm = 0;
|
||||
}
|
||||
break;
|
||||
case sysStat_Purge:
|
||||
if (globals.purgePulses > 0)
|
||||
{
|
||||
if (lubePulseTimestamp + LUBE_PULSE_PAUSE_MS < millis())
|
||||
{
|
||||
LubePulse();
|
||||
globals.purgePulses--;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
globals.systemStatus = globals.resumeStatus;
|
||||
}
|
||||
break;
|
||||
case sysStat_Error:
|
||||
case sysStat_Shutdown:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
switch (globals.systemStatus)
|
||||
{
|
||||
case sysStat_Normal:
|
||||
strcpy(globals.systemStatustxt, PSTR("Normal"));
|
||||
break;
|
||||
case sysStat_Purge:
|
||||
strcpy(globals.systemStatustxt, PSTR("Purge"));
|
||||
break;
|
||||
case sysStat_Rain:
|
||||
strcpy(globals.systemStatustxt, PSTR("Rain"));
|
||||
break;
|
||||
case sysStat_Startup:
|
||||
strcpy(globals.systemStatustxt, PSTR("Startup"));
|
||||
break;
|
||||
case sysStat_Error:
|
||||
strcpy(globals.systemStatustxt, PSTR("Error"));
|
||||
break;
|
||||
case sysStat_Shutdown:
|
||||
strcpy(globals.systemStatustxt, PSTR("Shutdown"));
|
||||
break;
|
||||
}
|
||||
|
||||
// maintain Pin-State of Lube-Pump
|
||||
if (lubePulseTimestamp > millis())
|
||||
digitalWrite(GPIO_PUMP, HIGH);
|
||||
else
|
||||
digitalWrite(GPIO_PUMP, LOW);
|
||||
}
|
||||
|
||||
void LubePulse()
|
||||
{
|
||||
lubePulseTimestamp = millis() + LUBE_PULSE_LENGHT_MS;
|
||||
if (PersistenceData.tankRemain_µl < LubeConfig.amountPerDose_µl)
|
||||
PersistenceData.tankRemain_µl = 0;
|
||||
else
|
||||
PersistenceData.tankRemain_µl = PersistenceData.tankRemain_µl - LubeConfig.amountPerDose_µl;
|
||||
}
|
Reference in New Issue
Block a user