Update GPS Adv Sports II.js

master
nujw 2022-02-09 15:25:50 +13:00 committed by GitHub
parent 09d0f424da
commit 5fbc33ef4c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 48 additions and 19 deletions

View File

@ -3,29 +3,49 @@
app.LoadPlugin("PuckJS"); app.LoadPlugin("PuckJS");
app.SetDebugEnabled(false);
//Called when application is started. conf = JSON.parse( app.LoadText( "settings", "{}" ))
function OnStart() { if ( typeof(conf.btAddr) != 'string' ) conf.btAddr = '' // Address of last connection
if ( typeof(conf.btName) != 'string' ) conf.btName = '' // Name of last connection
v = '1.50' // Version of this script v = '1.51' // Version of this script
requiredBangleVer = '1.47'; // Minimum speedalt2 version required on Bangle requiredBangleVer = '1.47'; // Minimum speedalt2 version required on Bangle
curBangleVer = '-.--' curBangleVer = '-.--'
isStopped = true; // Data receive turned off isStopped = true; // Data receive turned off
lastData = new Date().getTime() / 1000; // Time of last data received 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 // Mode = 0 // 0=SPD, 1=ALT, 2=DST, 3=VMG, 4=POSN, 5=TIME
btnOff = '#175A63' btnOff = '#175A63'
btnOn = '#4285F4' btnOn = '#4285F4'
col = new Array(['black'],['#64FF00'],['#FCFA00'],['#00E4FF']) // bg, main, units, wp - 0xFFFF,0x007F,0x0054,0x0054 col = new Array(['black'],['#64FF00'],['#FCFA00'],['#00E4FF']) // bg, main, units, wp - 0xFFFF,0x007F,0x0054,0x0054
//Called when application is started.
function OnStart() {
// Connect to Bangle // Connect to Bangle
if( !app.IsBluetoothEnabled() ) app.SetBluetoothEnabled( true ); if( !app.IsBluetoothEnabled() ) app.SetBluetoothEnabled( true );
puck = app.CreatePuckJS(); puck = app.CreatePuckJS();
puck.SetOnConnect(onConnect); // Callback. puck.SetOnConnect(onConnect); // Callback.
puck.SetOnReceive(readResponse); // Callback to capture console output from app. puck.SetOnReceive(readResponse); // Callback to capture console output from app.
if ( conf.btAddr == '' ) {
console.log('Scanning')
puck.Scan("Bangle"); 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 setInterval(checkConnection,5000) // Periodic check for data timeout and attempt a reconnect
// Controls // Controls
@ -200,7 +220,7 @@ function readResponse(data) {
if (d.m == 5) { // Time if (d.m == 5) { // Time
val.SetTextSize(90) val.SetTextSize(90)
val2.SetTextSize(10) val2.SetTextSize(0)
dt = new Date(); dt = new Date();
@ -224,10 +244,16 @@ function setLED(canvas,on,colour) {
canvas.Update() canvas.Update()
} }
function onConnect(name, address, bonded, rssi) { function onConnect(name, address) {
addr = address // app.SetDebugEnabled(true)
console.log( "Connected to " + address );
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 btn_OnStart() // Once connect tell app to start sending updates
app.SetDebugEnabled(false)
} }
// Periodic check for data timeout and attempt a reconnect // Periodic check for data timeout and attempt a reconnect
@ -235,17 +261,20 @@ function checkConnection() {
if (isStopped) return if (isStopped) return
if ( parseFloat(new Date().getTime() / 1000) - lastData > 30 ) { 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. // Flash orange 'led' indicator for connection attempts.
setLED(led,true,"#FC8A00") setLED(led,true,"#FC8A00")
setTimeout(function() {setLED(led,false,-1)}, 500) setTimeout(function() {setLED(led,false,-1)}, 500)
puck.Connect(addr) puck.Connect(conf.btAddr)
} }
} }
function btn_OnAbout() { 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() { function btn_OnStart() {