在此範例中,我們將向您展示如何使用第三方 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 執行關聯的操作。
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();
|