@@ -35,6 +35,61 @@ func Named(name string) resource.Name {
35
35
36
36
// Controller is a logical "container" more than an actual device
37
37
// Could be a single gamepad, or a collection of digitalInterrupts and analogReaders, a keyboard, etc.
38
+ //
39
+ // Controls example:
40
+ //
41
+ // // Get the list of Controls provided by the controller.
42
+ // controls, err := myController.Controls(context.Background(), nil)
43
+ //
44
+ // Events example:
45
+ //
46
+ // // Get the most recent Event for each Control.
47
+ // recent_events, err := myController.Events(context.Background(), nil)
48
+ //
49
+ // RegisterControlCallback example:
50
+ //
51
+ // // Define a function that handles the controller.
52
+ // func handleController(ctx context.Context, logger logging.Logger, controller input.Controller) error {
53
+ // // Define a function to handle pressing the Start Menu button, "ButtonStart", on your controller and logging the start time
54
+ // printStartTime := func(ctx context.Context, event input.Event) {
55
+ // logger.Info("Start Menu Button was pressed at this time: %v", event.Time)
56
+ // }
57
+ //
58
+ // // Define the EventType "ButtonPress" to serve as the trigger for printStartTime.
59
+ // triggers := []input.EventType{input.ButtonPress}
60
+ //
61
+ // // Get the controller's Controls.
62
+ // controls, err := controller.Controls(ctx, nil)
63
+ //
64
+ // // If the "ButtonStart" Control is found, register the function printStartTime to fire when "ButtonStart" has the event "ButtonPress" occur.
65
+ // if !slices.Contains(controls, input.ButtonStart) {
66
+ // return errors.New("button `ButtonStart` not found; controller may be disconnected")
67
+ // }
68
+ // return controller.RegisterControlCallback(context.Background(), Control: input.ButtonStart, triggers, printStartTime, nil)
69
+ // }
70
+ //
71
+ // func main() {
72
+ // utils.ContextualMain(mainWithArgs, logging.NewLogger("client"))
73
+ // }
74
+ //
75
+ // func mainWithArgs(ctx context.Context, args []string, logger logging.Logger) error {
76
+ // // < Insert code sample from your machine's CONNECT tab >
77
+ //
78
+ // // Get the controller from the machine.
79
+ // myController, err := input.FromRobot(machine, "my_controller")
80
+ // if err != nil {
81
+ // return err
82
+ // }
83
+ //
84
+ // // Run the handleController function.
85
+ // if err = handleController(myController) {
86
+ // return err
87
+ // }
88
+ // // < Insert any other code for main function >
89
+ //
90
+ // <-ctx.Done()
91
+ // return nil
92
+ // }
38
93
type Controller interface {
39
94
resource.Resource
40
95
0 commit comments