/**** Includes ****/
#include "../utils/utils.h"
#include "button_force.h"

using namespace logic;

/**** Private definitions ****/
/**** Private constants ****/
/**** Private variables ****/
/**** Private function declarations ****/

/**** Public function definitions ****/
logic::ButtonForce::ButtonForce(hw::Button* btn_up, hw::Button* btn_down)
{
	this->btn_up = btn_up;
	this->btn_down = btn_down;
	this->force = 0;
	this->step = 10;
	this->is_new = 0;
}

logic::ButtonForce::~ButtonForce(void)
{
	return;
}

uint8_t logic::ButtonForce::update(void)
{	
	uint8_t next_force = 0;
	
	if((this->btn_up->is_new)&&(this->btn_up->state == hw::BUTTON_ON))
	{
		next_force = util::sat_add(this->force, this->step);
		if(next_force > 100) next_force = 100;
		this->btn_up->is_new = 0;
	};
	
	if((this->btn_down->is_new)&&(this->btn_down->state == hw::BUTTON_ON))
	{
		next_force = util::sat_subtract(this->force, this->step);
		this->btn_down->is_new = 0;
	};
	
	if(next_force != this->force) this->is_new = 1;
	
	this->force = next_force;
	
	return this->force;
}

/**** Private function definitions ****/
