mirror of https://github.com/espruino/BangleApps
Update app.js
parent
8c579f274c
commit
b1f4548ee1
|
@ -5,7 +5,16 @@ Mike Bennett mike[at]kereru.com
|
||||||
1.01 : Third mode large clock display
|
1.01 : Third mode large clock display
|
||||||
1.02 : add smoothing with kalman filter
|
1.02 : add smoothing with kalman filter
|
||||||
*/
|
*/
|
||||||
var v = '1.02g';
|
//var v = '1.02g';
|
||||||
|
|
||||||
|
const BANGLEJS2 = process.env.HWVERSION==2;
|
||||||
|
const screenH = g.getHeight();
|
||||||
|
const screenH_Half = screenH / 2;
|
||||||
|
const screenH_Third = screenH / 3;
|
||||||
|
const screenH_TwoThirds = screenH * 2 / 3;
|
||||||
|
const screenW = g.getWidth();
|
||||||
|
const screenW_Half = screenW / 2;
|
||||||
|
const fontFactorB2 = 2/3;
|
||||||
|
|
||||||
/*kalmanjs, Wouter Bulten, MIT, https://github.com/wouterbulten/kalmanjs */
|
/*kalmanjs, Wouter Bulten, MIT, https://github.com/wouterbulten/kalmanjs */
|
||||||
var KalmanFilter = (function () {
|
var KalmanFilter = (function () {
|
||||||
|
@ -171,10 +180,11 @@ var KalmanFilter = (function () {
|
||||||
}());
|
}());
|
||||||
|
|
||||||
|
|
||||||
var buf = Graphics.createArrayBuffer(240,160,2,{msb:true});
|
|
||||||
|
|
||||||
// Load fonts
|
var buf = Graphics.createArrayBuffer(screenW,screenH_TwoThirds,2,{msb:true});
|
||||||
require("Font7x11Numeric7Seg").add(Graphics);
|
|
||||||
|
if (!BANGLEJS2)
|
||||||
|
require("Font7x11Numeric7Seg").add(Graphics); // Load fonts
|
||||||
|
|
||||||
var lf = {fix:0,satellites:0};
|
var lf = {fix:0,satellites:0};
|
||||||
var showMax = 0; // 1 = display the max values. 0 = display the cur fix
|
var showMax = 0; // 1 = display the max values. 0 = display the cur fix
|
||||||
|
@ -188,9 +198,10 @@ max.spd = 0;
|
||||||
max.alt = 0;
|
max.alt = 0;
|
||||||
max.n = 0; // counter. Only start comparing for max after a certain number of fixes to allow kalman filter to have smoohed the data.
|
max.n = 0; // counter. Only start comparing for max after a certain number of fixes to allow kalman filter to have smoohed the data.
|
||||||
|
|
||||||
var emulator = (process.env.BOARD=="EMSCRIPTEN")?1:0; // 1 = running in emulator. Supplies test values;
|
var emulator = (process.env.BOARD=="EMSCRIPTEN" || process.env.BOARD=="EMSCRIPTEN2")?1:0; // 1 = running in emulator. Supplies test values;
|
||||||
|
|
||||||
var wp = {}; // Waypoint to use for distance from cur position.
|
var wp = {}; // Waypoint to use for distance from cur position.
|
||||||
|
var SATinView = 0;
|
||||||
|
|
||||||
function nxtWp(inc){
|
function nxtWp(inc){
|
||||||
cfg.wp+=inc;
|
cfg.wp+=inc;
|
||||||
|
@ -260,6 +271,18 @@ function drawFix(dat) {
|
||||||
}
|
}
|
||||||
else drawSats('Sats:'+dat.sats);
|
else drawSats('Sats:'+dat.sats);
|
||||||
|
|
||||||
|
/* else if (!BANGLEJS2) {
|
||||||
|
drawSats('Sats:'+dat.sats);
|
||||||
|
} else {
|
||||||
|
if (lf.fix) {
|
||||||
|
if(emulator)console.log("fix "+lf.fix);
|
||||||
|
drawSats('Sats:'+dat.sats);
|
||||||
|
} else {
|
||||||
|
if(emulator)console.log("inView: "+SATinView);
|
||||||
|
drawSats('View:' + SATinView);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*/
|
||||||
g.reset();
|
g.reset();
|
||||||
g.drawImage(img,0,40);
|
g.drawImage(img,0,40);
|
||||||
|
|
||||||
|
@ -275,7 +298,7 @@ function drawClock() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function drawPrimary(n,u) {
|
function drawPrimary(n,u) {
|
||||||
|
if(emulator)console.log("drawPrimary: " + n +" "+ u);
|
||||||
// Primary Display
|
// Primary Display
|
||||||
|
|
||||||
var s=40; // Font size
|
var s=40; // Font size
|
||||||
|
@ -289,54 +312,63 @@ function drawPrimary(n,u) {
|
||||||
|
|
||||||
buf.setFontAlign(0,-1); //Centre
|
buf.setFontAlign(0,-1); //Centre
|
||||||
buf.setColor(1);
|
buf.setColor(1);
|
||||||
|
if (BANGLEJS2) s *= fontFactorB2;
|
||||||
buf.setFontVector(s);
|
buf.setFontVector(s);
|
||||||
buf.drawString(n,110,0);
|
buf.drawString(n,screenW_Half-10,0);
|
||||||
|
|
||||||
|
// Primary Units
|
||||||
|
s = 35; // Font size
|
||||||
// Primary Units
|
|
||||||
buf.setFontAlign(1,-1,3); //right
|
buf.setFontAlign(1,-1,3); //right
|
||||||
buf.setColor(2);
|
buf.setColor(2);
|
||||||
buf.setFontVector(35);
|
if (BANGLEJS2) s = 20;
|
||||||
buf.drawString(u,210,0);
|
buf.setFontVector(s);
|
||||||
|
buf.drawString(u,screenW-30,0);
|
||||||
}
|
}
|
||||||
|
|
||||||
function drawSecondary(n,u) {
|
function drawSecondary(n,u) {
|
||||||
|
if(emulator)console.log("drawSecondary: " + n +" "+ u);
|
||||||
var s=180; // units X position
|
var xu = 180; // units X position
|
||||||
var l=n.length;
|
var l=n.length;
|
||||||
if ( l <= 5 ) s=155;
|
if ( l <= 5 ) xu = 155;
|
||||||
if ( l <= 4 ) s=125;
|
if ( l <= 4 ) xu = 125;
|
||||||
if ( l <= 3 ) s=100;
|
if ( l <= 3 ) xu = 100;
|
||||||
if ( l <= 2 ) s=65;
|
if ( l <= 2 ) xu = 65;
|
||||||
if ( l <= 1 ) s=35;
|
if ( l <= 1 ) xu = 35;
|
||||||
|
|
||||||
buf.setFontAlign(-1,1); //left, bottom
|
buf.setFontAlign(-1,1); //left, bottom
|
||||||
buf.setColor(1);
|
buf.setColor(1);
|
||||||
buf.setFontVector(45);
|
var s = 45; // Font size
|
||||||
buf.drawString(n,5,140);
|
if (BANGLEJS2) s *= fontFactorB2;
|
||||||
|
buf.setFontVector(s);
|
||||||
|
buf.drawString(n,5,screenH_TwoThirds-20);
|
||||||
|
|
||||||
// Secondary Units
|
// Secondary Units
|
||||||
buf.setFontAlign(-1,1); //left, bottom
|
buf.setFontAlign(-1,1); //left, bottom
|
||||||
|
|
||||||
buf.setColor(2);
|
buf.setColor(2);
|
||||||
buf.setFontVector(30);
|
s = 30; // Font size
|
||||||
buf.drawString(u,s,135);
|
if (BANGLEJS2) s *= fontFactorB2;
|
||||||
|
buf.setFontVector(s);
|
||||||
|
buf.drawString(u,xu - (BANGLEJS2*20),screenH_TwoThirds-25);
|
||||||
}
|
}
|
||||||
|
|
||||||
function drawTime() {
|
function drawTime() {
|
||||||
var x, y;
|
var x, y;
|
||||||
|
|
||||||
if ( cfg.modeA == 2 ) {
|
if ( cfg.modeA == 2 ) {
|
||||||
x=120;
|
x = screenW_Half;
|
||||||
y=0;
|
y = 0;
|
||||||
buf.setFontAlign(0,-1);
|
buf.setFontAlign(0,-1);
|
||||||
buf.setFontVector(80);
|
buf.setFontVector(screenH_Third);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
x = 0;
|
x = 0;
|
||||||
y = 160;
|
y = screenH_TwoThirds;
|
||||||
buf.setFontAlign(-1,1);
|
buf.setFontAlign(-1,1);
|
||||||
|
if (!BANGLEJS2)
|
||||||
buf.setFont("7x11Numeric7Seg", 2);
|
buf.setFont("7x11Numeric7Seg", 2);
|
||||||
|
else
|
||||||
|
buf.setFont("6x8", 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -347,21 +379,28 @@ function drawTime() {
|
||||||
buf.drawString(time,x,y);
|
buf.drawString(time,x,y);
|
||||||
}
|
}
|
||||||
|
|
||||||
function drawWP() {
|
function drawWP() { // from waypoints.json - see README.md
|
||||||
var nm = wp.name;
|
var nm = wp.name;
|
||||||
if ( nm == undefined || nm == 'NONE' || cfg.modeA ==1 ) nm = '';
|
if ( nm == undefined || nm == 'NONE' || cfg.modeA ==1 ) nm = '';
|
||||||
|
if (emulator) nm="waypoint";
|
||||||
buf.setColor(2);
|
buf.setColor(2);
|
||||||
|
var s = 20; // Font size
|
||||||
|
|
||||||
if ( cfg.modeA == 0 ) { // dist mode
|
if ( cfg.modeA == 0 ) { // dist mode
|
||||||
|
if(emulator)console.log("drawWP() 0: "+nm);
|
||||||
buf.setFontAlign(-1,1); //left, bottom
|
buf.setFontAlign(-1,1); //left, bottom
|
||||||
buf.setFontVector(20);
|
if (BANGLEJS2) s *= fontFactorB2;
|
||||||
buf.drawString(nm.substring(0,6),72,160);
|
buf.setFontVector(s);
|
||||||
|
buf.drawString(nm.substring(0,6),72,screenH_TwoThirds);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( cfg.modeA == 2 ) { // clock/large mode
|
if ( cfg.modeA == 2 ) { // clock/large mode
|
||||||
|
if(emulator)console.log("drawWP() 2: "+nm);
|
||||||
|
s = 55; // Font size
|
||||||
buf.setFontAlign(0,1); //left, bottom
|
buf.setFontAlign(0,1); //left, bottom
|
||||||
buf.setFontVector(55);
|
if (BANGLEJS2) s *= fontFactorB2;
|
||||||
buf.drawString(nm.substring(0,6),120,160);
|
buf.setFontVector(s);
|
||||||
|
buf.drawString(nm.substring(0,6),screenW_Half,screenH_TwoThirds);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -371,19 +410,21 @@ function drawSats(sats) {
|
||||||
buf.setColor(3);
|
buf.setColor(3);
|
||||||
buf.setFont("6x8", 2);
|
buf.setFont("6x8", 2);
|
||||||
buf.setFontAlign(1,1); //right, bottom
|
buf.setFontAlign(1,1); //right, bottom
|
||||||
buf.drawString(sats,240,160);
|
buf.drawString(sats,screenW,screenH_TwoThirds);
|
||||||
|
|
||||||
buf.setFontVector(30);
|
s = 30; // Font size
|
||||||
|
if (BANGLEJS2) s = 18;
|
||||||
|
buf.setFontVector(s);
|
||||||
buf.setColor(2);
|
buf.setColor(2);
|
||||||
|
|
||||||
if ( cfg.modeA == 1 ) {
|
if ( cfg.modeA == 1 ) {
|
||||||
buf.drawString('A',240,140);
|
buf.drawString('A',screenW,140-(BANGLEJS2 * 40));
|
||||||
if ( showMax ) {
|
if ( showMax ) {
|
||||||
buf.setFontAlign(0,1); //centre, bottom
|
buf.setFontAlign(0,1); //centre, bottom
|
||||||
buf.drawString('MAX',120,164);
|
buf.drawString('MAX',120,164);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ( cfg.modeA == 0 ) buf.drawString('D',240,140);
|
if ( cfg.modeA == 0 ) buf.drawString('D',screenW,140-(BANGLEJS2 * 40));
|
||||||
}
|
}
|
||||||
|
|
||||||
function onGPS(fix) {
|
function onGPS(fix) {
|
||||||
|
@ -411,6 +452,8 @@ function onGPS(fix) {
|
||||||
|
|
||||||
if (lf.fix) {
|
if (lf.fix) {
|
||||||
|
|
||||||
|
// if (BANGLEJS2 && !emulator) Bangle.removeListener('GPS-raw', onGPSraw);
|
||||||
|
|
||||||
// Smooth data
|
// Smooth data
|
||||||
if ( lf.smoothed !== 1 ) {
|
if ( lf.smoothed !== 1 ) {
|
||||||
if ( cfg.spdFilt ) lf.speed = spdFilter.filter(lf.speed);
|
if ( cfg.spdFilt ) lf.speed = spdFilter.filter(lf.speed);
|
||||||
|
@ -494,7 +537,7 @@ function onGPS(fix) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function setButtons(){
|
function setButtons(){
|
||||||
|
if (!BANGLEJS2) { // Buttons for Bangle.js
|
||||||
// Spd+Dist : Select next waypoint
|
// Spd+Dist : Select next waypoint
|
||||||
setWatch(function(e) {
|
setWatch(function(e) {
|
||||||
var dur = e.time - e.lastTime;
|
var dur = e.time - e.lastTime;
|
||||||
|
@ -538,8 +581,39 @@ function setButtons(){
|
||||||
onGPS(lf); // Update display
|
onGPS(lf); // Update display
|
||||||
}, BTN4, {repeat:true,edge:"falling"});
|
}, BTN4, {repeat:true,edge:"falling"});
|
||||||
|
|
||||||
|
} else { // Buttons for Bangle.js 2
|
||||||
|
setWatch(function(e){ // Bangle.js BTN3
|
||||||
|
cfg.modeA = cfg.modeA+1;
|
||||||
|
if ( cfg.modeA > 2 ) cfg.modeA = 0;
|
||||||
|
if(emulator)console.log("cfg.modeA="+cfg.modeA);
|
||||||
|
savSettings();
|
||||||
|
onGPS(lf);
|
||||||
|
}, BTN1, {repeat:true,edge:"falling"});
|
||||||
|
|
||||||
|
/* Bangle.on('tap', function(data) { // data - {dir, double, x, y, z}
|
||||||
|
cfg.primSpd = !cfg.primSpd;
|
||||||
|
if(emulator)console.log("!cfg.primSpd");
|
||||||
|
}); */
|
||||||
|
|
||||||
|
/* Bangle.on('swipe', function(dir) {
|
||||||
|
if (dir < 0) { // left: Bangle.js BTN3
|
||||||
|
cfg.modeA = cfg.modeA+1;
|
||||||
|
if ( cfg.modeA > 2 ) cfg.modeA = 0;
|
||||||
|
if(emulator)console.log("cfg.modeA="+cfg.modeA);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{ // right: Bangle.js BTN4
|
||||||
|
cfg.primSpd = !cfg.primSpd;
|
||||||
|
if(emulator)console.log("!cfg.primSpd");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
*/
|
||||||
|
savSettings();
|
||||||
|
onGPS(lf);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function updateClock() {
|
function updateClock() {
|
||||||
if (!canDraw) return;
|
if (!canDraw) return;
|
||||||
drawTime();
|
drawTime();
|
||||||
|
@ -577,15 +651,15 @@ function setLpMode(m) {
|
||||||
let cfg = require('Storage').readJSON('speedalt.json',1)||{};
|
let cfg = require('Storage').readJSON('speedalt.json',1)||{};
|
||||||
|
|
||||||
cfg.spd = cfg.spd||0; // Multiplier for speed unit conversions. 0 = use the locale values for speed
|
cfg.spd = cfg.spd||0; // Multiplier for speed unit conversions. 0 = use the locale values for speed
|
||||||
cfg.spd_unit = cfg.spd_unit||''; // Displayed speed unit
|
cfg.spd_unit = cfg.spd_unit||'km/h'; // Displayed speed unit
|
||||||
cfg.alt = cfg.alt||0.3048;// Multiplier for altitude unit conversions.
|
cfg.alt = cfg.alt||1;// Multiplier for altitude unit conversions. (feet:'0.3048')
|
||||||
cfg.alt_unit = cfg.alt_unit||'feet'; // Displayed altitude units
|
cfg.alt_unit = cfg.alt_unit||'meter'; // Displayed altitude units ('feet')
|
||||||
cfg.dist = cfg.dist||1000;// Multiplier for distnce unit conversions.
|
cfg.dist = cfg.dist||1000;// Multiplier for distnce unit conversions.
|
||||||
cfg.dist_unit = cfg.dist_unit||'km'; // Displayed altitude units
|
cfg.dist_unit = cfg.dist_unit||'km'; // Displayed altitude units
|
||||||
cfg.colour = cfg.colour||0; // Colour scheme.
|
cfg.colour = cfg.colour||0; // Colour scheme.
|
||||||
cfg.wp = cfg.wp||0; // Last selected waypoint for dist
|
cfg.wp = cfg.wp||0; // Last selected waypoint for dist
|
||||||
cfg.modeA = cfg.modeA||0; // 0 = [D]ist, 1 = [A]ltitude, 2 = [C]lock
|
cfg.modeA = cfg.modeA||1; // 0 = [D]ist, 1 = [A]ltitude, 2 = [C]lock
|
||||||
cfg.primSpd = cfg.primSpd||0; // 1 = Spd in primary, 0 = Spd in secondary
|
cfg.primSpd = cfg.primSpd||1; // 1 = Spd in primary, 0 = Spd in secondary
|
||||||
|
|
||||||
cfg.spdFilt = cfg.spdFilt==undefined?true:cfg.spdFilt;
|
cfg.spdFilt = cfg.spdFilt==undefined?true:cfg.spdFilt;
|
||||||
cfg.altFilt = cfg.altFilt==undefined?true:cfg.altFilt;
|
cfg.altFilt = cfg.altFilt==undefined?true:cfg.altFilt;
|
||||||
|
@ -602,16 +676,17 @@ Colour Pallet Idx
|
||||||
2 : Units
|
2 : Units
|
||||||
3 : Sats
|
3 : Sats
|
||||||
*/
|
*/
|
||||||
|
const background = 0; // g.theme.bg = 0xFFFF = gelb!?
|
||||||
var img = {
|
var img = {
|
||||||
width:buf.getWidth(),
|
width:buf.getWidth(),
|
||||||
height:buf.getHeight(),
|
height:buf.getHeight(),
|
||||||
bpp:2,
|
bpp:2,
|
||||||
buffer:buf.buffer,
|
buffer:buf.buffer,
|
||||||
palette:new Uint16Array([0,0x4FE0,0xEFE0,0x07DB])
|
palette:new Uint16Array([background,0x4FE0,0xEFE0,0x07DB]) // "Default"
|
||||||
};
|
};
|
||||||
|
|
||||||
if ( cfg.colour == 1 ) img.palette = new Uint16Array([0,0xFFFF,0xFFF6,0xDFFF]);
|
if ( cfg.colour == 1 ) img.palette = new Uint16Array([background,0xFFFF,0xFFF6,0xDFFF]); // "Hi contrast"
|
||||||
if ( cfg.colour == 2 ) img.palette = new Uint16Array([0,0xFF800,0xFAE0,0xF813]);
|
if ( cfg.colour == 2 ) img.palette = new Uint16Array([background,0xFF800,0xFAE0,0xF813]); // "Night"
|
||||||
|
|
||||||
var SCREENACCESS = {
|
var SCREENACCESS = {
|
||||||
withApp:true,
|
withApp:true,
|
||||||
|
@ -625,6 +700,19 @@ Bangle.on('lcdPower',function(on) {
|
||||||
else stopDraw();
|
else stopDraw();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/*
|
||||||
|
function onGPSraw(nmea) {
|
||||||
|
var nofGP = 0, nofBD = 0, nofGL = 0;
|
||||||
|
if (nmea.slice(3,6) == "GSV") {
|
||||||
|
// console.log(nmea.slice(1,3) + " " + nmea.slice(11,13));
|
||||||
|
if (nmea.slice(0,7) == "$GPGSV,") nofGP = Number(nmea.slice(11,13));
|
||||||
|
if (nmea.slice(0,7) == "$BDGSV,") nofBD = Number(nmea.slice(11,13));
|
||||||
|
if (nmea.slice(0,7) == "$GLGSV,") nofGL = Number(nmea.slice(11,13));
|
||||||
|
SATinView = nofGP + nofBD + nofGL;
|
||||||
|
} }
|
||||||
|
if(BANGLEJS2) Bangle.on('GPS-raw', onGPSraw);
|
||||||
|
*/
|
||||||
|
|
||||||
var gpssetup;
|
var gpssetup;
|
||||||
try {
|
try {
|
||||||
gpssetup = require("gpssetup");
|
gpssetup = require("gpssetup");
|
||||||
|
@ -634,8 +722,6 @@ try {
|
||||||
|
|
||||||
// All set up. Lets go.
|
// All set up. Lets go.
|
||||||
g.clear();
|
g.clear();
|
||||||
Bangle.loadWidgets();
|
|
||||||
Bangle.drawWidgets();
|
|
||||||
onGPS(lf);
|
onGPS(lf);
|
||||||
Bangle.setGPSPower(1);
|
Bangle.setGPSPower(1);
|
||||||
|
|
||||||
|
@ -650,3 +736,5 @@ Bangle.on('GPS', onGPS);
|
||||||
|
|
||||||
setButtons();
|
setButtons();
|
||||||
setInterval(updateClock, 10000);
|
setInterval(updateClock, 10000);
|
||||||
|
Bangle.loadWidgets();
|
||||||
|
Bangle.drawWidgets();
|
||||||
|
|
Loading…
Reference in New Issue