From 77edfe693691df6d21443d99ae71aea620973567 Mon Sep 17 00:00:00 2001 From: 7kasper Date: Tue, 28 Nov 2023 19:30:12 +0100 Subject: [PATCH 01/11] Code cleanup + windows 11 support --- apps/presentor/app.js | 151 +++++++---------------------------- apps/presentor/metadata.json | 2 +- 2 files changed, 31 insertions(+), 122 deletions(-) diff --git a/apps/presentor/app.js b/apps/presentor/app.js index 6b7450a0c..ec9d41258 100644 --- a/apps/presentor/app.js +++ b/apps/presentor/app.js @@ -1,80 +1,12 @@ // Presentor by 7kasper (Kasper Müller) -// Version 3.0 - -const SpecialReport = new Uint8Array([ - 0x05, 0x01, // USAGE_PAGE (Generic Desktop) - 0x09, 0x02, // USAGE (Mouse) - 0xa1, 0x01, // COLLECTION (Application) - 0x85, 0x01, // REPORT_ID (1) - 0x09, 0x01, // USAGE (Pointer) - 0xa1, 0x00, // COLLECTION (Physical) - 0x05, 0x09, // USAGE_PAGE (Button) - 0x19, 0x01, // USAGE_MINIMUM (Button 1) - 0x29, 0x05, // USAGE_MAXIMUM (Button 5) - 0x15, 0x00, // LOGICAL_MINIMUM (0) - 0x25, 0x01, // LOGICAL_MAXIMUM (1) - 0x95, 0x05, // REPORT_COUNT (5) - 0x75, 0x01, // REPORT_SIZE (1) - 0x81, 0x02, // INPUT (Data,Var,Abs) - 0x95, 0x01, // REPORT_COUNT (1) - 0x75, 0x03, // REPORT_SIZE (3) - 0x81, 0x03, // INPUT (Cnst,Var,Abs) - 0x05, 0x01, // USAGE_PAGE (Generic Desktop) - 0x09, 0x30, // USAGE (X) - 0x09, 0x31, // USAGE (Y) - 0x09, 0x38, // USAGE (Wheel) - 0x15, 0x81, // LOGICAL_MINIMUM (-127) - 0x25, 0x7f, // LOGICAL_MAXIMUM (127) - 0x75, 0x08, // REPORT_SIZE (8) - 0x95, 0x03, // REPORT_COUNT (3) - 0x81, 0x06, // INPUT (Data,Var,Rel) - 0x05, 0x0c, // USAGE_PAGE (Consumer Devices) - 0x0a, 0x38, 0x02, // USAGE (AC Pan) - 0x15, 0x81, // LOGICAL_MINIMUM (-127) - 0x25, 0x7f, // LOGICAL_MAXIMUM (127) - 0x75, 0x08, // REPORT_SIZE (8) - 0x95, 0x01, // REPORT_COUNT (1) - 0x81, 0x06, // INPUT (Data,Var,Rel) - 0xc0, // END_COLLECTION - 0xc0, // END_COLLECTION - 0x05, 0x01, // USAGE_PAGE (Generic Desktop) - 0x09, 0x06, // USAGE (Keyboard) - 0xa1, 0x01, // COLLECTION (Application) - 0x85, 0x02, // REPORT_ID (2) - 0x05, 0x07, // USAGE_PAGE (Keyboard) - 0x19, 0xe0, // USAGE_MINIMUM (Keyboard LeftControl) - 0x29, 0xe7, // USAGE_MAXIMUM (Keyboard Right GUI) - 0x15, 0x00, // LOGICAL_MINIMUM (0) - 0x25, 0x01, // LOGICAL_MAXIMUM (1) - 0x75, 0x01, // REPORT_SIZE (1) - 0x95, 0x08, // REPORT_COUNT (8) - 0x81, 0x02, // INPUT (Data,Var,Abs) - 0x75, 0x08, // REPORT_SIZE (8) - 0x95, 0x01, // REPORT_COUNT (1) - 0x81, 0x01, // INPUT (Cnst,Ary,Abs) - 0x19, 0x00, // USAGE_MINIMUM (Reserved (no event indicated)) - 0x29, 0x73, // USAGE_MAXIMUM (Keyboard F24) - 0x15, 0x00, // LOGICAL_MINIMUM (0) - 0x25, 0x73, // LOGICAL_MAXIMUM (115) - 0x95, 0x05, // REPORT_COUNT (5) - 0x75, 0x08, // REPORT_SIZE (8) - 0x81, 0x00, // INPUT (Data,Ary,Abs) - 0xc0 // END_COLLECTION -]); - -const MouseButton = { - NONE : 0, - LEFT : 1, - RIGHT : 2, - MIDDLE : 4, - BACK : 8, - FORWARD: 16 -}; - -const kb = require("ble_hid_keyboard"); +// Version 4.0 +// Imports +const bt = require("ble_hid_combo"); const Layout = require("Layout"); const Locale = require("locale"); + +// App Layout let mainLayout = new Layout({ 'type': 'v', filly: 1, @@ -174,7 +106,7 @@ let ptimers = []; function delay(t, v) { return new Promise((resolve) => { - setTimeout(resolve, t) + setTimeout(resolve, t); }); } @@ -289,56 +221,34 @@ function doPPart(r) { drawMainFrame(); } -NRF.setServices(undefined, { hid : SpecialReport }); -// TODO: figure out how to detect HID. +// Turn on Bluetooth as presentor. +NRF.setServices(undefined, { hid : bt.report }); NRF.on('HID', function() { - HIDenabled = true; + if (!HIDenabled) { + Bangle.buzz(200); + HIDenabled = true; + } }); - -function moveMouse(x,y,b,wheel,hwheel,callback) { - if (!HIDenabled) return; - if (!b) b = 0; - if (!wheel) wheel = 0; - if (!hwheel) hwheel = 0; - NRF.sendHIDReport([1,b,x,y,wheel,hwheel,0,0], function() { - if (callback) callback(); - }); -} +// +NRF.setAdvertising([ + {}, // include original Advertising packet + [ // second packet containing 'appearance' + 2, 1, 6, // standard Bluetooth flags + 3,3,0x12,0x18, // HID Service + 3,0x19,0xCA,0x03 // Appearance: Presentation Remote + ] +]); // function getSign(x) { // return ((x > 0) - (x < 0)) || +x; // } -function scroll(wheel,hwheel,callback) { - moveMouse(0,0,0,wheel,hwheel,callback); -} - -// Single click a certain button (immidiatly release). -function clickMouse(b, callback) { - if (!HIDenabled) return; - NRF.sendHIDReport([1,b,0,0,0,0,0,0], function() { - NRF.sendHIDReport([1,0,0,0,0,0,0,0], function() { - if (callback) callback(); - }); - }); -} - -function pressKey(keyCode, modifiers, callback) { - if (!HIDenabled) return; - if (!modifiers) modifiers = 0; - NRF.sendHIDReport([2, modifiers,0,keyCode,0,0,0,0], function() { - NRF.sendHIDReport([2,0,0,0,0,0,0,0], function() { - if (callback) callback(); - }); - }); -} - function handleAcc(acc) { let rRoll = acc.y * -50; let rPitch = acc.x * -100; if (mCal > 10) { //console.log("x: " + (rRoll - homeRoll) + " y:" + (rPitch - homePitch)); - moveMouse(acc.y * -50 - homeRoll, acc.x * -100 - homePitch); + bt.moveMouse(acc.y * -50 - homeRoll, acc.x * -100 - homePitch); } else { //console.log("homeroll: " +homeRoll +"homepitch: " + homePitch); homeRoll = rRoll * 0.7 + homeRoll * 0.3; @@ -354,7 +264,7 @@ Bangle.on('lock', function(on) { }); function startHolding() { - pressKey(kb.KEY.F10); + bt.tapKey(bt.KEY.F10); holding = true; Bangle.buzz(); E.showMessage('Holding'); @@ -362,9 +272,9 @@ function startHolding() { Bangle.setLCDPower(1); } function stopHolding() { - clearTimeout(timeoutId); + clearTimeout(startHolding); if (holding) { - pressKey(kb.KEY.F10); + bt.tapKey(bt.KEY.F10); homePitch = 0; homeRoll = 0; holding = false; @@ -395,7 +305,7 @@ Bangle.on('drag', function(e) { //let qX = getSign(difX) * Math.pow(Math.abs(difX), 1.2); //let qY = getSign(difY) * Math.pow(Math.abs(difY), 1.2); let qX = difX + 0.02 * vX, qY = difY + 0.02 * vY; - moveMouse(qX, qY, 0, 0, 0, function() { + bt.moveMouse(qX, qY, 0, 0, 0, function() { setTimeout(function() {clearToSend = true;}, 50); }); lastx = e.x; @@ -406,12 +316,12 @@ Bangle.on('drag', function(e) { if (!e.b) { // short press if (getTime() - cttl < 0.2) { - clickMouse(MouseButton.LEFT); + bt.clickButton(bt.BUTTON.LEFT); console.log("click left"); } // longer press in center else if (getTime() - cttl < 0.6 && e.x > g.getWidth()/4 && e.x < 3 * g.getWidth()/4 && e.y > g.getHeight() / 4 && e.y < 3 * g.getHeight() / 4) { - clickMouse(MouseButton.RIGHT); + bt.clickButton(bt.BUTTON.RIGHT); console.log("click right"); } cttl = 0; @@ -430,11 +340,11 @@ Bangle.on('drag', function(e) { } else if(lastx > 40){ // E.showMessage('right'); //kb.tap(kb.KEY.RIGHT, 0); - scroll(-1); + bt.scroll(-1); } else if(lastx < -40){ // E.showMessage('left'); //kb.tap(kb.KEY.LEFT, 0); - scroll(1); + bt.scroll(1); } else if(lastx==0 && lasty==0 && holding == false){ // E.showMessage('press'); clickMouse(MouseButton.LEFT); @@ -452,7 +362,6 @@ Bangle.on('drag', function(e) { } }); - function onBtn() { if (trackPadMode) { trackPadMode = false; diff --git a/apps/presentor/metadata.json b/apps/presentor/metadata.json index 2d0a22102..f0372ecdb 100644 --- a/apps/presentor/metadata.json +++ b/apps/presentor/metadata.json @@ -1,7 +1,7 @@ { "id": "presentor", "name": "Presentor", - "version": "0.08", + "version": "0.09", "description": "Use your Bangle to present!", "icon": "app.png", "type": "app", From 7c8daaa6aa5e4404705742c0f4c446c55435b604 Mon Sep 17 00:00:00 2001 From: 7kasper Date: Tue, 28 Nov 2023 19:34:38 +0100 Subject: [PATCH 02/11] also add changelog >.< --- apps/presentor/ChangeLog | 1 + 1 file changed, 1 insertion(+) diff --git a/apps/presentor/ChangeLog b/apps/presentor/ChangeLog index 807f41e79..b87be0bb4 100644 --- a/apps/presentor/ChangeLog +++ b/apps/presentor/ChangeLog @@ -6,3 +6,4 @@ 0.06: Initial internal git(hub) release. Added icon and such. 0.07: Begin work on presentation parts. 0.08: Presentation parts! +0.09: Code cleanup and windows 11 support. From fc50f3d14f16ff005590e98433814d46ddf2df9a Mon Sep 17 00:00:00 2001 From: 7kasper Date: Tue, 28 Nov 2023 19:52:04 +0100 Subject: [PATCH 03/11] First readme fix. --- apps/presentor/README.md | 66 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/apps/presentor/README.md b/apps/presentor/README.md index 8b22eb228..1b4ab1afc 100644 --- a/apps/presentor/README.md +++ b/apps/presentor/README.md @@ -1,2 +1,68 @@ # Presentor Use your Bangle to present! +This app basically turns your BangleJS watch into a presntor tool. +Very useful for presentations or when you are teaching a lesson. + +## Features: ++ Control your (powerpoint) slides by swiping left and right. ++ See pre-programmed presentation notes by swiping up and down. ++ See if you are on time in your presentation. ++ Get notified if you go over-time for a certain subject or the whole presentation. ++ Control cursor or spotlight in mouse mode (pressing the button). + +## Usage: +Here is a step by step guide (thanks Mu1) +1. If bluetooth connected to PC/laptop (check in bluetooth settings): +Select Bangle.js > Remove Device + +2. On your smartphone, in "Gadgetbridge", close connection by long-pressing "Bangle.js" + +3. Open banglejs.com/apps and select "Connect" (right upper corner) + +4. Select Bangle.js in blue bar in pop-up window and select "Connect" + +5. Search "Presentor" app and select diskette icon + +6. Select "Clear" to start making new notes. + +7. Fill the subjects, times in minutes (seconds optional) and Notes (optional) +The subject/times are on your watch displayed in a tall font, the notes in a very small font + +8. Select "Save" and exit the pop-up window + +9. Select "Disconnect" (right upper corner) + +10. Open the Presentor app. This will start the correct HID service as well. + +11. Open "Bluetooth & other devices" screen on PC/laptop and select "+" to add a device + +12. Select "Bluetooth" and select Bangle.js +If "Try connecting your device again." is shown, switch PC/laptop bluetooth off and on again + +13. Start your presentation. +Swipe up to start timer for first subject +Swipe down to pause +Push button to switch between mouse mode and timer/presentation mode + +14. Timer function +Next subject: Swipe up +Previous subject: Swipe down +Pause timer: Swipe down to begin + +15. Presentation function +Next presentation slide: Swipe right or just touch +Previous presentation slide: Swipe left + +16. Mouse mode +Swipe to move pointer over the presentation screen +Note: sometimes "Holding" shows in Bangle screen (see Holding mode) + +17. Holding mode +In timer/presentation mode, hold one finger on your Bangle screen, point your arm foreward +Mouse up/down on screen: Tilt your hand up/down +Mouse left/right on screen: Rotate your hand counterclockwise/clockwise + +18. End of presentation? +Switch bluetooth PC/laptop off or see step 1 + +19. Re-activate smartphone bluetooth (incl. Gadgetbridge) \ No newline at end of file From 4db81c95ef7f599f14cce8df500a568344096f3e Mon Sep 17 00:00:00 2001 From: 7kasper Date: Tue, 28 Nov 2023 20:08:39 +0100 Subject: [PATCH 04/11] Do some bugfixes on presentor app. --- apps/presentor/ChangeLog | 1 + apps/presentor/README.md | 26 +++++++++++++------------- apps/presentor/app.js | 25 +++++++++++++++++-------- apps/presentor/metadata.json | 2 +- 4 files changed, 32 insertions(+), 22 deletions(-) diff --git a/apps/presentor/ChangeLog b/apps/presentor/ChangeLog index b87be0bb4..031b921b9 100644 --- a/apps/presentor/ChangeLog +++ b/apps/presentor/ChangeLog @@ -7,3 +7,4 @@ 0.07: Begin work on presentation parts. 0.08: Presentation parts! 0.09: Code cleanup and windows 11 support. +0.10: Bugfixes. diff --git a/apps/presentor/README.md b/apps/presentor/README.md index 1b4ab1afc..00e13b310 100644 --- a/apps/presentor/README.md +++ b/apps/presentor/README.md @@ -1,6 +1,6 @@ # Presentor Use your Bangle to present! -This app basically turns your BangleJS watch into a presntor tool. +This app basically turns your BangleJS watch into a presentor tool. Very useful for presentations or when you are teaching a lesson. ## Features: @@ -27,6 +27,7 @@ Select Bangle.js > Remove Device 7. Fill the subjects, times in minutes (seconds optional) and Notes (optional) The subject/times are on your watch displayed in a tall font, the notes in a very small font +Note: If you don't fill in any notes you can still save and the presentor will be for input only and not give any timing details. 8. Select "Save" and exit the pop-up window @@ -40,27 +41,26 @@ The subject/times are on your watch displayed in a tall font, the notes in a ver If "Try connecting your device again." is shown, switch PC/laptop bluetooth off and on again 13. Start your presentation. -Swipe up to start timer for first subject -Swipe down to pause -Push button to switch between mouse mode and timer/presentation mode + - Swipe up to start timer for first subject + - Swipe down to pause + - Push button to switch between mouse mode and timer/presentation mode 14. Timer function -Next subject: Swipe up -Previous subject: Swipe down -Pause timer: Swipe down to begin + - Next subject: Swipe up + - Previous subject: Swipe down + - Pause timer: Swipe down to begin 15. Presentation function -Next presentation slide: Swipe right or just touch -Previous presentation slide: Swipe left + - Next presentation slide: Swipe right or just touch + - Previous presentation slide: Swipe left 16. Mouse mode -Swipe to move pointer over the presentation screen -Note: sometimes "Holding" shows in Bangle screen (see Holding mode) + - Swipe to move pointer over the presentation screen 17. Holding mode In timer/presentation mode, hold one finger on your Bangle screen, point your arm foreward -Mouse up/down on screen: Tilt your hand up/down -Mouse left/right on screen: Rotate your hand counterclockwise/clockwise + - Mouse up/down on screen: Tilt your hand up/down + - Mouse left/right on screen: Rotate your hand counterclockwise/clockwise 18. End of presentation? Switch bluetooth PC/laptop off or see step 1 diff --git a/apps/presentor/app.js b/apps/presentor/app.js index ec9d41258..bd527539f 100644 --- a/apps/presentor/app.js +++ b/apps/presentor/app.js @@ -272,7 +272,7 @@ function startHolding() { Bangle.setLCDPower(1); } function stopHolding() { - clearTimeout(startHolding); + clearTimeout(timeoutHolding); if (holding) { bt.tapKey(bt.KEY.F10); homePitch = 0; @@ -282,9 +282,10 @@ function stopHolding() { Bangle.removeListener('accel', handleAcc); Bangle.buzz(); drawMain(); - } else { - timeoutId = setTimeout(drawMain, 1000); - } + } + // else { + // timeoutId = setTimeout(drawMain, 1000); + // } clearTimeout(timeoutHolding); timeoutHolding = -1; } @@ -345,10 +346,12 @@ Bangle.on('drag', function(e) { // E.showMessage('left'); //kb.tap(kb.KEY.LEFT, 0); bt.scroll(1); - } else if(lastx==0 && lasty==0 && holding == false){ - // E.showMessage('press'); - clickMouse(MouseButton.LEFT); - } + } + // Todo re-implement? Seems bit buggy or unnecessary for now. + // else if(lastx==0 && lasty==0 && holding == false){ + // // E.showMessage('press'); + // bt.clickButton(bt.BUTTON.LEFT); + // } stopHolding(); lastx = 0; lasty = 0; @@ -368,9 +371,15 @@ function onBtn() { stopHolding(); drawMain(); } else { + stopHolding(); clearToSend = true; trackPadMode = true; E.showMessage('Mouse'); + // Also skip drawing thingy for now. + if (timeoutDraw != -1) { + clearTimeout(timeoutDraw); + timeoutDraw = -1; + } } Bangle.buzz(); } diff --git a/apps/presentor/metadata.json b/apps/presentor/metadata.json index f0372ecdb..984ba39c6 100644 --- a/apps/presentor/metadata.json +++ b/apps/presentor/metadata.json @@ -1,7 +1,7 @@ { "id": "presentor", "name": "Presentor", - "version": "0.09", + "version": "0.10", "description": "Use your Bangle to present!", "icon": "app.png", "type": "app", From 1c160d773732e4ee5d85520c18c72751a1be8511 Mon Sep 17 00:00:00 2001 From: 7kasper Date: Tue, 28 Nov 2023 23:01:11 +0100 Subject: [PATCH 05/11] Little better readme --- apps/presentor/README.md | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/apps/presentor/README.md b/apps/presentor/README.md index 00e13b310..9f2a411e1 100644 --- a/apps/presentor/README.md +++ b/apps/presentor/README.md @@ -3,15 +3,15 @@ Use your Bangle to present! This app basically turns your BangleJS watch into a presentor tool. Very useful for presentations or when you are teaching a lesson. -## Features: +### Features: + Control your (powerpoint) slides by swiping left and right. + See pre-programmed presentation notes by swiping up and down. + See if you are on time in your presentation. -+ Get notified if you go over-time for a certain subject or the whole presentation. ++ Get notified if you go over-time for a certain subject. + Control cursor or spotlight in mouse mode (pressing the button). -## Usage: -Here is a step by step guide (thanks Mu1) +### Usage: +Here is a step by step guide (thanks mu1) 1. If bluetooth connected to PC/laptop (check in bluetooth settings): Select Bangle.js > Remove Device @@ -65,4 +65,8 @@ In timer/presentation mode, hold one finger on your Bangle screen, point your ar 18. End of presentation? Switch bluetooth PC/laptop off or see step 1 -19. Re-activate smartphone bluetooth (incl. Gadgetbridge) \ No newline at end of file +19. Re-activate smartphone bluetooth (incl. Gadgetbridge) + +### Creator +[7kasper](https://github.com/7kasper) +Issues or feature requests are welcome on my [Github](https://github.com/7kasper/BangleApps) or on the [Espruino Forums](https://forum.espruino.com/conversations/371443/)! \ No newline at end of file From 5a400480e00cf728012018097759b6e3c399609b Mon Sep 17 00:00:00 2001 From: 7kasper Date: Wed, 29 Nov 2023 00:18:59 +0100 Subject: [PATCH 06/11] Fix mousemove getting stuck. --- apps/presentor/ChangeLog | 1 + apps/presentor/app.js | 8 ++++++-- apps/presentor/metadata.json | 2 +- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/apps/presentor/ChangeLog b/apps/presentor/ChangeLog index 031b921b9..9e95f156f 100644 --- a/apps/presentor/ChangeLog +++ b/apps/presentor/ChangeLog @@ -8,3 +8,4 @@ 0.08: Presentation parts! 0.09: Code cleanup and windows 11 support. 0.10: Bugfixes. +0.11: Fix mouse move getting stuck. diff --git a/apps/presentor/app.js b/apps/presentor/app.js index bd527539f..ae7b4b096 100644 --- a/apps/presentor/app.js +++ b/apps/presentor/app.js @@ -264,7 +264,7 @@ Bangle.on('lock', function(on) { }); function startHolding() { - bt.tapKey(bt.KEY.F10); + bt.tapKey(0, bt.MODIFY.CTRL, () => bt.tapKey(0, bt.MODIFY.CTRL)); holding = true; Bangle.buzz(); E.showMessage('Holding'); @@ -274,7 +274,8 @@ function startHolding() { function stopHolding() { clearTimeout(timeoutHolding); if (holding) { - bt.tapKey(bt.KEY.F10); + bt.tapKey(0, bt.MODIFY.CTRL); + // bt.tapKey(bt.KEY.F10); homePitch = 0; homeRoll = 0; holding = false; @@ -319,11 +320,13 @@ Bangle.on('drag', function(e) { if (getTime() - cttl < 0.2) { bt.clickButton(bt.BUTTON.LEFT); console.log("click left"); + clearToSend = true; } // longer press in center else if (getTime() - cttl < 0.6 && e.x > g.getWidth()/4 && e.x < 3 * g.getWidth()/4 && e.y > g.getHeight() / 4 && e.y < 3 * g.getHeight() / 4) { bt.clickButton(bt.BUTTON.RIGHT); console.log("click right"); + clearToSend = true; } cttl = 0; lastx = 0; @@ -385,5 +388,6 @@ function onBtn() { } setWatch(onBtn, (process.env.HWVERSION==2) ? BTN1 : BTN2, {repeat: true}); +// Start App loadSettings(); drawMain(); \ No newline at end of file diff --git a/apps/presentor/metadata.json b/apps/presentor/metadata.json index 984ba39c6..f7d6b6063 100644 --- a/apps/presentor/metadata.json +++ b/apps/presentor/metadata.json @@ -1,7 +1,7 @@ { "id": "presentor", "name": "Presentor", - "version": "0.10", + "version": "0.11", "description": "Use your Bangle to present!", "icon": "app.png", "type": "app", From 825450f66338ac9499e0b157524574ddf9bbe122 Mon Sep 17 00:00:00 2001 From: 7kasper Date: Wed, 29 Nov 2023 00:31:20 +0100 Subject: [PATCH 07/11] Try drag mouse support --- apps/presentor/ChangeLog | 1 + apps/presentor/app.js | 23 ++++++++++++++++++++--- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/apps/presentor/ChangeLog b/apps/presentor/ChangeLog index 9e95f156f..19a4990bf 100644 --- a/apps/presentor/ChangeLog +++ b/apps/presentor/ChangeLog @@ -9,3 +9,4 @@ 0.09: Code cleanup and windows 11 support. 0.10: Bugfixes. 0.11: Fix mouse move getting stuck. +0.12: Added support for mouse dragging action (click then drag) diff --git a/apps/presentor/app.js b/apps/presentor/app.js index ae7b4b096..04f9de35a 100644 --- a/apps/presentor/app.js +++ b/apps/presentor/app.js @@ -90,6 +90,8 @@ let trackPadMode = false; let timeoutId = -1; let timeoutHolding = -1; let timeoutDraw = -1; +let timeoutSendMouse = -1; +let timeoutHoldMouse = -1; let homeRoll = 0; @@ -291,9 +293,20 @@ function stopHolding() { timeoutHolding = -1; } +function releaseMouseButtons() { + bt.releaseButton(bt.BUTTON.ALL); + clearTimeout(timeoutHoldMouse) + timeoutHoldMouse = -1; +} + Bangle.on('drag', function(e) { if (cttl == 0) { cttl = getTime(); } if (trackPadMode) { + // Upon other drag event: push holding further into the future. + if (timeoutHoldMouse != -1) { + clearTimeout(timeoutHoldMouse); + timeoutHoldMouse = setTimeout(releaseMouseButtons, 200); + } if (lastx + lasty == 0) { lastx = e.x; lasty = e.y; @@ -308,24 +321,28 @@ Bangle.on('drag', function(e) { //let qY = getSign(difY) * Math.pow(Math.abs(difY), 1.2); let qX = difX + 0.02 * vX, qY = difY + 0.02 * vY; bt.moveMouse(qX, qY, 0, 0, 0, function() { - setTimeout(function() {clearToSend = true;}, 50); + timeoutSendMouse = setTimeout(function() {clearToSend = true; timeoutSendMouse = -1;}, 50); }); lastx = e.x; lasty = e.y; mttl = getTime(); console.log("Dx: " + (qX) + " Dy: " + (qY)); + } else if (timeoutSendMouse == -1) { // Can happen perhaps on single bluetooth failure. + timeoutSendMouse = setTimeout(function() {clearToSend = true; timeoutSendMouse = -1;}, 50); } if (!e.b) { // short press if (getTime() - cttl < 0.2) { - bt.clickButton(bt.BUTTON.LEFT); + bt.holdButton(bt.BUTTON.LEFT); console.log("click left"); + timeoutHoldMouse = setTimeout(releaseMouseButtons, 200); clearToSend = true; } // longer press in center else if (getTime() - cttl < 0.6 && e.x > g.getWidth()/4 && e.x < 3 * g.getWidth()/4 && e.y > g.getHeight() / 4 && e.y < 3 * g.getHeight() / 4) { - bt.clickButton(bt.BUTTON.RIGHT); + bt.holdButton(bt.BUTTON.RIGHT); console.log("click right"); + timeoutHoldMouse = setTimeout(releaseMouseButtons, 200); clearToSend = true; } cttl = 0; From d160a78231644b75e8eac6e56aa2ae0bb5e7470a Mon Sep 17 00:00:00 2001 From: 7kasper Date: Wed, 29 Nov 2023 00:54:41 +0100 Subject: [PATCH 08/11] Next attempt at holding mouse --- apps/presentor/app.js | 23 +++++++++-------------- apps/presentor/metadata.json | 2 +- 2 files changed, 10 insertions(+), 15 deletions(-) diff --git a/apps/presentor/app.js b/apps/presentor/app.js index 04f9de35a..186f9b1ce 100644 --- a/apps/presentor/app.js +++ b/apps/presentor/app.js @@ -91,14 +91,13 @@ let timeoutId = -1; let timeoutHolding = -1; let timeoutDraw = -1; let timeoutSendMouse = -1; -let timeoutHoldMouse = -1; - let homeRoll = 0; let homePitch = 0; let mCal = 0; let mttl = 0; let cttl = 0; +let httl = 0; // BT helper. let clearToSend = true; @@ -293,19 +292,15 @@ function stopHolding() { timeoutHolding = -1; } -function releaseMouseButtons() { - bt.releaseButton(bt.BUTTON.ALL); - clearTimeout(timeoutHoldMouse) - timeoutHoldMouse = -1; -} - Bangle.on('drag', function(e) { if (cttl == 0) { cttl = getTime(); } if (trackPadMode) { - // Upon other drag event: push holding further into the future. - if (timeoutHoldMouse != -1) { - clearTimeout(timeoutHoldMouse); - timeoutHoldMouse = setTimeout(releaseMouseButtons, 200); + // When we are dragging mouse release after small time amount otherwise keep dragging. + if (getTime() - httl < 0.2) { + httl = getTime(); + } else if (httl != 0) { + httl = 0; + bt.releaseButton(bt.BUTTON.ALL); } if (lastx + lasty == 0) { lastx = e.x; @@ -335,14 +330,14 @@ Bangle.on('drag', function(e) { if (getTime() - cttl < 0.2) { bt.holdButton(bt.BUTTON.LEFT); console.log("click left"); - timeoutHoldMouse = setTimeout(releaseMouseButtons, 200); + httl = getTime(); clearToSend = true; } // longer press in center else if (getTime() - cttl < 0.6 && e.x > g.getWidth()/4 && e.x < 3 * g.getWidth()/4 && e.y > g.getHeight() / 4 && e.y < 3 * g.getHeight() / 4) { bt.holdButton(bt.BUTTON.RIGHT); console.log("click right"); - timeoutHoldMouse = setTimeout(releaseMouseButtons, 200); + httl = getTime(); clearToSend = true; } cttl = 0; diff --git a/apps/presentor/metadata.json b/apps/presentor/metadata.json index f7d6b6063..f176a1738 100644 --- a/apps/presentor/metadata.json +++ b/apps/presentor/metadata.json @@ -1,7 +1,7 @@ { "id": "presentor", "name": "Presentor", - "version": "0.11", + "version": "0.12", "description": "Use your Bangle to present!", "icon": "app.png", "type": "app", From a0b42267ff34f51ec3a70bead552393e2a7dfb86 Mon Sep 17 00:00:00 2001 From: 7kasper Date: Wed, 29 Nov 2023 01:03:57 +0100 Subject: [PATCH 09/11] Testing ctrl keypress --- apps/presentor/app.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/presentor/app.js b/apps/presentor/app.js index 186f9b1ce..330cd2195 100644 --- a/apps/presentor/app.js +++ b/apps/presentor/app.js @@ -265,7 +265,7 @@ Bangle.on('lock', function(on) { }); function startHolding() { - bt.tapKey(0, bt.MODIFY.CTRL, () => bt.tapKey(0, bt.MODIFY.CTRL)); + bt.tapKey(bt.KEY.A, bt.MODIFY.CTRL, () => bt.tapKey(bt.KEY.A, bt.MODIFY.CTRL)); holding = true; Bangle.buzz(); E.showMessage('Holding'); From ff4a57de768660eef4db7136fb360607e3de096a Mon Sep 17 00:00:00 2001 From: 7kasper Date: Wed, 29 Nov 2023 01:16:42 +0100 Subject: [PATCH 10/11] Remove dragging and fix cntrl (hopefully) --- apps/presentor/ChangeLog | 3 ++- apps/presentor/app.js | 16 +++------------- apps/presentor/metadata.json | 2 +- 3 files changed, 6 insertions(+), 15 deletions(-) diff --git a/apps/presentor/ChangeLog b/apps/presentor/ChangeLog index 19a4990bf..26f9ed6d7 100644 --- a/apps/presentor/ChangeLog +++ b/apps/presentor/ChangeLog @@ -9,4 +9,5 @@ 0.09: Code cleanup and windows 11 support. 0.10: Bugfixes. 0.11: Fix mouse move getting stuck. -0.12: Added support for mouse dragging action (click then drag) +0.12: Added support for mouse dragging action (click then drag). +0.13: Removed mouse dragging (too buggy/unuseful). \ No newline at end of file diff --git a/apps/presentor/app.js b/apps/presentor/app.js index 330cd2195..27403c919 100644 --- a/apps/presentor/app.js +++ b/apps/presentor/app.js @@ -97,7 +97,6 @@ let homePitch = 0; let mCal = 0; let mttl = 0; let cttl = 0; -let httl = 0; // BT helper. let clearToSend = true; @@ -258,14 +257,14 @@ function handleAcc(acc) { } } Bangle.on('lock', function(on) { - if (on && holding) { + if (on && (holding || trackPadMode)) { Bangle.setLocked(false); Bangle.setLCDPower(1); } }); function startHolding() { - bt.tapKey(bt.KEY.A, bt.MODIFY.CTRL, () => bt.tapKey(bt.KEY.A, bt.MODIFY.CTRL)); + bt.tapKey(0xE0, () => bt.tapKey(0xE0)); holding = true; Bangle.buzz(); E.showMessage('Holding'); @@ -275,7 +274,7 @@ function startHolding() { function stopHolding() { clearTimeout(timeoutHolding); if (holding) { - bt.tapKey(0, bt.MODIFY.CTRL); + bt.tapKey(0xE0); // bt.tapKey(bt.KEY.F10); homePitch = 0; homeRoll = 0; @@ -295,13 +294,6 @@ function stopHolding() { Bangle.on('drag', function(e) { if (cttl == 0) { cttl = getTime(); } if (trackPadMode) { - // When we are dragging mouse release after small time amount otherwise keep dragging. - if (getTime() - httl < 0.2) { - httl = getTime(); - } else if (httl != 0) { - httl = 0; - bt.releaseButton(bt.BUTTON.ALL); - } if (lastx + lasty == 0) { lastx = e.x; lasty = e.y; @@ -330,14 +322,12 @@ Bangle.on('drag', function(e) { if (getTime() - cttl < 0.2) { bt.holdButton(bt.BUTTON.LEFT); console.log("click left"); - httl = getTime(); clearToSend = true; } // longer press in center else if (getTime() - cttl < 0.6 && e.x > g.getWidth()/4 && e.x < 3 * g.getWidth()/4 && e.y > g.getHeight() / 4 && e.y < 3 * g.getHeight() / 4) { bt.holdButton(bt.BUTTON.RIGHT); console.log("click right"); - httl = getTime(); clearToSend = true; } cttl = 0; diff --git a/apps/presentor/metadata.json b/apps/presentor/metadata.json index f176a1738..babb4b14a 100644 --- a/apps/presentor/metadata.json +++ b/apps/presentor/metadata.json @@ -1,7 +1,7 @@ { "id": "presentor", "name": "Presentor", - "version": "0.12", + "version": "0.13", "description": "Use your Bangle to present!", "icon": "app.png", "type": "app", From 65fa387739fc35b1be7be83a0facab6f1ec95504 Mon Sep 17 00:00:00 2001 From: 7kasper Date: Wed, 29 Nov 2023 11:20:07 +0100 Subject: [PATCH 11/11] Fixes and add spotlight and default screen --- apps/presentor/ChangeLog | 3 +- apps/presentor/README.md | 12 ++++++-- apps/presentor/app.js | 57 ++++++++++++++++++++++++------------ apps/presentor/metadata.json | 2 +- 4 files changed, 51 insertions(+), 23 deletions(-) diff --git a/apps/presentor/ChangeLog b/apps/presentor/ChangeLog index 26f9ed6d7..a42c6594d 100644 --- a/apps/presentor/ChangeLog +++ b/apps/presentor/ChangeLog @@ -10,4 +10,5 @@ 0.10: Bugfixes. 0.11: Fix mouse move getting stuck. 0.12: Added support for mouse dragging action (click then drag). -0.13: Removed mouse dragging (too buggy/unuseful). \ No newline at end of file +0.13: Removed mouse dragging (too buggy/unuseful). +0.14: Bugfix and add pointer mode. Also added default screen when no parts are there. \ No newline at end of file diff --git a/apps/presentor/README.md b/apps/presentor/README.md index 9f2a411e1..37d3e0009 100644 --- a/apps/presentor/README.md +++ b/apps/presentor/README.md @@ -56,16 +56,24 @@ If "Try connecting your device again." is shown, switch PC/laptop bluetooth off 16. Mouse mode - Swipe to move pointer over the presentation screen + - Tap to left click. + - Hold longer to right click. 17. Holding mode In timer/presentation mode, hold one finger on your Bangle screen, point your arm foreward - Mouse up/down on screen: Tilt your hand up/down - Mouse left/right on screen: Rotate your hand counterclockwise/clockwise -18. End of presentation? +18. Spotlight mode + - Dubble press button to go into presentor mode. + - Allows to move mouse but no clicking. + - Presses SHIFT+F10 on start (you can use app such as powertoys to set spotlight to this combo) + - Presses F10 at the end (will dis-engage spotlight for instance in powertoys) + +19. End of presentation? Switch bluetooth PC/laptop off or see step 1 -19. Re-activate smartphone bluetooth (incl. Gadgetbridge) +20. Re-activate smartphone bluetooth (incl. Gadgetbridge) ### Creator [7kasper](https://github.com/7kasper) diff --git a/apps/presentor/app.js b/apps/presentor/app.js index 27403c919..a501b3376 100644 --- a/apps/presentor/app.js +++ b/apps/presentor/app.js @@ -1,5 +1,5 @@ // Presentor by 7kasper (Kasper Müller) -// Version 4.0 +// Version 0.14 // Imports const bt = require("ble_hid_combo"); @@ -85,6 +85,7 @@ let lasty = 0; // Mouse states let holding = false; let trackPadMode = false; +let focusMode = false; // Timeout IDs. let timeoutId = -1; @@ -97,6 +98,7 @@ let homePitch = 0; let mCal = 0; let mttl = 0; let cttl = 0; +let bttl = 0; // BT helper. let clearToSend = true; @@ -198,6 +200,11 @@ function drawMain() { function doPPart(r) { pparti += r; + if (settings.pparts.length == 0) { + mainLayout.Subject.label = 'PRESENTOR'; + mainLayout.Notes.label = ''; + return; + } if (pparti < 0) { pparti = -1; mainLayout.Subject.label = 'PAUSED'; @@ -264,21 +271,22 @@ Bangle.on('lock', function(on) { }); function startHolding() { - bt.tapKey(0xE0, () => bt.tapKey(0xE0)); + bt.tapKey(bt.KEY.F10, bt.MODIFY.SHIFT); holding = true; + focusMode = true; Bangle.buzz(); E.showMessage('Holding'); Bangle.on('accel', handleAcc); Bangle.setLCDPower(1); } function stopHolding() { - clearTimeout(timeoutHolding); if (holding) { - bt.tapKey(0xE0); + bt.tapKey(bt.KEY.F10); // bt.tapKey(bt.KEY.F10); homePitch = 0; homeRoll = 0; holding = false; + focusMode = false; mCal = 0; Bangle.removeListener('accel', handleAcc); Bangle.buzz(); @@ -318,17 +326,17 @@ Bangle.on('drag', function(e) { timeoutSendMouse = setTimeout(function() {clearToSend = true; timeoutSendMouse = -1;}, 50); } if (!e.b) { - // short press - if (getTime() - cttl < 0.2) { - bt.holdButton(bt.BUTTON.LEFT); - console.log("click left"); - clearToSend = true; - } - // longer press in center - else if (getTime() - cttl < 0.6 && e.x > g.getWidth()/4 && e.x < 3 * g.getWidth()/4 && e.y > g.getHeight() / 4 && e.y < 3 * g.getHeight() / 4) { - bt.holdButton(bt.BUTTON.RIGHT); - console.log("click right"); - clearToSend = true; + if (!focusMode) { + // short press + if (getTime() - cttl < 0.2) { + bt.clickButton(bt.BUTTON.LEFT); + console.log("click left"); + } + // longer press in center + else if (getTime() - cttl < 0.6 && e.x > g.getWidth()/4 && e.x < 3 * g.getWidth()/4 && e.y > g.getHeight() / 4 && e.y < 3 * g.getHeight() / 4) { + bt.clickButton(bt.BUTTON.RIGHT); + console.log("click right"); + } } cttl = 0; lastx = 0; @@ -372,9 +380,19 @@ Bangle.on('drag', function(e) { function onBtn() { if (trackPadMode) { - trackPadMode = false; - stopHolding(); - drawMain(); + if ((getTime() - bttl < 0.4 && !focusMode)) { + E.showMessage('Pointer'); + focusMode = true; + bt.tapKey(bt.KEY.F10, bt.MODIFY.SHIFT); + } else { + trackPadMode = false; + stopHolding(); + drawMain(); + if (focusMode) { + bt.tapKey(bt.KEY.F10); + focusMode = false; + } + } } else { stopHolding(); clearToSend = true; @@ -384,7 +402,8 @@ function onBtn() { if (timeoutDraw != -1) { clearTimeout(timeoutDraw); timeoutDraw = -1; - } + } + bttl = getTime(); } Bangle.buzz(); } diff --git a/apps/presentor/metadata.json b/apps/presentor/metadata.json index babb4b14a..e44684fda 100644 --- a/apps/presentor/metadata.json +++ b/apps/presentor/metadata.json @@ -1,7 +1,7 @@ { "id": "presentor", "name": "Presentor", - "version": "0.13", + "version": "0.14", "description": "Use your Bangle to present!", "icon": "app.png", "type": "app",