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