Change Interval to Increment

This commit is contained in:
Unknown
2020-03-28 00:50:44 -04:00
parent a8d47894ca
commit 163ce7d21a
3 changed files with 8 additions and 7 deletions
+2 -2
View File
@@ -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) {
+5 -4
View File
@@ -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<T>(timer_ + interval_, timeout_);
timer_ = std::min<T>(timer_ + increment_, timeout_);
}
void reset() {
@@ -36,6 +37,6 @@ class Timer {
private:
T timer_ = static_cast<T>(0); // Current state
T timeout_ = static_cast<T>(0); // Time to count
T interval_ = static_cast<T>(0); // Amount to increment each time update() is called
T increment_ = static_cast<T>(0); // Amount to increment each time update() is called
bool running_ = false; // update() only increments if runing_ is true
};
+1 -1
View File
@@ -6,7 +6,7 @@
TEST_CASE_TEMPLATE("Timer2", T, float, int, char, uint32_t){
Timer<T> myTimer;
myTimer.setTimeout(10);
myTimer.setInterval(1);
myTimer.setIncrement(1);
CHECK(!myTimer.expired());
myTimer.start();