Skip to content

Commit d9e16a6

Browse files
authored
Cleaned up mrc_port (#257)
* In mrc_port.ts. - Added constants for port types. - Added constants for field prefixes. - Added constants for visible port labels. - Removed type MrcPortType, ports_ from PortMixin, and ports from PortExtraState. - Renamed PortMixin portType_ to mrcPortType. - Added mrcPortCount to PortMixin. - Rewrote loadExtraState to create the appropriate fields for the portType. - Removed updateShape. - Simplified the code in pythonFromBlock that collects the ports. - Generate code for CompoundPort without trailing backslashes. - Changed Order.ATOMIC to Order.FUNCTION_CALL. - Updated createPort to specify the field values. In field_number_dropdown.ts: Removed defaultVal parameter in createFieldNumberDropdown function. In external_samples/port.py: Replace PortType enum value BASE_COMPOUND with a module variable named _base_compound. Removed PortType enum value SERVO_PORT. Added PortType enum value USB_HUB_PORT. Removed external_samples/servo.py. * Changed _base_compound to _BASE_COMPOUND. * Removed SMART_MOTOR_PORT. Added a TODO comment about adding port for MotionCore.
1 parent f002bce commit d9e16a6

File tree

6 files changed

+168
-419
lines changed

6 files changed

+168
-419
lines changed

external_samples/port.py

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,27 @@
1717
# @author [email protected] (Alan Smith)
1818
from abc import ABC, abstractmethod
1919
from enum import Enum
20-
from typing import Self
20+
from typing import Final, Self
21+
22+
_BASE_COMPOUND: Final[int] = 256
2123

2224
class PortType(Enum):
25+
# Ports on the SystemCore.
2326
CAN_PORT = 1
2427
SMART_IO_PORT = 2
25-
SMART_MOTOR_PORT = 3
26-
SERVO_PORT = 4
27-
I2C_PORT = 5
28-
USB_PORT = 6
29-
EXPANSION_HUB_MOTOR_PORT = 7 # This is the port on the expansion hub
30-
EXPANSION_HUB_SERVO_PORT = 8 # This is the port on the expansion hub
28+
I2C_PORT = 3
29+
USB_PORT = 4
30+
31+
# Ports on other devices.
32+
USB_HUB_PORT = 5 # A port on a usb hub.
33+
EXPANSION_HUB_MOTOR_PORT = 6 # A motor port on an Expansion Hub.
34+
EXPANSION_HUB_SERVO_PORT = 7 # A servo port on an Expansion Hub.
35+
# TODO: Add the ports for MotionCore.
3136

32-
BASE_COMPOUND = 256
33-
USB_HUB = BASE_COMPOUND + 1
34-
EXPANSION_HUB_MOTOR = BASE_COMPOUND + 2 # This is combination expansion hub and motor
35-
EXPANSION_HUB_SERVO = BASE_COMPOUND + 3 # This is combination expansion hub and servo
37+
# Compound ports
38+
USB_HUB = _BASE_COMPOUND + 1 # A compound port with USB_PORT and USB_HUB_PORT.
39+
EXPANSION_HUB_MOTOR = _BASE_COMPOUND + 2 # A compound port with USB_PORT and EXPANSION_HUB_MOTOR_PORT.
40+
EXPANSION_HUB_SERVO = _BASE_COMPOUND + 3 # A compound port with USB_PORT and EXPANSION_HUB_SERVO_PORT.
3641

3742
class Port(ABC):
3843
"""Abstract base class for all port types."""
@@ -58,7 +63,7 @@ def __init__(self, port_type: PortType, location: int):
5863
port_type: PortType for this port (must be a simple type)
5964
location: int location for this port
6065
"""
61-
if port_type.value >= PortType.BASE_COMPOUND.value:
66+
if port_type.value >= _BASE_COMPOUND:
6267
raise ValueError("Port must be of a simple type")
6368
super().__init__(port_type)
6469
self.location = location
@@ -80,7 +85,7 @@ def __init__(self, port_type: PortType, port1: Port, port2: Port):
8085
port1: First Port for compound ports
8186
port2: Second Port for compound ports
8287
"""
83-
if port_type.value < PortType.BASE_COMPOUND.value:
88+
if port_type.value < _BASE_COMPOUND:
8489
raise ValueError("Port must be of a compound type")
8590
super().__init__(port_type)
8691
self.port1 = port1

external_samples/servo.py

Lines changed: 0 additions & 61 deletions
This file was deleted.

python_tools/generate_json.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@
6363
import expansion_hub_servo
6464
import port
6565
import rev_touch_sensor
66-
import servo
6766
import smart_motor
6867
import spark_mini
6968
import sparkfun_led_stick
@@ -126,7 +125,6 @@ def main(argv):
126125
expansion_hub_servo,
127126
port,
128127
rev_touch_sensor,
129-
servo,
130128
smart_motor,
131129
spark_mini,
132130
sparkfun_led_stick,

0 commit comments

Comments
 (0)