Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 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
57 changes: 57 additions & 0 deletions external_samples/component.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
from abc import ABC, abstractmethod
from enum import Enum

class PortType(Enum):
CAN_PORT = 1
SMART_IO_PORT = 2
SMART_MOTOR_PORT = 3
SERVO_PORT = 4
I2C_PORT = 5
USB_PORT = 6

# This is an abstract class
class Component:
# This is the manufacturer of the component
@abstractmethod
def get_manufacturer(self) -> str:
pass
# This is the name of the component
@abstractmethod
def get_name(self) -> str:
pass
# This is the part number of the component
@abstractmethod
def get_part_number(self) -> str:
pass
# This is the URL of the component
@abstractmethod
def get_url(self) -> str:
pass
# This is the version of the software (returned as a (major, minor, revision) tuple where
# major and minor are positive integers
# revision is an optional string
@abstractmethod
def get_version(self) -> tuple[int, int, str]:
pass

# This stops all movement (if any) for the component
@abstractmethod
def stop(self) -> None:
pass

# any reset required (if any) at the beginning of each opmode
# This might remove any registered callbacks
@abstractmethod
def reset(self) -> None:
pass

# This returns a list (can be empty, one, or multipe) of the ports this connects to
# of the PortType enumeration
@abstractmethod
def get_connection_port_type(self) -> list[PortType]:
pass

# This is called periodically when an opmode is running
@abstractmethod
def periodic(self) -> None:
pass
38 changes: 38 additions & 0 deletions external_samples/rev_touch_sensor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
from component import Component, PortType
from _collections_abc import Callable

class RevTouchSensor(Component):
# Required methods
def get_manufacturer(self) -> str:
return "REV Robotics"
def get_name(self) -> str:
return "Touch Sensor"
def get_part_number(self) -> str:
return "REV-31-1425"
def get_url(self) -> str:
return "https://www.revrobotics.com/rev-31-1425/"
def get_version(self) -> tuple[int, int, str]:
return (1, 0, "")
def stop(self) -> None:
pass
def reset(self) -> None:
pass
def get_connection_port_type(self) -> list[PortType]:
return [PortType.SMART_IO_PORT]
def periodic(self) -> None:
# This would poll the hardware and see if it needs to fire any events
pass

# Methods
def is_pressed(self) -> bool:
# Code to communicate using WPILib would go here
return True

# Events
def register_when_pressed(callback: Callable[[], None]) -> None:
# Code to register callback here
pass

def register_when_released(callback: Callable[[], None]) -> None:
# Code to register callback here
pass