Skip to content

Commit

Permalink
feat(hci): added missing reset function (#4)
Browse files Browse the repository at this point in the history
* chore(actions): on pull request

* fix(prebuildify):  patch only on cross

* feat(hci): added missing reset function

* fix(hci): cleanup reset

---------

Co-authored-by: Marek Serafin <[email protected]>
  • Loading branch information
stoprocent and Marek Serafin authored Sep 27, 2024
1 parent 6037396 commit 67869a7
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
5 changes: 2 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
name: Build
on:
push:
branches:
- main
- beta
pull_request:
concurrency:
group: build-${{ github.ref }}
cancel-in-progress: false
Expand Down Expand Up @@ -60,6 +58,7 @@ jobs:
needs: prebuild
name: Release
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main'
steps:
- uses: actions/checkout@v4
- uses: actions/download-artifact@v4
Expand Down
12 changes: 12 additions & 0 deletions lib/native.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ const { BluetoothHciSocket } = require('node-gyp-build')(dir);

inherits(BluetoothHciSocket, events.EventEmitter);

const HCI_COMMAND_PKT = 0x01;
const OGF_HOST_CTL = 0x03;
const OCF_RESET = 0x0003;

class BluetoothHciSocketWrapped extends BluetoothHciSocket {
start () {
if (this._timer) {
Expand All @@ -22,6 +26,14 @@ class BluetoothHciSocketWrapped extends BluetoothHciSocket {
clearInterval(this._timer);
return super.stop();
}

reset () {
const cmd = Buffer.alloc(4);
cmd.writeUInt8(HCI_COMMAND_PKT, 0);
cmd.writeUInt16LE(OCF_RESET | OGF_HOST_CTL << 10, 1);
cmd.writeUInt8(0x00, 3);
this.write(cmd);
}
}

// extend prototype
Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,10 @@
},
"scripts": {
"install": "node-gyp-build",
"postinstall": "patch-package",
"lint": "eslint \"**/*.js\"",
"lint-fix": "eslint \"**/*.js\" --fix",
"prebuildify": "prebuildify --napi --target 17.0.0 --force --strip --verbose",
"prebuildify-cross": "prebuildify-cross --napi --target 17.0.0 --force --strip --verbose",
"prebuildify-cross": "patch-package && prebuildify-cross --napi --target 17.0.0 --force --strip --verbose",
"semantic-release": "semantic-release",
"pretest": "npm run rebuild",
"rebuild": "node-gyp rebuild",
Expand Down

0 comments on commit 67869a7

Please sign in to comment.