Example on the Use of a Third-Party USB Input Device
In this example, we want to demonstrate how to operate specific tasks on a room or desk device by using the buttons on a third-party USB input device (in this case, a remote control).
We demonstrate how to use the keys on a Bluetooth remote control (in conjunction with a USB dongle) to adjust the volume, toggle the standby mode, and control the camera of a room or desk device. We develop a macro that acts as an event listener and then uses the application programming interface (API) of the desk or room device to carry out the appropriate activities.
This article provides more information regarding the Third-Party USB Input Device capability.
In the following illustration, it is necessary for you to enter the text that is formatted using a standard font. The response that was obtained from the room or desk device can be found in the text that is formatted with italics.
1. Log in to the room device or the device on the desk using SSH. You will need a user with local admin privileges.
2. Adjust the settings of the device so that a USB remote control from a third party can be used.
Mode for the xConfiguration Peripherals InputDevice is On ** end OK.
You can use this command to determine whether the configuration is On or Off by selecting the appropriate option:
*c xConfiguration Peripherals InputDevice Mode xConfiguration Peripherals InputDevice Mode Peripherals InputDevice Mode: On ** end OK in xConfiguration
3. Sign up for feedback so that we can be informed when the buttons on the remote control are pressed and when they are released.
xFeedback Register ** end OK @ userinterface/event/userinterface/inputdevice
By executing this command, you will be able to determine for which feedbacks the device is registered:
xFeedback list ** end OK // event // user interface // input device
4. To ensure that feedback registration is functioning properly, depress and then release a button located on the remote control.
Pressed and Released are the two events that are produced as a result of this action. You won’t stop seeing the Pressed event until the button you’re pressing and holding is no longer being pressed. The Released event is then generated after that.
The following events are generated whenever the Enter key is pressed and then released:
UserInterface InputDevice Key Action Key: KEY_ENTER *e UserInterface InputDevice Key** UserInterface Key Action Code for InputDevice: 28UserInterface InputDevice Key Action Type: Pressed ** end * e UserInterface InputDevice Key*e UserInterface InputDevice Key Action Key: KEY_ENTER *e UserInterface InputDevice Key Action Code: 28 *e UserInterface InputDevice Key Action Code: 28 *eUserInterface InputDevice Key Action Type: Released end e UserInterface
5. Create a macro that monitors for the appropriate InputDevice events, then uses the device’s application programming interface (API) to carry out the activities that are connected with those events.
Awaken the dormant standby, volume up, and volume down buttons. The relevant commands are carried out by the macro whenever it detects an event containing the keystrokes KEY_VOLUMEUP, KEY_VOLUMEDOWN, or KEY_SLEEP.
Develop a function that allows the arrow keys to control the camera. As long as the button is pressed, we want the camera to continue traveling in the same direction. When the button is released, the movement of the camera will come to a halt. The macro will carry out the appropriate commands in response to an event that contains the string “KEY_LEFT,” “KEY_RIGHT,” “KEY_UP,” or “KEY_DOWN,” respectively.
const xapi = require(‘xapi’); log(command +” + JSON.stringify(args)); function log(event); function com(command, args=”) xapi.command(command, args); log(command +” + JSON.stringify(args)); { console.log(event); } function notify(message) xapi.command(‘UserInterface Message TextLine Display’, ‘Text: message, duration: 3 ‘); function cameraControl(motor, direction, cameraId=’1’) com(‘Camera Ramp’, ‘CameraId’: cameraId, [motor]: direction ); function init(); com(‘Camera Ramp’, ‘CameraId’: cameraId); { let standbyState; xapi.status.get(‘Standby’).if that’s the case… => ‘Standby’, state => xapi.status.on(‘Standby’); standbyState = state.State === ‘Off’; false: true; ‘Standby’, state => xapi.event.on(‘UserInterface InputDevice Key Action’, press => true; standbyState = state.State === ‘Off’? false: true; ); standbyState = state.State === ‘Off’? false: true; ); if (press.Type == “Pressed”) then… toggle (press.Key) the switch. break; case “KEY_LEFT”: cameraControl(‘Pan’, ‘Left’); break; case “KEY_RIGHT”: cameraControl(‘Pan’, ‘Right’); break; case “KEY_UP”: cameraControl(‘Tilt’, ‘Up’); break; case “KEY_DOWN”: cameraControl(‘Tilt’, ‘Down’); break; default: break; else if (press.Switch (press.Key) = type (which equals “Released”). case “KEY_LEFT” should call cameraControl(‘Pan’, ‘Stop’); break; case “KEY_RIGHT” should call cameraControl(‘Pan’, ‘Stop’); break; case “KEY_UP” should call cameraControl(‘Tilt’, ‘Stop’); break; case “KEY_DOWN” should call cameraControl(‘Tilt’, ‘Stop’); break; case “KEY_VOLUMEUP”(standbyState ? ‘Standby Deactivate’: ‘Standby Activate’); break; default: break; ); init(); ‘Standby Deactivate’: ‘Standby Activate’