Skip to content

Commit b87d1c3

Browse files
author
Wil Bennett
committed
Initial changes
1 parent b90ea40 commit b87d1c3

File tree

7 files changed

+34
-2
lines changed

7 files changed

+34
-2
lines changed

pitop/core/mixins/recreatable.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
class Recreatable:
1010
"""Represents an object that keeps track of a set of parameters that will
11-
allow to be recreate it in the future.
11+
allow it to be recreated in the future.
1212
1313
The values for each key provided in the :param:`config_dict`
1414
parameter can be a constant value or a reference to a function,

pitop/pma/adc_base.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
)
77
from pitop.pma.plate_interface import PlateInterface
88
from pitop.pma.common import get_pin_for_port
9+
from pitop.pma.common.utils import Port
910

1011

1112
class ADCBase(Stateful, Recreatable):
@@ -22,6 +23,12 @@ class ADCBase(Stateful, Recreatable):
2223
"""
2324

2425
def __init__(self, port_name, pin_number=1, name="adcbase"):
26+
if port_name not in Port.keys():
27+
raise ValueError(f"{port_name} is not a valid port name. An example of a valid port name is A0")
28+
29+
if not port_name.startswith("A"):
30+
raise ValueError(f"{port_name} is not a valid port type for an analog component. Try using an analog port, such as A0")
31+
2532
self._pma_port = port_name
2633
self.name = name
2734

pitop/pma/button.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ def __init__(self, port_name, name="button"):
1818
self._pma_port = port_name
1919
self.name = name
2020

21+
if port_name not in Port.keys():
22+
raise ValueError(f"{port_name} is not a valid port name. An example of a valid port name is D0")
23+
24+
if not port_name.startswith("D"):
25+
raise ValueError(f"{port_name} is not a valid port type for a button. Try using a digital port, such as D0")
26+
2127
Stateful.__init__(self)
2228
Recreatable.__init__(self, {"port_name": port_name, "name": self.name})
2329
gpiozero_Button.__init__(self, get_pin_for_port(self._pma_port))

pitop/pma/buzzer.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@ def __init__(self, port_name, name="buzzer"):
1717
self._pma_port = port_name
1818
self.name = name
1919

20+
if port_name not in Port.keys():
21+
raise ValueError(f"{port_name} is not a valid port name. An example of a valid port name is D0")
22+
23+
if not port_name.startswith("D"):
24+
raise ValueError(f"{port_name} is not a valid port type for a buzzer. Try using a digital port, such as D0")
25+
2026
Stateful.__init__(self)
2127
Recreatable.__init__(self, {"port_name": port_name, "name": self.name})
2228
gpiozero_Buzzer.__init__(self, get_pin_for_port(self._pma_port))

pitop/pma/encoder_motor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class EncoderMotor(Stateful, Recreatable):
2626
2727
The conversions between angle, rotations and RPM used by the motor to meters and meters/second are performed considering
2828
the :data:`wheel_diameter` parameter. This parameter defaults to the diameter of the wheel included with MMK.
29-
If a wheel of different dimmensions is attached to the motor, you'll need to measure it's diameter, in order for these
29+
If a wheel of different dimensions is attached to the motor, you'll need to measure it's diameter, in order for these
3030
methods to work properly.
3131
3232
:type port_name: str

pitop/pma/led.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ def __init__(self, port_name, name="led"):
1818
self._pma_port = port_name
1919
self.name = name
2020

21+
if port_name not in Port.keys():
22+
raise ValueError(f"{port_name} is not a valid port name. An example of a valid port name is D0")
23+
24+
if not port_name.startswith("D"):
25+
raise ValueError(f"{port_name} is not a valid port type for an LED. Try using a digital port, such as D0")
26+
2127
Stateful.__init__(self)
2228
Recreatable.__init__(self, {"port_name": port_name, "name": self.name})
2329
gpiozero_LED.__init__(self, get_pin_for_port(self._pma_port))

pitop/pma/ultrasonic_sensor.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,13 @@ def __init__(
3030
self._pma_port = port_name
3131
self.name = name
3232

33+
if port_name not in Port.keys():
34+
raise ValueError(f"{port_name} is not a valid port name. An example of a valid port name is D0")
35+
36+
# todo: what ports do we allow for ultrasonic? Is the MCU now capable of handling ultrasonic, and if so do we unconditionally allow all D or A ports to be used?
37+
#if not port_name.startswith("D"):
38+
# raise ValueError(f"{port_name} is not a valid port type for an ultrasonic sensor. Try using a digital port, such as D0")
39+
3340
SmoothedInputDevice.__init__(self,
3441
get_pin_for_port(self._pma_port),
3542
pull_up=False,

0 commit comments

Comments
 (0)