Skip to content

Commit

Permalink
Merge pull request #4 from espruino/master
Browse files Browse the repository at this point in the history
update from upstream
  • Loading branch information
dapgo committed Mar 7, 2021
2 parents 79fe999 + a7efdb9 commit e0084e6
Show file tree
Hide file tree
Showing 40 changed files with 1,324 additions and 94 deletions.
63 changes: 57 additions & 6 deletions apps.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
"name": "Notifications (default)",
"shortName":"Notifications",
"icon": "notify.png",
"version":"0.06",
"version":"0.07",
"description": "A handler for displaying notifications that displays them in a bar at the top of the screen",
"tags": "widget",
"type": "notify",
Expand Down Expand Up @@ -139,7 +139,7 @@
{ "id": "gbridge",
"name": "Gadgetbridge",
"icon": "app.png",
"version":"0.20",
"version":"0.21",
"description": "The default notification handler for Gadgetbridge notifications from Android",
"tags": "tool,system,android,widget",
"readme": "README.md",
Expand Down Expand Up @@ -584,7 +584,7 @@
{ "id": "hrm",
"name": "Heart Rate Monitor",
"icon": "heartrate.png",
"version":"0.02",
"version":"0.03",
"description": "Measure your heart rate and see live sensor data",
"tags": "health",
"storage": [
Expand Down Expand Up @@ -1590,7 +1590,7 @@
"name": "BangleRun",
"shortName": "BangleRun",
"icon": "banglerun.png",
"version": "0.09",
"version": "0.10",
"interface": "interface.html",
"description": "An app for running sessions. Displays info and logs your run for later viewing.",
"tags": "run,running,fitness,outdoors",
Expand Down Expand Up @@ -2822,8 +2822,8 @@
"name": "Walkers Clock",
"shortName":"Walkers Clock",
"icon": "walkersclock48.png",
"version":"0.02",
"description": "A larg font watch, displays steps, can switch GPS on/off, displays grid reference",
"version":"0.03",
"description": "A large font watch, displays steps, can switch GPS on/off, displays grid reference",
"type":"clock",
"tags": "clock, gps, tools, outdoors",
"readme": "README.md",
Expand Down Expand Up @@ -2856,6 +2856,18 @@
{"name":"widhrt.wid.js","url":"widget.js"}
]
},
{ "id": "countdowntimer",
"name" : "Countdown Timer",
"icon": "countdowntimer.png",
"version": "0.01",
"description": "A simple countdown timer with a focus on usability",
"tags": "timer, tool",
"readme": "README.md",
"storage": [
{"name": "countdowntimer.app.js", "url": "countdowntimer.js"},
{"name": "countdowntimer.img", "url": "countdowntimer-icon.js", "evaluate": true}
]
},
{ "id": "helloworld",
"name": "hello,world!",
"shortName":"helloworld",
Expand All @@ -2868,5 +2880,44 @@
{"name":"helloworld.app.js","url":"app.js"},
{"name":"helloworld.img","url":"app-icon.js","evaluate":true}
]
},
{ "id": "widcom",
"name": "Compass Widget",
"icon": "widget.png",
"version":"0.01",
"description": "Tiny widget to show the power on/off status of the Compass. Requires firmware v2.08.167 or later",
"tags": "widget, compass",
"type":"widget",
"readme": "README.md",
"storage": [
{"name":"widcom.wid.js","url":"widget.js"}
]
},
{ "id": "arrow",
"name": "Arrow Compass",
"icon": "arrow.png",
"type":"app",
"version":"0.02",
"description": "Moving arrow compass that points North, shows heading, with tilt correction. Based on jeffmer's Navigation Compass",
"tags": "tool,outdoors",
"readme": "README.md",
"storage": [
{"name":"arrow.app.js","url":"app.js"},
{"name":"arrow.img","url":"icon.js","evaluate":true}
]
},
{ "id": "waypointer",
"name": "Way Pointer",
"icon": "waypointer.png",
"version":"0.01",
"description": "Navigate to a waypoint using the GPS for bearing and compass to point way, uses the same waypoint interface as GPS Navigation",
"tags": "tool,outdoors,gps",
"readme": "README.md",
"interface":"waypoints.html",
"storage": [
{"name":"waypointer.app.js","url":"app.js"},
{"name":"waypoints.json","url":"waypoints.json","evaluate":false},
{"name":"waypointer.img","url":"icon.js","evaluate":true}
]
}
]
41 changes: 41 additions & 0 deletions apps/arrow/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Arrow Compass

