Files
uDCCD/firmware/src/logic/user_force.c
2024-03-12 21:22:26 +02:00

53 lines
1.2 KiB
C

/**** Includes ****/
#include "user_force.h"
/**** Private definitions ****/
/**** Private constants ****/
static const uint8_t MAX_PERCENT = USER_FORCE_MAX_PERCENT;
static const uint8_t MIN_PERCENT = USER_FORCE_MIN_PERCENT;
/**** Private variables ****/
/**** Private function declarations ****/
/**** Public function definitions ****/
#ifdef TESTING
#endif
uint8_t user_force_btn(uint8_t prev_force, uint8_t up_act, uint8_t down_act, uint8_t delta)
{
uint8_t new_froce = prev_force;
if(up_act)
{
new_froce = prev_force + delta;
// Limit overflow and top value
if(new_froce < prev_force) new_froce = 100;
else if(new_froce < MIN_PERCENT) new_froce = MIN_PERCENT;
};
if(down_act)
{
new_froce = prev_force - delta;
// Limit overflow and top value
if(new_froce > prev_force) new_froce = 0;
else if(new_froce > MAX_PERCENT) new_froce = MAX_PERCENT;
};
// Do deadband
if(new_froce < MIN_PERCENT) new_froce = 0;
else if(new_froce > MAX_PERCENT) new_froce = 100;
return new_froce;
}
uint8_t user_force_pot(uint8_t prev_force, uint8_t pot, uint8_t hyst)
{
uint8_t new_froce = pot;
if(new_froce < MIN_PERCENT) new_froce = 0;
else if(new_froce > MAX_PERCENT) new_froce = 100;
return new_froce;
}
/**** Private function definitions ****/