diff --git a/Firmware/MotorControl/endstop.cpp b/Firmware/MotorControl/endstop.cpp index b9730984..c4e4a9fa 100644 --- a/Firmware/MotorControl/endstop.cpp +++ b/Firmware/MotorControl/endstop.cpp @@ -1,5 +1,4 @@ #include -#include Endstop::Endstop(EndstopConfig_t &config) : config_(config) { @@ -12,9 +11,9 @@ static void endstop_cb_wrapper(void* ctx){ void Endstop::update() { if (config_.enabled) { float now = axis_->loop_counter_ * current_meas_period; - if ((now - debounce_timer_) >= (config_.debounce_ms * 0.001)) { // Debounce timer expired, take the new pin state - endstop_state_ = config_.is_active_high ? pin_state_ : !pin_state_; // endstop_state is the logical state - debounce_timer_ = now - (config_.debounce_ms * 0.001); // Ensure timer doesn't have overflow issues + if ((now - debounce_timer_) >= (config_.debounce_ms * 0.001f)) { // Debounce timer expired, take the new pin state + endstop_state_ = config_.is_active_high ? pin_state_ : !pin_state_; // endstop_state is the logical state + debounce_timer_ = now - (config_.debounce_ms * 0.001f); // Ensure timer doesn't have overflow issues } else { endstop_state_ = endstop_state_; // Do nothing } diff --git a/Firmware/MotorControl/endstop.hpp b/Firmware/MotorControl/endstop.hpp index dcaf0e27..6a13eb68 100644 --- a/Firmware/MotorControl/endstop.hpp +++ b/Firmware/MotorControl/endstop.hpp @@ -7,7 +7,7 @@ struct EndstopConfig_t { bool enabled = false; int32_t offset = 0; bool is_active_high = false; - float debounce_ms = 100; + float debounce_ms = 100.0f; }; class Endstop {