Fix a bug where calibration routines could potentially overwrite the early memory areas in EEPROM

This commit is contained in:
Josh Stewart 2019-02-14 19:53:16 +11:00
parent f2c1d6c615
commit 21cd8609ea
3 changed files with 10 additions and 9 deletions

View File

@ -8,6 +8,7 @@ A full copy of the license may be found in the projects root directory
#include "globals.h"
#include "maths.h"
#include "storage.h"
#include "comms.h"
void initialiseADC()
{
@ -106,13 +107,13 @@ void initialiseADC()
//Sanity checks to ensure none of the filter values are set above 240 (Which would include the 255 value which is the default on a new arduino)
//If an invalid value is detected, it's reset to the default the value and burned to EEPROM.
//Each sensor has it's own default value
if(configPage4.ADCFILTER_TPS > 240) { configPage4.ADCFILTER_TPS = 50; writeConfig(4); }
if(configPage4.ADCFILTER_CLT > 240) { configPage4.ADCFILTER_CLT = 180; writeConfig(4); }
if(configPage4.ADCFILTER_IAT > 240) { configPage4.ADCFILTER_IAT = 180; writeConfig(4); }
if(configPage4.ADCFILTER_O2 > 240) { configPage4.ADCFILTER_O2 = 100; writeConfig(4); }
if(configPage4.ADCFILTER_BAT > 240) { configPage4.ADCFILTER_BAT = 128; writeConfig(4); }
if(configPage4.ADCFILTER_MAP > 240) { configPage4.ADCFILTER_MAP = 20; writeConfig(4); }
if(configPage4.ADCFILTER_BARO > 240) { configPage4.ADCFILTER_BARO = 64; writeConfig(4); }
if(configPage4.ADCFILTER_TPS > 240) { configPage4.ADCFILTER_TPS = 50; writeConfig(ignSetPage); }
if(configPage4.ADCFILTER_CLT > 240) { configPage4.ADCFILTER_CLT = 180; writeConfig(ignSetPage); }
if(configPage4.ADCFILTER_IAT > 240) { configPage4.ADCFILTER_IAT = 180; writeConfig(ignSetPage); }
if(configPage4.ADCFILTER_O2 > 240) { configPage4.ADCFILTER_O2 = 100; writeConfig(ignSetPage); }
if(configPage4.ADCFILTER_BAT > 240) { configPage4.ADCFILTER_BAT = 128; writeConfig(ignSetPage); }
if(configPage4.ADCFILTER_MAP > 240) { configPage4.ADCFILTER_MAP = 20; writeConfig(ignSetPage); }
if(configPage4.ADCFILTER_BARO > 240) { configPage4.ADCFILTER_BARO = 64; writeConfig(ignSetPage); }
}

View File

@ -12,7 +12,7 @@ void writeCalibration();
//These are utility functions that prevent other files from having to use EEPROM.h directly
byte readLastBaro();
void storeLastBaro(byte);
void storeCalibrationValue(byte, byte);
void storeCalibrationValue(uint16_t, byte);
byte readEEPROMVersion();
void storeEEPROMVersion(byte);

View File

@ -652,6 +652,6 @@ void writeCalibration()
// By having these in this file, it prevents other files from calling EEPROM functions directly. This is useful due to differences in the EEPROM libraries on different devces
byte readLastBaro() { return EEPROM.read(EEPROM_LAST_BARO); }
void storeLastBaro(byte newValue) { EEPROM.update(EEPROM_LAST_BARO, newValue); }
void storeCalibrationValue(byte location, byte value) { EEPROM.update(location, value); } //This is essentially just an abstraction for EEPROM.update()
void storeCalibrationValue(uint16_t location, byte value) { EEPROM.update(location, value); } //This is essentially just an abstraction for EEPROM.update()
byte readEEPROMVersion() { return EEPROM.read(EEPROM_DATA_VERSION); }
void storeEEPROMVersion(byte newVersion) { EEPROM.update(EEPROM_DATA_VERSION, newVersion); }