示例
list-menu反馈?

在此示例中,我们想向您展示如何使用第三方 USB 输入设备(在本例中为遥控器)的键来控制 Cisco 设备上的某些功能。

我们将向您展示如何使用 Bluetooth 遥控器(通过 USB 加密狗连接)上的按钮来管理待机、音量调整和 Cisco 摄像头设备控制等功能。 您可以开发一个宏,该宏侦听相关事件并通过 Cisco 设备的 API 执行相应的操作。

在下面的示例中,您必须输入以普通字体书写的文本。 斜体文本是从 Cisco 设备收到的响应。

1

在 SSH 上登录 Cisco 设备。 您需要本地 管理员 用户。

2

将设备配置为允许使用第三方 USB 远程控制。


       xConfiguration Peripherals InputDevice Mode: On 
      ** end OK  
               

 

您可以使用以下命令检查配置是“打开”还是“关闭”:


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

注册以获取反馈,以便在按下和松开遥控器按钮时收到通知。


       xFeedback Register /event/userinterface/inputdevice 
       ** end OK  
               

 

您可以使用以下命令检查设备注册了哪些反馈:


        xFeedback list 
       /event/userinterface/inputdevice ** end OK  
                  
4

按下并松开遥控器上的按钮以检查反馈注册是否正常工作。

此操作将生成两个事件:“ 已按下 ”和 “已发布”。 如果按住某个按钮,则会看到 Pressed 事件,直到您松开该按钮。 然后生成已发布 事件。

按下并释放 Enter 键时会引发以下事件:

 
                   *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

编写一个宏,用于侦听相关的 InputDevice 事件,并使用设备的 API 执行关联的操作。

  • 使待机、调高音量和调低音量按钮栩栩如生。 当宏看到包含 KEY_VOLUMEUP、KEY_VOLUMEDOWN 或 KEY_SLEEP 的事件时,它会执行相关的命令。

  • 为箭头键创建相机控制功能。 只要按下按钮,我们就希望继续移动相机。 松开按钮后,摄像机将停止移动。 当宏看到包含 KEY_LEFT、KEY_RIGHT、KEY_UP 或 KEY_DOWN 的事件时,它会执行相关的命令。


       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(); 
     
这篇文章对您有帮助吗?
这篇文章对您有帮助吗?