diff --git a/apps/hidmouse/README.md b/apps/hidmouse/README.md new file mode 100644 index 0000000000..92b5264cc2 --- /dev/null +++ b/apps/hidmouse/README.md @@ -0,0 +1,5 @@ +# Mouse + +Connect to a computer, drag the screen to move your mouse. Tap or press the BangleJS2's button to left-click. + +Note that HID must be enabled in settings for bluetooth devices to recognise the bangle as a mouse. diff --git a/apps/hidmouse/app-icon.js b/apps/hidmouse/app-icon.js new file mode 100644 index 0000000000..500ffd5691 --- /dev/null +++ b/apps/hidmouse/app-icon.js @@ -0,0 +1 @@ +require("heatshrink").decompress(atob("mEwxH+ACXXABAdTFjAyiEQusABAyeFotWlavHldWGIpccFpAxEMTKvGFwRVBAA1WGATGXC42BEQOBdhINKFyvXKQKCHTg1WBY4uU1iNCFxI+DgA+IFySADLxQ/OFyJ/LT6ReTdpQRQFx6uDwOsABgvCOJSNOFwQATqyRNXhQAWYRIvLLoVWRpOCmgABrGCSIYXDF5ReKVJXXxLVLMBYvIdYQjJ1utBZLzCF6rXJ1uDwYwJDJYuICpRbBFoIADMY5JMF6OtxIoBAA4ZKfIIvXEoZdBBQgZJ1krehIvOAgYvRSh4v/F9PRYg/RF8uD05dBAAYGBd8pfB1unL4ICBL5gFBFxqPNFIKVFDJoAD/y/VAAhfMFwwvREow5JF73X04SHBAwvNGA4VCwInNG4+BF5IuCF5ErgFWLBCJBSoJmIq0AlYvSCwQwBwOsAAuCwV8wQKGwIXDRxRgLACxeMGBVWGKkrqwuOSJBiDlaSHRgoQCFo4vJGBOBJwIeJIAa7KFxIwJD5g/OFxQwJqx/LT4Y+IFxgwIKAWBLxgNHFxwwIKIJSBdo5sBNoIuXGA6CCABScHFyQxHKoIxIlZpBFrRiJABBcbYxoAIFjgyPDiQ=")) diff --git a/apps/hidmouse/app.js b/apps/hidmouse/app.js new file mode 100644 index 0000000000..2adf441246 --- /dev/null +++ b/apps/hidmouse/app.js @@ -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(); diff --git a/apps/hidmouse/app.png b/apps/hidmouse/app.png new file mode 100644 index 0000000000..f9d6cb547e Binary files /dev/null and b/apps/hidmouse/app.png differ diff --git a/apps/hidmouse/metadata.json b/apps/hidmouse/metadata.json new file mode 100644 index 0000000000..e59ed9ac0a --- /dev/null +++ b/apps/hidmouse/metadata.json @@ -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} + ] +} diff --git a/apps/presentor/metadata.json b/apps/presentor/metadata.json index 0edc07f2bc..362f036eef 100644 --- a/apps/presentor/metadata.json +++ b/apps/presentor/metadata.json @@ -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"],