Skip to content

Commit

Permalink
chore: refactor perchè così è più bello
Browse files Browse the repository at this point in the history
  • Loading branch information
federico-carbone committed Aug 31, 2024
1 parent 44b2f1a commit 2c7f72d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 18 deletions.
2 changes: 1 addition & 1 deletion Core/Inc/conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
/* ---------- Exported constants --------------------------------------------*/
#define VERSION_MAJOR 1
#define VERSION_MINOR 0
#define VERSION_PATCH 4
#define VERSION_PATCH 5

#define DEBUG_SERIAL
#define DEBUG_AIN
Expand Down
39 changes: 22 additions & 17 deletions Core/Src/bsp.c
Original file line number Diff line number Diff line change
Expand Up @@ -207,11 +207,7 @@ static float ROT_SW_ain_V_to_state_map[ROT_SW_State_NUM][2U] = {
(4.89) + ROT_SW_STATE_ERR_MARGIN_V},
};
/*---------- Private Functions -----------------------------------------------*/
enum ROT_SW_State __ROT_SW_analogV_to_state(float analogV, enum ROT_SW_Device device) {
static enum ROT_SW_State last_state1 = ROT_SW_State_NUM+1;
static enum ROT_SW_State last_state2 = ROT_SW_State_NUM+1;

enum ROT_SW_State *last_state = device == ROT_SW_Device1 ? &last_state1 : &last_state2;
enum ROT_SW_State __ROT_SW_analogV_to_state(float analogV) {
enum ROT_SW_State state = ROT_SW_State_NUM+1;

if (analogV >= ROT_SW_ain_V_to_state_map[ROT_SW_State0][0] &&
Expand Down Expand Up @@ -245,17 +241,7 @@ enum ROT_SW_State __ROT_SW_analogV_to_state(float analogV, enum ROT_SW_Device de
analogV < ROT_SW_ain_V_to_state_map[ROT_SW_State9][1]) {
state = ROT_SW_State9;
}

if(*last_state == ROT_SW_State_NUM+1) {
*last_state = state;
}

if(state == *last_state || state == (*last_state)+1 || state == (*last_state)-1) {
*last_state = state;
} else {
state = *last_state;
}


return state;
}

Expand All @@ -273,7 +259,26 @@ float ROT_SW_getAanalog_V(enum ROT_SW_Device device) {
}
enum ROT_SW_State ROT_SW_getState(enum ROT_SW_Device device) {
assert_param(device != ROT_SW_State_NUM);
return __ROT_SW_analogV_to_state(ROT_SW_getAanalog_V(device), device);

static enum ROT_SW_State last_state1 = ROT_SW_State_NUM+1;
static enum ROT_SW_State last_state2 = ROT_SW_State_NUM+1;

enum ROT_SW_State *last_state = device == ROT_SW_Device1 ? &last_state1 : &last_state2;
enum ROT_SW_State state = ROT_SW_State_NUM+1;

state = __ROT_SW_analogV_to_state(ROT_SW_getAanalog_V(device));

if(*last_state == ROT_SW_State_NUM+1) {
*last_state = state;
}

if(state == *last_state || state == (*last_state)+1 || state == (*last_state)-1) {
*last_state = state;
} else {
state = *last_state;
}

return state;
}

/* LED MONO (Monochrome Leds) ################################################*/
Expand Down

0 comments on commit 2c7f72d

Please sign in to comment.