From b632c232aa1b7f0ef060321e137022aa2721bc9f Mon Sep 17 00:00:00 2001 From: Hank Date: Thu, 30 Jun 2022 10:15:01 +0200 Subject: [PATCH 1/8] Minor changes --- apps/hworldclock/app.js | 59 ++++++++++++++++------------------------- 1 file changed, 23 insertions(+), 36 deletions(-) diff --git a/apps/hworldclock/app.js b/apps/hworldclock/app.js index d4c677d26..c41706d07 100644 --- a/apps/hworldclock/app.js +++ b/apps/hworldclock/app.js @@ -48,8 +48,8 @@ SunCalc = require("hsuncalc.js"); const LOCATION_FILE = "mylocation.json"; var rise = "07:00"; var set = "20:00"; -var pos = {altitude: 20, azimuth: 135}; -var noonpos = {altitude: 37, azimuth: 180}; +//var pos = {altitude: 20, azimuth: 135}; +//var noonpos = {altitude: 37, azimuth: 180}; //=======Sun var ampm = "AM"; @@ -113,19 +113,19 @@ g.setBgColor(g.theme.bg); function queueDraw() { if (drawTimeout) clearTimeout(drawTimeout); drawTimeout = setTimeout(function() { - drawTimeout = undefined; - draw(); - }, 60000 - (Date.now() % 60000)); + drawTimeout = undefined; + draw(); + }, 60000 - (Date.now() % 60000)); } // schedule a draw for the next second function queueDrawSeconds() { if (drawTimeoutSeconds) clearTimeout(drawTimeoutSeconds); drawTimeoutSeconds = setTimeout(function() { - drawTimeoutSeconds = undefined; - drawSeconds(); - //console.log("TO: " + secondsTimeout); - }, secondsTimeout - (Date.now() % secondsTimeout)); + drawTimeoutSeconds = undefined; + drawSeconds(); + //console.log("TO: " + secondsTimeout); + }, secondsTimeout - (Date.now() % secondsTimeout)); } function doublenum(x) { @@ -138,11 +138,11 @@ function getCurrentTimeFromOffset(dt, offset) { function updatePos() { coord = require("Storage").readJSON(LOCATION_FILE,1)|| {"lat":53.3,"lon":10.1,"location":"Pattensen"}; - pos = SunCalc.getPosition(Date.now(), coord.lat, coord.lon); + //pos = SunCalc.getPosition(Date.now(), coord.lat, coord.lon); times = SunCalc.getTimes(Date.now(), coord.lat, coord.lon); rise = times.sunrise.toString().split(" ")[4].substr(0,5); set = times.sunset.toString().split(" ")[4].substr(0,5); - noonpos = SunCalc.getPosition(times.solarNoon, coord.lat, coord.lon); + //noonpos = SunCalc.getPosition(times.solarNoon, coord.lat, coord.lon); } @@ -152,11 +152,7 @@ function drawSeconds() { var da = d.toString().split(" "); // default draw styles - g.reset(); - g.setBgColor(g.theme.bg); - - // drawSting centered - g.setFontAlign(0, 0); + g.reset().setBgColor(g.theme.bg).setFontAlign(0, 0); // draw time var time = da[4].split(":"); @@ -187,11 +183,7 @@ function draw() { var da = d.toString().split(" "); // default draw styles - g.reset(); - g.setBgColor(g.theme.bg); - - // drawSting centered - g.setFontAlign(0, 0); + g.reset().setBgColor(g.theme.bg).setFontAlign(0, 0); // draw time var time = da[4].split(":"); @@ -237,8 +229,7 @@ function draw() { //DATE var localDate = require("locale").date(new Date(), 1); localDate = localDate.substring(0, localDate.length - 5); - g.setFont("Vector", 17); - g.drawString(require("locale").dow(new Date(), 1).toUpperCase() + ", " + localDate, xyCenter, yposDate, true); + g.setFont("Vector", 17).drawString(require("locale").dow(new Date(), 1).toUpperCase() + ", " + localDate, xyCenter, yposDate, true); g.setFont(font, primaryDateFontSize); // set gmt to UTC+0 @@ -255,14 +246,11 @@ function draw() { var date = [require("locale").dow(new Date(), 1), require("locale").date(new Date(), 1)]; // For a single secondary timezone, draw it bigger and drop time zone to second line const xOffset = 30; - g.setFont(font, secondaryTimeFontSize); - g.drawString(`${hours}:${minutes}`, xyCenter, yposTime2, true); - g.setFont(font, secondaryTimeZoneFontSize); - g.drawString(offset[OFFSET_TIME_ZONE], xyCenter, yposTime2 + 30, true); + g.setFont(font, secondaryTimeFontSize).drawString(`${hours}:${minutes}`, xyCenter, yposTime2, true); + g.setFont(font, secondaryTimeZoneFontSize).drawString(offset[OFFSET_TIME_ZONE], xyCenter, yposTime2 + 30, true); // draw Day, name of month, Date - g.setFont(font, secondaryTimeZoneFontSize); - g.drawString(date, xyCenter, yposDate, true); + g.setFont(font, secondaryTimeZoneFontSize).drawString(date, xyCenter, yposDate, true); } else if (index < 3) { // For > 1 extra timezones, render as columns / rows g.setFont(font, secondaryRowColFontSize); @@ -280,10 +268,8 @@ function draw() { if (showSunInfo) { g.setFontAlign(-1, 0); - g.setFont("Vector",12); - g.drawString(`^${rise}`, 10, 3 + yposWorld + 3 * 15, true); // draw riseset - g.setFontAlign(1, 0); - g.drawString(`v${set}`, xcol2, 3 + yposWorld + 3 * 15, true); // draw riseset + g.setFont("Vector",12).drawString(`^${rise}`, 10, 3 + yposWorld + 3 * 15, true); // draw riseset + g.setFontAlign(1, 0).drawString(`v${set}`, xcol2, 3 + yposWorld + 3 * 15, true); // draw riseset } //debug settings //g.setFontAlign(1, 0); @@ -358,7 +344,6 @@ Bangle.on('lock',on=>{ if (PosInterval != 0) clearInterval(PosInterval); PosInterval = setInterval(updatePos, 60*10E3); // refesh every 10 mins } - secondsTimeout = 1000; if (secondsMode != "none") { if (drawTimeoutSeconds) clearTimeout(drawTimeoutSeconds); @@ -381,8 +366,10 @@ Bangle.on('lock',on=>{ if (drawTimeout) clearTimeout(drawTimeout); drawTimeout = undefined; - if (PosInterval != 0) clearInterval(PosInterval); - PosInterval = setInterval(updatePos, 60*60E3); // refesh every 60 mins + if (showSunInfo) { + if (PosInterval != 0) clearInterval(PosInterval); + PosInterval = setInterval(updatePos, 60*60E3); // refesh every 60 mins + } draw(); // draw immediately, queue redraw if (showSunInfo) updatePos(); } From 7e2f03adb1cf5bdbca34b896d0cc146cea241b3b Mon Sep 17 00:00:00 2001 From: Hank Date: Fri, 1 Jul 2022 18:30:26 +0200 Subject: [PATCH 2/8] Small fixes --- apps/hworldclock/ChangeLog | 1 + apps/hworldclock/app.js | 28 ++++++++++++---------------- apps/hworldclock/metadata.json | 2 +- 3 files changed, 14 insertions(+), 17 deletions(-) diff --git a/apps/hworldclock/ChangeLog b/apps/hworldclock/ChangeLog index 199393d2a..8a2c0fec4 100644 --- a/apps/hworldclock/ChangeLog +++ b/apps/hworldclock/ChangeLog @@ -6,3 +6,4 @@ 0.20: Add theme support 0.21: Add Settings 0.22: Use default Bangle formatter for booleans +0.23: Small fixes diff --git a/apps/hworldclock/app.js b/apps/hworldclock/app.js index c41706d07..f7444d319 100644 --- a/apps/hworldclock/app.js +++ b/apps/hworldclock/app.js @@ -229,7 +229,8 @@ function draw() { //DATE var localDate = require("locale").date(new Date(), 1); localDate = localDate.substring(0, localDate.length - 5); - g.setFont("Vector", 17).drawString(require("locale").dow(new Date(), 1).toUpperCase() + ", " + localDate, xyCenter, yposDate, true); + g.setFont("Vector", 17); + g.drawString(require("locale").dow(new Date(), 1).toUpperCase() + ", " + localDate, xyCenter, yposDate, true); g.setFont(font, primaryDateFontSize); // set gmt to UTC+0 @@ -253,22 +254,19 @@ function draw() { g.setFont(font, secondaryTimeZoneFontSize).drawString(date, xyCenter, yposDate, true); } else if (index < 3) { // For > 1 extra timezones, render as columns / rows - g.setFont(font, secondaryRowColFontSize); - g.setFontAlign(-1, 0); + g.setFont(font, secondaryRowColFontSize).setFontAlign(-1, 0); g.drawString( offset[OFFSET_TIME_ZONE], xcol1, yposWorld + index * 15, true ); - g.setFontAlign(1, 0); - g.drawString(`${hours}:${minutes}`, xcol2, yposWorld + index * 15, true); + g.setFontAlign(1, 0).drawString(`${hours}:${minutes}`, xcol2, yposWorld + index * 15, true); } }); if (showSunInfo) { - g.setFontAlign(-1, 0); - g.setFont("Vector",12).drawString(`^${rise}`, 10, 3 + yposWorld + 3 * 15, true); // draw riseset + g.setFontAlign(-1, 0).setFont("Vector",12).drawString(`^${rise}`, 10, 3 + yposWorld + 3 * 15, true); // draw riseset g.setFontAlign(1, 0).drawString(`v${set}`, xcol2, 3 + yposWorld + 3 * 15, true); // draw riseset } //debug settings @@ -277,7 +275,6 @@ function draw() { //g.drawString(showSunInfo, xcol2, 3 + yposWorld + 3 * 15, true); //g.drawString(colorWhenDark, xcol2, 3 + yposWorld + 3 * 15, true); - queueDraw(); if (secondsMode != "none") queueDrawSeconds(); @@ -303,6 +300,7 @@ if (!Bangle.isLocked()) { // Initial state if (showSunInfo) { if (PosInterval != 0) clearInterval(PosInterval); PosInterval = setInterval(updatePos, 60*10E3); // refesh every 10 mins + updatePos(); } secondsTimeout = 1000; @@ -312,9 +310,8 @@ if (!Bangle.isLocked()) { // Initial state } if (drawTimeout) clearTimeout(drawTimeout); drawTimeout = undefined; - draw(); // draw immediately, queue redraw - if (showSunInfo) updatePos(); + }else{ if (secondsMode == "always") secondsTimeout = 1000; if (secondsMode == "when unlocked") secondsTimeout = 10 * 1000; @@ -329,21 +326,21 @@ if (!Bangle.isLocked()) { // Initial state if (showSunInfo) { if (PosInterval != 0) clearInterval(PosInterval); PosInterval = setInterval(updatePos, 60*60E3); // refesh every 60 mins + updatePos(); } draw(); // draw immediately, queue redraw - if (showSunInfo) updatePos(); + } - - - Bangle.on('lock',on=>{ if (!on) { // UNlocked if (showSunInfo) { if (PosInterval != 0) clearInterval(PosInterval); PosInterval = setInterval(updatePos, 60*10E3); // refesh every 10 mins + updatePos(); } + secondsTimeout = 1000; if (secondsMode != "none") { if (drawTimeoutSeconds) clearTimeout(drawTimeoutSeconds); @@ -353,7 +350,6 @@ Bangle.on('lock',on=>{ drawTimeout = undefined; draw(); // draw immediately, queue redraw - if (showSunInfo) updatePos(); }else{ // locked if (secondsMode == "always") secondsTimeout = 1000; @@ -369,8 +365,8 @@ Bangle.on('lock',on=>{ if (showSunInfo) { if (PosInterval != 0) clearInterval(PosInterval); PosInterval = setInterval(updatePos, 60*60E3); // refesh every 60 mins + updatePos(); } draw(); // draw immediately, queue redraw - if (showSunInfo) updatePos(); } }); \ No newline at end of file diff --git a/apps/hworldclock/metadata.json b/apps/hworldclock/metadata.json index 8f1eb5a3c..653cfc59c 100644 --- a/apps/hworldclock/metadata.json +++ b/apps/hworldclock/metadata.json @@ -2,7 +2,7 @@ "id": "hworldclock", "name": "Hanks World Clock", "shortName": "Hanks World Clock", - "version": "0.22", + "version": "0.23", "description": "Current time zone plus up to three others", "allow_emulator":true, "icon": "app.png", From 44ce655023469b33d0dbd8002d5a9f44fc37b4ec Mon Sep 17 00:00:00 2001 From: Hank Date: Fri, 1 Jul 2022 19:12:53 +0200 Subject: [PATCH 3/8] Added missing position note --- apps/hworldclock/ChangeLog | 2 +- apps/hworldclock/README.md | 12 ++++-------- apps/hworldclock/app.js | 23 ++++++++++++++++------- apps/hworldclock/custom.html | 4 ++-- 4 files changed, 23 insertions(+), 18 deletions(-) diff --git a/apps/hworldclock/ChangeLog b/apps/hworldclock/ChangeLog index 8a2c0fec4..a4bd84390 100644 --- a/apps/hworldclock/ChangeLog +++ b/apps/hworldclock/ChangeLog @@ -6,4 +6,4 @@ 0.20: Add theme support 0.21: Add Settings 0.22: Use default Bangle formatter for booleans -0.23: Small fixes +0.23: Added note to configure position in "my location" if not done yet. Small fixes. diff --git a/apps/hworldclock/README.md b/apps/hworldclock/README.md index 0f4f9296c..170a2aa8b 100644 --- a/apps/hworldclock/README.md +++ b/apps/hworldclock/README.md @@ -8,6 +8,8 @@ If watch is locked, seconds get refreshed every 10 seconds. ## Usage +Location for sun set / rise set with mylocation app. + Provide names and the UTC offsets for up to three other timezones in the app store. These are stored in a json file on your watch. UTC offsets can be decimal (e.g., 5.5 for India). The clock does not handle summer time / daylight saving time changes automatically. If one of your three locations changes its UTC offset, you can simply change the setting in the app store and update. Currently the clock only supports 24 hour time format for the additional time zones. @@ -21,11 +23,5 @@ Please use [the Espruino Forum](http://forum.espruino.com/microcosms/1424/) if y Created by Hank. -Based on the great work of -================= -World Clock - 4 time zones -Made by [Scott Hale](https://www.github.com/computermacgyver), based upon the [Simple Clock](https://github.com/espruino/BangleApps/tree/master/apps/sclock). -===== a n d ===== -Sun Clock -[Sun Clock](https://github.com/espruino/BangleApps/tree/master/apps/sunclock) -================= +Based on the great work of "World Clock - 4 time zones". Made by [Scott Hale](https://www.github.com/computermacgyver), based upon the [Simple Clock](https://github.com/espruino/BangleApps/tree/master/apps/sclock). +And Sun Clock [Sun Clock](https://github.com/espruino/BangleApps/tree/master/apps/sunclock) \ No newline at end of file diff --git a/apps/hworldclock/app.js b/apps/hworldclock/app.js index f7444d319..b634f3f9c 100644 --- a/apps/hworldclock/app.js +++ b/apps/hworldclock/app.js @@ -46,8 +46,8 @@ setting = require("Storage").readJSON("setting.json",1); E.setTimeZone(setting.timezone); // timezone = 1 for MEZ, = 2 for MESZ SunCalc = require("hsuncalc.js"); const LOCATION_FILE = "mylocation.json"; -var rise = "07:00"; -var set = "20:00"; +var rise = null; +var set = null; //var pos = {altitude: 20, azimuth: 135}; //var noonpos = {altitude: 37, azimuth: 180}; //=======Sun @@ -137,12 +137,17 @@ function getCurrentTimeFromOffset(dt, offset) { } function updatePos() { - coord = require("Storage").readJSON(LOCATION_FILE,1)|| {"lat":53.3,"lon":10.1,"location":"Pattensen"}; + coord = require("Storage").readJSON(LOCATION_FILE,1)|| {"lat":0,"lon":0,"location":"-"}; //{"lat":53.3,"lon":10.1,"location":"Pattensen"}; + if (coord.lat != 0 && coord.lon != 0) { //pos = SunCalc.getPosition(Date.now(), coord.lat, coord.lon); times = SunCalc.getTimes(Date.now(), coord.lat, coord.lon); - rise = times.sunrise.toString().split(" ")[4].substr(0,5); - set = times.sunset.toString().split(" ")[4].substr(0,5); + rise = "^" + times.sunrise.toString().split(" ")[4].substr(0,5); + set = "v" + times.sunset.toString().split(" ")[4].substr(0,5); //noonpos = SunCalc.getPosition(times.solarNoon, coord.lat, coord.lon); + } else { + rise = null; + set = null; + } } @@ -266,8 +271,12 @@ function draw() { }); if (showSunInfo) { - g.setFontAlign(-1, 0).setFont("Vector",12).drawString(`^${rise}`, 10, 3 + yposWorld + 3 * 15, true); // draw riseset - g.setFontAlign(1, 0).drawString(`v${set}`, xcol2, 3 + yposWorld + 3 * 15, true); // draw riseset + if (rise != null){ + g.setFontAlign(-1, 0).setFont("Vector",12).drawString(`${rise}`, 10, 3 + yposWorld + 3 * 15, true); // draw riseset + g.setFontAlign(1, 0).drawString(`${set}`, xcol2, 3 + yposWorld + 3 * 15, true); // draw riseset + } else { + g.setFontAlign(-1, 0).setFont("Vector",11).drawString("set city in \'my location\' app!", 10, 3 + yposWorld + 3 * 15, true); + } } //debug settings //g.setFontAlign(1, 0); diff --git a/apps/hworldclock/custom.html b/apps/hworldclock/custom.html index 896d999f5..3e6d0b901 100644 --- a/apps/hworldclock/custom.html +++ b/apps/hworldclock/custom.html @@ -30,8 +30,8 @@ } } catch(e){ offsets=[ - [true,"London",0], - [true,"NY",-5], + [true,"London",1], + [true,"NY",-4], [true, "Denver",-6], ]; From 088cd53b9c43f97531ba14962a857a8347ab65af Mon Sep 17 00:00:00 2001 From: Hank Date: Fri, 1 Jul 2022 19:25:54 +0200 Subject: [PATCH 4/8] Fixes --- apps/hworldclock/app.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/apps/hworldclock/app.js b/apps/hworldclock/app.js index b634f3f9c..a0fb4cd20 100644 --- a/apps/hworldclock/app.js +++ b/apps/hworldclock/app.js @@ -46,8 +46,8 @@ setting = require("Storage").readJSON("setting.json",1); E.setTimeZone(setting.timezone); // timezone = 1 for MEZ, = 2 for MESZ SunCalc = require("hsuncalc.js"); const LOCATION_FILE = "mylocation.json"; -var rise = null; -var set = null; +var rise = "read"; +var set = "..."; //var pos = {altitude: 20, azimuth: 135}; //var noonpos = {altitude: 37, azimuth: 180}; //=======Sun @@ -272,11 +272,11 @@ function draw() { if (showSunInfo) { if (rise != null){ - g.setFontAlign(-1, 0).setFont("Vector",12).drawString(`${rise}`, 10, 3 + yposWorld + 3 * 15, true); // draw riseset - g.setFontAlign(1, 0).drawString(`${set}`, xcol2, 3 + yposWorld + 3 * 15, true); // draw riseset + g.setFontAlign(-1, 0).setFont("Vector",12).drawString(`${rise}`, 10, 3 + yposWorld + 3 * 15, true); // draw rise + g.setFontAlign(1, 0).drawString(`${set}`, xcol2, 3 + yposWorld + 3 * 15, true); // draw set } else { g.setFontAlign(-1, 0).setFont("Vector",11).drawString("set city in \'my location\' app!", 10, 3 + yposWorld + 3 * 15, true); - } + } } //debug settings //g.setFontAlign(1, 0); From c99a0de9a90d35a4b8db7822ba41e57dfd8841d8 Mon Sep 17 00:00:00 2001 From: Hank Date: Fri, 1 Jul 2022 19:49:35 +0200 Subject: [PATCH 5/8] widbt_notify: Added "connection restored" notification. Fixed restoring of the watchface. --- apps/widbt_notify/ChangeLog | 1 + apps/widbt_notify/metadata.json | 2 +- apps/widbt_notify/widget.js | 15 +++++++++++++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/apps/widbt_notify/ChangeLog b/apps/widbt_notify/ChangeLog index 3708089c1..7214407bb 100644 --- a/apps/widbt_notify/ChangeLog +++ b/apps/widbt_notify/ChangeLog @@ -9,3 +9,4 @@ 0.10: Bug fix 0.11: Avoid too many notifications. Change disconnected colour to red. 0.12: Prevent repeated execution of `draw()` from the current app. +0.13: Added "connection restored" notification. Fixed restoring of the watchface. diff --git a/apps/widbt_notify/metadata.json b/apps/widbt_notify/metadata.json index 0a144ade1..bab4a777c 100644 --- a/apps/widbt_notify/metadata.json +++ b/apps/widbt_notify/metadata.json @@ -1,7 +1,7 @@ { "id": "widbt_notify", "name": "Bluetooth Widget with Notification", - "version": "0.12", + "version": "0.13", "description": "Show the current Bluetooth connection status in the top right of the clock and vibrate when disconnected.", "icon": "widget.png", "type": "widget", diff --git a/apps/widbt_notify/widget.js b/apps/widbt_notify/widget.js index fd088c670..517ab5965 100644 --- a/apps/widbt_notify/widget.js +++ b/apps/widbt_notify/widget.js @@ -15,13 +15,28 @@ WIDGETS.bluetooth_notify = { redrawCurrentApp: function(){ if(typeof(draw)=='function'){ + g.clear(); draw(); + Bangle.loadWidgets(); + Bangle.drawWidgets(); }else{ load(); // fallback. This might reset some variables } }, connect: function() { + if(WIDGETS.bluetooth_notify.warningEnabled == 1){ + E.showMessage(/*LANG*/'Connection\n restored.', 'Bluetooth'); + setTimeout(()=>{WIDGETS.bluetooth_notify.redrawCurrentApp();}, 3000); // clear message - this will reload the widget, resetting 'warningEnabled'. + + WIDGETS.bluetooth_notify.warningEnabled = 0; + setTimeout('WIDGETS.bluetooth_notify.warningEnabled = 1;', 30000); // don't buzz for the next 30 seconds. + + var quiet = (require('Storage').readJSON('setting.json',1)||{}).quiet; + if(!quiet){ + Bangle.buzz(700, 1); // buzz on connection loss + } + } WIDGETS.bluetooth_notify.draw(); }, From d83396036bd7b846561a30bd0b2c18f3acfb7f9e Mon Sep 17 00:00:00 2001 From: Hank Date: Fri, 1 Jul 2022 23:01:48 +0200 Subject: [PATCH 6/8] widbt: Added configuration option --- apps/widbt_notify/ChangeLog | 1 + apps/widbt_notify/metadata.json | 10 +++- apps/widbt_notify/settings.js | 62 +++++++++++++++++++ apps/widbt_notify/widget.js | 103 +++++++++++++++++++++----------- 4 files changed, 139 insertions(+), 37 deletions(-) create mode 100644 apps/widbt_notify/settings.js diff --git a/apps/widbt_notify/ChangeLog b/apps/widbt_notify/ChangeLog index 7214407bb..a9b23f438 100644 --- a/apps/widbt_notify/ChangeLog +++ b/apps/widbt_notify/ChangeLog @@ -10,3 +10,4 @@ 0.11: Avoid too many notifications. Change disconnected colour to red. 0.12: Prevent repeated execution of `draw()` from the current app. 0.13: Added "connection restored" notification. Fixed restoring of the watchface. +0.14: Added configuration option \ No newline at end of file diff --git a/apps/widbt_notify/metadata.json b/apps/widbt_notify/metadata.json index bab4a777c..d6dffc858 100644 --- a/apps/widbt_notify/metadata.json +++ b/apps/widbt_notify/metadata.json @@ -1,13 +1,17 @@ { "id": "widbt_notify", "name": "Bluetooth Widget with Notification", - "version": "0.13", + "version": "0.14", "description": "Show the current Bluetooth connection status in the top right of the clock and vibrate when disconnected.", "icon": "widget.png", "type": "widget", "tags": "widget,bluetooth", "supports": ["BANGLEJS","BANGLEJS2"], "storage": [ - {"name":"widbt_notify.wid.js","url":"widget.js"} - ] + {"name":"widbt_notify.wid.js","url":"widget.js"}, + {"name":"widbt_notify.settings.js","url":"settings.js"} + ], + "data": [ + {"name":"widbt_notify.json"} + ] } diff --git a/apps/widbt_notify/settings.js b/apps/widbt_notify/settings.js new file mode 100644 index 000000000..ad0a65a5f --- /dev/null +++ b/apps/widbt_notify/settings.js @@ -0,0 +1,62 @@ +(function(back) { + var FILE = "widbt_notify.json"; + var settings = Object.assign({ + secondsOnUnlock: false, + }, require('Storage').readJSON(FILE, true) || {}); + + function writeSettings() { + require('Storage').writeJSON(FILE, settings); + } + + // Helper method which uses int-based menu item for set of string values + function stringItems(startvalue, writer, values) { + return { + value: (startvalue === undefined ? 0 : values.indexOf(startvalue)), + format: v => values[v], + min: 0, + max: values.length - 1, + wrap: true, + step: 1, + onchange: v => { + writer(values[v]); + writeSettings(); + } + }; + } + + // Helper method which breaks string set settings down to local settings object + function stringInSettings(name, values) { + return stringItems(settings[name], v => settings[name] = v, values); + } + + var mainmenu = { + "": { + "title": "Bluetooth Widget WN" + }, + "< Back": () => back(), + "Show Widget": { + value: (settings.showWidget !== undefined ? settings.showWidget : true), + onchange: v => { + settings.showWidget = v; + writeSettings(); + } + }, + "Buzz on Connect": { + value: (settings.buzzOnConnect !== undefined ? settings.buzzOnConnect : true), + onchange: v => { + settings.buzzOnConnect = v; + writeSettings(); + } + }, + "Buzz on loss": { + value: (settings.buzzOnLoss !== undefined ? settings.buzzOnLoss : true), + onchange: v => { + settings.buzzOnLoss = v; + writeSettings(); + } + } + }; + + E.showMenu(mainmenu); + +}); diff --git a/apps/widbt_notify/widget.js b/apps/widbt_notify/widget.js index 517ab5965..43a3b1ed1 100644 --- a/apps/widbt_notify/widget.js +++ b/apps/widbt_notify/widget.js @@ -2,57 +2,92 @@ WIDGETS.bluetooth_notify = { area: "tr", width: 15, warningEnabled: 1, + + // ------------ Settings -------- very lame - need to improve + readshowWidget: function() { + var showWidget; + const SETTINGSFILE = "widbt_notify.json"; + function def (value, def) {return value !== undefined ? value : def;} + var settings = require('Storage').readJSON(SETTINGSFILE, true) || {}; + showWidget = def(settings.showWidget, true); + return showWidget; + }, + + readBuzzOnConnect: function() { + var buzzOnConnect; + const SETTINGSFILE = "widbt_notify.json"; + function def (value, def) {return value !== undefined ? value : def;} + var settings = require('Storage').readJSON(SETTINGSFILE, true) || {}; + buzzOnConnect = def(settings.buzzOnConnect, true); + return buzzOnConnect; + }, + + readBuzzOnLoss: function() { + var buzzOnLoss; + const SETTINGSFILE = "widbt_notify.json"; + function def (value, def) {return value !== undefined ? value : def;} + var settings = require('Storage').readJSON(SETTINGSFILE, true) || {}; + buzzOnLoss = def(settings.buzzOnLoss, true); + return buzzOnLoss; + }, + // ------------ Settings -------- + draw: function() { - g.reset(); - if (NRF.getSecurityStatus().connected) { - g.setColor((g.getBPP() > 8) ? "#07f" : (g.theme.dark ? "#0ff" : "#00f")); - } else { - // g.setColor(g.theme.dark ? "#666" : "#999"); - g.setColor("#f00"); // red is easier to distinguish from blue + if (WIDGETS.bluetooth_notify.readshowWidget()){ + g.reset(); + if (NRF.getSecurityStatus().connected) { + g.setColor((g.getBPP() > 8) ? "#07f" : (g.theme.dark ? "#0ff" : "#00f")); + } else { + // g.setColor(g.theme.dark ? "#666" : "#999"); + g.setColor("#f00"); // red is easier to distinguish from blue + } + g.drawImage(atob("CxQBBgDgFgJgR4jZMawfAcA4D4NYybEYIwTAsBwDAA=="), 2 + this.x, 2 + this.y); } - g.drawImage(atob("CxQBBgDgFgJgR4jZMawfAcA4D4NYybEYIwTAsBwDAA=="), 2 + this.x, 2 + this.y); }, redrawCurrentApp: function(){ if(typeof(draw)=='function'){ - g.clear(); + g.clear(); draw(); - Bangle.loadWidgets(); - Bangle.drawWidgets(); + Bangle.loadWidgets(); + Bangle.drawWidgets(); }else{ load(); // fallback. This might reset some variables } }, connect: function() { - if(WIDGETS.bluetooth_notify.warningEnabled == 1){ - E.showMessage(/*LANG*/'Connection\n restored.', 'Bluetooth'); - setTimeout(()=>{WIDGETS.bluetooth_notify.redrawCurrentApp();}, 3000); // clear message - this will reload the widget, resetting 'warningEnabled'. - - WIDGETS.bluetooth_notify.warningEnabled = 0; - setTimeout('WIDGETS.bluetooth_notify.warningEnabled = 1;', 30000); // don't buzz for the next 30 seconds. - - var quiet = (require('Storage').readJSON('setting.json',1)||{}).quiet; - if(!quiet){ - Bangle.buzz(700, 1); // buzz on connection loss - } - } - WIDGETS.bluetooth_notify.draw(); + + if(WIDGETS.bluetooth_notify.warningEnabled == 1){ + E.showMessage(/*LANG*/'Connection\nrestored.', 'Bluetooth'); + setTimeout(()=>{WIDGETS.bluetooth_notify.redrawCurrentApp();}, 3000); // clear message - this will reload the widget, resetting 'warningEnabled'. + + WIDGETS.bluetooth_notify.warningEnabled = 0; + setTimeout('WIDGETS.bluetooth_notify.warningEnabled = 1;', 300); // don't buzz for the next 30 seconds. + + var quiet = (require('Storage').readJSON('setting.json',1)||{}).quiet; + if(!quiet && WIDGETS.bluetooth_notify.readBuzzOnConnect()){ + Bangle.buzz(700, 1); // buzz on connection resume + } + } + WIDGETS.bluetooth_notify.draw(); + }, disconnect: function() { - if(WIDGETS.bluetooth_notify.warningEnabled == 1){ - E.showMessage(/*LANG*/'Connection\nlost.', 'Bluetooth'); - setTimeout(()=>{WIDGETS.bluetooth_notify.redrawCurrentApp();}, 3000); // clear message - this will reload the widget, resetting 'warningEnabled'. - - WIDGETS.bluetooth_notify.warningEnabled = 0; - setTimeout('WIDGETS.bluetooth_notify.warningEnabled = 1;', 30000); // don't buzz for the next 30 seconds. - - var quiet = (require('Storage').readJSON('setting.json',1)||{}).quiet; - if(!quiet){ - Bangle.buzz(700, 1); // buzz on connection loss + if(WIDGETS.bluetooth_notify.warningEnabled == 1){ + E.showMessage(/*LANG*/ 'Connection\nlost.', 'Bluetooth'); + setTimeout(()=>{WIDGETS.bluetooth_notify.redrawCurrentApp();}, 3000); // clear message - this will reload the widget, resetting 'warningEnabled'. + + WIDGETS.bluetooth_notify.warningEnabled = 0; + setTimeout('WIDGETS.bluetooth_notify.warningEnabled = 1;', 300); // don't buzz for the next 30 seconds. + + var quiet = (require('Storage').readJSON('setting.json',1)||{}).quiet; + if(!quiet && WIDGETS.bluetooth_notify.readBuzzOnLoss()){ + Bangle.buzz(700, 1); // buzz on connection loss + } } - } + WIDGETS.bluetooth_notify.draw(); } }; From 371dd94a03a054dc0ffdb375e4d64b583d8e2df4 Mon Sep 17 00:00:00 2001 From: Hank Date: Sat, 2 Jul 2022 08:54:27 +0200 Subject: [PATCH 7/8] fix ms --- apps/widbt_notify/widget.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/widbt_notify/widget.js b/apps/widbt_notify/widget.js index 43a3b1ed1..09ff83d72 100644 --- a/apps/widbt_notify/widget.js +++ b/apps/widbt_notify/widget.js @@ -63,7 +63,7 @@ WIDGETS.bluetooth_notify = { setTimeout(()=>{WIDGETS.bluetooth_notify.redrawCurrentApp();}, 3000); // clear message - this will reload the widget, resetting 'warningEnabled'. WIDGETS.bluetooth_notify.warningEnabled = 0; - setTimeout('WIDGETS.bluetooth_notify.warningEnabled = 1;', 300); // don't buzz for the next 30 seconds. + setTimeout('WIDGETS.bluetooth_notify.warningEnabled = 1;', 30000); // don't buzz for the next 30 seconds. var quiet = (require('Storage').readJSON('setting.json',1)||{}).quiet; if(!quiet && WIDGETS.bluetooth_notify.readBuzzOnConnect()){ @@ -80,7 +80,7 @@ WIDGETS.bluetooth_notify = { setTimeout(()=>{WIDGETS.bluetooth_notify.redrawCurrentApp();}, 3000); // clear message - this will reload the widget, resetting 'warningEnabled'. WIDGETS.bluetooth_notify.warningEnabled = 0; - setTimeout('WIDGETS.bluetooth_notify.warningEnabled = 1;', 300); // don't buzz for the next 30 seconds. + setTimeout('WIDGETS.bluetooth_notify.warningEnabled = 1;', 30000); // don't buzz for the next 30 seconds. var quiet = (require('Storage').readJSON('setting.json',1)||{}).quiet; if(!quiet && WIDGETS.bluetooth_notify.readBuzzOnLoss()){ From d0a33541a5e143bb65488dcdebbaa59b7537a5a9 Mon Sep 17 00:00:00 2001 From: Hank Date: Mon, 4 Jul 2022 09:45:15 +0200 Subject: [PATCH 8/8] 0.15: Added option to hide widget when connected --- apps/widbt_notify/ChangeLog | 3 ++- apps/widbt_notify/metadata.json | 2 +- apps/widbt_notify/settings.js | 9 ++++++++- apps/widbt_notify/widget.js | 18 ++++++++++++++++-- 4 files changed, 27 insertions(+), 5 deletions(-) diff --git a/apps/widbt_notify/ChangeLog b/apps/widbt_notify/ChangeLog index a9b23f438..8f1dab908 100644 --- a/apps/widbt_notify/ChangeLog +++ b/apps/widbt_notify/ChangeLog @@ -10,4 +10,5 @@ 0.11: Avoid too many notifications. Change disconnected colour to red. 0.12: Prevent repeated execution of `draw()` from the current app. 0.13: Added "connection restored" notification. Fixed restoring of the watchface. -0.14: Added configuration option \ No newline at end of file +0.14: Added configuration option +0.15: Added option to hide widget when connected \ No newline at end of file diff --git a/apps/widbt_notify/metadata.json b/apps/widbt_notify/metadata.json index d6dffc858..566a51b57 100644 --- a/apps/widbt_notify/metadata.json +++ b/apps/widbt_notify/metadata.json @@ -1,7 +1,7 @@ { "id": "widbt_notify", "name": "Bluetooth Widget with Notification", - "version": "0.14", + "version": "0.15", "description": "Show the current Bluetooth connection status in the top right of the clock and vibrate when disconnected.", "icon": "widget.png", "type": "widget", diff --git a/apps/widbt_notify/settings.js b/apps/widbt_notify/settings.js index ad0a65a5f..1e0d5036b 100644 --- a/apps/widbt_notify/settings.js +++ b/apps/widbt_notify/settings.js @@ -54,7 +54,14 @@ settings.buzzOnLoss = v; writeSettings(); } - } + }, + "Hide connected": { + value: (settings.hideConnected !== undefined ? settings.hideConnected : false), + onchange: v => { + settings.hideConnected = v; + writeSettings(); + } + } }; E.showMenu(mainmenu); diff --git a/apps/widbt_notify/widget.js b/apps/widbt_notify/widget.js index 09ff83d72..de2baa3cf 100644 --- a/apps/widbt_notify/widget.js +++ b/apps/widbt_notify/widget.js @@ -30,18 +30,32 @@ WIDGETS.bluetooth_notify = { buzzOnLoss = def(settings.buzzOnLoss, true); return buzzOnLoss; }, + + readHideConnected: function() { + var hideConnected; + const SETTINGSFILE = "widbt_notify.json"; + function def (value, def) {return value !== undefined ? value : def;} + var settings = require('Storage').readJSON(SETTINGSFILE, true) || {}; + hideConnected = def(settings.hideConnected, true); + return hideConnected; + }, + + // ------------ Settings -------- draw: function() { if (WIDGETS.bluetooth_notify.readshowWidget()){ g.reset(); if (NRF.getSecurityStatus().connected) { - g.setColor((g.getBPP() > 8) ? "#07f" : (g.theme.dark ? "#0ff" : "#00f")); + if (!WIDGETS.bluetooth_notify.readHideConnected()) { + g.setColor((g.getBPP() > 8) ? "#07f" : (g.theme.dark ? "#0ff" : "#00f")); + g.drawImage(atob("CxQBBgDgFgJgR4jZMawfAcA4D4NYybEYIwTAsBwDAA=="), 2 + this.x, 2 + this.y); + } } else { // g.setColor(g.theme.dark ? "#666" : "#999"); g.setColor("#f00"); // red is easier to distinguish from blue + g.drawImage(atob("CxQBBgDgFgJgR4jZMawfAcA4D4NYybEYIwTAsBwDAA=="), 2 + this.x, 2 + this.y); } - g.drawImage(atob("CxQBBgDgFgJgR4jZMawfAcA4D4NYybEYIwTAsBwDAA=="), 2 + this.x, 2 + this.y); } },