We show how to use the keys of a Bluetooth remote control (with a USB dongle) to control the standby function, increase and decrease the volume, and control the camera of a room or desk device. We create a macro that listens for relevant events, and carries out the associated actions using the API of the room or desk device.

The Third-Party USB Input Device feature is described in this article.

In the following example, you must enter the text that is written in normal font. The text in italics is the response that is received from the room or desk device.

1

Sign in to the room or desk device on SSH. You need a local admin user.

2

Configure the device to allow the use of a third-party USB remote control.

xConfiguration Peripherals InputDevice Mode: On
** end

OK

               

 

You can check if the configuration is On or Off by using this command:

xConfiguration Peripherals InputDevice Mode
*c xConfiguration Peripherals InputDevice Mode: On
** end

OK

                  
3

Register for feedback, so that we are notified when the remote control buttons are pressed and released.

xFeedback Register /event/userinterface/inputdevice
** end

OK

               

 

You can check which feedbacks the device is registered for using this command:

xFeedback list
/event/userinterface/inputdevice
** end

OK

                  
4

Press and release a button on the remote control to check that feedback registration works.

This action generates two events: Pressed and Released. If you press and hold a button, you see the Pressed event until you release the button. Then the Released event is generated.

These events are issued when pressing and releasing the Enter key:

 
                  
*e UserInterface InputDevice Key Action Key: KEY_ENTER
*e UserInterface InputDevice Key Action Code: 28
*e UserInterface InputDevice Key Action Type: Pressed
** end
*e UserInterface InputDevice Key Action Key: KEY_ENTER
*e UserInterface InputDevice Key Action Code: 28
*e UserInterface InputDevice Key Action Type: Released
** end

               
5

Write a macro that listens for the relevant InputDevice events, and carries out the associated actions using the API of the device.

  • Bring the standby, volume up and volume down buttons to life. When the macro sees an event containing KEY_VOLUMEUP, KEY_VOLUMEDOWN, or KEY_SLEEP, it executes the related commands.

  • Create a camera control function for the arrow keys. We want to keep moving the camera as long as the button is pressed. When the button is released, the camera movement stops. When the macro sees an event containing KEY_LEFT, KEY_RIGHT, KEY_UP, or KEY_DOWN, it executes the related commands.

const xapi = require('xapi');

function com(command, args='') {
  xapi.command(command, args);
  log(command + ' ' + JSON.stringify(args));
}

function log(event) {
  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() {
  let standbyState;
  xapi.status.get('Standby').then((state) => {standbyState = state.State === 'Off' ? false : true; });
  xapi.status.on('Standby', state => {
      standbyState = state.State === 'Off' ? false : true; 
  });
  
  xapi.event.on('UserInterface InputDevice Key Action', press => {
    if (press.Type == "Pressed") {
      switch (press.Key) {
        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.Type == "Released") {
        switch (press.Key) {
          case "KEY_LEFT":
            cameraControl('Pan', 'Stop');
          break;
          case "KEY_RIGHT":
            cameraControl('Pan', 'Stop');
          break;
          case "KEY_UP":
            cameraControl('Tilt', 'Stop');
          break;
          case "KEY_DOWN":
            cameraControl('Tilt', 'Stop');
          break;
          case 'KEY_VOLUMEUP':
            com('Audio Volume Increase');
            break;
          case 'KEY_VOLUMEDOWN':
            com('Audio Volume Decrease');
            break;
          case 'KEY_SLEEP':
            com(standbyState ? 'Standby Deactivate' : 'Standby Activate');
            break;
          default:
            break;
          }
      } 
  });
}

init();