Compare commits
5 Commits
e7797e8d1c
...
e4bd6d2e04
| Author | SHA1 | Date | |
|---|---|---|---|
| e4bd6d2e04 | |||
| c3bc42fa18 | |||
| a3d4ffd548 | |||
| 8449ca098e | |||
| 57ab8bda6a |
@@ -58,6 +58,8 @@ void devices_update_inputs(void)
|
||||
|
||||
sup_fuse.update();
|
||||
out_fuse.update();
|
||||
|
||||
display.process_timer();
|
||||
}
|
||||
|
||||
/**** Private function definitions ****/
|
||||
|
||||
@@ -30,6 +30,9 @@ hw::DisplayLed::DisplayLed(bsp::DigitalOut* led0, bsp::DigitalOut* led1, bsp::Di
|
||||
this->led4->write(0);
|
||||
this->led5->write(0);
|
||||
this->common->write(0);
|
||||
|
||||
this->lock_counter = 0;
|
||||
this->locked = 1;
|
||||
}
|
||||
|
||||
hw::DisplayLed::~DisplayLed(void)
|
||||
@@ -91,6 +94,18 @@ void hw::DisplayLed::set_brigthness(uint8_t percent)
|
||||
this->common->write(percent);
|
||||
}
|
||||
|
||||
void hw::DisplayLed::set_lock(uint16_t timeout)
|
||||
{
|
||||
this->lock_counter = timeout;
|
||||
this->locked = 1;
|
||||
}
|
||||
|
||||
void hw::DisplayLed::process_timer(void)
|
||||
{
|
||||
if(this->lock_counter) this->lock_counter--;
|
||||
else this->locked = 0;
|
||||
}
|
||||
|
||||
/**** Private function definitions ****/
|
||||
static uint8_t img_gen_dot10(uint8_t percent)
|
||||
{
|
||||
|
||||
@@ -21,6 +21,8 @@ class DisplayLed
|
||||
bsp::DigitalOut* led5;
|
||||
bsp::PWMout* common;
|
||||
|
||||
uint16_t lock_counter;
|
||||
|
||||
public:
|
||||
typedef enum {
|
||||
LED_DSP_DOT20,
|
||||
@@ -35,6 +37,11 @@ class DisplayLed
|
||||
void write(uint8_t image);
|
||||
|
||||
void set_brigthness(uint8_t percent);
|
||||
|
||||
void set_lock(uint16_t timeout);
|
||||
void process_timer(void);
|
||||
|
||||
uint8_t locked;
|
||||
};
|
||||
|
||||
/**** Public function declarations ****/
|
||||
|
||||
@@ -27,7 +27,9 @@ hw::Potentiometer::~Potentiometer(void)
|
||||
uint8_t hw::Potentiometer::update(void)
|
||||
{
|
||||
// Calculate percent
|
||||
this->percent = util::interpolate(this->ain_ch->last_read, this->low_deadzone, this->high_deadzone, 0, 100);
|
||||
if(this->ain_ch->last_read <= this->low_deadzone) this->percent = 0;
|
||||
else if(this->ain_ch->last_read >= this->high_deadzone ) this->percent = 100;
|
||||
else this->percent = util::interpolate(this->ain_ch->last_read, this->low_deadzone, this->high_deadzone, 0, 100);
|
||||
|
||||
return this->percent;
|
||||
}
|
||||
|
||||
@@ -11,15 +11,21 @@ static const uint16_t addr_bmode = 0x0001;
|
||||
static const uint16_t addr_pot_mode = 0x0002;
|
||||
static const uint16_t addr_dsp_brigth = 0x0003;
|
||||
static const uint16_t addr_dsp_dimm = 0x0004;
|
||||
static const uint16_t addr_lock_current = 0x0005;
|
||||
static const uint16_t addr_brake_force = 0x0005;
|
||||
static const uint16_t addr_max_hbrake_time = 0x0006;
|
||||
static const uint16_t addr_lock_current = 0x0008;
|
||||
|
||||
static const uint8_t def_btn_force = 0;
|
||||
static const uint8_t def_pot_mode = 0;
|
||||
static const uint8_t def_bmode = 0;
|
||||
static const uint8_t def_dimm = 50;
|
||||
static const uint8_t def_brigth = 100;
|
||||
static const uint8_t def_brake_force = 100;
|
||||
static const uint16_t def_max_hbrake_time = 1000;
|
||||
static const uint16_t def_lock_current = 4500;
|
||||
|
||||
static const uint16_t max_lock_current = 6000;
|
||||
|
||||
/**** Private variables ****/
|
||||
/**** Private function declarations ****/
|
||||
/**** Public function definitions ****/
|
||||
@@ -30,6 +36,8 @@ logic::CfgMemory::CfgMemory(void)
|
||||
this->mem_pot_mode = 0;
|
||||
this->mem_dsp_brigth = 0;
|
||||
this->mem_dsp_dimm = 0;
|
||||
this->mem_brake_force = 0;
|
||||
this->mem_max_hbrake_time = 0;
|
||||
this->mem_lock_current = 0;
|
||||
|
||||
this->restore();
|
||||
@@ -47,8 +55,11 @@ void logic::CfgMemory::init(void)
|
||||
this->mem_pot_mode = mcu::eeprom_read8b(addr_pot_mode);
|
||||
this->mem_dsp_brigth = mcu::eeprom_read8b(addr_dsp_brigth);
|
||||
this->mem_dsp_dimm = mcu::eeprom_read8b(addr_dsp_dimm);
|
||||
this->mem_brake_force = mcu::eeprom_read8b(addr_brake_force);
|
||||
this->mem_max_hbrake_time = mcu::eeprom_read16b(addr_max_hbrake_time);
|
||||
this->mem_lock_current = mcu::eeprom_read16b(addr_lock_current);
|
||||
|
||||
// Validate EEPROM data
|
||||
if(this->mem_btn_force > 100)
|
||||
{
|
||||
this->mem_btn_force = def_btn_force;
|
||||
@@ -79,7 +90,22 @@ void logic::CfgMemory::init(void)
|
||||
mcu::eeprom_write8b(addr_dsp_dimm, this->mem_dsp_dimm);
|
||||
};
|
||||
|
||||
if(this->mem_lock_current > 6000)
|
||||
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 > max_lock_current)
|
||||
{
|
||||
this->mem_lock_current = def_lock_current;
|
||||
mcu::eeprom_write16b(addr_lock_current, this->mem_lock_current);
|
||||
@@ -125,10 +151,22 @@ void logic::CfgMemory::save_all(void)
|
||||
mcu::eeprom_write8b(addr_dsp_dimm, this->mem_dsp_dimm);
|
||||
};
|
||||
|
||||
if(this->brake_force != this->mem_brake_force)
|
||||
{
|
||||
this->mem_brake_force = this->brake_force;
|
||||
mcu::eeprom_write8b(addr_brake_force, this->mem_brake_force);
|
||||
};
|
||||
|
||||
if(this->max_hbrake_time != this->mem_max_hbrake_time)
|
||||
{
|
||||
this->mem_max_hbrake_time = this->max_hbrake_time;
|
||||
mcu::eeprom_write16b(addr_max_hbrake_time, this->mem_max_hbrake_time);
|
||||
};
|
||||
|
||||
if(this->lock_current != this->mem_lock_current)
|
||||
{
|
||||
this->mem_lock_current = this->lock_current;
|
||||
mcu::eeprom_write8b(addr_lock_current, this->mem_lock_current);
|
||||
mcu::eeprom_write16b(addr_lock_current, this->mem_lock_current);
|
||||
};
|
||||
}
|
||||
|
||||
@@ -139,6 +177,8 @@ void logic::CfgMemory::restore(void)
|
||||
this->pot_mode = this->mem_pot_mode;
|
||||
this->dsp_brigth = this->mem_dsp_brigth;
|
||||
this->dsp_dimm = this->mem_dsp_dimm;
|
||||
this->brake_force = this->mem_brake_force;
|
||||
this->max_hbrake_time = this->mem_max_hbrake_time;
|
||||
this->lock_current = this->mem_lock_current;
|
||||
}
|
||||
|
||||
|
||||
@@ -17,6 +17,8 @@ class CfgMemory
|
||||
uint8_t mem_pot_mode;
|
||||
uint8_t mem_dsp_brigth;
|
||||
uint8_t mem_dsp_dimm;
|
||||
uint8_t mem_brake_force;
|
||||
uint16_t mem_max_hbrake_time;
|
||||
uint16_t mem_lock_current;
|
||||
|
||||
public:
|
||||
@@ -28,6 +30,8 @@ class CfgMemory
|
||||
uint8_t pot_mode;
|
||||
uint8_t dsp_brigth;
|
||||
uint8_t dsp_dimm;
|
||||
uint8_t brake_force;
|
||||
uint16_t max_hbrake_time;
|
||||
uint16_t lock_current;
|
||||
|
||||
void init(void);
|
||||
|
||||
@@ -55,7 +55,7 @@ uint8_t logic::DccdForce::update(uint8_t user_force)
|
||||
|
||||
// Determine target force source
|
||||
uint8_t next_force = user_force;
|
||||
if((this->handbrake->state == hw::BUTTON_ON)&&(this->handbrake->time < this->max_hbrake_time))
|
||||
if((this->handbrake->state == hw::BUTTON_ON)&&((this->handbrake->time < this->max_hbrake_time)||(this->max_hbrake_time == 0)))
|
||||
{
|
||||
next_force = 0;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
/**** Includes ****/
|
||||
#include "utils/utils.h"
|
||||
#include "utils/interpolate.h"
|
||||
|
||||
#include "hw/devices.h"
|
||||
|
||||
@@ -14,9 +13,6 @@
|
||||
static const uint16_t dsp_lock_bmode = 1000;
|
||||
static const uint16_t dsp_lock_force = 50;
|
||||
|
||||
static const uint16_t cfg_max_hbrake_time = 1000;
|
||||
static const uint8_t cfg_brake_force = 100;
|
||||
|
||||
/**** Private variables ****/
|
||||
static logic::CfgMemory cfg_mem = logic::CfgMemory();
|
||||
|
||||
@@ -34,12 +30,11 @@ int main(void)
|
||||
cfg_mem.init();
|
||||
|
||||
uint8_t user_force = 0;
|
||||
uint16_t dsp_lock = 0;
|
||||
|
||||
button_force.force = cfg_mem.btn_force;
|
||||
dccd_force.brake_mode = cfg_mem.bmode;
|
||||
dccd_force.max_hbrake_time = cfg_max_hbrake_time;
|
||||
dccd_force.brake_force = cfg_brake_force;
|
||||
dccd_force.max_hbrake_time = cfg_mem.max_hbrake_time;
|
||||
dccd_force.brake_force = cfg_mem.brake_force;
|
||||
|
||||
// Super loop
|
||||
while(1)
|
||||
@@ -85,20 +80,16 @@ int main(void)
|
||||
break;
|
||||
}
|
||||
display.write(bmode_img);
|
||||
dsp_lock = dsp_lock_bmode;
|
||||
display.set_lock(dsp_lock_bmode);
|
||||
dccd_force.is_new_bmode = 0;
|
||||
}
|
||||
else if((button_force.is_new)&&(cfg_mem.pot_mode==0))
|
||||
{
|
||||
display.show_percent(dccd_force.force, hw::DisplayLed::LED_DSP_DOT10);
|
||||
dsp_lock = dsp_lock_force;
|
||||
display.set_lock(dsp_lock_force);
|
||||
button_force.is_new = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(dsp_lock) dsp_lock--;
|
||||
else display.show_percent(dccd_force.force, hw::DisplayLed::LED_DSP_DOT10);
|
||||
}
|
||||
else if(display.locked==0) display.show_percent(dccd_force.force, hw::DisplayLed::LED_DSP_DOT10);
|
||||
|
||||
// Process dimm
|
||||
if(sw_dimm.state == hw::BUTTON_ON) display.set_brigthness(cfg_mem.dsp_dimm);
|
||||
|
||||
Reference in New Issue
Block a user