From 0dae17cf70db3c24825f0939d86f64c16aeff81d Mon Sep 17 00:00:00 2001 From: Marco H Date: Fri, 29 Apr 2022 15:45:16 +0200 Subject: [PATCH 1/9] Fix potential crash --- apps/widbaroalarm/ChangeLog | 1 + apps/widbaroalarm/metadata.json | 2 +- apps/widbaroalarm/widget.js | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/apps/widbaroalarm/ChangeLog b/apps/widbaroalarm/ChangeLog index c12cc0d65..5786741c7 100644 --- a/apps/widbaroalarm/ChangeLog +++ b/apps/widbaroalarm/ChangeLog @@ -1,2 +1,3 @@ 0.01: Initial version 0.02: Do not warn multiple times for the same exceedance +0.03: Fix crash diff --git a/apps/widbaroalarm/metadata.json b/apps/widbaroalarm/metadata.json index 9c58a41ab..134f03623 100644 --- a/apps/widbaroalarm/metadata.json +++ b/apps/widbaroalarm/metadata.json @@ -2,7 +2,7 @@ "id": "widbaroalarm", "name": "Barometer Alarm Widget", "shortName": "Barometer Alarm", - "version": "0.02", + "version": "0.03", "description": "A widget that can alarm on when the pressure reaches defined thresholds.", "icon": "widget.png", "type": "widget", diff --git a/apps/widbaroalarm/widget.js b/apps/widbaroalarm/widget.js index 5d62156eb..2745db8ad 100644 --- a/apps/widbaroalarm/widget.js +++ b/apps/widbaroalarm/widget.js @@ -104,7 +104,7 @@ saveSetting("lastHighWarningTs", 0); } - if (!alreadyWarned) { + if (history3.length > 0 && !alreadyWarned) { // 3h change detection const drop3halarm = setting("drop3halarm"); const raise3halarm = setting("raise3halarm"); From f3fb1465147335acf62d30098ad8c199f3e6a7e2 Mon Sep 17 00:00:00 2001 From: Alessandro Cocco Date: Fri, 29 Apr 2022 22:52:21 +0200 Subject: [PATCH 2/9] Add .jekyll-cache to .gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index fce2efb1a..231851dd6 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,4 @@ tests/Layout/bin/tmp.* tests/Layout/testresult.bmp apps.local.json _site +.jekyll-cache From 73f976c86bcd8ff7c64d48e71275b30109638ee2 Mon Sep 17 00:00:00 2001 From: Erik Andresen Date: Sun, 1 May 2022 22:22:52 +0200 Subject: [PATCH 3/9] gpsautotime: Add setting to hide the widget --- apps/gpsautotime/ChangeLog | 1 + apps/gpsautotime/metadata.json | 8 +++++--- apps/gpsautotime/widget.js | 20 +++++++++++++++----- 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/apps/gpsautotime/ChangeLog b/apps/gpsautotime/ChangeLog index 2827c9e5c..97b80ecdf 100644 --- a/apps/gpsautotime/ChangeLog +++ b/apps/gpsautotime/ChangeLog @@ -1,2 +1,3 @@ 0.01: New App! 0.02: Set Bangle.js 2 compatible +0.03: Add setting to hide the widget diff --git a/apps/gpsautotime/metadata.json b/apps/gpsautotime/metadata.json index 766961276..217a27931 100644 --- a/apps/gpsautotime/metadata.json +++ b/apps/gpsautotime/metadata.json @@ -2,13 +2,15 @@ "id": "gpsautotime", "name": "GPS auto time", "shortName": "GPS auto time", - "version": "0.02", + "version": "0.03", "description": "A widget that automatically updates the Bangle.js time to the GPS time whenever there is a valid GPS fix.", "icon": "widget.png", "type": "widget", "tags": "widget,gps", "supports": ["BANGLEJS","BANGLEJS2"], "storage": [ - {"name":"gpsautotime.wid.js","url":"widget.js"} - ] + {"name":"gpsautotime.wid.js","url":"widget.js"}, + {"name":"gpsautotime.settings.js","url":"settings.js"} + ], + "data": [{"name":"gpsautotime.json"}] } diff --git a/apps/gpsautotime/widget.js b/apps/gpsautotime/widget.js index a1d1b2b08..a21c14619 100644 --- a/apps/gpsautotime/widget.js +++ b/apps/gpsautotime/widget.js @@ -1,6 +1,13 @@ (() => { var lastTimeSet = 0; + var settings = Object.assign({ + // default values + show: true, + }, require('Storage').readJSON("gpsautotime.json", true) || {}); + const show = settings.show; + delete settings; + Bangle.on('GPS',function(fix) { if (fix.fix) { var curTime = fix.time.getTime()/1000; @@ -14,8 +21,9 @@ // add your widget WIDGETS["gpsAutoTime"]={ area:"tl", // tl (top left), tr (top right), bl (bottom left), br (bottom right) - width: 28, // width of the widget + width: show ? 4*6+2 : 0, // width of the widget draw: function() { + if (!show) return; g.reset(); // reset the graphics context to defaults (color/font/etc) g.setFont("6x8"); if ((getTime() - lastTimeSet) <= 60) { @@ -27,7 +35,9 @@ } }; - setInterval(function() { - WIDGETS["gpsAutoTime"].draw(WIDGETS["gpsAutoTime"]); - }, 1*60000); // update every minute -})() + if (show) { + setInterval(function() { + WIDGETS["gpsAutoTime"].draw(WIDGETS["gpsAutoTime"]); + }, 1*60000); // update every minute + } +})(); From 7c0b0e978b78b6ad625c572369a958ffb81ec444 Mon Sep 17 00:00:00 2001 From: Erik Andresen Date: Sun, 1 May 2022 22:24:29 +0200 Subject: [PATCH 4/9] sleepphasealarm: check for day of week --- apps/sleepphasealarm/ChangeLog | 1 + apps/sleepphasealarm/README.md | 2 ++ apps/sleepphasealarm/app.js | 8 +++++--- apps/sleepphasealarm/metadata.json | 2 +- 4 files changed, 9 insertions(+), 4 deletions(-) diff --git a/apps/sleepphasealarm/ChangeLog b/apps/sleepphasealarm/ChangeLog index 53c993376..ec3fe3a23 100644 --- a/apps/sleepphasealarm/ChangeLog +++ b/apps/sleepphasealarm/ChangeLog @@ -5,3 +5,4 @@ 0.05: Refactor decodeTime() to scheduling library 0.06: Add logging use Layout library and display ETA +0.07: Add check for day of week diff --git a/apps/sleepphasealarm/README.md b/apps/sleepphasealarm/README.md index 04388194f..c33c9c807 100644 --- a/apps/sleepphasealarm/README.md +++ b/apps/sleepphasealarm/README.md @@ -1,5 +1,7 @@ # Sleep Phase Alarm +The alarm must be in the next 24h. + The display shows: - the current time diff --git a/apps/sleepphasealarm/app.js b/apps/sleepphasealarm/app.js index 9bde85452..8ccd43eb2 100644 --- a/apps/sleepphasealarm/app.js +++ b/apps/sleepphasealarm/app.js @@ -51,8 +51,10 @@ active.forEach(alarm => { if (dateAlarm < now) { // dateAlarm in the past, add 24h dateAlarm.setTime(dateAlarm.getTime() + (24*60*60*1000)); } - if (nextAlarm === undefined || dateAlarm < nextAlarm) { - nextAlarm = dateAlarm; + if ((alarm.dow >> dateAlarm.getDay()) & 1) { // check valid day of week + if (nextAlarm === undefined || dateAlarm < nextAlarm) { + nextAlarm = dateAlarm; + } } }); @@ -80,7 +82,7 @@ function drawApp() { layout.date.label = locale.time(now, BANGLEJS2 && Bangle.isLocked() ? 1 : 0); // hide seconds on bangle 2 const diff = nextAlarm - now; const diffHour = Math.floor((diff % 86400000) / 3600000).toString(); - const diffMinutes = Math.round(((diff % 86400000) % 3600000) / 60000).toString(); + const diffMinutes = Math.floor(((diff % 86400000) % 3600000) / 60000).toString(); layout.eta.label = "ETA: -"+ diffHour + ":" + diffMinutes.padStart(2, '0'); layout.render(); } diff --git a/apps/sleepphasealarm/metadata.json b/apps/sleepphasealarm/metadata.json index f55854f35..d74590704 100644 --- a/apps/sleepphasealarm/metadata.json +++ b/apps/sleepphasealarm/metadata.json @@ -2,7 +2,7 @@ "id": "sleepphasealarm", "name": "SleepPhaseAlarm", "shortName": "SleepPhaseAlarm", - "version": "0.06", + "version": "0.07", "description": "Uses the accelerometer to estimate sleep and wake states with the principle of Estimation of Stationary Sleep-segments (ESS, see https://ubicomp.eti.uni-siegen.de/home/datasets/ichi14/index.html.en). This app will read the next alarm from the alarm application and will wake you up to 30 minutes early at the best guessed time when you are almost already awake.", "icon": "app.png", "tags": "alarm", From cfb737e1c0c49ee7929d259a8a555698d8a3a254 Mon Sep 17 00:00:00 2001 From: thyttan <97237430+thyttan@users.noreply.github.com> Date: Mon, 2 May 2022 01:36:24 +0200 Subject: [PATCH 5/9] kbtouch v0.02 - introduce settings for layout... ...and functionality. --- apps/kbtouch/ChangeLog | 1 + apps/kbtouch/README.md | 11 ++++++ apps/kbtouch/lib.js | 81 ++++++++++++++++++++++++++++---------- apps/kbtouch/metadata.json | 5 ++- apps/kbtouch/settings.js | 59 +++++++++++++++++++++++++++ 5 files changed, 135 insertions(+), 22 deletions(-) create mode 100644 apps/kbtouch/settings.js diff --git a/apps/kbtouch/ChangeLog b/apps/kbtouch/ChangeLog index 5560f00bc..17e824c00 100644 --- a/apps/kbtouch/ChangeLog +++ b/apps/kbtouch/ChangeLog @@ -1 +1,2 @@ 0.01: New App! +0.02: Introduced settings to customize the layout and functionality of the keyboard. diff --git a/apps/kbtouch/README.md b/apps/kbtouch/README.md index 513ba9239..07188ff0c 100644 --- a/apps/kbtouch/README.md +++ b/apps/kbtouch/README.md @@ -2,6 +2,17 @@ A library that provides an on-screen keyboard for text input. +## Settings ( -> Apps -> kbtouch ) +Text size - small or big text font. Default=Big. Suggested=Small. + +Offset keyboard - display the keyboard on top, making it faster to see what character you have selected. Default=No. Suggested=Yes. + +Loop around - should the keyboard highlight loop around when going past the edges? Default=Yes. Suggested=No. + +One-to-one input and release to select - should the input correspond directly to discrete areas on the screen, instead of being handled by scaled relative changes in position on swipes? Default=No. Suggested=Yes. + +Speed scaling - how much should a swipe move the highligt on the keyboard? Higher number corresponds to slower movement. Not applicable if using one-to-one input. Default=24. Suggested=15. + ## Usage In your app's metadata, add: diff --git a/apps/kbtouch/lib.js b/apps/kbtouch/lib.js index 3dfdce00c..a1c90795a 100644 --- a/apps/kbtouch/lib.js +++ b/apps/kbtouch/lib.js @@ -69,13 +69,29 @@ var KEYEXTRA = [ String.fromCharCode(27,91,53,126), // 0x84 page up String.fromCharCode(27,91,54,126), // 0x85 page down ]; + +var settings = Object.assign({ + // default values + textSize: 1, + offsetKeyboard: 0, + loopAround: 1, + oneToOne: 0, + speedScaling: 24 +}, require('Storage').readJSON("kbtouch.settings.json", true) || {}); +print(settings); + +//settings = { "textSize": 1, "offsetKeyboard": 0, "oneToOne": 1, +// "speedScaling": 15, "loopAround": 0 /*, "releaseToSelect": 0*/}; + +print(settings); // state const R = Bangle.appRect; var kbx = 0, kby = 0, kbdx = 0, kbdy = 0, kbShift = false, flashToggle = false; -const PX=12, PY=16, DRAGSCALE=24; -var xoff = 3, yoff = g.getHeight()-PY*4; +const PX=12, PY=16, DRAGSCALE=settings.speedScaling; +var xoff = 3, yoff = g.getHeight()-PY*(4+5*settings.offsetKeyboard); function draw() { + "ram"; var map = kbShift ? KEYMAPUPPER : KEYMAPLOWER; //g.drawImage(KEYIMG,0,yoff); g.reset().setFont("6x8:2"); @@ -88,9 +104,9 @@ function draw() { g.drawString(map[1],xoff,yoff+PY); g.drawString(map[2],xoff,yoff+PY*2); g.drawString(map[3],xoff,yoff+PY*3); - var l = g.setFont("6x8:4").wrapString(text+(flashToggle?"_":" "), R.w-8); - if (l.length>2) l=l.slice(-2); - g.drawString(l.join("\n"),R.x+4,R.y+4); + var l = g.setFont(settings.textSize ? "6x8:4":"6x8:2").wrapString(text+(flashToggle?"_":" "), R.w-8); + if (l.length>2+2*settings.textSize) l=l.slice(-(2+2*settings.textSize)); + g.drawString(l.join("\n"),R.x+4,R.y+4 +82*settings.offsetKeyboard); g.flip(); } @@ -104,24 +120,49 @@ function draw() { return new Promise((resolve,reject) => { Bangle.setUI({mode:"custom", drag:e=>{ - kbdx += e.dx; - kbdy += e.dy; - var dx = Math.round(kbdx/DRAGSCALE), dy = Math.round(kbdy/DRAGSCALE); - kbdx -= dx*DRAGSCALE; - kbdy -= dy*DRAGSCALE; - if (dx || dy) { - kbx = (kbx+dx+15)%15; - kby = (kby+dy+4)%4; + if (settings.oneToOne) { + kbx = Math.max(Math.min(Math.floor((e.x-16) / (6*2)) , 13) , 0); + kby = Math.max(Math.min(Math.floor((e.y-120) / (8*2)) , 4) , 0); + //print(e.y, kby, e.x, kbx); + } + + if (!settings.oneToOne) { + kbdx += e.dx; + kbdy += e.dy; + var dx = Math.round(kbdx/DRAGSCALE), dy = Math.round(kbdy/DRAGSCALE); + kbdx -= dx*DRAGSCALE; + kbdy -= dy*DRAGSCALE; + if (dx || dy) { + if (settings.loopAround) { + kbx = (kbx+dx+15)%15; + kby = (kby+dy+4)%4; + } else { + kbx = Math.max(Math.min((kbx+dx),13),0); + kby = Math.max(Math.min((kby+dy),3),0); + } + } + } + draw(); + + if (!e.b && e.y>Bangle.appRect.y && settings.oneToOne /*&& settings.releaseToSelect*/) { + var map = kbShift ? KEYMAPUPPER : KEYMAPLOWER; + var ch = map[kby][kbx]; + if (ch=="\2") kbShift=!kbShift; + else if (ch=="\b") text = text.slice(0,-1); + else text += ch; + Bangle.buzz(20); draw(); } },touch:()=>{ - var map = kbShift ? KEYMAPUPPER : KEYMAPLOWER; - var ch = map[kby][kbx]; - if (ch=="\2") kbShift=!kbShift; - else if (ch=="\b") text = text.slice(0,-1); - else text += ch; - Bangle.buzz(20); - draw(); + if ( !settings.oneToOne /*|| !settings.releaseToSelect*/) { + var map = kbShift ? KEYMAPUPPER : KEYMAPLOWER; + var ch = map[kby][kbx]; + if (ch=="\2") kbShift=!kbShift; + else if (ch=="\b") text = text.slice(0,-1); + else text += ch; + Bangle.buzz(20); + draw(); + } },back:()=>{ clearInterval(flashInterval); Bangle.setUI(); diff --git a/apps/kbtouch/metadata.json b/apps/kbtouch/metadata.json index da8b6c3c6..f6d6d5228 100644 --- a/apps/kbtouch/metadata.json +++ b/apps/kbtouch/metadata.json @@ -1,6 +1,6 @@ { "id": "kbtouch", "name": "Touch keyboard", - "version":"0.01", + "version":"0.02", "description": "A library for text input via onscreen keyboard", "icon": "app.png", "type":"textinput", @@ -9,6 +9,7 @@ "screenshots": [{"url":"screenshot.png"}], "readme": "README.md", "storage": [ - {"name":"textinput","url":"lib.js"} + {"name":"textinput","url":"lib.js"}, + {"name":"kbtouch.settings.js","url":"settings.js"} ] } diff --git a/apps/kbtouch/settings.js b/apps/kbtouch/settings.js new file mode 100644 index 000000000..871cc5d32 --- /dev/null +++ b/apps/kbtouch/settings.js @@ -0,0 +1,59 @@ +(function(back) { + function settings() { + let settings = require('Storage').readJSON("kbtouch.settings.json", true) || {}; + if (settings.textSize===undefined) settings.textSize=1; + if (settings.offsetKeyboard===undefined) settings.offsetKeyboard=0; + if (settings.loopAround===undefined) settings.loopAround=1; + if (settings.oneToOne===undefined) settings.oneToOne=0; + if (settings.speedScaling===undefined) settings.speedScaling=24; + return settings; + } + + function updateSetting(setting, value) { + let settings = require('Storage').readJSON("kbtouch.settings.json", true) || {}; + settings[setting] = value; + require('Storage').writeJSON("kbtouch.settings.json", settings); + } + + var mainmenu = { + "" : { "title" : /*LANG*/"Touch Keyboard" }, + "< Back" : back, + /*LANG*/'Text size': { + value: settings().textSize, + min: 0, max: 1, + format: v => [/*LANG*/"Small",/*LANG*/"Big"][v], + onchange: v => updateSetting("textSize", v) + }, + /*LANG*/'Offset keyboard': { + value: settings().offsetKeyboard, + min: 0, max: 1, + format: v => [/*LANG*/"No",/*LANG*/"Yes"][v], + onchange: v => updateSetting("offsetKeyboard", v) + }, + /*LANG*/'Loop around': { + value: settings().loopAround, + min: 0, max: 1, + format: v => [/*LANG*/"No",/*LANG*/"Yes"][v], + onchange: v => updateSetting("loopAround", v) + }, + /*LANG*/'One-to-one input and release to select': { + value: settings().oneToOne, + min: 0, max: 1, + format: v => [/*LANG*/"No",/*LANG*/"Yes"][v], + onchange: v => updateSetting("oneToOne", v) + }, + /*LANG*/'Speed scaling': { + value: settings().speedScaling, + min: 1, max: 24, step : 1, + format: v => v, + onchange: v => updateSetting("speedScaling", v) + } + ///*LANG*/'Release to select': { + // value: 1|settings().fontSize, + // min: 0, max: 1, + // format: v => [/*LANG*/"No",/*LANG*/"Yes"][v], + // onchange: v => updateSetting("releaseToSelect", v) + //} + }; + E.showMenu(mainmenu); +}) From d0f57e9b2fe5cb930098ac4ac9efd6ecea336132 Mon Sep 17 00:00:00 2001 From: thyttan <97237430+thyttan@users.noreply.github.com> Date: Mon, 2 May 2022 01:43:51 +0200 Subject: [PATCH 6/9] Update README.md --- apps/kbtouch/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/kbtouch/README.md b/apps/kbtouch/README.md index 07188ff0c..6bd0337a8 100644 --- a/apps/kbtouch/README.md +++ b/apps/kbtouch/README.md @@ -2,7 +2,7 @@ A library that provides an on-screen keyboard for text input. -## Settings ( -> Apps -> kbtouch ) +## Settings Text size - small or big text font. Default=Big. Suggested=Small. Offset keyboard - display the keyboard on top, making it faster to see what character you have selected. Default=No. Suggested=Yes. From d32735c6864a01570706954faca20538a1daf247 Mon Sep 17 00:00:00 2001 From: thyttan <97237430+thyttan@users.noreply.github.com> Date: Mon, 2 May 2022 02:11:27 +0200 Subject: [PATCH 7/9] Update lib.js --- apps/kbtouch/lib.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/kbtouch/lib.js b/apps/kbtouch/lib.js index a1c90795a..614fb8e96 100644 --- a/apps/kbtouch/lib.js +++ b/apps/kbtouch/lib.js @@ -122,7 +122,7 @@ function draw() { Bangle.setUI({mode:"custom", drag:e=>{ if (settings.oneToOne) { kbx = Math.max(Math.min(Math.floor((e.x-16) / (6*2)) , 13) , 0); - kby = Math.max(Math.min(Math.floor((e.y-120) / (8*2)) , 4) , 0); + kby = Math.max(Math.min(Math.floor((e.y-120) / (8*2)) , 3) , 0); //print(e.y, kby, e.x, kbx); } From 0f47f917467dc989d1d4047c745f56fe06039d49 Mon Sep 17 00:00:00 2001 From: thyttan <97237430+thyttan@users.noreply.github.com> Date: Mon, 2 May 2022 02:13:38 +0200 Subject: [PATCH 8/9] Update lib.js --- apps/kbtouch/lib.js | 5 ----- 1 file changed, 5 deletions(-) diff --git a/apps/kbtouch/lib.js b/apps/kbtouch/lib.js index 614fb8e96..db90440b9 100644 --- a/apps/kbtouch/lib.js +++ b/apps/kbtouch/lib.js @@ -78,12 +78,7 @@ var settings = Object.assign({ oneToOne: 0, speedScaling: 24 }, require('Storage').readJSON("kbtouch.settings.json", true) || {}); -print(settings); -//settings = { "textSize": 1, "offsetKeyboard": 0, "oneToOne": 1, -// "speedScaling": 15, "loopAround": 0 /*, "releaseToSelect": 0*/}; - -print(settings); // state const R = Bangle.appRect; var kbx = 0, kby = 0, kbdx = 0, kbdy = 0, kbShift = false, flashToggle = false; From 1398cea7b86d4c11c308ec699c830f7595bc588a Mon Sep 17 00:00:00 2001 From: Erik Andresen Date: Mon, 2 May 2022 07:29:09 +0200 Subject: [PATCH 9/9] gpsautotime: Add missing settings.js --- apps/gpsautotime/settings.js | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 apps/gpsautotime/settings.js diff --git a/apps/gpsautotime/settings.js b/apps/gpsautotime/settings.js new file mode 100644 index 000000000..dbdd121d1 --- /dev/null +++ b/apps/gpsautotime/settings.js @@ -0,0 +1,25 @@ +(function(back) { + var FILE = "gpsautotime.json"; + // Load settings + var settings = Object.assign({ + show: true, + }, require('Storage').readJSON(FILE, true) || {}); + + function writeSettings() { + require('Storage').writeJSON(FILE, settings); + } + + // Show the menu + E.showMenu({ + "" : { "title" : "GPS auto time" }, + "< Back" : () => back(), + 'Show widget?': { + value: !!settings.show, // !! converts undefined to false + format: v => v?"Show":"Hide", + onchange: v => { + settings.show = v; + writeSettings(); + } + }, + }); +})