@@ -146,6 +146,18 @@ async def get_controls(self, *, extra: Optional[Dict[str, Any]] = None, timeout:
146146 """
147147 Returns a list of Controls provided by the Controller
148148
149+ ::
150+
151+ # Get the controller from the machine.
152+ my_controller = Controller.from_robot(
153+ robot=myRobotWithController, name="my_controller")
154+
155+ # Get the list of Controls provided by the controller.
156+ controls = await my_controller.get_controls()
157+
158+ # Print the list of Controls provided by the controller.
159+ print(f"Controls: {controls}")
160+
149161 Returns:
150162 List[Control]: List of controls provided by the Controller
151163 """
@@ -159,6 +171,18 @@ async def get_events(
159171 Returns the most recent Event for each input
160172 (which should be the current state)
161173
174+ ::
175+
176+ # Get the controller from the machine.
177+ my_controller = Controller.from_robot(
178+ robot=myRobotWithController, name="my_controller")
179+
180+ # Get the most recent Event for each Control.
181+ recent_events = await my_controller.get_events()
182+
183+ # Print out the most recent Event for each Control.
184+ print(f"Recent Events: {recent_events}")
185+
162186 Returns:
163187 Dict[Control, Event]: The most recent event for each input
164188 """
@@ -178,6 +202,46 @@ def register_control_callback(
178202 Register a function that will fire on given EventTypes for a given
179203 Control
180204
205+ ::
206+
207+ # Define a function to handle pressing the Start Menu Button "BUTTON_START" on
208+ # your controller, printing out the start time.
209+ def print_start_time(event):
210+ print(f"Start Menu Button was pressed at this time: {event.time}")
211+
212+
213+ # Define a function that handles the controller.
214+ async def handle_controller(controller):
215+ # Get the list of Controls on the controller.
216+ controls = await controller.get_controls()
217+
218+ # If the "BUTTON_START" Control is found, register the function
219+ # print_start_time to fire when "BUTTON_START" has the event "ButtonPress"
220+ # occur.
221+ if Control.BUTTON_START in controls:
222+ controller.register_control_callback(
223+ Control.BUTTON_START, [EventType.BUTTON_PRESS], print_start_time)
224+ else:
225+ print("Oops! Couldn't find the start button control! Is your "
226+ "controller connected?")
227+ exit()
228+
229+ while True:
230+ await asyncio.sleep(1.0)
231+
232+
233+ async def main():
234+ # ... < INSERT CONNECTION CODE FROM MACHINE'S CODE SAMPLE TAB >
235+
236+ # Get your controller from the machine.
237+ my_controller = Controller.from_robot(
238+ robot=myRobotWithController, name="my_controller")
239+
240+ # Run the handleController function.
241+ await handleController(my_controller)
242+
243+ # ... < INSERT ANY OTHER CODE FOR MAIN FUNCTION >
244+
181245 Args:
182246 control (Control): The control to register the function for
183247 triggers (List[EventType]): The events that will
@@ -197,6 +261,16 @@ async def trigger_event(
197261 ) -> None : # Explicitly return None for typechecking, as this is technically a NoReturn default implementation
198262 """Directly send an Event (such as a button press) from external code
199263
264+ ::
265+
266+ # Define a "Button is Pressed" event for the control BUTTON_START.
267+ button_is_pressed_event = Event(
268+ time(), EventType.BUTTON_PRESS, Control.BUTTON_START, 1.0)
269+
270+ # Trigger the event on your controller. Set this trigger to timeout if it has
271+ # not completed in 7 seconds.
272+ await myController.trigger_event(event=my_event, timeout=7.0)
273+
200274 Args:
201275 event (Event): The event to trigger
202276 """
0 commit comments