Skip to content

Commit

Permalink
uuid
Browse files Browse the repository at this point in the history
  • Loading branch information
arsize committed Jan 26, 2021
1 parent 71ff0d3 commit fd90478
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 21 deletions.
31 changes: 10 additions & 21 deletions utils/btls/ble.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import errToString from "./error"
const tools = require("./tools")

const PRINT_SHOW = true //开启流程展示

Expand All @@ -21,12 +22,7 @@ class BLE {
}
showline(`初始化成功!`)

let [search_err, search] = await _startSearch.call(this)
if (search_err != null) {
showline(`搜寻设备失败!${search_err}`)
return
}
showline(`搜索成功,得到结果`, search)
_startSearch.call(this)
}
}

Expand All @@ -45,23 +41,16 @@ function _openAdapter() {
*/
function _startSearch() {
showline(`准备搜寻附近的蓝牙外围设备...`)
return promisify("wx.startBluetoothDevicesDiscovery", {
services: [this.uuid]
}).then(
res => [null, res],
err => [err, null]
)
}
function promisify(fn, args) {
return new Promise((resolve, reject) => {
fn({
...(args || {}),
success: res => resolve(res),
fail: err => reject(err)
});
});
return tools.promisify(wx.startBluetoothDevicesDiscovery, {
services: [this.uuid],
}).then(res => {
console.log('ok')
}, err => {
console.log('not ok', err)
})
}


function showline(str) {
PRINT_SHOW ? console.log(str) : null
}
Expand Down
Empty file added utils/btls/test.js
Empty file.
14 changes: 14 additions & 0 deletions utils/btls/tools.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
function promisify(fn, args) {
return new Promise((resolve, reject) => {
fn({
...args || {},
success: res => resolve(res),
fail: err => reject(err)
});
});

}

module.exports = {
promisify: promisify
}

0 comments on commit fd90478

Please sign in to comment.