From 4a501139c2152e247e9a7cfa216370a968073ef6 Mon Sep 17 00:00:00 2001 From: Alec Delaney <89490472+tekktrik@users.noreply.github.com> Date: Fri, 6 Jan 2023 00:59:47 -0500 Subject: [PATCH 1/4] Allow for transformed PWMOut-based error --- adafruit_motor/stepper.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/adafruit_motor/stepper.py b/adafruit_motor/stepper.py index e2289e1..5eedb69 100755 --- a/adafruit_motor/stepper.py +++ b/adafruit_motor/stepper.py @@ -113,8 +113,13 @@ def __init__( # set a safe pwm freq for each output self._coil = (ain2, bin1, ain1, bin2) for i in range(4): - if self._coil[i].frequency < 1500: + if self._coil[i].frequency < 1500 and self._coil[i].variable_frequency: self._coil[i].frequency = 2000 + else: + raise RuntimeError( + "PWMOut outputs must either be set to at least " + "1500 Hz or allow variable frequency." + ) if microsteps < 2: raise ValueError("Microsteps must be at least 2") if microsteps % 2 == 1: From 44bdcf4037958c9317366cc251944b44d0007a1e Mon Sep 17 00:00:00 2001 From: Alec Delaney <89490472+tekktrik@users.noreply.github.com> Date: Fri, 6 Jan 2023 09:25:49 -0500 Subject: [PATCH 2/4] Use ValueError instead of RuntimeError Co-authored-by: Dan Halbert --- adafruit_motor/stepper.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_motor/stepper.py b/adafruit_motor/stepper.py index 5eedb69..b3adb8e 100755 --- a/adafruit_motor/stepper.py +++ b/adafruit_motor/stepper.py @@ -116,7 +116,7 @@ def __init__( if self._coil[i].frequency < 1500 and self._coil[i].variable_frequency: self._coil[i].frequency = 2000 else: - raise RuntimeError( + raise ValueError( "PWMOut outputs must either be set to at least " "1500 Hz or allow variable frequency." ) From 4701a641d2924b14e727cedb408a71a7630bb455 Mon Sep 17 00:00:00 2001 From: Alec Delaney <89490472+tekktrik@users.noreply.github.com> Date: Mon, 9 Jan 2023 12:14:55 -0500 Subject: [PATCH 3/4] Fix logic for checking PWMOut Thanks @jepler for catching the faulty logic! --- adafruit_motor/stepper.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/adafruit_motor/stepper.py b/adafruit_motor/stepper.py index b3adb8e..397d031 100755 --- a/adafruit_motor/stepper.py +++ b/adafruit_motor/stepper.py @@ -113,13 +113,12 @@ def __init__( # set a safe pwm freq for each output self._coil = (ain2, bin1, ain1, bin2) for i in range(4): - if self._coil[i].frequency < 1500 and self._coil[i].variable_frequency: - self._coil[i].frequency = 2000 - else: + if self._coil[i].frequency < 1500 and not self._coil[i].variable_frequency: raise ValueError( "PWMOut outputs must either be set to at least " "1500 Hz or allow variable frequency." ) + self._coil[i].frequency = 2000 if microsteps < 2: raise ValueError("Microsteps must be at least 2") if microsteps % 2 == 1: From bdf122d48c52ea19ae045a32825da796d6b1be61 Mon Sep 17 00:00:00 2001 From: Alec Delaney Date: Mon, 9 Jan 2023 12:44:05 -0500 Subject: [PATCH 4/4] Reformatted per pre-commit --- adafruit_motor/stepper.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/adafruit_motor/stepper.py b/adafruit_motor/stepper.py index 397d031..9374e43 100755 --- a/adafruit_motor/stepper.py +++ b/adafruit_motor/stepper.py @@ -113,7 +113,10 @@ def __init__( # set a safe pwm freq for each output self._coil = (ain2, bin1, ain1, bin2) for i in range(4): - if self._coil[i].frequency < 1500 and not self._coil[i].variable_frequency: + if ( + self._coil[i].frequency < 1500 + and not self._coil[i].variable_frequency + ): raise ValueError( "PWMOut outputs must either be set to at least " "1500 Hz or allow variable frequency."