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

using namespace dccd;

/**** Private definitions ****/
/**** Private constants ****/
/**** Private variables ****/
/**** Private function declarations ****/
/**** Public function definitions ****/
dccd::Brakes::Brakes(void)
{
	return;
}

dccd::Brakes::~Brakes(void)
{
	return;
}

void dccd::Brakes::init(dccd::DccdHw* dccd_hw)
{	
	this->hardware = dccd_hw;
	this->mode = OPEN;
	this->is_active = 0;
	this->is_new_mode = 0;
}

void dccd::Brakes::cfg_debounce(uint16_t dbnc_time)
{
	this->hardware->brakes.dbnc_lim = dbnc_time;
}

uint8_t dccd::Brakes::process(void)
{
	if(this->hardware->brakes.state > 0)
	{
		this->is_active = 1;
	}
	else
	{
		this->is_active = 0;
	}
	
	return this->is_active;
}

Brakes::bmode_t dccd::Brakes::cycle_mode(void)
{
	switch(this->mode)
	{
		case OPEN:
		this->mode = KEEP;
		
		case KEEP:
		this->mode = LOCK;
		
		case LOCK:
		this->mode = OPEN;
		
		default:
		this->mode = OPEN;
	}
	
	this->is_new_mode = 1;
	
	return this->mode;
}

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