Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions apps/hidmouse/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Mouse

Connect to a computer, drag the screen to move your mouse. Tap or press the BangleJS2's button to left-click.
1 change: 1 addition & 0 deletions apps/hidmouse/app-icon.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

89 changes: 89 additions & 0 deletions apps/hidmouse/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
const mouse = require("ble_hid_mouse");
const SENSITIVITY = 3;

// x, y, *wheel: -127 ..= 127
const send = (x, y, btn, wheel, hwheel, cb) => {
"ram";
if(btn == null) btn = 0;
if(wheel == null) wheel = 0;
if(hwheel == null) hwheel = 0;

try{
NRF.sendHIDReport([btn, x, y, wheel, hwheel, 0, 0, 0], function() {
"ram";
try{
NRF.sendHIDReport([0, 0, 0, 0, 0, 0, 0, 0], function() {
"ram";
if(cb) cb();
});
}catch(e){
if(cb) cb();
}
});
}catch(e){
if(cb) cb();
}
};

const tap = () => {
send(0, 0, mouse.BUTTONS.LEFT);
};

const initBLE = () => {
NRF.setServices(undefined, { hid: mouse.report });
};

const queue = {
dx: 0,
dy: 0,
flushing: false,
};

const flushQueue = () => {
if(queue.flushing) return;
queue.flushing = true;

const dx = queue.dx;
const dy = queue.dy;
queue.dx = 0;
queue.dy = 0;

send(dx, dy, null, null, null, () => {
queue.flushing = false;
});
};

const draw = () => {
const W = Bangle.appRect.w;
const H = Bangle.appRect.h;

g.clear();

const img = require("Storage").read("hidmouse.img");
if (img) g.drawImage(img, W/2, H/2 - 20, {center: true});

g
.setFont("6x8", 2)
.setColor(1, 1, 1)
.setFontAlign(0, -1, 0);

const connected = NRF.getSecurityStatus().connected;
g.drawString(connected ? "Connected" : "Disconnected", W/2, H/2 + 40);
};

Bangle.on("drag", e => { // e: x, y, dx, dy, b
"ram";
queue.dx += e.dx * SENSITIVITY;
queue.dy += e.dy * SENSITIVITY;
flushQueue();
});

Bangle.on("tap", tap);

setWatch(tap, BTN, { edge: "rising", repeat: true, debounce: 50 });

initBLE();

NRF.on('connect', draw);
NRF.on('disconnect', draw);
draw();
Binary file added apps/hidmouse/app.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 16 additions & 0 deletions apps/hidmouse/metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"id": "hidmouse",
"name": "BLE Mouse",
"version": "0.01",
"author": "bobrippling",
"description": "A mouse app - use your watch as a bluetooth mouse",
"icon": "app.png",
"type": "app",
"tags": "mouse,bluetooth,hid",
"supports" : ["BANGLEJS2"],
"readme": "README.md",
"storage": [
{"name": "hidmouse.app.js", "url": "app.js"},
{"name": "hidmouse.img", "url": "app-icon.js", "evaluate": true}
]
}
2 changes: 1 addition & 1 deletion apps/presentor/metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"description": "Use your Bangle to present!",
"icon": "app.png",
"type": "app",
"tags": "tool,bluetooth",
"tags": "tool,bluetooth,mouse,hid",
"interface": "interface.html",
"readme":"README.md",
"supports": ["BANGLEJS", "BANGLEJS2"],
Expand Down