Skip to content

Commit

Permalink
add a safety mode counter
Browse files Browse the repository at this point in the history
  • Loading branch information
rbiasini committed Nov 27, 2019
1 parent a6797a2 commit 2d4cb05
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
1 change: 1 addition & 0 deletions board/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -699,6 +699,7 @@ void TIM1_BRK_TIM9_IRQHandler(void) {

// on to the next one
uptime_cnt += 1U;
safety_mode_cnt += 1U;
}
TIM9->SR = 0;
}
Expand Down
5 changes: 3 additions & 2 deletions board/safety.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,14 @@ const safety_hook_config safety_hook_registry[] = {
};

int set_safety_hooks(uint16_t mode, int16_t param) {
int set_status = -1; // not set
safety_mode_cnt = 0U; // reset safety mode timer
int set_status = -1; // not set
int hook_config_count = sizeof(safety_hook_registry) / sizeof(safety_hook_config);
for (int i = 0; i < hook_config_count; i++) {
if (safety_hook_registry[i].id == mode) {
current_hooks = safety_hook_registry[i].hooks;
current_safety_mode = safety_hook_registry[i].id;
set_status = 0; // set
set_status = 0; // set
break;
}
}
Expand Down
3 changes: 3 additions & 0 deletions board/safety_declarations.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,8 @@ int gas_interceptor_prev = 0;
// This is set by USB command 0xdf
bool long_controls_allowed = true;

// time since safety mode has been changed
uint32_t safety_mode_cnt = 0U;

// avg between 2 tracks
#define GET_INTERCEPTOR(msg) (((GET_BYTE((msg), 0) << 8) + GET_BYTE((msg), 1) + ((GET_BYTE((msg), 2) << 8) + GET_BYTE((msg), 3)) / 2 ) / 2)

0 comments on commit 2d4cb05

Please sign in to comment.