Update to 0.03 - includes waypoint editor

pull/428/head
jeffmer 2020-05-17 11:55:25 +01:00 committed by GitHub
parent fcd5a06e21
commit 7514fc09fa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 54 additions and 32 deletions

View File

@ -1 +1,4 @@
0.01: New App!
0.02: Add SCREENACCESS interface
0.03: Add Waypoint Editor

View File

@ -26,22 +26,19 @@ The app indicates that WP2 is now marked by adding the prefix @ to it's name. Th
### Waypoint JSON file
When the app is loaded from the app loader, a file named waypoints.json is loaded along with the javascript etc. The file has the following contents:
When the app is loaded from the app loader, a file named `waypoints.json` is loaded along with the javascript etc. The file has the following contents:
~~~
```
[
{
"mark":0,
"name":"NONE"
},
{
"mark":1,
"name":"No10",
"lat":51.5032,
"lon":-0.1269
},
{
"mark":1,
"name":"Stone",
"lat":51.1788,
"lon":-1.8260
@ -52,15 +49,14 @@ When the app is loaded from the app loader, a file named waypoints.json is loade
{ "name":"WP3" },
{ "name":"WP4" }
]
~~~
```
The file contains the initial NONE waypoint which is useful if you just want to display course and speed. The next two entries are waypoints to No 10 Downing Street and to Stone Henge - obtained from Google Maps. The last five entries are entries which can be *marked*.
You add and delete entries using the Web IDE to load and then save the file from and to watch storage. The app itself does not limit the number of entries although it does load the entire file into RAM which will obviously limit this.
I plan to release an accompanying watch app to edit waypoint files in the near future and a way to download your own waypoint file using the app loader.
### Waypoint Editor
Clicking on the download icon of gpsnav in the app loader invokes the waypoint editor. The editor downloads and displays the current `waypoints.json` file. Clicking the `Edit` button beside an entry causes the entry to be deleted from the list and displayed in the edit boxes. It can be restored - by clicking the `Add waypoint` button. A new markable entry is created by using the `Add name` button. The edited `waypoints.json` file is uploaded to the Bangle by clicking the `Upload` button.
*Please report bugs etc. by raising an issue [here](https://github.com/jeffmer/JeffsBangleAppsDev). *

View File

@ -1,6 +1,7 @@
const Yoff = 40;
var pal2color = new Uint16Array([0x0000,0xffff,0x07ff,0xC618],0,2);
var buf = Graphics.createArrayBuffer(240,50,2,{msb:true});
var candraw = true;
function flip(b,y) {
g.drawImage({width:240,height:50,bpp:2,buffer:b.buffer, palette:pal2color},0,y);
@ -12,6 +13,7 @@ var wpindex=0;
const labels = ["N","NE","E","SE","S","SW","W","NW"];
function drawCompass(course) {
if (!candraw) return;
buf.setColor(1);
buf.setFont("Vector",16);
var start = course-90;
@ -143,7 +145,7 @@ function onGPS(fix) {
speed = isNaN(fix.speed) ? speed : fix.speed;
satellites = fix.satellites;
}
if (Bangle.isLCDOn()) {
if (candraw) {
if (fix!==undefined && fix.fix==1){
dist = distance(fix,wp);
if (isNaN(dist)) dist = 0;
@ -156,28 +158,19 @@ function onGPS(fix) {
var intervalRef;
function clearTimers() {
function stopdraw() {
candraw=false;
if(intervalRef) {clearInterval(intervalRef);}
}
function startTimers() {
candraw=true;
intervalRefSec = setInterval(function() {
newHeading(course,heading);
if (course!=heading) drawCompass(heading);
},200);
}
Bangle.on('lcdPower',function(on) {
if (on) {
g.clear();
Bangle.drawWidgets();
startTimers();
drawAll();
}else {
clearTimers();
}
});
function drawAll(){
g.setColor(1,0.5,0.5);
g.fillPoly([120,Yoff+50,110,Yoff+70,130,Yoff+70]);
@ -186,6 +179,42 @@ function drawAll(){
drawCompass(heading);
}
function startdraw(){
g.clear();
Bangle.drawWidgets();
startTimers();
drawAll();
}
function setButtons(){
setWatch(nextwp.bind(null,-1), BTN1, {repeat:true,edge:"falling"});
setWatch(doselect, BTN2, {repeat:true,edge:"falling"});
setWatch(nextwp.bind(null,1), BTN3, {repeat:true,edge:"falling"});
};
var SCREENACCESS = {
withApp:true,
request:function(){
this.withApp=false;
stopdraw();
clearWatch();
},
release:function(){
this.withApp=true;
startdraw();
setButtons();
}
}
Bangle.on('lcdPower',function(on) {
if (!SCREENACCESS.withApp) return;
if (on) {
startdraw();
} else {
stopdraw();
}
});
var waypoints = require("Storage").readJSON("waypoints.json")||[{name:"NONE"}];
wp=waypoints[0];
@ -199,8 +228,8 @@ function nextwp(inc){
}
function doselect(){
if (selected && waypoints[wpindex].mark===undefined && savedfix.fix) {
waypoints[wpindex] ={mark:1, name:"@"+wp.name, lat:savedfix.lat, lon:savedfix.lon};
if (selected && waypoints[wpindex].lat===undefined && savedfix.fix) {
waypoints[wpindex] ={name:"@"+wp.name, lat:savedfix.lat, lon:savedfix.lon};
wp = waypoints[wpindex];
require("Storage").writeJSON("waypoints.json", waypoints);
}
@ -218,7 +247,4 @@ drawAll();
startTimers();
Bangle.on('GPS', onGPS);
// Toggle selected
setWatch(nextwp.bind(null,-1), BTN1, {repeat:true,edge:"falling"});
setWatch(doselect, BTN2, {repeat:true,edge:"falling"});
setWatch(nextwp.bind(null,1), BTN3, {repeat:true,edge:"falling"});
setButtons();

View File

@ -1,16 +1,13 @@
[
{
"mark":0,
"name":"NONE"
},
{
"mark":1,
"name":"No10",
"lat":51.5032,
"lon":-0.1269
},
{
"mark":1,
"name":"Stone",
"lat":51.1788,
"lon":-1.8260