例子:冰狐脚本调用BleClient和蓝牙HID硬件通信 function main() { // 参数为蓝牙硬件中对应的service的uuid和characteristic的UUID,这个值一般是固定的 var ret = ble.connect('fe2342e1-d234-fee3-aae4-fe2e342211dc', 'cf3432fb-d234-fee3-aae4-fe2e342211dc'); console.log('ret:', ret) if (1 == ret) { bleHome(); } } function bleRelease() { var cmd = 'v'; console.log('cmd:' + cmd) var ret = ble.send(cmd) console.log('send ret:', ret) } function bleMove(x, y) { x = parseInt(x * 10000 / rsScreenWidth); y = parseInt(y * 10000 / rsScreenHeight); var cmd = `e${x},${y}`; console.log('cmd:' + cmd) var ret = ble.send(cmd) console.log('send ret:', ret) } function bleClick(x, y, duration) { x = parseInt(x * 10000 / rsScreenWidth); y = parseInt(y * 10000 / rsScreenHeight); if (null == duration) { duration = 200 } var cmd = `c${x},${y},${duration}`; console.log('cmd:' + cmd) var ret = ble.send(cmd) console.log('send ret:', ret) } // curvable为1表示模拟真人曲线滑动,0表示直线滑动,默认为1. function bleSwipe(x1, y1, x2, y2, duration, curvable) { x1 = parseInt(x1 * 10000 / rsScreenWidth); y1 = parseInt(y1 * 10000 / rsScreenHeight); x2 = parseInt(x2 * 10000 / rsScreenWidth); y2 = parseInt(y2 * 10000 / rsScreenHeight); if (null == duration) { duration = 500; } if (null == curvable) { curvable = 1; } var cmd = `m${x1},${y1},${x2},${y2},${duration},${curvable}`; console.log('cmd:' + cmd) var ret = ble.send(cmd) console.log('send ret:', ret) } function bleSelectAll() { var ret = ble.send('s') console.log('send ret:', ret) } function bleCopy() { var ret = ble.send('o') console.log('send ret:', ret) } function bleCut() { var ret = ble.send('t') console.log('send ret:', ret) } function blePaste() { var ret = ble.send('p') console.log('send ret:', ret) } function bleHome() { var ret = ble.send('h') console.log('send ret:', ret) } function bleBack() { var ret = ble.send('b') console.log('send ret:', ret) }
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
serviceUUID | string | 必填 | 服务的uuid |
characteristicUUID | string | 必填 | characteristic的UUID |
name | string | 选填 | 设备名,可以为部分设备名,比如设备名的前缀等。默认为空 |
timeout | integer | 选填 | 超时时间,单位毫秒,默认值3000 |
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
data | string/byte array | 必填 | 数据 |
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
timeout | integer | 选填 | 超时时间,单位毫秒,默认值10000 |