Improved config memory
This commit is contained in:
@@ -16,6 +16,7 @@ static const uint16_t addr_max_hbrake_time = 0x0006;
|
||||
static const uint16_t addr_lock_current = 0x0008;
|
||||
static const uint16_t addr_max_out_voltage = 0x000A;
|
||||
static const uint16_t addr_min_out_voltage = 0x000C;
|
||||
static const uint16_t addr_cfg_good = 0x000D;
|
||||
|
||||
static const uint8_t def_btn_force = 0;
|
||||
static const uint8_t def_pot_mode = 0;
|
||||
@@ -28,15 +29,13 @@ static const uint16_t def_lock_current = 4500;
|
||||
static const uint16_t def_max_out_voltage = 7000;
|
||||
static const uint16_t def_min_out_voltage = 200;
|
||||
|
||||
static const uint16_t lim_saved_lock_current = 6000;
|
||||
static const uint16_t lim_saved_max_voltage = 8000;
|
||||
static const uint16_t lim_saved_min_voltage = 1000;
|
||||
|
||||
/**** Private variables ****/
|
||||
/**** Private function declarations ****/
|
||||
/**** Public function definitions ****/
|
||||
logic::CfgMemory::CfgMemory(void)
|
||||
{
|
||||
this->cfg_good = 0;
|
||||
|
||||
this->mem_btn_force = 0;
|
||||
this->mem_bmode = 0;
|
||||
this->mem_pot_mode = 0;
|
||||
@@ -58,6 +57,7 @@ logic::CfgMemory::~CfgMemory(void)
|
||||
|
||||
void logic::CfgMemory::init(void)
|
||||
{
|
||||
uint8_t cfg_good_magic = mcu::eeprom_read8b(addr_cfg_good);
|
||||
this->mem_btn_force = mcu::eeprom_read8b(addr_btn_force);
|
||||
this->mem_bmode = mcu::eeprom_read8b(addr_bmode);
|
||||
this->mem_pot_mode = mcu::eeprom_read8b(addr_pot_mode);
|
||||
@@ -70,68 +70,22 @@ void logic::CfgMemory::init(void)
|
||||
this->mem_min_out_voltage = mcu::eeprom_read16b(addr_min_out_voltage);
|
||||
|
||||
// Validate EEPROM data
|
||||
if(this->mem_btn_force > 100)
|
||||
if(cfg_good_magic == 0x37) this->cfg_good = 1;
|
||||
else this->cfg_good = 0;
|
||||
|
||||
if(this->cfg_good != 1)
|
||||
{
|
||||
this->mem_btn_force = def_btn_force;
|
||||
mcu::eeprom_write8b(addr_btn_force, this->mem_btn_force);
|
||||
};
|
||||
|
||||
if(this->mem_bmode > 2)
|
||||
{
|
||||
this->mem_bmode = def_bmode;
|
||||
mcu::eeprom_write8b(addr_bmode, this->mem_bmode);
|
||||
};
|
||||
|
||||
if(this->mem_pot_mode > 1)
|
||||
{
|
||||
this->mem_pot_mode = def_pot_mode;
|
||||
mcu::eeprom_write8b(addr_pot_mode, this->mem_pot_mode);
|
||||
};
|
||||
|
||||
if(this->mem_dsp_brigth > 100)
|
||||
{
|
||||
this->mem_dsp_brigth = def_brigth;
|
||||
mcu::eeprom_write8b(addr_dsp_brigth, this->mem_dsp_brigth);
|
||||
};
|
||||
|
||||
if(this->mem_dsp_dimm > 100)
|
||||
{
|
||||
this->mem_dsp_dimm = def_dimm;
|
||||
mcu::eeprom_write8b(addr_dsp_dimm, this->mem_dsp_dimm);
|
||||
};
|
||||
|
||||
if(this->mem_brake_force > 100)
|
||||
{
|
||||
this->mem_brake_force = def_brake_force;
|
||||
mcu::eeprom_write8b(addr_brake_force, this->mem_brake_force);
|
||||
};
|
||||
|
||||
/*
|
||||
No wrong value
|
||||
if(this->mem_max_hbrake_time > 1000)
|
||||
{
|
||||
this->mem_max_hbrake_time = def_max_hbrake_time;
|
||||
mcu::eeprom_write16b(addr_lock_current, this->mem_max_hbrake_time);
|
||||
};
|
||||
*/
|
||||
|
||||
if(this->mem_lock_current > lim_saved_lock_current)
|
||||
{
|
||||
this->mem_lock_current = def_lock_current;
|
||||
mcu::eeprom_write16b(addr_lock_current, this->mem_lock_current);
|
||||
};
|
||||
|
||||
if(this->mem_max_out_voltage > lim_saved_max_voltage)
|
||||
{
|
||||
this->mem_max_out_voltage = def_max_out_voltage;
|
||||
mcu::eeprom_write16b(addr_max_out_voltage, this->mem_max_out_voltage);
|
||||
};
|
||||
|
||||
if(this->mem_min_out_voltage > lim_saved_min_voltage)
|
||||
{
|
||||
this->mem_min_out_voltage = def_min_out_voltage;
|
||||
mcu::eeprom_write16b(addr_min_out_voltage, this->mem_min_out_voltage);
|
||||
};
|
||||
}
|
||||
|
||||
this->restore();
|
||||
}
|
||||
@@ -218,4 +172,22 @@ void logic::CfgMemory::restore(void)
|
||||
this->min_out_voltage = this->mem_min_out_voltage;
|
||||
}
|
||||
|
||||
uint8_t logic::CfgMemory::checksum(void)
|
||||
{
|
||||
uint32_t cs = 0;
|
||||
cs += (uint32_t)this->mem_btn_force;
|
||||
cs += (uint32_t)this->mem_bmode;
|
||||
cs += (uint32_t)this->mem_pot_mode;
|
||||
cs += (uint32_t)this->mem_dsp_brigth;
|
||||
cs += (uint32_t)this->mem_dsp_dimm;
|
||||
cs += (uint32_t)this->mem_brake_force;
|
||||
cs += (uint32_t)this->mem_max_hbrake_time;
|
||||
cs += (uint32_t)this->mem_lock_current;
|
||||
cs += (uint32_t)this->mem_max_out_voltage;
|
||||
cs += (uint32_t)this->mem_min_out_voltage;
|
||||
|
||||
return (uint8_t)cs;
|
||||
}
|
||||
|
||||
|
||||
/**** Private function definitions ****/
|
||||
|
||||
@@ -27,6 +27,7 @@ class CfgMemory
|
||||
CfgMemory(void);
|
||||
~CfgMemory(void);
|
||||
|
||||
uint8_t cfg_good;
|
||||
uint8_t btn_force;
|
||||
uint8_t bmode;
|
||||
uint8_t pot_mode;
|
||||
@@ -42,6 +43,7 @@ class CfgMemory
|
||||
void save(void);
|
||||
void save_all(void);
|
||||
void restore(void);
|
||||
uint8_t checksum(void);
|
||||
};
|
||||
|
||||
/**** Public function declarations ****/
|
||||
|
||||
@@ -29,19 +29,20 @@ int main(void)
|
||||
// Read saved config
|
||||
cfg_mem.init();
|
||||
|
||||
#ifdef OVERRIDE_CONFIG
|
||||
cfg_mem.btn_force = 0;
|
||||
cfg_mem.bmode = 0;
|
||||
cfg_mem.pot_mode = 0;
|
||||
cfg_mem.dsp_brigth = 100;
|
||||
cfg_mem.dsp_dimm = 50;
|
||||
cfg_mem.brake_force = 100;
|
||||
cfg_mem.max_hbrake_time = 1000;
|
||||
cfg_mem.lock_current = 4200;
|
||||
cfg_mem.max_out_voltage = 6500;
|
||||
cfg_mem.min_out_voltage = 500;
|
||||
cfg_mem.save_all();
|
||||
#endif
|
||||
if(cfg_mem.cfg_good !=1 )
|
||||
{
|
||||
cfg_mem.btn_force = 0;
|
||||
cfg_mem.bmode = 0;
|
||||
cfg_mem.pot_mode = 0;
|
||||
cfg_mem.dsp_brigth = 100;
|
||||
cfg_mem.dsp_dimm = 50;
|
||||
cfg_mem.brake_force = 100;
|
||||
cfg_mem.max_hbrake_time = 1000;
|
||||
cfg_mem.lock_current = 4200;
|
||||
cfg_mem.max_out_voltage = 6500;
|
||||
cfg_mem.min_out_voltage = 500;
|
||||
cfg_mem.save_all();
|
||||
};
|
||||
|
||||
uint8_t user_force = 0;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user