From e79c95022abfe0a6fc7f0daad221b5f5ac1d3774 Mon Sep 17 00:00:00 2001 From: Pavel Machek Date: Thu, 2 Mar 2023 00:26:50 +0100 Subject: [PATCH 01/13] openstmap: display waypoints If waypoints module is available, display the waypoints on the map. Also update the documentation and fix some english in the documentation. --- apps/openstmap/README.md | 12 ++++++------ apps/openstmap/app.js | 18 ++++++++++++++++++ 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/apps/openstmap/README.md b/apps/openstmap/README.md index f19b13bd1..bf247c7b7 100644 --- a/apps/openstmap/README.md +++ b/apps/openstmap/README.md @@ -17,20 +17,20 @@ To add a map: * Scroll and zoom to the area of interest or use the Search button in the top left * Now choose the size you want to upload (Small/Medium/etc) * On Bangle.js 1 you can choose if you want a 3 bits per pixel map (this is lower -quality but uploads faster and takes less space). On Bangle.js 2 you only have a 3bpp -display so can only use 3bpp. +quality, but uploads faster and takes less space). Bangle.js 2 is limited to 3bpp. * Click `Get Map`, and a preview will be displayed. If you need to adjust the area you can change settings, move the map around, and click `Get Map` again. * When you're ready, click `Upload` ## Bangle.js App -The Bangle.js app allows you to view a map - it also turns the GPS on and marks -the path that you've been travelling (if enabled). +The Bangle.js app allows you to view a map. It also turns the GPS on +and marks the path that you've been travelling (if enabled), and +displays waypoints in the watch (if dependencies exist). * Drag on the screen to move the map -* Press the button to bring up a menu, where you can zoom, go to GPS location -, put the map back in its default location, or choose whether to draw the currently +* Press the button to bring up a menu, where you can zoom, go to GPS location, +put the map back in its default location, or choose whether to draw the currently recording GPS track (from the `Recorder` app). **Note:** If enabled, drawing the currently recorded GPS track can take a second diff --git a/apps/openstmap/app.js b/apps/openstmap/app.js index 89e2d2ddb..e7629f2e1 100644 --- a/apps/openstmap/app.js +++ b/apps/openstmap/app.js @@ -10,6 +10,7 @@ var settings = require("Storage").readJSON("openstmap.json",1)||{}; function redraw() { g.setClipRect(R.x,R.y,R.x2,R.y2); m.draw(); + drawPOI(); drawMarker(); // if track drawing is enabled... if (settings.drawTrack) { @@ -25,6 +26,23 @@ function redraw() { g.setClipRect(0,0,g.getWidth()-1,g.getHeight()-1); } +// Draw the POIs +function drawPOI() { + var waypoints = require("waypoints").load(); + if (!waypoints) + return; + g.setFont("Vector", 18); + waypoints.forEach((wp, idx) => { + var p = m.latLonToXY(wp.lat, wp.lon); + var sz = 2; + g.setColor(0,0,0); + g.fillRect(p.x-sz, p.y-sz, p.x+sz, p.y+sz); + g.setColor(0,0,0); + g.drawString(wp.name, p.x, p.y); + print(wp.name); + }) +} + // Draw the marker for where we are function drawMarker() { if (!fix.fix) return; From c18d1d4a42f5eb8882e12b0797c5c5605b1989f1 Mon Sep 17 00:00:00 2001 From: Pavel Machek Date: Fri, 3 Mar 2023 17:50:48 +0100 Subject: [PATCH 02/13] openstmap: fix operation without waypoints, increase version --- apps/openstmap/ChangeLog | 1 + apps/openstmap/app.js | 7 +++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/apps/openstmap/ChangeLog b/apps/openstmap/ChangeLog index 7f788c139..a256b459c 100644 --- a/apps/openstmap/ChangeLog +++ b/apps/openstmap/ChangeLog @@ -16,3 +16,4 @@ Support for zooming in on map Satellite count moved to widget bar to leave more room for the map 0.15: Make track drawing an option (default off) +0.16: Draw waypoints, too. diff --git a/apps/openstmap/app.js b/apps/openstmap/app.js index e7629f2e1..a5130d23e 100644 --- a/apps/openstmap/app.js +++ b/apps/openstmap/app.js @@ -28,9 +28,12 @@ function redraw() { // Draw the POIs function drawPOI() { - var waypoints = require("waypoints").load(); - if (!waypoints) + try { + var waypoints = require("waypoints").load(); + } catch (ex) { + // Waypoints module not available. return; + } g.setFont("Vector", 18); waypoints.forEach((wp, idx) => { var p = m.latLonToXY(wp.lat, wp.lon); From 2f53b732bc8384beb6c8f2787d514891f71c21e0 Mon Sep 17 00:00:00 2001 From: Pavel Machek Date: Fri, 3 Mar 2023 17:54:53 +0100 Subject: [PATCH 03/13] openstmap: We updated changelog, so increase version. --- apps/openstmap/metadata.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/openstmap/metadata.json b/apps/openstmap/metadata.json index 819dc4122..4419cd411 100644 --- a/apps/openstmap/metadata.json +++ b/apps/openstmap/metadata.json @@ -2,7 +2,7 @@ "id": "openstmap", "name": "OpenStreetMap", "shortName": "OpenStMap", - "version": "0.15", + "version": "0.16", "description": "Loads map tiles from OpenStreetMap onto your Bangle.js and displays a map of where you are. Once installed this also adds map functionality to `GPS Recorder` and `Recorder` apps", "readme": "README.md", "icon": "app.png", From 783686866e23bf8b11ea7d70a47f97ecfa96521d Mon Sep 17 00:00:00 2001 From: Pavel Machek Date: Fri, 3 Mar 2023 18:46:46 +0100 Subject: [PATCH 04/13] altimeter: Display sea-level pressure, too, and allow calibration Add display of sea-level pressure and temperature, and allow calibration by setting the altitude. That way, you can get precise altitude if you already know sea-level pressure (from example from forecast), or you can calibrate using known altitude and have precise readings for a while. --- apps/altimeter/ChangeLog | 1 + apps/altimeter/app.js | 55 +++++++++++++++++++++++++++++++----- apps/altimeter/metadata.json | 2 +- 3 files changed, 50 insertions(+), 8 deletions(-) diff --git a/apps/altimeter/ChangeLog b/apps/altimeter/ChangeLog index 29388520e..8d21cf797 100644 --- a/apps/altimeter/ChangeLog +++ b/apps/altimeter/ChangeLog @@ -1,2 +1,3 @@ 0.01: New App! 0.02: Actually upload correct code +0.03: Display sea-level pressure, too, and allow calibration diff --git a/apps/altimeter/app.js b/apps/altimeter/app.js index cac4e80fd..de664af39 100644 --- a/apps/altimeter/app.js +++ b/apps/altimeter/app.js @@ -1,4 +1,4 @@ -Bangle.setBarometerPower(true, "app"); +Bangle.setBarometerPower(true, "altimeter"); g.clear(1); Bangle.loadWidgets(); @@ -10,21 +10,62 @@ var MEDIANLENGTH = 20; var avr = [], median; var value = 0; +function getStandardPressure(altitude) { + const P0 = 1013.25; // standard pressure at sea level in hPa + const T0 = 288.15; // standard temperature at sea level in K + const g0 = 9.80665; // standard gravitational acceleration in m/s^2 + const R = 8.31432; // gas constant in J/(mol*K) + const M = 0.0289644; // molar mass of air in kg/mol + const L = -0.0065; // temperature lapse rate in K/m + + const temperature = T0 + L * altitude; // temperature at the given altitude + const pressure = P0 * Math.pow((temperature / T0), (-g0 * M) / (R * L)); // pressure at the given altitude + + return pressure; +} + +function convertToSeaLevelPressure(pressure, altitude) { + return 1013.25 * (pressure / getStandardPressure(altitude)); +} + Bangle.on('pressure', function(e) { while (avr.length>MEDIANLENGTH) avr.pop(); avr.unshift(e.altitude); median = avr.slice().sort(); - g.reset().clearRect(0,y-30,g.getWidth()-10,y+30); + g.reset().clearRect(0,y-30,g.getWidth()-10,R.h); if (median.length>10) { var mid = median.length>>1; value = E.sum(median.slice(mid-4,mid+5)) / 9; - g.setFont("Vector",50).setFontAlign(0,0).drawString((value-zero).toFixed(1), g.getWidth()/2, y); + t = value-zero; + if ((t > -100) && (t < 1000)) + t = t.toFixed(1); + else + t = t.toFixed(0); + g.setFont("Vector",50).setFontAlign(0,0).drawString(t, g.getWidth()/2, y); + sea = convertToSeaLevelPressure(e.pressure, value-zero); + t = sea.toFixed(1) + " " + e.temperature.toFixed(1); + if (0) { + print("alt raw:", value.toFixed(1)); + print("temperature:", e.temperature); + print("pressure:", e.pressure); + print("sea pressure:", sea); + print("std pressure:", getStandardPressure(value-zero)); + } + g.setFont("Vector",25).setFontAlign(-1,0).drawString(t, + 10, R.y+R.h - 35); } }); +print(g.getFonts()); g.reset(); -g.setFont("6x8").setFontAlign(0,0).drawString(/*LANG*/"ALTITUDE (m)", g.getWidth()/2, y-40); +g.setFont("Vector:15"); +g.setFontAlign(0,0); +g.drawString(/*LANG*/"ALTITUDE (m)", g.getWidth()/2, y-40); +g.drawString(/*LANG*/"SEA L (hPa) TEMP (C)", g.getWidth()/2, y+62); +g.flip(); g.setFont("6x8").setFontAlign(0,0,3).drawString(/*LANG*/"ZERO", g.getWidth()-5, g.getHeight()/2); -setWatch(function() { - zero = value; -}, (process.env.HWVERSION==2) ? BTN1 : BTN2, {repeat:true}); +Bangle.setUI("updown", btn=> { + if (!btn) zero=value; + if (btn<0) zero-=5; + if (btn>0) zero+=5; +}); diff --git a/apps/altimeter/metadata.json b/apps/altimeter/metadata.json index 8bdbf3022..8bf3772ed 100644 --- a/apps/altimeter/metadata.json +++ b/apps/altimeter/metadata.json @@ -1,6 +1,6 @@ { "id": "altimeter", "name": "Altimeter", - "version":"0.02", + "version":"0.03", "description": "Simple altimeter that can display height changed using Bangle.js 2's built in pressure sensor.", "icon": "app.png", "tags": "tool,outdoors", From 81fb1dafb04db2c81dd3ba9d72f21b1754d8759c Mon Sep 17 00:00:00 2001 From: Gabriele Monaco Date: Sat, 4 Mar 2023 15:56:50 +0100 Subject: [PATCH 05/13] weather: added monochrome parameter to `drawIcon` --- apps/weather/ChangeLog | 1 + apps/weather/clkinfo.js | 2 +- apps/weather/lib.js | 9 +++------ apps/weather/metadata.json | 2 +- 4 files changed, 6 insertions(+), 8 deletions(-) diff --git a/apps/weather/ChangeLog b/apps/weather/ChangeLog index 0010a58fd..50c033600 100644 --- a/apps/weather/ChangeLog +++ b/apps/weather/ChangeLog @@ -21,3 +21,4 @@ 0.22: Automatic translation of strings, some left untranslated. 0.23: Update clock_info to avoid a redraw 0.24: Redraw clock_info on update and provide color field for condition +0.25: Added monochrome parameter to drawIcon in lib diff --git a/apps/weather/clkinfo.js b/apps/weather/clkinfo.js index ef3b7d139..4e526b977 100644 --- a/apps/weather/clkinfo.js +++ b/apps/weather/clkinfo.js @@ -22,7 +22,7 @@ function weatherIcon(code) { var ovr = Graphics.createArrayBuffer(24,24,1,{msb:true}); - weatherLib.drawIcon({code:code},12,12,12,ovr); + weatherLib.drawIcon({code:code},12,12,12,ovr,true); var img = ovr.asImage(); img.transparent = 0; return img; diff --git a/apps/weather/lib.js b/apps/weather/lib.js index 14ca77ec6..af6aa4d7e 100644 --- a/apps/weather/lib.js +++ b/apps/weather/lib.js @@ -155,14 +155,11 @@ exports.getColor = function(code) { * @param y Top * @param r Icon Size * @param ovr Graphics instance (or undefined for g) + * @param monochrome If true, produce a monochromatic icon */ -exports.drawIcon = function(cond, x, y, r, ovr) { +exports.drawIcon = function(cond, x, y, r, ovr, monochrome) { var palette; - var monochrome=1; - if(!ovr) { - ovr = g; - monochrome=0; - } + if(!ovr) ovr = g; palette = getPalette(monochrome, ovr); diff --git a/apps/weather/metadata.json b/apps/weather/metadata.json index bcb2fe109..55c2973b0 100644 --- a/apps/weather/metadata.json +++ b/apps/weather/metadata.json @@ -1,7 +1,7 @@ { "id": "weather", "name": "Weather", - "version": "0.24", + "version": "0.25", "description": "Show Gadgetbridge weather report", "icon": "icon.png", "screenshots": [{"url":"screenshot.png"}], From 326afaf72eaef69906dc8aeda12e851ec078e42f Mon Sep 17 00:00:00 2001 From: Rob Pilling Date: Thu, 29 Dec 2022 21:59:23 +0000 Subject: [PATCH 06/13] New widget: bt2 --- apps/widbt2/metadata.json | 14 ++++++++ apps/widbt2/widget.js | 65 ++++++++++++++++++++++++++++++++++++++ apps/widbt2/widget.png | Bin 0 -> 1119 bytes 3 files changed, 79 insertions(+) create mode 100644 apps/widbt2/metadata.json create mode 100644 apps/widbt2/widget.js create mode 100644 apps/widbt2/widget.png diff --git a/apps/widbt2/metadata.json b/apps/widbt2/metadata.json new file mode 100644 index 000000000..af7728958 --- /dev/null +++ b/apps/widbt2/metadata.json @@ -0,0 +1,14 @@ +{ + "id": "widbt2", + "name": "Bluetooth Widget 2", + "version": "0.01", + "description": "If active, shows a white bluetooth icon, if connected, a blue one", + "icon": "widget.png", + "type": "widget", + "tags": "widget,bluetooth,clkinfo", + "provides_widgets" : ["bluetooth"], + "supports": ["BANGLEJS","BANGLEJS2"], + "storage": [ + {"name":"widbt2.wid.js","url":"widget.js"} + ] +} diff --git a/apps/widbt2/widget.js b/apps/widbt2/widget.js new file mode 100644 index 000000000..8b1fc3ede --- /dev/null +++ b/apps/widbt2/widget.js @@ -0,0 +1,65 @@ +(function(){ + "ram"; + + // 0: asleep, 1: active, 2: connected + let state = NRF.getSecurityStatus().connected + ? 2 + : 0; // could be active, assuming not here + + const width = () => state > 0 ? 15 : 0; + + const update = (newState) => { + state = newState; + WIDGETS.bluetooth.width = width(); + setTimeout(Bangle.drawWidgets, 50); // no need for .bind() + }; + + // { {key: State]: { boolean: string } } + // ^ dark theme + const colours = { + 1: { // active: white + false: "#fff", + true: "#fff", + }, + 2: { // connected: blue + false: "#0ff", + true: "#00f", + }, + }; + + WIDGETS.bluetooth = { + area: "tl", + sortorder: -1, + draw: function() { + if (state == 0) + return; + + g.reset(); + + g.setColor(colours[state][g.theme.dark]); + + g.drawImage( + atob("CxQBBgDgFgJgR4jZMawfAcA4D4NYybEYIwTAsBwDAA=="), + this.x + 2, + this.y + 2 + ); + }, + width: width(), + }; + + NRF.on("connect", update.bind(null, 2)); + NRF.on("disconnect", update.bind(null, 1)); + + let origWake = NRF.wake; + let origSleep = NRF.sleep; + + NRF.wake = function() { + update(1); + return origWake.apply(this, arguments); + }; + + NRF.sleep = function() { + update(0); + return origSleep.apply(this, arguments); + }; +})(); diff --git a/apps/widbt2/widget.png b/apps/widbt2/widget.png new file mode 100644 index 0000000000000000000000000000000000000000..1a884a62c1029ae43243f8f58ef9dc3a3327e437 GIT binary patch literal 1119 zcmV-l1fctgP)cE5(396`@Dz$wLqIPzYppJ*B(brZX|I zHChYW;Hm1lL~9feUi^283bm!!Ka0DG`v(zZvk8h?W%2@c?XT zES*ZPJU3a{7h{cB0RRrPTh=dGr*a^!0&xQX?DMczGEQwQ4)Y`c0EQJR_Oa?r)W%5x z0HhI_x1HK2pc0j7k^sKW*iQXQ=2YX6D9n-q_%qO+(!1;R%(3!ggBm9SkZ!j|fYm^E zR%O?(qZ5_=gLo$b@WZ#`wXJ`4=)@t~Y>Yv)Y!7y;OB zeO8rs?l*_RK!7NCKLhRU0}||esEhzCyx)O;I=Y5XtC(@B$NTljy45^tT?SHJ10ruX zOS$(<@@!=?P@`0+S)vnkL!=bB)DOg{Q*}L+GO)XAK;&$g@DSo22n#XlR9!)?07D(! zDxz;SOSunBbNCAVm!5U2c~9jVx@WU3=u3)pJ!ur3cu;sm-)NQ!pM}i;0{{TnZpA^Z ztASvff%b#?JdoF$<=hv8)Q159pyx{LBoBD4SyIzhb(HlW;>}!J+1=AqCDO_A6&XN}=e)0!pcibn z_HtD9d_@BAknp}zDCb9=>MK#y^fmCZ_8GoYkv>KTT7e$nHy?0mXP*UpX*>1PgVgRc z3#Fdn#d~2}5mATky^{qxZ#%U!Ve5AonQN!;&C-!_@cJGbKmk6^xYakqWbkDSU>e?6 zF9=onXw<2mHO=A62q0{DUp*iYB(+@Ja7a-n2aQU$C-1do)^M)j_l7Z`m-DHf;N2WNgeIsEr6@kFmJ z8_YbwGn3bL?QPY+LOBr_TDRcEMmfJ|;s=HR0IQ!ry9xAti1(G5Y&@#1^&${_&Hfi+ z9c`2jUpMuHhg{we{KebpwXs3NLqaRiAr)b6sg!$n>kZxDN)lj0k<-mm?qZatNdeqJ z)Lky+8&Ml40dUjvB)_tlzY&Ld+&A&{bh~wEWib~^c!+ZagoS&X-t=l^d_A@r#J2*U lKABp3ezkHW*6{xc{R@3@kib`1LqGrk002ovPDHLkV1l684mkh- literal 0 HcmV?d00001 From 3808b0bc3cd11337406e955bd8e0746a17524024 Mon Sep 17 00:00:00 2001 From: Rob Pilling Date: Sat, 25 Feb 2023 23:04:41 +0000 Subject: [PATCH 07/13] widbt2: convert to typescript --- apps/widbt2/widget.js | 111 ++++++++++++++++++------------------------ apps/widbt2/widget.ts | 73 +++++++++++++++++++++++++++ 2 files changed, 120 insertions(+), 64 deletions(-) create mode 100644 apps/widbt2/widget.ts diff --git a/apps/widbt2/widget.js b/apps/widbt2/widget.js index 8b1fc3ede..441a0a099 100644 --- a/apps/widbt2/widget.js +++ b/apps/widbt2/widget.js @@ -1,65 +1,48 @@ -(function(){ - "ram"; - - // 0: asleep, 1: active, 2: connected - let state = NRF.getSecurityStatus().connected - ? 2 - : 0; // could be active, assuming not here - - const width = () => state > 0 ? 15 : 0; - - const update = (newState) => { - state = newState; - WIDGETS.bluetooth.width = width(); - setTimeout(Bangle.drawWidgets, 50); // no need for .bind() - }; - - // { {key: State]: { boolean: string } } - // ^ dark theme - const colours = { - 1: { // active: white - false: "#fff", - true: "#fff", - }, - 2: { // connected: blue - false: "#0ff", - true: "#00f", - }, - }; - - WIDGETS.bluetooth = { - area: "tl", - sortorder: -1, - draw: function() { - if (state == 0) - return; - - g.reset(); - - g.setColor(colours[state][g.theme.dark]); - - g.drawImage( - atob("CxQBBgDgFgJgR4jZMawfAcA4D4NYybEYIwTAsBwDAA=="), - this.x + 2, - this.y + 2 - ); - }, - width: width(), - }; - - NRF.on("connect", update.bind(null, 2)); - NRF.on("disconnect", update.bind(null, 1)); - - let origWake = NRF.wake; - let origSleep = NRF.sleep; - - NRF.wake = function() { - update(1); - return origWake.apply(this, arguments); - }; - - NRF.sleep = function() { - update(0); - return origSleep.apply(this, arguments); - }; +"use strict"; +(function () { + "ram"; + var _a; + var state = NRF.getSecurityStatus().connected + ? 2 + : 0; + var width = function () { return state > 0 ? 15 : 0; }; + var update = function (newState) { + state = newState; + WIDGETS["bluetooth"].width = width(); + setTimeout(Bangle.drawWidgets, 50); + }; + var colours = (_a = {}, + _a[1] = { + false: "#fff", + true: "#fff", + }, + _a[2] = { + false: "#0ff", + true: "#00f", + }, + _a); + WIDGETS["bluetooth"] = { + area: "tl", + sortorder: -1, + draw: function () { + if (state == 0) + return; + g.reset(); + g.setColor(colours[state]["".concat(g.theme.dark)]); + g.drawImage(atob("CxQBBgDgFgJgR4jZMawfAcA4D4NYybEYIwTAsBwDAA=="), this.x + 2, this.y + 2); + }, + width: width(), + }; + NRF.on("connect", update.bind(null, 2)); + NRF.on("disconnect", update.bind(null, 1)); + var origWake = NRF.wake; + var origSleep = NRF.sleep; + NRF.wake = function () { + update(1); + return origWake.apply(this, arguments); + }; + NRF.sleep = function () { + update(0); + return origSleep.apply(this, arguments); + }; })(); diff --git a/apps/widbt2/widget.ts b/apps/widbt2/widget.ts new file mode 100644 index 000000000..c63d187a5 --- /dev/null +++ b/apps/widbt2/widget.ts @@ -0,0 +1,73 @@ +(() => { + "ram"; + + const enum State { + Asleep, + Active, + Connected + } + + let state: State = NRF.getSecurityStatus().connected + ? State.Connected + : State.Asleep; // could be active, assuming not here + + const width = () => state > State.Asleep ? 15 : 0; + + const update = (newState: State) => { + state = newState; + WIDGETS["bluetooth"]!.width = width(); + setTimeout(Bangle.drawWidgets, 50); // no need for .bind() + }; + + type DarkTheme = `${boolean}`; + const colours: { + [key in State.Active | State.Connected]: { + [key in DarkTheme]: ColorResolvable + } + } = { + [State.Active]: { + false: "#fff", + true: "#fff", + }, + [State.Connected]: { + false: "#0ff", + true: "#00f", + }, + }; + + WIDGETS["bluetooth"] = { + area: "tl", + sortorder: -1, + draw: function() { + if (state == State.Asleep) + return; + + g.reset(); + + g.setColor(colours[state][`${g.theme.dark}`]); + + g.drawImage( + atob("CxQBBgDgFgJgR4jZMawfAcA4D4NYybEYIwTAsBwDAA=="), + this.x + 2, + this.y + 2 + ); + }, + width: width(), + }; + + NRF.on("connect", update.bind(null, State.Connected)); + NRF.on("disconnect", update.bind(null, State.Active)); + + const origWake = NRF.wake; + const origSleep = NRF.sleep; + + NRF.wake = function() { + update(State.Active); + return origWake.apply(this, arguments); + }; + + NRF.sleep = function() { + update(State.Asleep); + return origSleep.apply(this, arguments); + }; +})(); From d9dc729abd4c1c25e7489f9de6abac498312abd2 Mon Sep 17 00:00:00 2001 From: Rob Pilling Date: Mon, 6 Mar 2023 11:44:27 +0000 Subject: [PATCH 08/13] Regenerate types - NRF.getSecurityStatus() --- apps/widbt2/widget.ts | 4 ++-- typescript/types/main.d.ts | 24 +++++++++++++++++++++--- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/apps/widbt2/widget.ts b/apps/widbt2/widget.ts index c63d187a5..d2585f1fb 100644 --- a/apps/widbt2/widget.ts +++ b/apps/widbt2/widget.ts @@ -48,8 +48,8 @@ g.drawImage( atob("CxQBBgDgFgJgR4jZMawfAcA4D4NYybEYIwTAsBwDAA=="), - this.x + 2, - this.y + 2 + this.x! + 2, + this.y! + 2 ); }, width: width(), diff --git a/typescript/types/main.d.ts b/typescript/types/main.d.ts index 1223f527d..944d55326 100644 --- a/typescript/types/main.d.ts +++ b/typescript/types/main.d.ts @@ -183,6 +183,23 @@ type NRFFilters = { manufacturerData?: object; }; +type NRFSecurityStatus = { + advertising: boolean, +} & ( + { + connected: true, + encrypted: boolean, + mitm_protected: boolean, + bonded: boolean, + connected_addr?: string, + } | { + connected: false, + encrypted: false, + mitm_protected: false, + bonded: false, + } +); + type ImageObject = { width: number; height: number; @@ -721,7 +738,7 @@ declare class NRF { * @returns {any} An object * @url http://www.espruino.com/Reference#l_NRF_getSecurityStatus */ - static getSecurityStatus(): any; + static getSecurityStatus(): NRFSecurityStatus; /** * @returns {any} An object @@ -1898,6 +1915,7 @@ declare class NRF { * encrypted // Communication on this link is encrypted. * mitm_protected // The encrypted communication is also protected against man-in-the-middle attacks. * bonded // The peer is bonded with us + * advertising // Are we currently advertising? * connected_addr // If connected=true, the MAC address of the currently connected device * } * ``` @@ -1906,7 +1924,7 @@ declare class NRF { * @returns {any} An object * @url http://www.espruino.com/Reference#l_NRF_getSecurityStatus */ - static getSecurityStatus(): any; + static getSecurityStatus(): NRFSecurityStatus; /** * @@ -4553,7 +4571,7 @@ declare class BluetoothRemoteGATTServer { * @returns {any} An object * @url http://www.espruino.com/Reference#l_BluetoothRemoteGATTServer_getSecurityStatus */ - getSecurityStatus(): any; + getSecurityStatus(): NRFSecurityStatus; /** * See `NRF.connect` for usage examples. From 832ec7a7a5eccab3c0e027d42ae7ea7a630c1624 Mon Sep 17 00:00:00 2001 From: Rob Pilling Date: Mon, 6 Mar 2023 12:04:58 +0000 Subject: [PATCH 09/13] Use NRF.getSecurityStatus().advertising for initial state --- apps/widbt2/widget.js | 11 ++++++++--- apps/widbt2/widget.ts | 10 +++++++--- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/apps/widbt2/widget.js b/apps/widbt2/widget.js index 441a0a099..1d32e1bc4 100644 --- a/apps/widbt2/widget.js +++ b/apps/widbt2/widget.js @@ -2,9 +2,14 @@ (function () { "ram"; var _a; - var state = NRF.getSecurityStatus().connected - ? 2 - : 0; + var state = (function () { + var status = NRF.getSecurityStatus(); + if (status.connected) + return 2; + if (status.advertising) + return 1; + return 0; + })(); var width = function () { return state > 0 ? 15 : 0; }; var update = function (newState) { state = newState; diff --git a/apps/widbt2/widget.ts b/apps/widbt2/widget.ts index d2585f1fb..8f02c1b8c 100644 --- a/apps/widbt2/widget.ts +++ b/apps/widbt2/widget.ts @@ -7,9 +7,13 @@ Connected } - let state: State = NRF.getSecurityStatus().connected - ? State.Connected - : State.Asleep; // could be active, assuming not here + let state: State = (() => { + const status = NRF.getSecurityStatus(); + + if (status.connected) return State.Connected; + if (status.advertising) return State.Active; + return State.Asleep; + })(); const width = () => state > State.Asleep ? 15 : 0; From c0194f260f99142159d35962ae480427ff026e9e Mon Sep 17 00:00:00 2001 From: Rob Pilling Date: Mon, 6 Mar 2023 12:14:56 +0000 Subject: [PATCH 10/13] Rename -> widbtstates --- apps/{widbt2 => widbtstates}/metadata.json | 8 ++++---- apps/{widbt2 => widbtstates}/widget.js | 0 apps/{widbt2 => widbtstates}/widget.png | Bin apps/{widbt2 => widbtstates}/widget.ts | 0 4 files changed, 4 insertions(+), 4 deletions(-) rename apps/{widbt2 => widbtstates}/metadata.json (64%) rename apps/{widbt2 => widbtstates}/widget.js (100%) rename apps/{widbt2 => widbtstates}/widget.png (100%) rename apps/{widbt2 => widbtstates}/widget.ts (100%) diff --git a/apps/widbt2/metadata.json b/apps/widbtstates/metadata.json similarity index 64% rename from apps/widbt2/metadata.json rename to apps/widbtstates/metadata.json index af7728958..ada530e1b 100644 --- a/apps/widbt2/metadata.json +++ b/apps/widbtstates/metadata.json @@ -1,14 +1,14 @@ { - "id": "widbt2", - "name": "Bluetooth Widget 2", + "id": "widbtstates", + "name": "Bluetooth States", "version": "0.01", - "description": "If active, shows a white bluetooth icon, if connected, a blue one", + "description": "If active, shows a white bluetooth icon, if connected, a blue one (nothing if sleeping)", "icon": "widget.png", "type": "widget", "tags": "widget,bluetooth,clkinfo", "provides_widgets" : ["bluetooth"], "supports": ["BANGLEJS","BANGLEJS2"], "storage": [ - {"name":"widbt2.wid.js","url":"widget.js"} + {"name":"widbtstates.wid.js","url":"widget.js"} ] } diff --git a/apps/widbt2/widget.js b/apps/widbtstates/widget.js similarity index 100% rename from apps/widbt2/widget.js rename to apps/widbtstates/widget.js diff --git a/apps/widbt2/widget.png b/apps/widbtstates/widget.png similarity index 100% rename from apps/widbt2/widget.png rename to apps/widbtstates/widget.png diff --git a/apps/widbt2/widget.ts b/apps/widbtstates/widget.ts similarity index 100% rename from apps/widbt2/widget.ts rename to apps/widbtstates/widget.ts From a135ba497f6d19f23a788f0a873446c42a5c0547 Mon Sep 17 00:00:00 2001 From: Rob Pilling Date: Mon, 6 Mar 2023 12:15:04 +0000 Subject: [PATCH 11/13] ChangeLog --- apps/widbtstates/ChangeLog | 1 + 1 file changed, 1 insertion(+) create mode 100644 apps/widbtstates/ChangeLog diff --git a/apps/widbtstates/ChangeLog b/apps/widbtstates/ChangeLog new file mode 100644 index 000000000..5560f00bc --- /dev/null +++ b/apps/widbtstates/ChangeLog @@ -0,0 +1 @@ +0.01: New App! From 8a3cb4480d51b90d22d0e39036833af435ef86a4 Mon Sep 17 00:00:00 2001 From: Christian Meichle Date: Mon, 6 Mar 2023 15:40:11 +0100 Subject: [PATCH 12/13] fixed typo in settings.js for DRAGDOWN that did cause the setting to not be saved correctly and hence wasn't settable --- apps/clockcal/settings.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/clockcal/settings.js b/apps/clockcal/settings.js index 4d8be6fbd..a406f3cf7 100644 --- a/apps/clockcal/settings.js +++ b/apps/clockcal/settings.js @@ -93,7 +93,7 @@ value: actions.indexOf(settings.DRAGDOWN), format: v => actions[v], onchange: v => { - settings.DRGDOWN = actions[v]; + settings.DRAGDOWN = actions[v]; writeSettings(); } }, From b1726ea33c3205093ebc5b0400b38884c75801db Mon Sep 17 00:00:00 2001 From: Christian Meichle Date: Mon, 6 Mar 2023 15:40:11 +0100 Subject: [PATCH 13/13] fixed typo in settings.js for DRAGDOWN that did cause the setting to not be saved correctly and hence wasn't settable --- apps/clockcal/ChangeLog | 1 + apps/clockcal/metadata.json | 2 +- apps/clockcal/settings.js | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/apps/clockcal/ChangeLog b/apps/clockcal/ChangeLog index 4c8c13366..5657bf26d 100644 --- a/apps/clockcal/ChangeLog +++ b/apps/clockcal/ChangeLog @@ -5,3 +5,4 @@ 0.05: Improved colors (connected vs disconnected) 0.06: Tell clock widgets to hide. 0.07: Convert Yes/No On/Off in settings to checkboxes +0.08: Fixed typo in settings.js for DRAGDOWN to make option work \ No newline at end of file diff --git a/apps/clockcal/metadata.json b/apps/clockcal/metadata.json index 03f5c3df2..998115827 100644 --- a/apps/clockcal/metadata.json +++ b/apps/clockcal/metadata.json @@ -1,7 +1,7 @@ { "id": "clockcal", "name": "Clock & Calendar", - "version": "0.07", + "version": "0.08", "description": "Clock with Calendar", "readme":"README.md", "icon": "app.png", diff --git a/apps/clockcal/settings.js b/apps/clockcal/settings.js index 4d8be6fbd..a406f3cf7 100644 --- a/apps/clockcal/settings.js +++ b/apps/clockcal/settings.js @@ -93,7 +93,7 @@ value: actions.indexOf(settings.DRAGDOWN), format: v => actions[v], onchange: v => { - settings.DRGDOWN = actions[v]; + settings.DRAGDOWN = actions[v]; writeSettings(); } },