Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 18 additions & 13 deletions external_samples/port.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,27 @@
# @author [email protected] (Alan Smith)
from abc import ABC, abstractmethod
from enum import Enum
from typing import Self
from typing import Final, Self

_BASE_COMPOUND: Final[int] = 256

class PortType(Enum):
# Ports on the SystemCore.
CAN_PORT = 1
SMART_IO_PORT = 2
SMART_MOTOR_PORT = 3
SERVO_PORT = 4
I2C_PORT = 5
USB_PORT = 6
EXPANSION_HUB_MOTOR_PORT = 7 # This is the port on the expansion hub
EXPANSION_HUB_SERVO_PORT = 8 # This is the port on the expansion hub
I2C_PORT = 3
USB_PORT = 4

# Ports on other devices.
USB_HUB_PORT = 5 # A port on a usb hub.
EXPANSION_HUB_MOTOR_PORT = 6 # A motor port on an Expansion Hub.
EXPANSION_HUB_SERVO_PORT = 7 # A servo port on an Expansion Hub.
# TODO: Add the ports for MotionCore.

BASE_COMPOUND = 256
USB_HUB = BASE_COMPOUND + 1
EXPANSION_HUB_MOTOR = BASE_COMPOUND + 2 # This is combination expansion hub and motor
EXPANSION_HUB_SERVO = BASE_COMPOUND + 3 # This is combination expansion hub and servo
# Compound ports
USB_HUB = _BASE_COMPOUND + 1 # A compound port with USB_PORT and USB_HUB_PORT.
EXPANSION_HUB_MOTOR = _BASE_COMPOUND + 2 # A compound port with USB_PORT and EXPANSION_HUB_MOTOR_PORT.
EXPANSION_HUB_SERVO = _BASE_COMPOUND + 3 # A compound port with USB_PORT and EXPANSION_HUB_SERVO_PORT.

class Port(ABC):
"""Abstract base class for all port types."""
Expand All @@ -58,7 +63,7 @@ def __init__(self, port_type: PortType, location: int):
port_type: PortType for this port (must be a simple type)
location: int location for this port
"""
if port_type.value >= PortType.BASE_COMPOUND.value:
if port_type.value >= _BASE_COMPOUND:
raise ValueError("Port must be of a simple type")
super().__init__(port_type)
self.location = location
Expand All @@ -80,7 +85,7 @@ def __init__(self, port_type: PortType, port1: Port, port2: Port):
port1: First Port for compound ports
port2: Second Port for compound ports
"""
if port_type.value < PortType.BASE_COMPOUND.value:
if port_type.value < _BASE_COMPOUND:
raise ValueError("Port must be of a compound type")
super().__init__(port_type)
self.port1 = port1
Expand Down
61 changes: 0 additions & 61 deletions external_samples/servo.py

This file was deleted.

2 changes: 0 additions & 2 deletions python_tools/generate_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@
import expansion_hub_servo
import port
import rev_touch_sensor
import servo
import smart_motor
import spark_mini
import sparkfun_led_stick
Expand Down Expand Up @@ -126,7 +125,6 @@ def main(argv):
expansion_hub_servo,
port,
rev_touch_sensor,
servo,
smart_motor,
spark_mini,
sparkfun_led_stick,
Expand Down
Loading