File tree Expand file tree Collapse file tree 2 files changed +85
-0
lines changed Expand file tree Collapse file tree 2 files changed +85
-0
lines changed Original file line number Diff line number Diff line change 1+ from abc import ABC , abstractmethod
2+ from enum import Enum
3+
4+ class PortType (Enum ):
5+ CAN_PORT = 1
6+ SMART_IO_PORT = 2
7+ SMART_MOTOR_PORT = 3
8+ SERVO_PORT = 4
9+ I2C_PORT = 5
10+ USB_PORT = 6
11+
12+ # This is an abstract class
13+ class Component :
14+ # This is the manufacturer of the component
15+ @abstractmethod
16+ def get_manufacturer (self ) -> str :
17+ pass
18+ # This is the name of the component
19+ @abstractmethod
20+ def get_name (self ) -> str :
21+ pass
22+ # This is the part number of the component
23+ @abstractmethod
24+ def get_part_number (self ) -> str :
25+ pass
26+ # This is the URL of the component
27+ @abstractmethod
28+ def get_url (self ) -> str :
29+ pass
30+ # This is the version of the software (returned as a (major, minor, revision) tuple where
31+ # major and minor are positive integers
32+ # revision is an optional string
33+ @abstractmethod
34+ def get_version (self ) -> tuple [int , int , str ]:
35+ pass
36+
37+ # This stops all movement (if any) for the component
38+ @abstractmethod
39+ def stop (self ) -> None :
40+ pass
41+
42+ # any reset required (if any) after it has stopped before it can be used
43+ @abstractmethod
44+ def reset (self ) -> None :
45+ pass
46+
47+ # This returns a list (can be empty, one, or multipe) of the ports this connects to
48+ # of the PortType enumeration
49+ @abstractmethod
50+ def get_connection_port_type (self ) -> list [PortType ]:
51+ pass
Original file line number Diff line number Diff line change 1+ from component import Component , PortType
2+ from _collections_abc import Callable
3+
4+ class RevTouchSensor (Component ):
5+ # Required methods
6+ def get_manufacturer (self ) -> str :
7+ return "REV Robotics"
8+ def get_name (self ) -> str :
9+ return "Touch Sensor"
10+ def get_part_number (self ) -> str :
11+ return "REV-31-1425"
12+ def get_url (self ) -> str :
13+ return "https://www.revrobotics.com/rev-31-1425/"
14+ def get_version (self ) -> tuple [int , int , str ]:
15+ return (1 , 0 , None )
16+ def stop (self ) -> None :
17+ pass
18+ def reset (self ) -> None :
19+ pass
20+ def get_connection_port_type (self ) -> list [PortType ]:
21+ return [PortType .SMART_IO_PORT ]
22+
23+ # Methods
24+ def is_pressed (self ) -> bool :
25+ # Code to communicate using WPILib would go here
26+ return True
27+
28+ # Events
29+ def whenPressedRegister (callback : Callable [[None , None ]]) -> None :
30+ # Code to register callback here
31+ pass
32+ def whenReleasedRegister (callback : Callable [[None , None ]]) -> None :
33+ # Code to register callback here
34+ pass
You can’t perform that action at this time.
0 commit comments