mirror of
https://github.com/odriverobotics/ODrive.git
synced 2026-09-25 19:13:39 +08:00
Change debounce logic so less is done in interrupts
This commit is contained in:
@@ -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){
|
||||
|
||||
Reference in New Issue
Block a user