commit
66100a6ac9
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -3,27 +3,66 @@
|
|||
|
||||
app.LoadPlugin("PuckJS");
|
||||
|
||||
app.SetDebugEnabled(true);
|
||||
|
||||
|
||||
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() {
|
||||
|
||||
v = '1.49' // Version of this script
|
||||
requiredBangleVer = '1.46'; // 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
|
||||
puck = app.CreatePuckJS();
|
||||
puck.SetOnConnect(onConnect); // Callback.
|
||||
puck.SetOnReceive(readResponse); // Callback to capture console output from app.
|
||||
puck.Scan("Bangle");
|
||||
if( !app.IsBluetoothEnabled() ) app.SetBluetoothEnabled( true );
|
||||
|
||||
// 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')
|
||||
bngl.Scan("Bangle");
|
||||
}
|
||||
else {
|
||||
console.log('Reconnecting to : '+conf.btAddr)
|
||||
bngl.address = conf.btAddr
|
||||
bngl.name = conf.btName
|
||||
bngl.Connect(bngl.address);
|
||||
}
|
||||
|
||||
app.SetDebugEnabled(false);
|
||||
|
||||
setInterval(checkConnection,5000) // Periodic check for data timeout and attempt a reconnect
|
||||
|
||||
// Controls
|
||||
|
|
@ -198,7 +237,7 @@ function readResponse(data) {
|
|||
|
||||
if (d.m == 5) { // Time
|
||||
val.SetTextSize(90)
|
||||
val2.SetTextSize(10)
|
||||
val2.SetTextSize(0)
|
||||
|
||||
dt = new Date();
|
||||
|
||||
|
|
@ -222,10 +261,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
|
||||
|
|
@ -233,30 +278,33 @@ 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)
|
||||
bngl.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() {
|
||||
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('')
|
||||
|
|
@ -268,6 +316,5 @@ function btn_OnStop() {
|
|||
function btn_OnScan() {
|
||||
btnStart.SetBackColor(btnOff)
|
||||
btnStop.SetBackColor(btnOff)
|
||||
puck.Scan("Bangle");
|
||||
bngl.Scan("Bangle");
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -6,8 +6,8 @@ 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 vDroid = '1.46'; // Required DroidScript program version
|
||||
var v = '1.49';
|
||||
var vDroid = '1.50'; // Required DroidScript program version
|
||||
|
||||
/*kalmanjs, Wouter Bulten, MIT, https://github.com/wouterbulten/kalmanjs */
|
||||
var KalmanFilter = (function () {
|
||||
|
|
@ -175,15 +175,17 @@ 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
|
||||
var pwrSav = 1; // 1 = default power saving with watch screen off and GPS to PMOO mode. 0 = screen kept on.
|
||||
|
|
@ -645,7 +647,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
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
"id": "speedalt2",
|
||||
"name": "GPS Adventure Sports II",
|
||||
"shortName":"GPS Adv Sport II",
|
||||
"version":"1.46",
|
||||
"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",
|
||||
|
|
|
|||
Loading…
Reference in New Issue