From b593fd56ffa8e6d065322864266de9112cf5fa07 Mon Sep 17 00:00:00 2001 From: Hank Date: Tue, 5 Jul 2022 10:51:38 +0200 Subject: [PATCH 1/5] hidcam: Bangle.js 2 support --- apps/hidcam/ChangeLog | 1 + apps/hidcam/README.md | 2 +- apps/hidcam/app.js | 47 ++++++++++++++++++++++++--------------- apps/hidcam/metadata.json | 4 ++-- 4 files changed, 33 insertions(+), 21 deletions(-) diff --git a/apps/hidcam/ChangeLog b/apps/hidcam/ChangeLog index 480d7d448..4a3ba28b8 100644 --- a/apps/hidcam/ChangeLog +++ b/apps/hidcam/ChangeLog @@ -1,3 +1,4 @@ 0.01: Core functionnality 0.02: Offer to enable HID if disabled 0.03: Adds Readme and tags to be used by App Loader +0.04: Adds Bangle.js 2 support diff --git a/apps/hidcam/README.md b/apps/hidcam/README.md index 5e8d40817..fa8e0153b 100644 --- a/apps/hidcam/README.md +++ b/apps/hidcam/README.md @@ -7,7 +7,7 @@ Control the camera shutter from your phone using your watch 1. In settings, enable HID for "Keyboard & Media". 2. Pair your watch to your phone. 3. Load your camera app on your phone. -4. There you go, launch the app on your watch and press button 2 to trigger the shutter ! +4. There you go, launch the app on your watch and press the button (button 2 on Bangle.js 1) to trigger the shutter ! ## How does it work ? diff --git a/apps/hidcam/app.js b/apps/hidcam/app.js index bb8ddf7e9..cedd278f0 100644 --- a/apps/hidcam/app.js +++ b/apps/hidcam/app.js @@ -1,25 +1,29 @@ var storage = require('Storage'); const settings = storage.readJSON('setting.json',1) || { HID: false }; - +const isB2 = process.env.HWVERSION === 2; var sendHid, camShot, profile; if (settings.HID=="kbmedia") { profile = 'camShutter'; sendHid = function (code, cb) { - try { - NRF.sendHIDReport([1,code], () => { - NRF.sendHIDReport([1,0], () => { - if (cb) cb(); - }); - }); - } catch(e) { - print(e); - } + + try { + NRF.sendHIDReport([1,code], () => { + NRF.sendHIDReport([1,0], () => { + if (cb) cb(); + }); + }); + } catch(e) { + print(e); + } + }; camShot = function (cb) { sendHid(0x80, cb); }; } else { + E.showPrompt("Enable HID?",{title:"HID disabled"}).then(function(enable) { + if (enable) { settings.HID = "kbmedia"; require("Storage").write('setting.json', settings); @@ -46,12 +50,19 @@ function drawApp() { g.fillRect(180,130, 240, 124); } -if (camShot) { - setWatch(function(e) { - E.showMessage('camShot !'); - setTimeout(drawApp, 1000); - camShot(() => {}); - }, BTN2, { edge:"falling",repeat:true,debounce:50}); - + if (camShot) { + if (!isB2) { // Bangle.js 1 + setWatch(function(e) { + E.showMessage('camShot !'); + setTimeout(drawApp, 1000); + camShot(() => {}); + }, BTN2, { edge:"falling",repeat:true,debounce:50}); + } else { // Bangle.js 2 + setWatch(function(e) { + E.showMessage('camShot !'); + setTimeout(drawApp, 1000); + camShot(() => {}); + }, BTN, { edge:"falling",repeat:true,debounce:50}); + } drawApp(); -} + } diff --git a/apps/hidcam/metadata.json b/apps/hidcam/metadata.json index b2ef33229..b57d41ed1 100644 --- a/apps/hidcam/metadata.json +++ b/apps/hidcam/metadata.json @@ -2,11 +2,11 @@ "id": "hidcam", "name": "Camera shutter", "shortName": "Cam shutter", - "version": "0.03", + "version": "0.04", "description": "Enable HID, connect to your phone, start your camera and trigger the shot on your Bangle", "icon": "app.png", "tags": "bluetooth,tool", - "supports": ["BANGLEJS"], + "supports": ["BANGLEJS","BANGLEJS2"], "readme": "README.md", "storage": [ {"name":"hidcam.app.js","url":"app.js"}, From ba186c24630a2479eebeba49bf95965720e31957 Mon Sep 17 00:00:00 2001 From: Hank Date: Tue, 5 Jul 2022 10:53:52 +0200 Subject: [PATCH 2/5] Fix tabs --- apps/hidcam/app.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/hidcam/app.js b/apps/hidcam/app.js index cedd278f0..1564578b8 100644 --- a/apps/hidcam/app.js +++ b/apps/hidcam/app.js @@ -23,7 +23,7 @@ if (settings.HID=="kbmedia") { } else { E.showPrompt("Enable HID?",{title:"HID disabled"}).then(function(enable) { - + if (enable) { settings.HID = "kbmedia"; require("Storage").write('setting.json', settings); @@ -57,7 +57,7 @@ function drawApp() { setTimeout(drawApp, 1000); camShot(() => {}); }, BTN2, { edge:"falling",repeat:true,debounce:50}); - } else { // Bangle.js 2 + } else { // Bangle.js 2 setWatch(function(e) { E.showMessage('camShot !'); setTimeout(drawApp, 1000); From 6fddc24d6044cfd7dfa169f330d1d31003b771d8 Mon Sep 17 00:00:00 2001 From: Hank Date: Tue, 5 Jul 2022 12:03:53 +0200 Subject: [PATCH 3/5] Enabled tap; fixed image position --- apps/hidcam/app.js | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/apps/hidcam/app.js b/apps/hidcam/app.js index 1564578b8..c5b58ced7 100644 --- a/apps/hidcam/app.js +++ b/apps/hidcam/app.js @@ -35,10 +35,15 @@ function drawApp() { g.clear(); Bangle.loadWidgets(); Bangle.drawWidgets(); - g.fillCircle(122,127,60); - g.drawImage(storage.read("hidcam.img"),100,105); - const d = g.getWidth() - 18; - + if (!isB2) { // Bangle.js 1 + g.fillCircle(122,127,60); + g.drawImage(storage.read("hidcam.img"),100,105); + const d = g.getWidth() - 18; + } else { + g.fillCircle(90,95,60); + g.drawImage(storage.read("hidcam.img"),65,70); + const d = g.getWidth() - 18; + } function c(a) { return { width: 8, @@ -54,15 +59,23 @@ function drawApp() { if (!isB2) { // Bangle.js 1 setWatch(function(e) { E.showMessage('camShot !'); + Bangle.buzz(300, 1); setTimeout(drawApp, 1000); camShot(() => {}); }, BTN2, { edge:"falling",repeat:true,debounce:50}); } else { // Bangle.js 2 setWatch(function(e) { E.showMessage('camShot !'); + Bangle.buzz(300, 1); setTimeout(drawApp, 1000); camShot(() => {}); }, BTN, { edge:"falling",repeat:true,debounce:50}); + Bangle.on('touch', function (wat, tap) { + E.showMessage('camShot !'); + Bangle.buzz(300, 1); + setTimeout(drawApp, 1000); + camShot(() => {}); + }); } drawApp(); } From e48bf9873951674c655f42f9628d3049a113f6ad Mon Sep 17 00:00:00 2001 From: Hank Date: Tue, 5 Jul 2022 12:05:17 +0200 Subject: [PATCH 4/5] Fix tabs --- apps/hidcam/app.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/hidcam/app.js b/apps/hidcam/app.js index c5b58ced7..639018db3 100644 --- a/apps/hidcam/app.js +++ b/apps/hidcam/app.js @@ -70,7 +70,7 @@ function drawApp() { setTimeout(drawApp, 1000); camShot(() => {}); }, BTN, { edge:"falling",repeat:true,debounce:50}); - Bangle.on('touch', function (wat, tap) { + Bangle.on('touch', function (wat, tap) { E.showMessage('camShot !'); Bangle.buzz(300, 1); setTimeout(drawApp, 1000); From 94aa001760016c6f6aa3759719ebf8f43f433186 Mon Sep 17 00:00:00 2001 From: Hank Date: Tue, 5 Jul 2022 12:14:19 +0200 Subject: [PATCH 5/5] Mod changelog --- apps/hidcam/ChangeLog | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/hidcam/ChangeLog b/apps/hidcam/ChangeLog index 4a3ba28b8..b0ba92aef 100644 --- a/apps/hidcam/ChangeLog +++ b/apps/hidcam/ChangeLog @@ -1,4 +1,4 @@ 0.01: Core functionnality 0.02: Offer to enable HID if disabled 0.03: Adds Readme and tags to be used by App Loader -0.04: Adds Bangle.js 2 support +0.04: Adds Bangle.js 2 support, Buzz and Touch