Added mode translators

This commit is contained in:
2024-09-17 23:24:01 +03:00
parent e199a2c2be
commit 25e6f593d3
7 changed files with 147 additions and 6 deletions

View File

@@ -74,4 +74,44 @@ Brakes::bmode_t dccd::Brakes::cycle_mode(void)
return this->mode; return this->mode;
} }
uint8_t dccd::Brakes::get_mode_int(void)
{
switch(this->mode)
{
case OPEN:
return 0;
case KEEP:
return 1;
case LOCK:
return 2;
default:
return 0;
}
}
void dccd::Brakes::set_mode_int(uint8_t mode_int)
{
switch(mode_int)
{
case 0:
this->mode = OPEN;
break;
case 1:
this->mode = KEEP;
break;
case 2:
this->mode = LOCK;
break;
default:
this->mode = OPEN;
break;
}
}
/**** Private function definitions ***/ /**** Private function definitions ***/

View File

@@ -30,6 +30,8 @@ class Brakes
void cfg_debounce(uint16_t dbnc_time); void cfg_debounce(uint16_t dbnc_time);
bmode_t cycle_mode(void); bmode_t cycle_mode(void);
uint8_t process(void); uint8_t process(void);
uint8_t get_mode_int(void);
void set_mode_int(uint8_t mode_int);
#ifdef TESTING #ifdef TESTING
protected: protected:

View File

@@ -83,9 +83,10 @@ void dccd::DccdApp::init(DccdHw* dccd_hw, cfg_app_t* def_cfg)
this->user_force.btn_force = 100; this->user_force.btn_force = 100;
this->nvmem.dynamic_cfg.btn_force = 100; this->nvmem.dynamic_cfg.btn_force = 100;
}; };
this->tps.mode = (Thtrottle::tpsmode_t)this->nvmem.dynamic_cfg.tps_mode;
this->hbrake.mode = (Handbrake::hbmode_t)this->nvmem.dynamic_cfg.hbrake_mode; this->tps.set_mode_int(this->nvmem.dynamic_cfg.tps_mode);
this->brakes.mode = (Brakes::bmode_t)this->nvmem.dynamic_cfg.brakes_mode; this->hbrake.set_mode_int(this->nvmem.dynamic_cfg.hbrake_mode);
this->brakes.set_mode_int(this->nvmem.dynamic_cfg.brakes_mode);
// Initialize state // Initialize state
this->hardware->read(); this->hardware->read();
@@ -116,17 +117,17 @@ void dccd::DccdApp::process(void)
if(this->hbrake.is_active) if(this->hbrake.is_active)
{ {
this->hbrake.cycle_mode(); this->hbrake.cycle_mode();
this->nvmem.dynamic_cfg.hbrake_mode = (uint8_t)this->hbrake.mode; this->nvmem.dynamic_cfg.hbrake_mode = this->hbrake.get_mode_int();
} }
else if (this->brakes.is_active) else if (this->brakes.is_active)
{ {
this->brakes.cycle_mode(); this->brakes.cycle_mode();
this->nvmem.dynamic_cfg.brakes_mode = (uint8_t)this->brakes.mode; this->nvmem.dynamic_cfg.brakes_mode = this->brakes.get_mode_int();
} }
else else
{ {
this->tps.cycle_mode(); this->tps.cycle_mode();
this->nvmem.dynamic_cfg.tps_mode = (uint8_t)this->tps.mode; this->nvmem.dynamic_cfg.tps_mode = this->tps.get_mode_int();
} }
}; };

View File

@@ -104,6 +104,53 @@ uint8_t dccd::Handbrake::process(void)
return this->is_active; return this->is_active;
} }
uint8_t dccd::Handbrake::get_mode_int(void)
{
switch(this->mode)
{
case LATCH0:
return 0;
case LATCH1:
return 1;
case LATCH2:
return 2;
case LATCH3:
return 3;
default:
return 0;
}
}
void dccd::Handbrake::set_mode_int(uint8_t mode_int)
{
switch(mode_int)
{
case 0:
this->mode = LATCH0;
break;
case 1:
this->mode = LATCH1;
break;
case 2:
this->mode = LATCH2;
break;
case 3:
this->mode = LATCH3;
break;
default:
this->mode = LATCH0;
break;
}
}
/**** Private function definitions ***/ /**** Private function definitions ***/
uint16_t dccd::Handbrake::act_latch_time(void) uint16_t dccd::Handbrake::act_latch_time(void)
{ {

View File

@@ -35,6 +35,8 @@ class Handbrake
uint8_t process(void); uint8_t process(void);
void cfg_debounce(uint16_t dbnc_time); void cfg_debounce(uint16_t dbnc_time);
hbmode_t cycle_mode(void); hbmode_t cycle_mode(void);
uint8_t get_mode_int(void);
void set_mode_int(uint8_t mode_int);
#ifdef TESTING #ifdef TESTING
protected: protected:

View File

@@ -102,6 +102,53 @@ void dccd::Thtrottle::process(void)
} }
} }
uint8_t dccd::Thtrottle::get_mode_int(void)
{
switch(this->mode)
{
case MODE0:
return 0;
case MODE1:
return 1;
case MODE2:
return 2;
case MODE3:
return 3;
default:
return 0;
}
}
void dccd::Thtrottle::set_mode_int(uint8_t mode_int)
{
switch(mode_int)
{
case 0:
this->mode = MODE0;
break;
case 1:
this->mode = MODE1;
break;
case 2:
this->mode = MODE2;
break;
case 3:
this->mode = MODE3;
break;
default:
this->mode = MODE0;
break;
}
}
uint8_t dccd::Thtrottle::is_active(void) uint8_t dccd::Thtrottle::is_active(void)
{ {
if(this->is_timed_out) return 0; if(this->is_timed_out) return 0;

View File

@@ -36,6 +36,8 @@ class Thtrottle
void process(void); void process(void);
tpsmode_t cycle_mode(void); tpsmode_t cycle_mode(void);
uint8_t get_mode_int(void);
void set_mode_int(uint8_t mode_int);
#ifdef TESTING #ifdef TESTING
protected: protected: