Change debounce logic so less is done in interrupts

This commit is contained in:
Unknown
2018-09-23 14:22:34 -04:00
parent 197d10f502
commit d713640681
2 changed files with 5 additions and 5 deletions
+3 -4
View File
@@ -10,6 +10,9 @@ static void endstop_cb_wrapper(void* ctx){
}
void Endstop::update() {
uint16_t gpio_pin = get_gpio_pin_by_pin(config_.gpio_num);
GPIO_TypeDef* gpio_port = get_gpio_port_by_pin(config_.gpio_num);
pin_state_ = HAL_GPIO_ReadPin(gpio_port, gpio_pin);
if (config_.enabled) {
float now = axis_->loop_counter_ * current_meas_period;
if ((now - debounce_timer_) >= (config_.debounce_ms * 0.001f)) { // Debounce timer expired, take the new pin state
@@ -28,11 +31,7 @@ bool Endstop::getEndstopState() {
}
void Endstop::endstop_cb() {
uint16_t gpio_pin = get_gpio_pin_by_pin(config_.gpio_num);
GPIO_TypeDef* gpio_port = get_gpio_port_by_pin(config_.gpio_num);
debounce_timer_ = axis_->loop_counter_ * current_meas_period;
pin_state_ = HAL_GPIO_ReadPin(gpio_port, gpio_pin);
}
void Endstop::set_endstop_enabled(bool enable){
+2 -1
View File
@@ -23,6 +23,7 @@ class Endstop {
bool getEndstopState();
bool endstop_state_ = false;
auto make_protocol_definitions(){
@@ -41,6 +42,6 @@ class Endstop {
private:
bool pin_state_ = false;
float debounce_timer_ = 0;
volatile float debounce_timer_ = 0;
};
#endif