From 3e9df1a711c3e138ef6364e83a10186bf29082e7 Mon Sep 17 00:00:00 2001 From: nujw Date: Tue, 8 Feb 2022 08:17:31 +1300 Subject: [PATCH 01/11] Update app.js --- apps/speedalt2/app.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/speedalt2/app.js b/apps/speedalt2/app.js index cf414296e..3cc47e875 100644 --- a/apps/speedalt2/app.js +++ b/apps/speedalt2/app.js @@ -6,7 +6,7 @@ Mike Bennett mike[at]kereru.com 1.34 : Add bluetooth data stream for Droidscript 1.43 : Keep GPS in SuperE mode while using Droiscript screen mirroring */ -var v = '1.46'; +var v = '1.47'; var vDroid = '1.46'; // Required DroidScript program version /*kalmanjs, Wouter Bulten, MIT, https://github.com/wouterbulten/kalmanjs */ @@ -645,7 +645,7 @@ function btSend(dat) { var dur = getTime() - btLast; if ( dur < 1.0 ) return; // Don't need to transmit more than every 1.0 secs. btLast = getTime(); - console.log(JSON.stringify(dat)); // transmit the data + Bluetooth.println(JSON.stringify(dat)); // transmit the data } // == Events From cd5807338346fa4a18bffe0d06bc7f10654866c8 Mon Sep 17 00:00:00 2001 From: nujw Date: Tue, 8 Feb 2022 08:17:59 +1300 Subject: [PATCH 02/11] Update metadata.json --- apps/speedalt2/metadata.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/speedalt2/metadata.json b/apps/speedalt2/metadata.json index bb3fefb35..35298d42d 100644 --- a/apps/speedalt2/metadata.json +++ b/apps/speedalt2/metadata.json @@ -2,7 +2,7 @@ "id": "speedalt2", "name": "GPS Adventure Sports II", "shortName":"GPS Adv Sport II", - "version":"1.46", + "version":"1.47", "description": "GPS speed, altitude and distance to waypoint display. Designed for easy viewing and use during outdoor activities such as para-gliding, hang-gliding, sailing, cycling etc.", "icon": "app.png", "type": "app", From d4e9aff5c9d4c555a1582788a65456b8e0baf4a5 Mon Sep 17 00:00:00 2001 From: nujw Date: Tue, 8 Feb 2022 08:27:32 +1300 Subject: [PATCH 03/11] Update app.js --- apps/speedalt2/app.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/speedalt2/app.js b/apps/speedalt2/app.js index 3cc47e875..9c5245dcf 100644 --- a/apps/speedalt2/app.js +++ b/apps/speedalt2/app.js @@ -7,7 +7,7 @@ Mike Bennett mike[at]kereru.com 1.43 : Keep GPS in SuperE mode while using Droiscript screen mirroring */ var v = '1.47'; -var vDroid = '1.46'; // Required DroidScript program version +var vDroid = '1.50'; // Required DroidScript program version /*kalmanjs, Wouter Bulten, MIT, https://github.com/wouterbulten/kalmanjs */ var KalmanFilter = (function () { From 09d0f424da56a1fc163734a96c3f4ae0b4ffb391 Mon Sep 17 00:00:00 2001 From: nujw Date: Tue, 8 Feb 2022 08:29:01 +1300 Subject: [PATCH 04/11] Update GPS Adv Sports II.js --- apps/speedalt2/GPS Adv Sports II.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/apps/speedalt2/GPS Adv Sports II.js b/apps/speedalt2/GPS Adv Sports II.js index 5eb9b64c8..bd8955328 100644 --- a/apps/speedalt2/GPS Adv Sports II.js +++ b/apps/speedalt2/GPS Adv Sports II.js @@ -7,8 +7,8 @@ app.LoadPlugin("PuckJS"); //Called when application is started. function OnStart() { - v = '1.49' // Version of this script - requiredBangleVer = '1.46'; // Minimum speedalt2 version required on Bangle + v = '1.50' // Version of this script + requiredBangleVer = '1.47'; // Minimum speedalt2 version required on Bangle curBangleVer = '-.--' isStopped = true; // Data receive turned off lastData = new Date().getTime() / 1000; // Time of last data received @@ -20,6 +20,8 @@ function OnStart() { col = new Array(['black'],['#64FF00'],['#FCFA00'],['#00E4FF']) // bg, main, units, wp - 0xFFFF,0x007F,0x0054,0x0054 // Connect to Bangle + if( !app.IsBluetoothEnabled() ) app.SetBluetoothEnabled( true ); + puck = app.CreatePuckJS(); puck.SetOnConnect(onConnect); // Callback. puck.SetOnReceive(readResponse); // Callback to capture console output from app. @@ -270,4 +272,3 @@ function btn_OnScan() { btnStop.SetBackColor(btnOff) puck.Scan("Bangle"); } - From 5fbc33ef4cbaa588fa5433f951b64df89ba196a2 Mon Sep 17 00:00:00 2001 From: nujw Date: Wed, 9 Feb 2022 15:25:50 +1300 Subject: [PATCH 05/11] Update GPS Adv Sports II.js --- apps/speedalt2/GPS Adv Sports II.js | 67 +++++++++++++++++++++-------- 1 file changed, 48 insertions(+), 19 deletions(-) diff --git a/apps/speedalt2/GPS Adv Sports II.js b/apps/speedalt2/GPS Adv Sports II.js index bd8955328..502a71001 100644 --- a/apps/speedalt2/GPS Adv Sports II.js +++ b/apps/speedalt2/GPS Adv Sports II.js @@ -3,21 +3,27 @@ app.LoadPlugin("PuckJS"); +app.SetDebugEnabled(false); + +conf = JSON.parse( app.LoadText( "settings", "{}" )) +if ( typeof(conf.btAddr) != 'string' ) conf.btAddr = '' // Address of last connection +if ( typeof(conf.btName) != 'string' ) conf.btName = '' // Name of last connection + +v = '1.51' // Version of this script +requiredBangleVer = '1.47'; // Minimum speedalt2 version required on Bangle +curBangleVer = '-.--' +isStopped = true; // Data receive turned off +lastData = new Date().getTime() / 1000; // Time of last data received + +// Mode = 0 // 0=SPD, 1=ALT, 2=DST, 3=VMG, 4=POSN, 5=TIME +btnOff = '#175A63' +btnOn = '#4285F4' +col = new Array(['black'],['#64FF00'],['#FCFA00'],['#00E4FF']) // bg, main, units, wp - 0xFFFF,0x007F,0x0054,0x0054 + //Called when application is started. function OnStart() { - v = '1.50' // Version of this script - requiredBangleVer = '1.47'; // Minimum speedalt2 version required on Bangle - curBangleVer = '-.--' - isStopped = true; // Data receive turned off - lastData = new Date().getTime() / 1000; // Time of last data received - addr = ''; // Address of last connection - - // Mode = 0 // 0=SPD, 1=ALT, 2=DST, 3=VMG, 4=POSN, 5=TIME - btnOff = '#175A63' - btnOn = '#4285F4' - col = new Array(['black'],['#64FF00'],['#FCFA00'],['#00E4FF']) // bg, main, units, wp - 0xFFFF,0x007F,0x0054,0x0054 // Connect to Bangle if( !app.IsBluetoothEnabled() ) app.SetBluetoothEnabled( true ); @@ -25,7 +31,21 @@ function OnStart() { puck = app.CreatePuckJS(); puck.SetOnConnect(onConnect); // Callback. puck.SetOnReceive(readResponse); // Callback to capture console output from app. - puck.Scan("Bangle"); + + + if ( conf.btAddr == '' ) { + console.log('Scanning') + puck.Scan("Bangle"); + } + else { + console.log('Reconnecting to : '+conf.btAddr) + puck.address = conf.btAddr + puck.name = conf.btName + puck.Connect(puck.address); + } + + app.SetDebugEnabled(false); + setInterval(checkConnection,5000) // Periodic check for data timeout and attempt a reconnect // Controls @@ -200,7 +220,7 @@ function readResponse(data) { if (d.m == 5) { // Time val.SetTextSize(90) - val2.SetTextSize(10) + val2.SetTextSize(0) dt = new Date(); @@ -224,10 +244,16 @@ function setLED(canvas,on,colour) { canvas.Update() } -function onConnect(name, address, bonded, rssi) { - addr = address - console.log( "Connected to " + address ); +function onConnect(name, address) { +// app.SetDebugEnabled(true) + + if ( typeof(address) == 'string' ) conf.btAddr = address + if ( typeof(name) == 'string' ) conf.btName = name + app.SaveText( "settings", JSON.stringify( conf )) // persist connection for future so no need to scan each time used. + + console.log( "Connected to : " + conf.btAddr ); btn_OnStart() // Once connect tell app to start sending updates + app.SetDebugEnabled(false) } // Periodic check for data timeout and attempt a reconnect @@ -235,17 +261,20 @@ function checkConnection() { if (isStopped) return if ( parseFloat(new Date().getTime() / 1000) - lastData > 30 ) { - console.log( "Reconnecting to : "+addr); + console.log( "Reconnecting to : "+conf.btAddr); // Flash orange 'led' indicator for connection attempts. setLED(led,true,"#FC8A00") setTimeout(function() {setLED(led,false,-1)}, 500) - puck.Connect(addr) + puck.Connect(conf.btAddr) } } function btn_OnAbout() { - app.ShowPopup("GPS Adv Sports II\nAndroid Mirror : "+v+"\nBangle.js : "+curBangleVer,"Long") + app.ShowPopup( + "GPS Adv Sports II\nAndroid Mirror : "+v+ + "\nBangle.js : "+curBangleVer+ + "\nConnected : "+conf.btName,"Long") } function btn_OnStart() { From 2cbdde59dee0417ef133797e4ac8dde4d862be18 Mon Sep 17 00:00:00 2001 From: nujw Date: Wed, 9 Feb 2022 15:32:48 +1300 Subject: [PATCH 06/11] Update app.js --- apps/speedalt2/app.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/apps/speedalt2/app.js b/apps/speedalt2/app.js index 9c5245dcf..bf5116fba 100644 --- a/apps/speedalt2/app.js +++ b/apps/speedalt2/app.js @@ -6,7 +6,7 @@ Mike Bennett mike[at]kereru.com 1.34 : Add bluetooth data stream for Droidscript 1.43 : Keep GPS in SuperE mode while using Droiscript screen mirroring */ -var v = '1.47'; +var v = '1.48'; var vDroid = '1.50'; // Required DroidScript program version /*kalmanjs, Wouter Bulten, MIT, https://github.com/wouterbulten/kalmanjs */ @@ -175,6 +175,7 @@ var KalmanFilter = (function () { var buf = Graphics.createArrayBuffer(240,160,2,{msb:true}); +/* let LED = // LED as minimal and only definition (as instance / singleton) { isOn: false // status on / off, not needed if you don't need to ask for it , set: function(v) { // turn on w/ no arg or truey, else off @@ -183,6 +184,7 @@ let LED = // LED as minimal and only definition (as instance / singleton) , write: function(v) { this.set(v); } // turn on w/ no arg or truey, else off , toggle: function() { this.set( ! this.isOn); } // toggle the LED }, LED1 = LED; // LED1 as 'synonym' for LED +*/ var lf = {fix:0,satellites:0}; var showMax = 0; // 1 = display the max values. 0 = display the cur fix From e1ffb6c5c7b94105ca4ab5d61c614cba9315c9a7 Mon Sep 17 00:00:00 2001 From: nujw Date: Wed, 9 Feb 2022 15:33:15 +1300 Subject: [PATCH 07/11] Update metadata.json --- apps/speedalt2/metadata.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/speedalt2/metadata.json b/apps/speedalt2/metadata.json index 35298d42d..8ff29c624 100644 --- a/apps/speedalt2/metadata.json +++ b/apps/speedalt2/metadata.json @@ -2,7 +2,7 @@ "id": "speedalt2", "name": "GPS Adventure Sports II", "shortName":"GPS Adv Sport II", - "version":"1.47", + "version":"1.48", "description": "GPS speed, altitude and distance to waypoint display. Designed for easy viewing and use during outdoor activities such as para-gliding, hang-gliding, sailing, cycling etc.", "icon": "app.png", "type": "app", From af0a286dcdf79e2f295922578c35962cdd206382 Mon Sep 17 00:00:00 2001 From: nujw Date: Wed, 9 Feb 2022 16:03:18 +1300 Subject: [PATCH 08/11] Update app.js --- apps/speedalt2/app.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/apps/speedalt2/app.js b/apps/speedalt2/app.js index bf5116fba..73fa3bacb 100644 --- a/apps/speedalt2/app.js +++ b/apps/speedalt2/app.js @@ -6,7 +6,7 @@ Mike Bennett mike[at]kereru.com 1.34 : Add bluetooth data stream for Droidscript 1.43 : Keep GPS in SuperE mode while using Droiscript screen mirroring */ -var v = '1.48'; +var v = '1.49'; var vDroid = '1.50'; // Required DroidScript program version /*kalmanjs, Wouter Bulten, MIT, https://github.com/wouterbulten/kalmanjs */ @@ -175,16 +175,16 @@ var KalmanFilter = (function () { var buf = Graphics.createArrayBuffer(240,160,2,{msb:true}); -/* + let LED = // LED as minimal and only definition (as instance / singleton) { isOn: false // status on / off, not needed if you don't need to ask for it , set: function(v) { // turn on w/ no arg or truey, else off - g.setColor((this.isOn=(v===undefined||!!v))?1:0,0,0).fillCircle(40,10,10); } + g.setColor((this.isOn=(v===undefined||!!v))?1:0,0,0).fillCircle(120,10,10); } , reset: function() { this.set(false); } // turn off , write: function(v) { this.set(v); } // turn on w/ no arg or truey, else off , toggle: function() { this.set( ! this.isOn); } // toggle the LED }, LED1 = LED; // LED1 as 'synonym' for LED -*/ + var lf = {fix:0,satellites:0}; var showMax = 0; // 1 = display the max values. 0 = display the cur fix From a33f848e261a3e1839a3456615882c44303e47c7 Mon Sep 17 00:00:00 2001 From: nujw Date: Wed, 9 Feb 2022 16:03:40 +1300 Subject: [PATCH 09/11] Update metadata.json --- apps/speedalt2/metadata.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/speedalt2/metadata.json b/apps/speedalt2/metadata.json index 8ff29c624..4ace46854 100644 --- a/apps/speedalt2/metadata.json +++ b/apps/speedalt2/metadata.json @@ -2,7 +2,7 @@ "id": "speedalt2", "name": "GPS Adventure Sports II", "shortName":"GPS Adv Sport II", - "version":"1.48", + "version":"1.49", "description": "GPS speed, altitude and distance to waypoint display. Designed for easy viewing and use during outdoor activities such as para-gliding, hang-gliding, sailing, cycling etc.", "icon": "app.png", "type": "app", From 0d5f62aac97946c773f86c2a9db4b46776f6ed44 Mon Sep 17 00:00:00 2001 From: nujw Date: Wed, 9 Feb 2022 16:28:04 +1300 Subject: [PATCH 10/11] Update GPS Adv Sports II.js --- apps/speedalt2/GPS Adv Sports II.js | 49 +++++++++++++++++++---------- 1 file changed, 33 insertions(+), 16 deletions(-) diff --git a/apps/speedalt2/GPS Adv Sports II.js b/apps/speedalt2/GPS Adv Sports II.js index 502a71001..176113248 100644 --- a/apps/speedalt2/GPS Adv Sports II.js +++ b/apps/speedalt2/GPS Adv Sports II.js @@ -3,23 +3,39 @@ app.LoadPlugin("PuckJS"); -app.SetDebugEnabled(false); +app.SetDebugEnabled(true); -conf = JSON.parse( app.LoadText( "settings", "{}" )) -if ( typeof(conf.btAddr) != 'string' ) conf.btAddr = '' // Address of last connection -if ( typeof(conf.btName) != 'string' ) conf.btName = '' // Name of last connection -v = '1.51' // Version of this script +v = '1.52' // Version of this script requiredBangleVer = '1.47'; // Minimum speedalt2 version required on Bangle curBangleVer = '-.--' isStopped = true; // Data receive turned off lastData = new Date().getTime() / 1000; // Time of last data received +//Colours // Mode = 0 // 0=SPD, 1=ALT, 2=DST, 3=VMG, 4=POSN, 5=TIME btnOff = '#175A63' btnOn = '#4285F4' col = new Array(['black'],['#64FF00'],['#FCFA00'],['#00E4FF']) // bg, main, units, wp - 0xFFFF,0x007F,0x0054,0x0054 +// Settings +conf = JSON.parse( app.LoadText( "settings", "{}" )) +if ( typeof(conf.btAddr) != 'string' ) conf.btAddr = '' // Address of last connection +if ( typeof(conf.btName) != 'string' ) conf.btName = '' // Name of last connection + +// Extend PuckJS +app.CreateBangleJS = function( options ) +{ + return new BangleJS( options ); +} + +class BangleJS extends PuckJS { + + constructor(options) { + super(options) + } + +} //Called when application is started. function OnStart() { @@ -28,20 +44,21 @@ function OnStart() { // Connect to Bangle if( !app.IsBluetoothEnabled() ) app.SetBluetoothEnabled( true ); - puck = app.CreatePuckJS(); - puck.SetOnConnect(onConnect); // Callback. - puck.SetOnReceive(readResponse); // Callback to capture console output from app. +// puck = app.CreatePuckJS(); + bngl = app.CreateBangleJS(); + bngl.SetOnConnect(onConnect); // Callback. + bngl.SetOnReceive(readResponse); // Callback to capture console output from app. if ( conf.btAddr == '' ) { console.log('Scanning') - puck.Scan("Bangle"); + bngl.Scan("Bangle"); } else { console.log('Reconnecting to : '+conf.btAddr) - puck.address = conf.btAddr - puck.name = conf.btName - puck.Connect(puck.address); + bngl.address = conf.btAddr + bngl.name = conf.btName + bngl.Connect(bngl.address); } app.SetDebugEnabled(false); @@ -266,7 +283,7 @@ function checkConnection() { // Flash orange 'led' indicator for connection attempts. setLED(led,true,"#FC8A00") setTimeout(function() {setLED(led,false,-1)}, 500) - puck.Connect(conf.btAddr) + bngl.Connect(conf.btAddr) } } @@ -280,14 +297,14 @@ function btn_OnAbout() { function btn_OnStart() { btnStart.SetBackColor(btnOn) btnStop.SetBackColor(btnOff) - puck.SendCode('btOn(1)\n') // Enable the data send + bngl.SendCode('btOn(1)\n') // Enable the data send isStopped = false } function btn_OnStop() { btnStart.SetBackColor(btnOff) btnStop.SetBackColor(btnOn) - puck.SendCode('btOn(0)\n') // Disable the data send + bngl.SendCode('btOn(0)\n') // Disable the data send isStopped = true val.SetText('') val2.SetText('') @@ -299,5 +316,5 @@ function btn_OnStop() { function btn_OnScan() { btnStart.SetBackColor(btnOff) btnStop.SetBackColor(btnOff) - puck.Scan("Bangle"); + bngl.Scan("Bangle"); } From 6be26f110ba9c399f0a319c2bf6c453276a5d2e1 Mon Sep 17 00:00:00 2001 From: nujw Date: Tue, 15 Feb 2022 09:47:51 +1300 Subject: [PATCH 11/11] Update ChangeLog --- apps/speedalt2/ChangeLog | 1 + 1 file changed, 1 insertion(+) diff --git a/apps/speedalt2/ChangeLog b/apps/speedalt2/ChangeLog index 4ff386666..602147856 100644 --- a/apps/speedalt2/ChangeLog +++ b/apps/speedalt2/ChangeLog @@ -12,3 +12,4 @@ 1.10: Adds Kalman filter. 1.14: Add VMG and coordinates screens 1.43: Adds mirroring of the watch face to an Android device. See README.md +1.48: Droidscript mirroring prog automatically uses last connection address. Auto connects when run.