From a60de44ef119a23df611a10e824336f9d1bf1790 Mon Sep 17 00:00:00 2001 From: Christ van Willegen Date: Wed, 29 May 2024 10:55:01 +0200 Subject: [PATCH] Change code to get rid of embedded ternary. --- esphome/components/stepper/stepper.cpp | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/esphome/components/stepper/stepper.cpp b/esphome/components/stepper/stepper.cpp index b66536eb8d..e918d1472c 100644 --- a/esphome/components/stepper/stepper.cpp +++ b/esphome/components/stepper/stepper.cpp @@ -38,8 +38,20 @@ int32_t Stepper::should_step_() { // assumes this method is called in a constant interval uint32_t dt = now - this->last_step_; if (dt >= (1 / this->current_speed_) * 1e6f) { - int32_t mag = (rotation_ == ROTATION_BOTH ? (this->target_position > this->current_position ? 1 : -1) - : (rotation_ == ROTATION_CW ? 1 : -1)); + int32_t mag = 0; + switch(rotation_) { + case ROTATION_CW: + mag = 1; + break; + + case ROTATION_CCW: + mag = -1; + break; + + default: + mag = this->target_position > this->current_position ? 1 : -1; + break; + } this->last_step_ = now; this->current_position += mag; return mag;