Skip to content

Commit

Permalink
Merge pull request #93 from fvlima/explicity-force-selection
Browse files Browse the repository at this point in the history
Add force_selection parameter to DC class
  • Loading branch information
jmsv committed Apr 5, 2019
2 parents 10e34e8 + 9dd9832 commit c026a9b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
8 changes: 8 additions & 0 deletions docs/user-guide/python-scripts.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ In this example, the GPIO pin numbers will be the same as listed in [Hardware Se
motor1 = l293d.DC(22, 18, 16)
```

In some cases, it may be necessary to use some pins that aren't considered valid, but we can force it
by expliciting the `force_selection` parameter as `True` in DC class initialization (by default, this
parameter is `False`).

```python
motor1 = l293d.DC(19, 21, 23, force_selection=True)
```

In this case, 'motor1' is what we're calling the DC motor object. You can call it whatever you want,
for example `wheel_motor`, `london_eye` or `spinny_thing`.

Expand Down
4 changes: 2 additions & 2 deletions l293d/driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class DC(object):
motor_pins[2] is pinC is L293D pin7 or pin15 : Clockwise positive
"""

def __init__(self, pin_a=0, pin_b=0, pin_c=0):
def __init__(self, pin_a=0, pin_b=0, pin_c=0, force_selection=False):
# Assign parameters to list
self.motor_pins = [0 for x in range(3)]
self.motor_pins[0] = pin_a
Expand All @@ -66,7 +66,7 @@ def __init__(self, pin_a=0, pin_b=0, pin_c=0):
self.reversed = False

# Check pins are valid
if pins_are_valid(self.motor_pins):
if pins_are_valid(self.motor_pins, force_selection):
self.exists = True
# Append to global list of pins in use
for pin in self.motor_pins:
Expand Down
13 changes: 13 additions & 0 deletions tests/test_l293d.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,19 @@ def test_import(self):
self.assertTrue(True)
reload(d.driver) # Revert changes

def test_create_motor_with_force_selection(self):
"""
Test DC class instance creation with explicity
force_selection parameter
"""
import l293d as d
cases = (([33, 36, 37], False), ([19, 21, 23], True))
for pins, force_selection in cases:
motor = d.DC(*pins, force_selection=force_selection)
self.assertEqual(d.pins_in_use, pins)
motor.remove()
reload(d.driver)

def test_pins_string_list(self):
"""
Test that the list of pins is returned correctly
Expand Down

0 comments on commit c026a9b

Please sign in to comment.