Skip to content

Commit f3655ef

Browse files
authored
Merge pull request #4025 from bobrippling/app/hidmouse
New app: hidmouse
2 parents d2d3595 + 3562eed commit f3655ef

File tree

6 files changed

+112
-1
lines changed

6 files changed

+112
-1
lines changed

apps/hidmouse/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Mouse
2+
3+
Connect to a computer, drag the screen to move your mouse. Tap or press the BangleJS2's button to left-click.
4+
5+
Note that HID must be enabled in settings for bluetooth devices to recognise the bangle as a mouse.

apps/hidmouse/app-icon.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apps/hidmouse/app.js

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
const mouse = require("ble_hid_mouse");
2+
const SENSITIVITY = 3;
3+
4+
// x, y, *wheel: -127 ..= 127
5+
const send = (x, y, btn, wheel, hwheel, cb) => {
6+
"ram";
7+
if(btn == null) btn = 0;
8+
if(wheel == null) wheel = 0;
9+
if(hwheel == null) hwheel = 0;
10+
11+
try{
12+
NRF.sendHIDReport([btn, x, y, wheel, hwheel, 0, 0, 0], function() {
13+
"ram";
14+
try{
15+
NRF.sendHIDReport([0, 0, 0, 0, 0, 0, 0, 0], function() {
16+
"ram";
17+
if(cb) cb();
18+
});
19+
}catch(e){
20+
if(cb) cb();
21+
}
22+
});
23+
}catch(e){
24+
if(cb) cb();
25+
}
26+
};
27+
28+
const tap = () => {
29+
send(0, 0, mouse.BUTTONS.LEFT);
30+
};
31+
32+
const initBLE = () => {
33+
NRF.setServices(undefined, { hid: mouse.report });
34+
};
35+
36+
const queue = {
37+
dx: 0,
38+
dy: 0,
39+
flushing: false,
40+
};
41+
42+
const flushQueue = () => {
43+
if(queue.flushing) return;
44+
queue.flushing = true;
45+
46+
const dx = queue.dx;
47+
const dy = queue.dy;
48+
queue.dx = 0;
49+
queue.dy = 0;
50+
51+
send(dx, dy, null, null, null, () => {
52+
queue.flushing = false;
53+
});
54+
};
55+
56+
const draw = () => {
57+
const W = Bangle.appRect.w;
58+
const H = Bangle.appRect.h;
59+
60+
g.clear();
61+
62+
const img = require("Storage").read("hidmouse.img");
63+
if (img) g.drawImage(img, W/2, H/2 - 20, {center: true});
64+
65+
g
66+
.setFont("6x8", 2)
67+
.setColor(1, 1, 1)
68+
.setFontAlign(0, -1, 0);
69+
70+
const connected = NRF.getSecurityStatus().connected;
71+
g.drawString(connected ? "Connected" : "Disconnected", W/2, H/2 + 40);
72+
};
73+
74+
Bangle.on("drag", e => { // e: x, y, dx, dy, b
75+
"ram";
76+
queue.dx += e.dx * SENSITIVITY;
77+
queue.dy += e.dy * SENSITIVITY;
78+
flushQueue();
79+
});
80+
81+
Bangle.on("tap", tap);
82+
83+
setWatch(tap, BTN, { edge: "rising", repeat: true, debounce: 50 });
84+
85+
initBLE();
86+
87+
NRF.on('connect', draw);
88+
NRF.on('disconnect', draw);
89+
draw();

apps/hidmouse/app.png

2.09 KB
Loading

apps/hidmouse/metadata.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"id": "hidmouse",
3+
"name": "BLE Mouse",
4+
"version": "0.01",
5+
"author": "bobrippling",
6+
"description": "A mouse app - use your watch as a bluetooth mouse",
7+
"icon": "app.png",
8+
"type": "app",
9+
"tags": "mouse,bluetooth,hid",
10+
"supports" : ["BANGLEJS2"],
11+
"readme": "README.md",
12+
"storage": [
13+
{"name": "hidmouse.app.js", "url": "app.js"},
14+
{"name": "hidmouse.img", "url": "app-icon.js", "evaluate": true}
15+
]
16+
}

apps/presentor/metadata.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"description": "Use your Bangle to present!",
66
"icon": "app.png",
77
"type": "app",
8-
"tags": "tool,bluetooth",
8+
"tags": "tool,bluetooth,mouse,hid",
99
"interface": "interface.html",
1010
"readme":"README.md",
1111
"supports": ["BANGLEJS", "BANGLEJS2"],

0 commit comments

Comments
 (0)