Skip to content

Commit e4cd9e2

Browse files
committed
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.
1 parent e4c550c commit e4cd9e2

File tree

6 files changed

+167
-417
lines changed

6 files changed

+167
-417
lines changed

external_samples/port.py

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,25 @@
1919
from enum import Enum
2020
from typing import Self
2121

22+
_base_compound = 256
23+
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+
SMART_MOTOR_PORT = 5 # A motor port on MotionCore.
33+
USB_HUB_PORT = 6 # A port on a usb hub.
34+
EXPANSION_HUB_MOTOR_PORT = 7 # A motor port on an expansion hub.
35+
EXPANSION_HUB_SERVO_PORT = 8 # A servo port on an expansion hub.
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)