Skip to content

Commit 90b7b74

Browse files
authored
Create ble_hid_mouse.js
Bluetooth HID mouse
1 parent 5f60421 commit 90b7b74

File tree

1 file changed

+70
-0
lines changed

1 file changed

+70
-0
lines changed

modules/ble_hid_mouse.js

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/* Copyright (c) 2018 Derek Arthur, Durnaford Ltd. Derived from the works of Gordon Williams, Pur3 Ltd. See the file LICENSE for copying permission. */
2+
/*
3+
Usage:
4+
var mouse = require("ble_hid_mouse");
5+
NRF.setServices(undefined, { hid : mouse.report });
6+
mouse.send(0,0,mouse.BUTTONS.LEFT); // X movement, Y movement, buttons pressed
7+
*/
8+
9+
exports.report = new Uint8Array([
10+
0x05, 0x01,
11+
0x09, 0x02,
12+
0xA1, 0x01,
13+
0x09, 0x01,
14+
15+
0xA1, 0x00,
16+
0x05, 0x09,
17+
0x19, 0x01,
18+
0x29, 0x03,
19+
20+
0x15, 0x00,
21+
0x25, 0x01,
22+
0x95, 0x03,
23+
0x75, 0x01,
24+
25+
0x81, 0x02,
26+
0x95, 0x01,
27+
0x75, 0x05,
28+
0x81, 0x01,
29+
30+
0x05, 0x01,
31+
0x09, 0x30,
32+
0x09, 0x31,
33+
0x09, 0x38,
34+
35+
0x15, 0x81,
36+
0x25, 0x7F,
37+
0x75, 0x08,
38+
0x95, 0x03,
39+
40+
0x81, 0x06,
41+
0xC0, 0x09,
42+
0x3c, 0x05,
43+
0xff, 0x09,
44+
45+
0x01, 0x15,
46+
0x00, 0x25,
47+
0x01, 0x75,
48+
0x01, 0x95,
49+
50+
0x02, 0xb1,
51+
0x22, 0x75,
52+
0x06, 0x95,
53+
0x01, 0xb1,
54+
55+
0x01, 0xc0 ]
56+
);
57+
58+
exports.BUTTONS = {
59+
NONE : 0,
60+
LEFT : 1,
61+
RIGHT : 2,
62+
MIDDLE : 4
63+
};
64+
exports.send = function(x,y,b, callback) {
65+
NRF.sendHIDReport([b,x,y,0,0,0,0,0], function() {
66+
NRF.sendHIDReport([0,0,0,0,0,0,0,0], function() {
67+
if (callback) callback();
68+
});
69+
});
70+
};

0 commit comments

Comments
 (0)