From e7797e8d1cc04d1021d8cdb6b88d6ee1378dda2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andis=20Z=C4=ABle?= Date: Fri, 12 Apr 2024 17:40:00 +0300 Subject: [PATCH] Added hbrake timeout and adjustable brake force --- firmware/src/logic/dccd_force.cpp | 11 ++++++++--- firmware/src/logic/dccd_force.h | 3 +++ firmware/src/main.cpp | 5 +++++ 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/firmware/src/logic/dccd_force.cpp b/firmware/src/logic/dccd_force.cpp index 9342f03..ae0493b 100644 --- a/firmware/src/logic/dccd_force.cpp +++ b/firmware/src/logic/dccd_force.cpp @@ -6,9 +6,11 @@ using namespace logic; /**** Private definitions ****/ /**** Private constants ****/ +static const uint16_t def_max_hbrake_time = 1000; +static const uint16_t def_brake_force = 100; + /**** Private variables ****/ /**** Private function declarations ****/ - /**** Public function definitions ****/ logic::DccdForce::DccdForce(hw::Button* btn_mode, hw::Button* sw_hbrake, hw::Button* sw_brakes) { @@ -19,6 +21,9 @@ logic::DccdForce::DccdForce(hw::Button* btn_mode, hw::Button* sw_hbrake, hw::But this->is_new = 0; this->force = 0; this->brake_mode = 0; + + this->max_hbrake_time = def_max_hbrake_time; + this->brake_force = def_brake_force; } logic::DccdForce::~DccdForce(void) @@ -50,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) + if((this->handbrake->state == hw::BUTTON_ON)&&(this->handbrake->time < this->max_hbrake_time)) { next_force = 0; } @@ -65,7 +70,7 @@ uint8_t logic::DccdForce::update(uint8_t user_force) next_force = user_force; default: - next_force = 100; + next_force = this->brake_force; } }; diff --git a/firmware/src/logic/dccd_force.h b/firmware/src/logic/dccd_force.h index f4533cb..c5291af 100644 --- a/firmware/src/logic/dccd_force.h +++ b/firmware/src/logic/dccd_force.h @@ -26,6 +26,9 @@ class DccdForce uint8_t brake_mode; uint8_t is_new_bmode; + uint16_t max_hbrake_time; + uint8_t brake_force; + uint8_t update(uint8_t user_force); }; diff --git a/firmware/src/main.cpp b/firmware/src/main.cpp index f3efffe..842f2ca 100644 --- a/firmware/src/main.cpp +++ b/firmware/src/main.cpp @@ -14,6 +14,9 @@ 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(); @@ -35,6 +38,8 @@ int main(void) 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; // Super loop while(1)