From 3adb3f1c2b28bab8a42e9cf5c92c179e9e153439 Mon Sep 17 00:00:00 2001 From: Andrew Gregory Date: Sun, 5 Dec 2021 19:27:50 +0800 Subject: [PATCH 01/20] Make main digits height configurable --- apps/authentiwatch/app.js | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/apps/authentiwatch/app.js b/apps/authentiwatch/app.js index c0cb608c0..392ed8940 100644 --- a/apps/authentiwatch/app.js +++ b/apps/authentiwatch/app.js @@ -1,4 +1,5 @@ -const tokenentryheight = 46; +const tokenextraheight = 16; +var tokendigitsheight = 30; // Hash functions const crypto = require("crypto"); const algos = { @@ -124,14 +125,14 @@ function drawToken(id, r) { // current token g.setColor(g.theme.fgH); g.setBgColor(g.theme.bgH); - g.setFont("Vector", 16); + g.setFont("Vector", tokenextraheight); // center just below top line g.setFontAlign(0, -1, 0); adj = y1; } else { g.setColor(g.theme.fg); g.setBgColor(g.theme.bg); - g.setFont("Vector", 30); + g.setFont("Vector", tokendigitsheight); // center in box g.setFontAlign(0, 0, 0); adj = (y1 + y2) / 2; @@ -148,14 +149,14 @@ function drawToken(id, r) { // counter - draw triangle as swipe hint let yc = (y1 + y2) / 2; g.fillPoly([0, yc, 10, yc - 10, 10, yc + 10, 0, yc]); - adj = 10; + adj = 12; } // digits just below label - sz = 30; + sz = tokendigitsheight; do { g.setFont("Vector", sz--); } while (g.stringWidth(state.otp) > (r.w - adj)); - g.drawString(state.otp, (x1 + adj + x2) / 2, y1 + 16, false); + g.drawString(state.otp, (x1 + adj + x2) / 2, y1 + tokenextraheight, false); } // shaded lines top and bottom g.setColor(0.5, 0.5, 0.5); @@ -196,15 +197,15 @@ function draw() { } if (tokens.length > 0) { var drewcur = false; - var id = Math.floor(state.listy / tokenentryheight); - var y = id * tokenentryheight + Bangle.appRect.y - state.listy; + var id = Math.floor(state.listy / (tokendigitsheight + tokenextraheight)); + var y = id * (tokendigitsheight + tokenextraheight) + Bangle.appRect.y - state.listy; while (id < tokens.length && y < Bangle.appRect.y2) { - drawToken(id, {x:Bangle.appRect.x, y:y, w:Bangle.appRect.w, h:tokenentryheight}); + drawToken(id, {x:Bangle.appRect.x, y:y, w:Bangle.appRect.w, h:(tokendigitsheight + tokenextraheight)}); if (id == state.curtoken && (tokens[id].period <= 0 || state.nextTime != 0)) { drewcur = true; } id += 1; - y += tokenentryheight; + y += (tokendigitsheight + tokenextraheight); } if (drewcur) { // the current token has been drawn - schedule a redraw @@ -226,7 +227,7 @@ function draw() { state.nexttime = 0; } } else { - g.setFont("Vector", 30); + g.setFont("Vector", tokendigitsheight); g.setFontAlign(0, 0, 0); g.drawString(notokens, Bangle.appRect.x + Bangle.appRect.w / 2, Bangle.appRect.y + Bangle.appRect.h / 2, false); } @@ -238,18 +239,18 @@ function draw() { function onTouch(zone, e) { if (e) { - var id = Math.floor((state.listy + (e.y - Bangle.appRect.y)) / tokenentryheight); + var id = Math.floor((state.listy + (e.y - Bangle.appRect.y)) / (tokendigitsheight + tokenextraheight)); if (id == state.curtoken || tokens.length == 0 || id >= tokens.length) { id = -1; } if (state.curtoken != id) { if (id != -1) { - var y = id * tokenentryheight - state.listy; + var y = id * (tokendigitsheight + tokenextraheight) - state.listy; if (y < 0) { state.listy += y; y = 0; } - y += tokenentryheight; + y += (tokendigitsheight + tokenextraheight); if (y > Bangle.appRect.h) { state.listy += (y - Bangle.appRect.h); } @@ -266,7 +267,7 @@ function onTouch(zone, e) { function onDrag(e) { if (e.x > g.getWidth() || e.y > g.getHeight()) return; if (e.dx == 0 && e.dy == 0) return; - var newy = Math.min(state.listy - e.dy, tokens.length * tokenentryheight - Bangle.appRect.h); + var newy = Math.min(state.listy - e.dy, tokens.length * (tokendigitsheight + tokenextraheight) - Bangle.appRect.h); state.listy = Math.max(0, newy); draw(); } @@ -296,7 +297,7 @@ function bangle1Btn(e) { state.curtoken = Math.max(state.curtoken, 0); state.curtoken = Math.min(state.curtoken, tokens.length - 1); var fakee = {}; - fakee.y = state.curtoken * tokenentryheight - state.listy + Bangle.appRect.y; + fakee.y = state.curtoken * (tokendigitsheight + tokenextraheight) - state.listy + Bangle.appRect.y; state.curtoken = -1; state.nextTime = 0; onTouch(0, fakee); From d9cb12bdf15f203052e3dd8eac5bdde9a44608c0 Mon Sep 17 00:00:00 2001 From: Andrew Gregory Date: Sun, 5 Dec 2021 19:42:44 +0800 Subject: [PATCH 02/20] Shrink label to fit --- apps/authentiwatch/app.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/apps/authentiwatch/app.js b/apps/authentiwatch/app.js index 392ed8940..bb797edc4 100644 --- a/apps/authentiwatch/app.js +++ b/apps/authentiwatch/app.js @@ -118,9 +118,10 @@ function drawToken(id, r) { var y1 = r.y; var x2 = r.x + r.w - 1; var y2 = r.y + r.h - 1; - var adj, sz; + var adj, lbl, sz; g.setClipRect(Math.max(x1, Bangle.appRect.x ), Math.max(y1, Bangle.appRect.y ), Math.min(x2, Bangle.appRect.x2), Math.min(y2, Bangle.appRect.y2)); + lbl = tokens[id].label.substr(0, 10); if (id == state.curtoken) { // current token g.setColor(g.theme.fgH); @@ -132,13 +133,16 @@ function drawToken(id, r) { } else { g.setColor(g.theme.fg); g.setBgColor(g.theme.bg); - g.setFont("Vector", tokendigitsheight); + sz = tokendigitsheight; + do { + g.setFont("Vector", sz--); + } while (g.stringWidth(lbl) > r.w); // center in box g.setFontAlign(0, 0, 0); adj = (y1 + y2) / 2; } g.clearRect(x1, y1, x2, y2); - g.drawString(tokens[id].label.substr(0, 10), (x1 + x2) / 2, adj, false); + g.drawString(lbl, (x1 + x2) / 2, adj, false); if (id == state.curtoken) { if (tokens[id].period > 0) { // timed - draw progress bar From 26079db909677e565a3718daae6ea7a181190048 Mon Sep 17 00:00:00 2001 From: Andrew Gregory Date: Fri, 31 Dec 2021 11:39:22 +0800 Subject: [PATCH 03/20] Update app.js Restore swipe to exit. --- apps/authentiwatch/app.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/apps/authentiwatch/app.js b/apps/authentiwatch/app.js index bb797edc4..de3d02163 100644 --- a/apps/authentiwatch/app.js +++ b/apps/authentiwatch/app.js @@ -277,6 +277,9 @@ function onDrag(e) { } function onSwipe(e) { + if (e == 1) { + Bangle.showLauncher(); + } if (e == -1 && state.curtoken != -1 && tokens[state.curtoken].period <= 0) { tokens[state.curtoken].period--; let newsettings={tokens:tokens,misc:settings.misc}; From d1e7a7a220626070f7e9f1a29211dec9bd9bec6c Mon Sep 17 00:00:00 2001 From: Andrew Gregory Date: Fri, 31 Dec 2021 12:00:11 +0800 Subject: [PATCH 04/20] Update app.js Fix extra zeros out of b32decode() --- apps/authentiwatch/app.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/apps/authentiwatch/app.js b/apps/authentiwatch/app.js index de3d02163..d2a72c8a8 100644 --- a/apps/authentiwatch/app.js +++ b/apps/authentiwatch/app.js @@ -45,9 +45,6 @@ function b32decode(seedstr) { } } } - if (bitcount > 0) { - retstr += String.fromCharCode(buf << (8 - bitcount)); - } var retbuf = new Uint8Array(retstr.length); for (i in retstr) { retbuf[i] = retstr.charCodeAt(i); From 7b6386ce5d0860ed81deed91a1c2a4304cb6e00b Mon Sep 17 00:00:00 2001 From: Andrew Gregory Date: Fri, 31 Dec 2021 15:56:39 +0800 Subject: [PATCH 05/20] Update app.js Use exitApp() --- apps/authentiwatch/app.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/authentiwatch/app.js b/apps/authentiwatch/app.js index d2a72c8a8..640183230 100644 --- a/apps/authentiwatch/app.js +++ b/apps/authentiwatch/app.js @@ -275,7 +275,7 @@ function onDrag(e) { function onSwipe(e) { if (e == 1) { - Bangle.showLauncher(); + exitApp(); } if (e == -1 && state.curtoken != -1 && tokens[state.curtoken].period <= 0) { tokens[state.curtoken].period--; From d16ee688d22e8bcf3f0a56e0a5bf75d19dba0842 Mon Sep 17 00:00:00 2001 From: Martin Boonk Date: Fri, 4 Feb 2022 13:03:22 +0100 Subject: [PATCH 06/20] BTHRM - Fix connection problem if no request grace period is configured --- apps/bthrm/boot.js | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/apps/bthrm/boot.js b/apps/bthrm/boot.js index c7f9cca53..da0205177 100644 --- a/apps/bthrm/boot.js +++ b/apps/bthrm/boot.js @@ -365,18 +365,18 @@ if (settings.gracePeriodRequest){ log("Add " + settings.gracePeriodRequest + "ms grace period after request"); - - promise = promise.then((d)=>{ - log("Got device: ", d); - d.on('gattserverdisconnected', onDisconnect); - device = d; - }); - - promise = promise.then(()=>{ - log("Wait after request"); - return waitingPromise(settings.gracePeriodRequest); - }); } + + promise = promise.then((d)=>{ + log("Got device: ", d); + d.on('gattserverdisconnected', onDisconnect); + device = d; + }); + + promise = promise.then(()=>{ + log("Wait after request"); + return waitingPromise(settings.gracePeriodRequest); + }); } else { promise = Promise.resolve(); From 228a2c410de2bbf2ba15220135694346355d717a Mon Sep 17 00:00:00 2001 From: Martin Boonk Date: Fri, 4 Feb 2022 13:04:47 +0100 Subject: [PATCH 07/20] BTHRM - Fix infinite recursion if no cached data is available --- apps/bthrm/boot.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/apps/bthrm/boot.js b/apps/bthrm/boot.js index da0205177..59cd2e718 100644 --- a/apps/bthrm/boot.js +++ b/apps/bthrm/boot.js @@ -426,14 +426,14 @@ }); promise = promise.then(()=>{ - var getCharacteristicsPromise = Promise.resolve(); + var characteristicsPromise = Promise.resolve(); if (characteristics.length == 0){ - getCharacteristicsPromise = getCharacteristicsPromise.then(()=>{ + characteristicsPromise = characteristicsPromise.then(()=>{ log("Getting services"); return gatt.getPrimaryServices(); }); - getCharacteristicsPromise = getCharacteristicsPromise().then((services)=>{ + characteristicsPromise = characteristicsPromise.then((services)=>{ log("Got services:", services); var result = Promise.resolve(); for (var service of services){ @@ -453,11 +453,11 @@ } else { for (var characteristic of characteristics){ - getCharacteristicsPromise = attachCharacteristicPromise(getCharacteristicsPromise, characteristic, true); + characteristicsPromise = attachCharacteristicPromise(characteristicsPromise, characteristic, true); } } - return getCharacteristicsPromise; + return characteristicsPromise; }); promise = promise.then(()=>{ From d347d0a0afd08c0c1aa334026447f189eec581c9 Mon Sep 17 00:00:00 2001 From: Martin Boonk Date: Fri, 4 Feb 2022 13:06:27 +0100 Subject: [PATCH 08/20] Bump version --- apps/bthrm/ChangeLog | 2 ++ apps/bthrm/metadata.json | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/apps/bthrm/ChangeLog b/apps/bthrm/ChangeLog index 0f776586c..df7e2caa9 100644 --- a/apps/bthrm/ChangeLog +++ b/apps/bthrm/ChangeLog @@ -14,3 +14,5 @@ Always emit BTHRM event Cleanup promises code and allow to configure custom additional waiting times to work around bugs Disconnect cleanly on exit +0.06: Fix bug if no request waiting time is set + Fix bug if no connection data was cached diff --git a/apps/bthrm/metadata.json b/apps/bthrm/metadata.json index dd5db7e1d..9aea5f3aa 100644 --- a/apps/bthrm/metadata.json +++ b/apps/bthrm/metadata.json @@ -2,7 +2,7 @@ "id": "bthrm", "name": "Bluetooth Heart Rate Monitor", "shortName": "BT HRM", - "version": "0.05", + "version": "0.06", "description": "Overrides Bangle.js's build in heart rate monitor with an external Bluetooth one.", "icon": "app.png", "type": "app", From f979da095b0862d7fd0894a7562ad60b94df4065 Mon Sep 17 00:00:00 2001 From: Andrew Gregory Date: Sun, 6 Feb 2022 13:10:40 +0800 Subject: [PATCH 09/20] Update interface.html Fix #6 --- apps/authentiwatch/interface.html | 290 ++++++++++++++++++++++++++++-- 1 file changed, 272 insertions(+), 18 deletions(-) diff --git a/apps/authentiwatch/interface.html b/apps/authentiwatch/interface.html index 26533b17b..33466d1b3 100644 --- a/apps/authentiwatch/interface.html +++ b/apps/authentiwatch/interface.html @@ -7,7 +7,10 @@