diff --git a/gpio.c b/gpio.c --- a/gpio.c +++ b/gpio.c @@ -21,17 +21,19 @@ void user_input(uint16_t* to_modify) // Increment/decrement signed variable with up/down buttons -void user_input_signed(int16_t* to_modify) +void user_input_signed(int32_t* to_modify) { - // TODO: Bounds check on int16_t + //fixme: need to cast to 16/32 bits correctly if(CHANGE_ELAPSED) { if(!HAL_GPIO_ReadPin(SW_UP) ) { CHANGE_RESET; - (*to_modify)++; + if (*to_modify < 32768) + (*to_modify)++; } else if(!HAL_GPIO_ReadPin(SW_DOWN)) { CHANGE_RESET; - (*to_modify)--; + if (*to_modify >= -32768) + (*to_modify)--; } } }