Skip to content

Commit

Permalink
Merge branch 'release/fw0.5'
Browse files Browse the repository at this point in the history
  • Loading branch information
MicBoucinha committed Feb 4, 2022
2 parents 5d666ed + 6e78613 commit f700bba
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 42 deletions.
71 changes: 67 additions & 4 deletions Firmware/Pump/app.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ void hwbp_app_initialize(void)
uint8_t hwH = 1;
uint8_t hwL = 1;
uint8_t fwH = 0;
uint8_t fwL = 4;
uint8_t fwL = 5;
uint8_t ass = 0;

/* Start core */
Expand Down Expand Up @@ -73,6 +73,7 @@ void core_callback_catastrophic_error_detected(void)

uint16_t inactivity_counter = 0;

/* Buttons */
uint8_t but_push_counter_ms = 0;
uint16_t but_long_push_counter_ms = 0;
bool but_push_long_press = false;
Expand All @@ -84,8 +85,12 @@ bool but_pull_long_press = false;
uint8_t but_reset_counter_ms = 0;
bool but_reset_pressed = false;
bool but_reset_dir_change = false;

/* Switches */
bool switch_f_active = false;
bool switch_r_active = false;
uint8_t sw_f_counter_ms = 0;
uint8_t sw_r_counter_ms = 0;

uint8_t curr_dir = DIR_FORWARD;
uint8_t prev_dir = DIR_FORWARD;
Expand Down Expand Up @@ -172,6 +177,18 @@ void clear_but_pull()
but_pull_long_press = false;
}

/* Switches */
extern void clear_sw_f()
{
switch_f_active = false;
sw_f_counter_ms = 50;
}

extern void clear_sw_r()
{
switch_r_active = false;
sw_r_counter_ms = 50;
}

/************************************************************************/
/* Initialization Callbacks */
Expand Down Expand Up @@ -330,9 +347,8 @@ void core_callback_t_before_exec(void)
else
{
// we reached the end, lets stop everything and reset variables
stop_and_reset_protocol();
app_regs.REG_PROTOCOL_STATE = 0;
app_write_REG_PROTOCOL_STATE(&app_regs.REG_PROTOCOL_STATE);
app_regs.REG_START_PROTOCOL = 0;
app_write_REG_START_PROTOCOL(&app_regs.REG_START_PROTOCOL);
}
}
}
Expand Down Expand Up @@ -403,6 +419,53 @@ void core_callback_t_1ms(void)
inactivity_counter = 0;
}

/* handle switches */
/* De-bounce Switch FORWARD */
if(sw_f_counter_ms)
{
if(read_SW_F)
{
if(!--sw_f_counter_ms)
{
switch_pressed(DIR_FORWARD);

if(app_regs.REG_EVT_ENABLE & B_EVT_SW_FORWARD_STATE)
core_func_send_event(ADD_REG_SW_FORWARD_STATE, true);

if((app_regs.REG_DO0_CONFIG & MSK_OUT0_CONF) == GM_OUT0_SWLIMIT)
{
if(read_SW_F)
set_OUT00;
else
clr_OUT00;
}
}
}
}

/* De-bounce Switch REVERSE */
if(sw_r_counter_ms)
{
if(read_SW_R)
{
if(!--sw_r_counter_ms)
{
switch_pressed(DIR_REVERSE);

if(app_regs.REG_EVT_ENABLE & B_EVT_SW_REVERSE_STATE)
core_func_send_event(ADD_REG_SW_REVERSE_STATE, true);

if((app_regs.REG_DO0_CONFIG & MSK_OUT0_CONF) == GM_OUT0_SWLIMIT)
{
if(read_SW_R)
set_OUT00;
else
clr_OUT00;
}
}
}
}

/* handle buttons */
/* De-bounce PUSH button */
if(but_push_counter_ms)
Expand Down
12 changes: 8 additions & 4 deletions Firmware/Pump/app_funcs.c
Original file line number Diff line number Diff line change
Expand Up @@ -124,14 +124,18 @@ bool app_write_REG_START_PROTOCOL(void *a)
if( running_protocol )
{
prev_dir = curr_dir;
//FIXME: seems that the first event is not triggered
app_write_REG_DIR_STATE(&app_regs.REG_PROTOCOL_DIRECTION);
}

app_regs.REG_START_PROTOCOL = reg;
app_regs.REG_PROTOCOL_STATE = reg;
app_write_REG_PROTOCOL_STATE(&app_regs.REG_PROTOCOL_STATE);


if(app_regs.REG_PROTOCOL_STATE != reg)
{
app_regs.REG_PROTOCOL_STATE = reg;
app_write_REG_PROTOCOL_STATE(&app_regs.REG_PROTOCOL_STATE);
}


return true;
}

Expand Down
43 changes: 9 additions & 34 deletions Firmware/Pump/interrupts.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,58 +79,33 @@ ISR(PORTB_INT0_vect, ISR_NAKED)
/************************************************************************/
/* SW_F, SW_R, TYPE0 & TYPE1 */
/************************************************************************/
extern void clear_sw_f();
extern void clear_sw_r();

ISR(PORTC_INT0_vect, ISR_NAKED)
{
if(read_SW_F)
{
// TODO: change this to use DIR_FORWARD
switch_pressed(1);

if(app_regs.REG_EVT_ENABLE & B_EVT_SW_FORWARD_STATE)
core_func_send_event(ADD_REG_SW_FORWARD_STATE, true);
}
else
if(!(read_SW_F))
{
// should send event when down (only if previously was up)
if(switch_f_active)
{
app_regs.REG_SW_FORWARD_STATE = 0;
if(app_regs.REG_EVT_ENABLE & B_EVT_SW_FORWARD_STATE)
core_func_send_event(ADD_REG_SW_FORWARD_STATE, true);
}

switch_f_active = false;
clear_sw_f();
}

if(read_SW_R)
if(!(read_SW_R))
{
// TODO: change this to use DIR_REVERSE
switch_pressed(0);

if(app_regs.REG_EVT_ENABLE & B_EVT_SW_REVERSE_STATE)
core_func_send_event(ADD_REG_SW_REVERSE_STATE, true);
}
else
{
// should send event when down (only if previously was up)
if(switch_r_active)
{
app_regs.REG_SW_REVERSE_STATE = 0;
if(app_regs.REG_EVT_ENABLE & B_EVT_SW_REVERSE_STATE)
core_func_send_event(ADD_REG_SW_REVERSE_STATE, true);
}

switch_r_active = false;
clear_sw_r();
}

if((app_regs.REG_DO0_CONFIG & MSK_OUT0_CONF) == GM_OUT0_SWLIMIT)
{
if(read_SW_F || read_SW_R)
set_OUT00;
else
clr_OUT00;
}


reti();
}

Expand Down

0 comments on commit f700bba

Please sign in to comment.