mirror of https://github.com/espruino/BangleApps
Fix true wind computation bug, add swipe gesture to pause GPS
parent
a8392e34f5
commit
1dbcbd47f8
|
@ -1 +1,2 @@
|
||||||
0.01: New App!
|
0.01: New App!
|
||||||
|
0.02: Fix true wind computation, add swipe gesture to pause GPS
|
||||||
|
|
|
@ -14,7 +14,9 @@ additionally displayed in red. In this mode, the speed over ground in knots is
|
||||||
|
|
||||||
## Controls
|
## Controls
|
||||||
|
|
||||||
There are no controls in the main app, but there are two settings in the settings app that can be changed:
|
In the main app, when true wind mode is enabled (see below), swiping left on the screen will temporarily disable GPS (to preserve battery); a small
|
||||||
|
red satellite symbol will appear on the bottom right. Swiping right will turn GPS back on.
|
||||||
|
The settings app provides the following two settings:
|
||||||
|
|
||||||
* True wind: enables or disables true wind calculations; enabling this will turn on GPS inside the app
|
* True wind: enables or disables true wind calculations; enabling this will turn on GPS inside the app
|
||||||
* Mounting angle: mounting relative to the boat of the wind instrument (in degrees)
|
* Mounting angle: mounting relative to the boat of the wind instrument (in degrees)
|
||||||
|
|
|
@ -1,16 +1,20 @@
|
||||||
OW_CHAR_UUID = '0000cc91-0000-1000-8000-00805f9b34fb';
|
OW_CHAR_UUID = '0000cc91-0000-1000-8000-00805f9b34fb';
|
||||||
require("Font7x11Numeric7Seg").add(Graphics);
|
require("Font7x11Numeric7Seg").add(Graphics);
|
||||||
gatt = {};
|
var gatt = {};
|
||||||
cx = g.getWidth()/2;
|
var cx = g.getWidth()/2;
|
||||||
cy = 24+(g.getHeight()-24)/2;
|
var cy = 24+(g.getHeight()-24)/2;
|
||||||
w = (g.getWidth()-24)/2;
|
var w = (g.getWidth()-24)/2;
|
||||||
|
var y1 = 24;
|
||||||
gps_course = { spd: 0 };
|
var y2 = g.getHeight()-1;
|
||||||
|
var gps_course = { spd: 0 };
|
||||||
|
var course_marker_len = g.getWidth()/4;
|
||||||
|
|
||||||
var settings = require("Storage").readJSON('openwindsettings.json', 1) || {};
|
var settings = require("Storage").readJSON('openwindsettings.json', 1) || {};
|
||||||
|
|
||||||
i = 0;
|
var pause_gps = false;
|
||||||
hullpoly = [];
|
|
||||||
|
var i = 0;
|
||||||
|
var hullpoly = [];
|
||||||
for (y=-1; y<=1; y+=0.1) {
|
for (y=-1; y<=1; y+=0.1) {
|
||||||
hullpoly[i++] = cx - (y<0 ? 1+y*0.15 : (Math.sqrt(1-0.7*y*y)-Math.sqrt(0.3))/(1-Math.sqrt(0.3)))*w*0.3;
|
hullpoly[i++] = cx - (y<0 ? 1+y*0.15 : (Math.sqrt(1-0.7*y*y)-Math.sqrt(0.3))/(1-Math.sqrt(0.3)))*w*0.3;
|
||||||
hullpoly[i++] = cy - y*w*0.7;
|
hullpoly[i++] = cy - y*w*0.7;
|
||||||
|
@ -22,21 +26,22 @@ for (y=1; y>=-1; y-=0.1) {
|
||||||
|
|
||||||
function wind_updated(ev) {
|
function wind_updated(ev) {
|
||||||
if (ev.target.uuid == "0xcc91") {
|
if (ev.target.uuid == "0xcc91") {
|
||||||
awa = settings.mount_angle-ev.target.value.getInt16(1, true)*0.1;
|
awa = settings.mount_angle+ev.target.value.getInt16(1, true)*0.1;
|
||||||
|
if (awa<0) awa += 360;
|
||||||
aws = ev.target.value.getInt16(3, true)*0.01;
|
aws = ev.target.value.getInt16(3, true)*0.01;
|
||||||
// console.log(awa, aws);
|
//console.log(awa, aws);
|
||||||
if (gps_course.spd > 0) {
|
if (gps_course.spd > 0) {
|
||||||
wv = { // wind vector (in fixed reference frame)
|
wv = { // wind vector (in "earth" reference frame)
|
||||||
lon: Math.sin(Math.PI*(gps_course.course+awa)/180)*aws,
|
vlon: Math.sin(Math.PI*(gps_course.course+(awa+180))/180)*aws,
|
||||||
lat: Math.cos(Math.PI*(gps_course.course+awa)/180)*aws
|
vlat: Math.cos(Math.PI*(gps_course.course+(awa+180))/180)*aws
|
||||||
};
|
};
|
||||||
twv = { lon: wv.lon+gps_course.lon, lat: wv.lat+gps_course.lat };
|
twv = { vlon: wv.vlon+gps_course.vlon, vlat: wv.vlat+gps_course.vlat };
|
||||||
tws = Math.sqrt(Math.pow(twv.lon,2)+Math.pow(twv.lat, 2));
|
tws = Math.sqrt(Math.pow(twv.vlon,2)+Math.pow(twv.vlat, 2));
|
||||||
twa = Math.atan2(twv.lat, twv.lon)*180/Math.PI-gps_course.course;
|
twa = 180+Math.atan2(twv.vlon, twv.vlat)*180/Math.PI-gps_course.course;
|
||||||
if (twa<0) twa += 360;
|
if (twa<0) twa += 360;
|
||||||
if (twa>360) twa -=360;
|
if (twa>360) twa -=360;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
tws = -1;
|
tws = -1;
|
||||||
twa = 0;
|
twa = 0;
|
||||||
}
|
}
|
||||||
|
@ -57,15 +62,18 @@ function draw_compass(awa, aws, twa, tws) {
|
||||||
a = i*Math.PI/2+Math.PI/4;
|
a = i*Math.PI/2+Math.PI/4;
|
||||||
g.drawLineAA(cx+Math.cos(a)*w*0.85, cy+Math.sin(a)*w*0.85, cx+Math.cos(a)*w*0.99, cy+Math.sin(a)*w*0.99);
|
g.drawLineAA(cx+Math.cos(a)*w*0.85, cy+Math.sin(a)*w*0.85, cx+Math.cos(a)*w*0.99, cy+Math.sin(a)*w*0.99);
|
||||||
}
|
}
|
||||||
g.setColor(0, 1, 0).fillCircle(cx+Math.sin(Math.PI*awa/180)*w*0.9, cy+Math.cos(Math.PI*awa/180)*w*0.9, w*0.1);
|
g.setColor(0, 1, 0).fillCircle(cx+Math.sin(Math.PI*awa/180)*w*0.9, cy-Math.cos(Math.PI*awa/180)*w*0.9, w*0.1);
|
||||||
if (tws>0) g.setColor(1, 0, 0).fillCircle(cx+Math.sin(Math.PI*twa/180)*w*0.9, cy+Math.cos(Math.PI*twa/180)*w*0.9, w*0.1);
|
if (tws>0) g.setColor(1, 0, 0).fillCircle(cx+Math.sin(Math.PI*twa/180)*w*0.9, cy+Math.cos(Math.PI*twa/180)*w*0.9, w*0.1);
|
||||||
g.setColor(0, 1, 0).setFont("7x11Numeric7Seg",w*0.06);
|
g.setColor(0, 1, 0).setFont("7x11Numeric7Seg",w*0.06);
|
||||||
g.setFontAlign(0, 0, 0).drawString(aws.toFixed(1), cx, cy-0.32*w);
|
g.setFontAlign(0, 0, 0).drawString(aws.toFixed(1), cx, cy-0.32*w);
|
||||||
if (tws>0) g.setColor(1, 0, 0).drawString(tws.toFixed(1), cx, cy+0.32*w);
|
if (!pause_gps) {
|
||||||
if (settings.truewind && typeof gps_course.spd!=='undefined') {
|
if (tws>0) g.setColor(1, 0, 0).drawString(tws.toFixed(1), cx, cy+0.32*w);
|
||||||
spd = gps_course.spd/1.852;
|
if (settings.truewind && gps_course.spd!=-1) {
|
||||||
g.setColor(g.theme.fg).setFont("7x11Numeric7Seg", w*0.03).setFontAlign(-1, 1, 0).drawString(spd.toFixed(1), 1, g.getHeight()-1);
|
spd = gps_course.spd/1.852;
|
||||||
|
g.setColor(g.theme.fg).setFont("7x11Numeric7Seg", w*0.03).setFontAlign(-1, 1, 0).drawString(spd.toFixed(1), 1, g.getHeight()-1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
if (pause_gps) g.setColor("#f00").drawImage(atob("DAwBEAKARAKQE4DwHkPqPRGKAEAA"),g.getWidth()-15, g.getHeight()-15);
|
||||||
}
|
}
|
||||||
|
|
||||||
function parseDevice(d) {
|
function parseDevice(d) {
|
||||||
|
@ -96,8 +104,10 @@ if (settings.truewind) {
|
||||||
Bangle.on('GPS',function(fix) {
|
Bangle.on('GPS',function(fix) {
|
||||||
if (fix.fix && fix.satellites>3 && fix.speed>2) { // only uses fixes w/ more than 3 sats and speed > 2kph
|
if (fix.fix && fix.satellites>3 && fix.speed>2) { // only uses fixes w/ more than 3 sats and speed > 2kph
|
||||||
gps_course =
|
gps_course =
|
||||||
{ lon: Math.sin(Math.PI*fix.course/180)*fix.speed/1.852,
|
{ vlon: Math.sin(Math.PI*fix.course/180)*fix.speed/1.852,
|
||||||
lat: Math.cos(Math.PI*fix.course/180)*fix.speed/1.852,
|
vlat: Math.cos(Math.PI*fix.course/180)*fix.speed/1.852,
|
||||||
|
lat: fix.lat,
|
||||||
|
lon: fix.lon,
|
||||||
spd: fix.speed,
|
spd: fix.speed,
|
||||||
course: fix.course
|
course: fix.course
|
||||||
};
|
};
|
||||||
|
@ -107,6 +117,20 @@ if (settings.truewind) {
|
||||||
Bangle.setGPSPower(1, "app");
|
Bangle.setGPSPower(1, "app");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (settings.truewind) {
|
||||||
|
Bangle.on("swipe", (d)=>{
|
||||||
|
if (d==-1 && !pause_gps) {
|
||||||
|
pause_gps = true;
|
||||||
|
Bangle.setGPSPower(0);
|
||||||
|
draw_compass(0, 0, 0, 0);
|
||||||
|
}
|
||||||
|
else if (d==1 && pause_gps) {
|
||||||
|
pause_gps = false;
|
||||||
|
Bangle.setGPSPower(1, "app");
|
||||||
|
draw_compass(0, 0, 0, 0);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
Bangle.loadWidgets();
|
Bangle.loadWidgets();
|
||||||
Bangle.drawWidgets();
|
Bangle.drawWidgets();
|
||||||
draw_compass(0, 0, 0, 0);
|
draw_compass(0, 0, 0, 0);
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
{ "id": "openwind",
|
{ "id": "openwind",
|
||||||
"name": "OpenWind",
|
"name": "OpenWind",
|
||||||
"shortName":"OpenWind",
|
"shortName":"OpenWind",
|
||||||
"version":"0.01",
|
"version":"0.02",
|
||||||
"description": "OpenWind",
|
"description": "OpenWind",
|
||||||
"icon": "openwind.png",
|
"icon": "openwind.png",
|
||||||
"readme": "README.md",
|
"readme": "README.md",
|
||||||
|
|
Loading…
Reference in New Issue