Skip to content

Commit

Permalink
refactored test_dir_step_en function
Browse files Browse the repository at this point in the history
  • Loading branch information
Chr157i4n committed Oct 26, 2024
1 parent e6bab4a commit 51f94f1
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 45 deletions.
2 changes: 1 addition & 1 deletion src/TMC_2209/TMC_2209_StepperDriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class TMC_2209:
)

from ._TMC_2209_test import (
test_dir_step_en, test_step, test_uart, test_stallguard_threshold
test_pin, test_dir_step_en, test_step, test_uart, test_stallguard_threshold
)

BOARD = BOARD
Expand Down
69 changes: 25 additions & 44 deletions src/TMC_2209/_TMC_2209_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,61 +16,42 @@



def test_dir_step_en(self):
"""tests the EN, DIR and STEP pin
def test_pin(self, pin, ioin_reg):
"""tests one pin
this sets the EN, DIR and STEP pin to HIGH, LOW and HIGH
and checks the IOIN Register of the TMC meanwhile
this function checks the connection to a pin
by toggling it and reading the IOIN register
"""
pin_dir_ok = pin_step_ok = pin_en_ok = True
pin_ok = True

TMC_gpio.gpio_output(self._pin_dir, Gpio.HIGH)
TMC_gpio.gpio_output(self._pin_step, Gpio.HIGH)
TMC_gpio.gpio_output(self._pin_en, Gpio.HIGH)
time.sleep(0.1)
ioin = self.read_ioin()
if not ioin & tmc_reg.io_dir:
pin_dir_ok = False
if not ioin & tmc_reg.io_step:
pin_step_ok = False
if not ioin & tmc_reg.io_enn:
pin_en_ok = False

TMC_gpio.gpio_output(self._pin_dir, Gpio.HIGH)
TMC_gpio.gpio_output(self._pin_step, Gpio.LOW)
TMC_gpio.gpio_output(self._pin_en, Gpio.HIGH)
time.sleep(0.1)
ioin = self.read_ioin()
if not ioin & tmc_reg.io_dir:
pin_dir_ok = False
if ioin & tmc_reg.io_step:
pin_step_ok = False
if not ioin & tmc_reg.io_enn:
pin_en_ok = False

TMC_gpio.gpio_output(self._pin_dir, Gpio.LOW)
TMC_gpio.gpio_output(self._pin_step, Gpio.HIGH)
TMC_gpio.gpio_output(self._pin_en, Gpio.HIGH)
time.sleep(0.1)
ioin = self.read_ioin()
if ioin & tmc_reg.io_dir:
pin_dir_ok = False
if not ioin & tmc_reg.io_step:
pin_step_ok = False
if not ioin & tmc_reg.io_enn:
pin_en_ok = False
if not ioin & ioin_reg:
pin_ok = False

TMC_gpio.gpio_output(self._pin_dir, Gpio.HIGH)
TMC_gpio.gpio_output(self._pin_step, Gpio.HIGH)
TMC_gpio.gpio_output(self._pin_en, Gpio.LOW)
TMC_gpio.gpio_output(pin, Gpio.LOW)
time.sleep(0.1)

ioin = self.read_ioin()
if not ioin & tmc_reg.io_dir:
pin_dir_ok = False
if not ioin & tmc_reg.io_step:
pin_step_ok = False
if ioin & tmc_reg.io_enn:
pin_en_ok = False
if ioin & ioin_reg:
pin_ok = False

return pin_ok



def test_dir_step_en(self):
"""tests the EN, DIR and STEP pin
this sets the EN, DIR and STEP pin to HIGH, LOW and HIGH
and checks the IOIN Register of the TMC meanwhile
"""
pin_dir_ok = self.test_pin(self._pin_dir, tmc_reg.io_dir)
pin_step_ok = self.test_pin(self._pin_step, tmc_reg.io_step)
pin_en_ok = self.test_pin(self._pin_en, tmc_reg.io_enn)

self.set_motor_enabled(False)

Expand Down

0 comments on commit 51f94f1

Please sign in to comment.