A variation of jeffmer's Navigation Compass. The compass points
North and shows the current heading.

This is a tilt and roll compensated compass with a linear
display. The compass will display the same direction that it shows
when flat as when it is tilted (rotation around the W-S axis) or
rolled (rotation around the N-S) axis. *Even with compensation, it
would be beyond foolish to rely solely on this app for any serious
navigational purpose.*

![](arrow_screenshot.jpg)

## Calibration

Correct operation of this app depends critically on calibration. When
first run on a Bangle, the app will request calibration. This lasts
for 30 seconds during which you should move the watch slowly through
figures of 8. It is important that during calibration the watch is
fully rotated around each of it axes. If the app does give the
correct direction heading or is not stable with respect to tilt and
roll - redo the calibration by pressing *BTN3*. Calibration data is
recorded in a storage file named `magnav.json`.

It is also worth noting that the presence of the magnetic charging
clamps will require the compass to be recalibrated after every
charge.

## Controls

*BTN1* - switches to your selected clock app.

*BTN2* - switches to the app launcher.

*BTN3* - invokes calibration ( can be cancelled if pressed accidentally)


## Acknowledgement

This app is based in the work done by [jeffmer](https://github.com/jeffmer/JeffsBangleAppsDev)
179 changes: 179 additions & 0 deletions apps/arrow/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
var pal1color = new Uint16Array([0x0000,0xFFC0],0,1);
var pal2color = new Uint16Array([0x0000,0xffff],0,1);
var buf1 = Graphics.createArrayBuffer(160,160,1,{msb:true});
var buf2 = Graphics.createArrayBuffer(80,40,1,{msb:true});
var img = require("heatshrink").decompress(atob("lEowIPMjAEDngEDvwED/4DCgP/wAEBgf/4AEBg//8AEBh//+AEBj///AEBn///gEBv///wmCAAImCAAIoBFggE/AkaaEABo="));

var bearing=0; // always point north
var heading = 0;
var candraw = false;
var CALIBDATA = require("Storage").readJSON("magnav.json",1)||null;

Bangle.setLCDTimeout(30);

function flip1(x,y) {
g.drawImage({width:160,height:160,bpp:1,buffer:buf1.buffer, palette:pal1color},x,y);
buf1.clear();
}

function flip2(x,y) {
g.drawImage({width:80,height:40,bpp:1,buffer:buf2.buffer, palette:pal2color},x,y);
buf2.clear();
}

function radians(d) {
return (d*Math.PI) / 180;
}

function drawCompass(course) {
if(!candraw) return;

buf1.setColor(1);
buf1.fillCircle(80,80,79,79);
buf1.setColor(0);
buf1.fillCircle(80,80,69,69);
buf1.setColor(1);
buf1.drawImage(img, 80, 80, {scale:3, rotate:radians(course)} );
flip1(40, 30);
}

function newHeading(m,h){
var s = Math.abs(m - h);
var delta = (m>h)?1:-1;
if (s>=180){s=360-s; delta = -delta;}
if (s<2) return h;
var hd = h + delta*(1 + Math.round(s/5));
if (hd<0) hd+=360;
if (hd>360)hd-= 360;
return hd;
}

function tiltfixread(O,S){
var start = Date.now();
var m = Bangle.getCompass();
var g = Bangle.getAccel();
m.dx =(m.x-O.x)*S.x; m.dy=(m.y-O.y)*S.y; m.dz=(m.z-O.z)*S.z;
var d = Math.atan2(-m.dx,m.dy)*180/Math.PI;
if (d<0) d+=360;
var phi = Math.atan(-g.x/-g.z);
var cosphi = Math.cos(phi), sinphi = Math.sin(phi);
var theta = Math.atan(-g.y/(-g.x*sinphi-g.z*cosphi));
var costheta = Math.cos(theta), sintheta = Math.sin(theta);
var xh = m.dy*costheta + m.dx*sinphi*sintheta + m.dz*cosphi*sintheta;
var yh = m.dz*sinphi - m.dx*cosphi;
var psi = Math.atan2(yh,xh)*180/Math.PI;
if (psi<0) psi+=360;
return psi;
}

// Note actual mag is 360-m, error in firmware
function reading() {
var d = tiltfixread(CALIBDATA.offset,CALIBDATA.scale);
heading = newHeading(d,heading);
var dir = bearing - heading;
if (dir < 0) dir += 360;
if (dir > 360) dir -= 360;
drawCompass(dir); // we want compass to show us where to go
buf2.setColor(1);
buf2.setFontAlign(-1,-1);
buf2.setFont("Vector",38);
var course = Math.round(heading);
var cs = course.toString();
cs = course<10?"00"+cs : course<100 ?"0"+cs : cs;
buf2.drawString(cs,0,0);
flip2(90, 200);
}

function calibrate(){
var max={x:-32000, y:-32000, z:-32000},
min={x:32000, y:32000, z:32000};
var ref = setInterval(()=>{
var m = Bangle.getCompass();
max.x = m.x>max.x?m.x:max.x;
max.y = m.y>max.y?m.y:max.y;
max.z = m.z>max.z?m.z:max.z;
min.x = m.x<min.x?m.x:min.x;
min.y = m.y<min.y?m.y:min.y;
min.z = m.z<min.z?m.z:min.z;
}, 100);
return new Promise((resolve) => {
setTimeout(()=>{
if(ref) clearInterval(ref);
var offset = {x:(max.x+min.x)/2,y:(max.y+min.y)/2,z:(max.z+min.z)/2};
var delta = {x:(max.x-min.x)/2,y:(max.y-min.y)/2,z:(max.z-min.z)/2};
var avg = (delta.x+delta.y+delta.z)/3;
var scale = {x:avg/delta.x, y:avg/delta.y, z:avg/delta.z};
resolve({offset:offset,scale:scale});
},30000);
});
}

function docalibrate(e,first){
const title = "Calibrate";
const msg = "takes 30 seconds";
function action(b){
if (b) {
buf1.setColor(1);
buf1.setFont("Vector", 30);
buf1.setFontAlign(0,-1);
buf1.drawString("Figure 8s",80, 40);
buf1.drawString("to",80, 80);
buf1.drawString("Calibrate",80, 120);
flip1(40,40);

calibrate().then((r)=>{
require("Storage").write("magnav.json",r);
Bangle.buzz();
CALIBDATA = r;
startdraw();
setButtons();
});
} else {
startdraw();
setTimeout(setButtons,1000);
}
}
if (first===undefined) first=false;
stopdraw();
clearWatch();
if (first)
E.showAlert(msg,title).then(action.bind(null,true));
else
E.showPrompt(msg,{title:title,buttons:{"Start":true,"Cancel":false}}).then(action);
}

var intervalRef;

function startdraw(){
g.clear();
g.setColor(1,1,1);
Bangle.drawWidgets();
candraw = true;
intervalRef = setInterval(reading,200);
}

function stopdraw() {
candraw=false;
if(intervalRef) {clearInterval(intervalRef);}
}

function setButtons(){
setWatch(()=>{load();}, BTN1, {repeat:false,edge:"falling"});
setWatch(Bangle.showLauncher, BTN2, {repeat:false,edge:"falling"});
setWatch(docalibrate, BTN3, {repeat:false,edge:"falling"});
}

Bangle.on('lcdPower',function(on) {
if (on) {
startdraw();
} else {
stopdraw();
}
});

Bangle.on('kill',()=>{Bangle.setCompassPower(0);});

Bangle.loadWidgets();
Bangle.setCompassPower(1);
startdraw();
setButtons();
Binary file added apps/arrow/arrow.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added apps/arrow/arrow_screenshot.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions apps/arrow/icon.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions apps/banglerun/ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,7 @@
0.07: Fixed GPS update, added guards against NaN values
0.08: Fix issue with GPS coordinates being wrong after the first one
0.09: Another GPS fix (log raw coordinates - not filtered ones)
0.10: Removed kalman filtering to allow distance log to work
Only log data every 5 seconds (not 1 sec)
Don't create a file until the first log entry is ready
Add labels for buttons
2 changes: 1 addition & 1 deletion apps/banglerun/app.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit e0084e6

Please sign in to comment.