From 4a72c6badceebcb435d70b6dfc7bb843e9228e36 Mon Sep 17 00:00:00 2001 From: perfrankling <78272942+perfrankling@users.noreply.github.com> Date: Sun, 2 Feb 2025 22:55:06 +0100 Subject: [PATCH] Add files via upload Checks for division by zero --- Somfy.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Somfy.cpp b/Somfy.cpp index 6c85a9d..9024478 100644 --- a/Somfy.cpp +++ b/Somfy.cpp @@ -3052,10 +3052,10 @@ void SomfyShade::moveToTarget(float pos, float tilt) { pos = 100; if(tilt < this->currentTiltPos) { cmd = somfy_commands::StepUp; //Converted to somfy_commands::Up in sendCommand for non-80-bits shades - step = (this->currentTiltPos - tilt) * this->tiltTime / this->stepSize / 100; + if (this->stepSize > 0) step = (this->currentTiltPos - tilt) * this->tiltTime / this->stepSize / 100; } else if(tilt > this->currentTiltPos) { cmd = somfy_commands::StepDown; //Converted to somfy_commands::Down in sendCommand for non-80-bits shades - step = (tilt - this->currentTiltPos) * this->tiltTime / this->stepSize / 100; + if (this->stepSize > 0) step = (tilt - this->currentTiltPos) * this->tiltTime / this->stepSize / 100; } } else { @@ -3065,10 +3065,10 @@ void SomfyShade::moveToTarget(float pos, float tilt) { cmd = somfy_commands::Down; else if(tilt >= 0 && tilt < this->currentTiltPos){ cmd = somfy_commands::StepUp; //Converted to somfy_commands::Up in sendCommand for non-80-bits shades - step = (this->currentTiltPos - tilt) * this->tiltTime / this->stepSize / 100; + if (this->stepSize > 0) step = (this->currentTiltPos - tilt) * this->tiltTime / this->stepSize / 100; } else if(tilt >= 0 && tilt > this->currentTiltPos){ cmd = somfy_commands::StepDown; //Converted to somfy_commands::Down in sendCommand for non-80-bits shades - step = (tilt - this->currentTiltPos) * this->tiltTime / this->stepSize / 100; + if (this->stepSize > 0) step = (tilt - this->currentTiltPos) * this->tiltTime / this->stepSize / 100; } } if(cmd != somfy_commands::Stop) {