mirror of
https://github.com/esphome/esphome.git
synced 2024-11-28 12:46:22 +01:00
Change code to get rid of embedded ternary.
This commit is contained in:
parent
f21bd4947b
commit
a60de44ef1
@ -38,8 +38,20 @@ int32_t Stepper::should_step_() {
|
|||||||
// assumes this method is called in a constant interval
|
// assumes this method is called in a constant interval
|
||||||
uint32_t dt = now - this->last_step_;
|
uint32_t dt = now - this->last_step_;
|
||||||
if (dt >= (1 / this->current_speed_) * 1e6f) {
|
if (dt >= (1 / this->current_speed_) * 1e6f) {
|
||||||
int32_t mag = (rotation_ == ROTATION_BOTH ? (this->target_position > this->current_position ? 1 : -1)
|
int32_t mag = 0;
|
||||||
: (rotation_ == ROTATION_CW ? 1 : -1));
|
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->last_step_ = now;
|
||||||
this->current_position += mag;
|
this->current_position += mag;
|
||||||
return mag;
|
return mag;
|
||||||
|
Loading…
Reference in New Issue
Block a user