From 163ce7d21ad9a8f9a2f0b13f00bb8959df95c4ac Mon Sep 17 00:00:00 2001 From: Unknown Date: Sat, 28 Mar 2020 00:50:44 -0400 Subject: [PATCH] Change Interval to Increment --- Firmware/MotorControl/endstop.cpp | 4 ++-- Firmware/MotorControl/timer.hpp | 9 +++++---- Firmware/Tests/test_timer.cpp | 2 +- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/Firmware/MotorControl/endstop.cpp b/Firmware/MotorControl/endstop.cpp index 2f8c6410..7febba16 100644 --- a/Firmware/MotorControl/endstop.cpp +++ b/Firmware/MotorControl/endstop.cpp @@ -3,7 +3,7 @@ Endstop::Endstop(Endstop::Config_t& config) : config_(config) { update_config(); - debounceTimer_.setInterval(current_meas_period); + debounceTimer_.setIncrement(current_meas_period); } @@ -33,7 +33,7 @@ bool Endstop::get_state() { void Endstop::update_config() { set_enabled(config_.enabled); - debounceTimer_.setInterval(config_.debounce_ms * 0.001f); + debounceTimer_.setIncrement(config_.debounce_ms * 0.001f); } void Endstop::set_enabled(bool enable) { diff --git a/Firmware/MotorControl/timer.hpp b/Firmware/MotorControl/timer.hpp index db9557ad..ae539bb8 100644 --- a/Firmware/MotorControl/timer.hpp +++ b/Firmware/MotorControl/timer.hpp @@ -8,8 +8,8 @@ class Timer { timeout_ = timeout; } - void setInterval(const T interval) { - interval_ = interval; + void setIncrement(const T increment) { + increment_ = increment; } void start() { @@ -20,9 +20,10 @@ class Timer { running_ = false; } + // If the timer is started, increment the timer void update() { if (running_) - timer_ = std::min(timer_ + interval_, timeout_); + timer_ = std::min(timer_ + increment_, timeout_); } void reset() { @@ -36,6 +37,6 @@ class Timer { private: T timer_ = static_cast(0); // Current state T timeout_ = static_cast(0); // Time to count - T interval_ = static_cast(0); // Amount to increment each time update() is called + T increment_ = static_cast(0); // Amount to increment each time update() is called bool running_ = false; // update() only increments if runing_ is true }; diff --git a/Firmware/Tests/test_timer.cpp b/Firmware/Tests/test_timer.cpp index 60bf8822..4b3d81ac 100644 --- a/Firmware/Tests/test_timer.cpp +++ b/Firmware/Tests/test_timer.cpp @@ -6,7 +6,7 @@ TEST_CASE_TEMPLATE("Timer2", T, float, int, char, uint32_t){ Timer myTimer; myTimer.setTimeout(10); - myTimer.setInterval(1); + myTimer.setIncrement(1); CHECK(!myTimer.expired()); myTimer.start();