forked from viamrobotics/viam-typescript-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinput-controller.ts
62 lines (59 loc) · 1.95 KB
/
input-controller.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import type { PlainMessage, Struct } from '@bufbuild/protobuf';
import * as pb from '../../gen/component/inputcontroller/v1/input_controller_pb';
import type { Resource } from '../../types';
export type InputControllerEvent = PlainMessage<pb.Event>;
export const { Event: InputControllerEvent } = pb;
/**
* Represents a human interface device like a mouse or keyboard that emits
* events for controls.
*/
export interface InputController extends Resource {
/**
* Returns a list of events representing the last event on each control.
*
* @example
*
* ```ts
* const controller = new VIAM.InputControllerClient(
* machine,
* 'my_controller'
* );
*
* // Get the most recent Event for each Control
* const recentEvents = await controller.getEvents();
* console.log('Recent events:', recentEvents);
* ```
*
* For more information, see [Input Controller
* API](https://docs.viam.com/dev/reference/apis/components/input-controller/#getevents).
*/
getEvents(extra?: Struct): Promise<InputControllerEvent[]>;
/**
* TriggerEvent, where supported, injects an InputControllerEvent into an
* input controller to (virtually) generate events like button presses or axis
* movements.
*
* @example
*
* ```ts
* const controller = new VIAM.InputControllerClient(
* machine,
* 'my_controller'
* );
*
* // Create a "Button is Pressed" event for the control BUTTON_START
* const buttonPressEvent = new VIAM.InputControllerEvent({
* time: { seconds: BigInt(Math.floor(Date.now() / 1000)) },
* event: 'ButtonPress',
* control: 'ButtonStart',
* value: 1.0,
* });
* // Trigger the event
* await controller.triggerEvent(buttonPressEvent);
* ```
*
* For more information, see [Input Controller
* API](https://docs.viam.com/dev/reference/apis/components/input-controller/#triggerevent).
*/
triggerEvent(event: InputControllerEvent, extra?: Struct): Promise<void>;
}