some Code-simplification
This commit is contained in:
parent
caff1c185f
commit
aff1d40297
@ -3,6 +3,7 @@
|
||||
|
||||
#define Q(x) #x
|
||||
#define QUOTE(x) Q(x)
|
||||
#define SET_BIT(value, bitPosition) ((value) |= (1U << (bitPosition)))
|
||||
|
||||
#if PCB_REV == 1
|
||||
#define GPIO_BUTTON D7
|
||||
|
@ -258,84 +258,84 @@ uint32_t ConfigSanityCheck(bool autocorrect)
|
||||
|
||||
if (!(LubeConfig.DistancePerLube_Default > 0) || !(LubeConfig.DistancePerLube_Default < 50000))
|
||||
{
|
||||
setting_reset_bits = setting_reset_bits | (1 << 0);
|
||||
SET_BIT(setting_reset_bits, 0);
|
||||
if (autocorrect)
|
||||
LubeConfig.DistancePerLube_Default = LubeConfig_defaults.DistancePerLube_Default;
|
||||
}
|
||||
|
||||
if (!(LubeConfig.DistancePerLube_Rain > 0) || !(LubeConfig.DistancePerLube_Rain < 50000))
|
||||
{
|
||||
setting_reset_bits = setting_reset_bits | (1 << 1);
|
||||
SET_BIT(setting_reset_bits, 1);
|
||||
if (autocorrect)
|
||||
LubeConfig.DistancePerLube_Rain = LubeConfig_defaults.DistancePerLube_Rain;
|
||||
}
|
||||
|
||||
if (!(LubeConfig.tankCapacity_ml > 0) || !(LubeConfig.tankCapacity_ml < 5000))
|
||||
{
|
||||
setting_reset_bits = setting_reset_bits | (1 << 2);
|
||||
SET_BIT(setting_reset_bits, 2);
|
||||
if (autocorrect)
|
||||
LubeConfig.tankCapacity_ml = LubeConfig_defaults.tankCapacity_ml;
|
||||
}
|
||||
|
||||
if (!(LubeConfig.amountPerDose_microL > 0) || !(LubeConfig.amountPerDose_microL < 100))
|
||||
{
|
||||
setting_reset_bits = setting_reset_bits | (1 << 3);
|
||||
SET_BIT(setting_reset_bits, 3);
|
||||
if (autocorrect)
|
||||
LubeConfig.amountPerDose_microL = LubeConfig_defaults.amountPerDose_microL;
|
||||
}
|
||||
|
||||
if (!(LubeConfig.TankRemindAtPercentage >= 0) || !(LubeConfig.TankRemindAtPercentage <= 100))
|
||||
{
|
||||
setting_reset_bits = setting_reset_bits | (1 << 4);
|
||||
SET_BIT(setting_reset_bits, 4);
|
||||
if (autocorrect)
|
||||
LubeConfig.TankRemindAtPercentage = LubeConfig_defaults.TankRemindAtPercentage;
|
||||
}
|
||||
|
||||
if (!(LubeConfig.PulsePerRevolution > 0) || !(LubeConfig.PulsePerRevolution < 1000))
|
||||
{
|
||||
setting_reset_bits = setting_reset_bits | (1 << 5);
|
||||
SET_BIT(setting_reset_bits, 5);
|
||||
if (autocorrect)
|
||||
LubeConfig.PulsePerRevolution = LubeConfig_defaults.PulsePerRevolution;
|
||||
}
|
||||
|
||||
if (!(LubeConfig.TireWidth_mm > 0) || !(LubeConfig.TireWidth_mm < 500))
|
||||
{
|
||||
setting_reset_bits = setting_reset_bits | (1 << 6);
|
||||
SET_BIT(setting_reset_bits, 6);
|
||||
if (autocorrect)
|
||||
LubeConfig.TireWidth_mm = LubeConfig_defaults.TireWidth_mm;
|
||||
}
|
||||
|
||||
if (!(LubeConfig.TireWidthHeight_Ratio > 0) || !(LubeConfig.TireWidthHeight_Ratio < 150))
|
||||
{
|
||||
setting_reset_bits = setting_reset_bits | (1 << 7);
|
||||
SET_BIT(setting_reset_bits, 7);
|
||||
if (autocorrect)
|
||||
LubeConfig.TireWidthHeight_Ratio = LubeConfig_defaults.TireWidthHeight_Ratio;
|
||||
}
|
||||
|
||||
if (!(LubeConfig.RimDiameter_Inch > 0) || !(LubeConfig.RimDiameter_Inch < 30))
|
||||
{
|
||||
setting_reset_bits = setting_reset_bits | (1 << 8);
|
||||
SET_BIT(setting_reset_bits, 8);
|
||||
if (autocorrect)
|
||||
LubeConfig.RimDiameter_Inch = LubeConfig_defaults.RimDiameter_Inch;
|
||||
}
|
||||
|
||||
if (!(LubeConfig.DistancePerRevolution_mm > 0) || !(LubeConfig.DistancePerRevolution_mm < 10000))
|
||||
{
|
||||
setting_reset_bits = setting_reset_bits | (1 << 9);
|
||||
SET_BIT(setting_reset_bits, 9);
|
||||
if (autocorrect)
|
||||
LubeConfig.DistancePerRevolution_mm = LubeConfig_defaults.DistancePerRevolution_mm;
|
||||
}
|
||||
|
||||
if (!(LubeConfig.BleedingPulses > 0) || !(LubeConfig.BleedingPulses < 1001))
|
||||
{
|
||||
setting_reset_bits = setting_reset_bits | (1 << 10);
|
||||
SET_BIT(setting_reset_bits, 10);
|
||||
if (autocorrect)
|
||||
LubeConfig.BleedingPulses = LubeConfig_defaults.BleedingPulses;
|
||||
}
|
||||
|
||||
if (!(LubeConfig.SpeedSource >= 0) || !(LubeConfig.SpeedSource < SpeedSourceString_Elements))
|
||||
{
|
||||
setting_reset_bits = setting_reset_bits | (1 << 11);
|
||||
SET_BIT(setting_reset_bits, 11);
|
||||
if (autocorrect)
|
||||
LubeConfig.SpeedSource = LubeConfig_defaults.SpeedSource;
|
||||
}
|
||||
@ -343,7 +343,7 @@ uint32_t ConfigSanityCheck(bool autocorrect)
|
||||
#ifdef FEATURE_ENABLE_GPS
|
||||
if (!(LubeConfig.GPSBaudRate >= 0) || !(LubeConfig.GPSBaudRate < GPSBaudRateString_Elements))
|
||||
{
|
||||
setting_reset_bits = setting_reset_bits | (1 << 12);
|
||||
SET_BIT(setting_reset_bits, 12);
|
||||
if (autocorrect)
|
||||
LubeConfig.GPSBaudRate = LubeConfig_defaults.GPSBaudRate;
|
||||
}
|
||||
@ -352,7 +352,7 @@ uint32_t ConfigSanityCheck(bool autocorrect)
|
||||
#ifdef FEATURE_ENABLE_CAN
|
||||
if (!(LubeConfig.CANSource >= 0) || !(LubeConfig.CANSource < CANSourceString_Elements))
|
||||
{
|
||||
setting_reset_bits = setting_reset_bits | (1 << 13);
|
||||
SET_BIT(setting_reset_bits, 13);
|
||||
if (autocorrect)
|
||||
LubeConfig.CANSource = LubeConfig_defaults.CANSource;
|
||||
}
|
||||
|
@ -22,6 +22,7 @@ void RunLubeApp(uint32_t add_milimeters)
|
||||
switch (globals.systemStatus)
|
||||
{
|
||||
case sysStat_Startup:
|
||||
strcpy_P(globals.systemStatustxt, PSTR("Startup"));
|
||||
if (millis() > STARTUP_DELAY)
|
||||
{
|
||||
globals.systemStatus = sysStat_Normal;
|
||||
@ -30,6 +31,7 @@ void RunLubeApp(uint32_t add_milimeters)
|
||||
break;
|
||||
|
||||
case sysStat_Normal:
|
||||
strcpy_P(globals.systemStatustxt, PSTR("Normal"));
|
||||
if (PersistenceData.TravelDistance_highRes_mm / 1000 > LubeConfig.DistancePerLube_Default)
|
||||
{
|
||||
LubePulse();
|
||||
@ -38,6 +40,7 @@ void RunLubeApp(uint32_t add_milimeters)
|
||||
break;
|
||||
|
||||
case sysStat_Rain:
|
||||
strcpy_P(globals.systemStatustxt, PSTR("Rain"));
|
||||
if (PersistenceData.TravelDistance_highRes_mm / 1000 > LubeConfig.DistancePerLube_Rain)
|
||||
{
|
||||
LubePulse();
|
||||
@ -45,12 +48,14 @@ void RunLubeApp(uint32_t add_milimeters)
|
||||
}
|
||||
break;
|
||||
case sysStat_Purge:
|
||||
strcpy_P(globals.systemStatustxt, PSTR("Purge"));
|
||||
if (globals.purgePulses > 0)
|
||||
{
|
||||
if (lubePulseTimestamp + LUBE_PULSE_PAUSE_MS < millis())
|
||||
{
|
||||
LubePulse();
|
||||
globals.purgePulses--;
|
||||
Debug_pushMessage("Purge remain: %d\n", globals.purgePulses);
|
||||
}
|
||||
}
|
||||
else
|
||||
@ -58,32 +63,14 @@ void RunLubeApp(uint32_t add_milimeters)
|
||||
globals.systemStatus = globals.resumeStatus;
|
||||
}
|
||||
break;
|
||||
case sysStat_Error:
|
||||
case sysStat_Shutdown:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
switch (globals.systemStatus)
|
||||
{
|
||||
case sysStat_Normal:
|
||||
strcpy_P(globals.systemStatustxt, PSTR("Normal"));
|
||||
break;
|
||||
case sysStat_Purge:
|
||||
strcpy_P(globals.systemStatustxt, PSTR("Purge"));
|
||||
break;
|
||||
case sysStat_Rain:
|
||||
strcpy_P(globals.systemStatustxt, PSTR("Rain"));
|
||||
break;
|
||||
case sysStat_Startup:
|
||||
strcpy_P(globals.systemStatustxt, PSTR("Startup"));
|
||||
break;
|
||||
case sysStat_Error:
|
||||
strcpy_P(globals.systemStatustxt, PSTR("Error"));
|
||||
break;
|
||||
case sysStat_Shutdown:
|
||||
strcpy_P(globals.systemStatustxt, PSTR("Shutdown"));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
// maintain Pin-State of Lube-Pump
|
||||
|
Loading…
x
Reference in New Issue
Block a user