1
0
Fork 0

Merge branch 'master' of github.com:espruino/BangleApps

master
Gordon Williams 2023-04-27 11:03:17 +01:00
commit d8ba658769
19 changed files with 401 additions and 1 deletions

View File

@ -0,0 +1 @@
0.01: First version

61
apps/clkinfogps/README.md Normal file
View File

@ -0,0 +1,61 @@
# GPS Clock Info
![](app.png)
A clock info that displays the Ordanance Survey (OS) grid reference
- The primary use is for walking where a GPS fix that is 2 minutes old is
perfectly fine for providing an OS map grid reference.
- Saves power by only turning the GPS on for the time it takes to get a fix.
- It then switches the GPS off for 90 seconds before trying to get the next fix
- At the start of the walk update the GPS with using one of the AGPS apps. This will
significantly reduce the time to the first fix.
- Displays the GPS time and number of satelites while waiting for a fix.
- The fix is invalidated after 4 minutes and will display 00:00:00 0
or the gps time while the gps is powered on and searching for a fix.
- If the display is shows solid 00:00:00 0 then tap the clkinfo to restart it
as it will have timed out after 4 minutes
- I suggest installing the GPS power widget so that you can be assured
when the GPS is draining power.
- It is unlikley that this style of gps clock info will work well with the Recorder
app as that would hold the GPS power permantly on all the time during the
recording.
## Screenshots
![](screenshot0.png)
- Above: The GPS is powered on and waiting for a fix.
- The GPS widget shows yellow indicating powered on
- The time from the GPS chip is displayed with the satellite count
- The time from the GPS chip is incrementing approximately every second
- Note the time on the GPS is in UTC and not the current timezone
![](screenshot1.png)
- Above: The GPS has a fix
- The OS grid reference has been calculated
- The GPS has been turned off for 90 seconds
- The GPS widget is grey showing the GPS is off
- You will not see the GPS widget turn green as the GPS is turned off after a fix
![](screenshot2.png)
- Above: The GPS has been powered on after 90 seconds and is waiting for a fix
![](screenshot3.png)
- Above: The GPS has not had a fix for 4 minutes and the cycle has stopped
- The time from the GPS is 00:00:00 0, indicating that the GPS not on
- The GPS widget is grey showing the GPS is off
- Tap the clock_info to restart the GPS clock info
Written by: [Hugh Barney](https://github.com/hughbarney) For support and discussion please post in the [Bangle JS Forum](http://forum.espruino.com/microcosms/1424/)

BIN
apps/clkinfogps/app.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 789 B

127
apps/clkinfogps/clkinfo.js Normal file
View File

@ -0,0 +1,127 @@
(function () {
var timeout;
var last_fix;
var fixTs;
var geo = require("geotools");
var debug = function(o) {
console.log(o);
};
var resetLastFix = function() {
last_fix = {
fix: 0,
alt: 0,
lat: 0,
lon: 0,
speed: 0,
time: 0,
course: 0,
satellites: 0
};
};
var formatTime = function(now) {
try {
var fd = now.toUTCString().split(" ");
return fd[4];
} catch (e) {
return "00:00:00";
}
};
var clearTimer = function() {
if (timeout) {
clearTimeout(timeout);
timeout = undefined;
debug("timer cleared");
}
};
var queueGPSon = function() {
clearTimer();
// power on the GPS again in 90 seconds
timeout = setTimeout(function() {
timeout = undefined;
Bangle.setGPSPower(1,"clkinfo");
}, 90000);
debug("gps on queued");
};
var onGPS = function(fix) {
//console.log(fix);
last_fix.time = fix.time;
// we got a fix
if (fix.fix) {
last_fix = fix;
fixTs = Math.round(getTime());
// cancel the timeout, if not already timed out
clearTimer();
// power off the GPS
Bangle.setGPSPower(0,"clkinfo");
queueGPSon();
}
// if our last fix was more than 4 minutes ago, reset the fix to show gps time + satelites
if (Math.round(getTime()) - fixTs > 240) {
resetLastFix();
fixTs = Math.round(getTime());
// cancel the timeout and power off the gps, tap required to restart
clearTimer();
Bangle.setGPSPower(0,"clkinfo");
}
info.items[0].emit("redraw");
};
var img = function() {
return atob("GBgBAAAAAAAAABgAAb2ABzzgB37gD37wHn54AAAADEwIPn58Pn58Pv58Pn58FmA4AAAAHn54D37wD37gBzzAAb2AABgAAAAAAAAA");
};
var gpsText = function() {
if (last_fix === undefined)
return '';
// show gps time and satelite count
if (!last_fix.fix)
return formatTime(last_fix.time) + ' ' + last_fix.satellites;
return geo.gpsToOSMapRef(last_fix);
};
var info = {
name: "Gps",
items: [
{
name: "gridref",
get: function () { return ({
img: img(),
text: gpsText()
}); },
run : function() {
console.log("run");
// if the timer is already runnuing reset it, we can get multiple run calls by tapping
clearTimer();
Bangle.setGPSPower(1,"clkinfo");
},
show: function () {
console.log("show");
resetLastFix();
fixTs = Math.round(getTime());
Bangle.on("GPS",onGPS);
this.run();
},
hide: function() {
console.log("hide");
clearTimer();
Bangle.setGPSPower(0,"clkinfo");
Bangle.removeListener("GPS", onGPS);
resetLastFix();
}
}
]
};
return info;
});

128
apps/clkinfogps/geotools.js Normal file
View File

@ -0,0 +1,128 @@
/**
*
* A module of Geo functions for use with gps fixes
*
* let geo = require("geotools");
* let os = geo.gpsToOSGrid(fix);
* let ref = geo.gpsToOSMapRef(fix);
*
*/
Number.prototype.toRad = function() { return this*Math.PI/180; };
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
/* Ordnance Survey Grid Reference functions (c) Chris Veness 2005-2014 */
/* - www.movable-type.co.uk/scripts/gridref.js */
/* - www.movable-type.co.uk/scripts/latlon-gridref.html */
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
function OsGridRef(easting, northing) {
this.easting = 0|easting;
this.northing = 0|northing;
}
OsGridRef.latLongToOsGrid = function(point) {
var lat = point.lat.toRad();
var lon = point.lon.toRad();
var a = 6377563.396, b = 6356256.909; // Airy 1830 major & minor semi-axes
var F0 = 0.9996012717; // NatGrid scale factor on central meridian
var lat0 = (49).toRad(), lon0 = (-2).toRad(); // NatGrid true origin is 49�N,2�W
var N0 = -100000, E0 = 400000; // northing & easting of true origin, metres
var e2 = 1 - (b*b)/(a*a); // eccentricity squared
var n = (a-b)/(a+b), n2 = n*n, n3 = n*n*n;
var cosLat = Math.cos(lat), sinLat = Math.sin(lat);
var nu = a*F0/Math.sqrt(1-e2*sinLat*sinLat); // transverse radius of curvature
var rho = a*F0*(1-e2)/Math.pow(1-e2*sinLat*sinLat, 1.5); // meridional radius of curvature
var eta2 = nu/rho-1;
var Ma = (1 + n + (5/4)*n2 + (5/4)*n3) * (lat-lat0);
var Mb = (3*n + 3*n*n + (21/8)*n3) * Math.sin(lat-lat0) * Math.cos(lat+lat0);
var Mc = ((15/8)*n2 + (15/8)*n3) * Math.sin(2*(lat-lat0)) * Math.cos(2*(lat+lat0));
var Md = (35/24)*n3 * Math.sin(3*(lat-lat0)) * Math.cos(3*(lat+lat0));
var M = b * F0 * (Ma - Mb + Mc - Md); // meridional arc
var cos3lat = cosLat*cosLat*cosLat;
var cos5lat = cos3lat*cosLat*cosLat;
var tan2lat = Math.tan(lat)*Math.tan(lat);
var tan4lat = tan2lat*tan2lat;
var I = M + N0;
var II = (nu/2)*sinLat*cosLat;
var III = (nu/24)*sinLat*cos3lat*(5-tan2lat+9*eta2);
var IIIA = (nu/720)*sinLat*cos5lat*(61-58*tan2lat+tan4lat);
var IV = nu*cosLat;
var V = (nu/6)*cos3lat*(nu/rho-tan2lat);
var VI = (nu/120) * cos5lat * (5 - 18*tan2lat + tan4lat + 14*eta2 - 58*tan2lat*eta2);
var dLon = lon-lon0;
var dLon2 = dLon*dLon, dLon3 = dLon2*dLon, dLon4 = dLon3*dLon, dLon5 = dLon4*dLon, dLon6 = dLon5*dLon;
var N = I + II*dLon2 + III*dLon4 + IIIA*dLon6;
var E = E0 + IV*dLon + V*dLon3 + VI*dLon5;
return new OsGridRef(E, N);
};
/*
* converts northing, easting to standard OS grid reference.
*
* [digits=10] - precision (10 digits = metres)
* to_map_ref(8, 651409, 313177); => 'TG 5140 1317'
* to_map_ref(0, 651409, 313177); => '651409,313177'
*
*/
function to_map_ref(digits, easting, northing) {
if (![ 0,2,4,6,8,10,12,14,16 ].includes(Number(digits))) throw new RangeError(`invalid precision '${digits}'`); // eslint-disable-line comma-spacing
let e = easting;
let n = northing;
// use digits = 0 to return numeric format (in metres) - note northing may be >= 1e7
if (digits == 0) {
const format = { useGrouping: false, minimumIntegerDigits: 6, maximumFractionDigits: 3 };
const ePad = e.toLocaleString('en', format);
const nPad = n.toLocaleString('en', format);
return `${ePad},${nPad}`;
}
// get the 100km-grid indices
const e100km = Math.floor(e / 100000), n100km = Math.floor(n / 100000);
// translate those into numeric equivalents of the grid letters
let l1 = (19 - n100km) - (19 - n100km) % 5 + Math.floor((e100km + 10) / 5);
let l2 = (19 - n100km) * 5 % 25 + e100km % 5;
// compensate for skipped 'I' and build grid letter-pairs
if (l1 > 7) l1++;
if (l2 > 7) l2++;
const letterPair = String.fromCharCode(l1 + 'A'.charCodeAt(0), l2 + 'A'.charCodeAt(0));
// strip 100km-grid indices from easting & northing, and reduce precision
e = Math.floor((e % 100000) / Math.pow(10, 5 - digits / 2));
n = Math.floor((n % 100000) / Math.pow(10, 5 - digits / 2));
// pad eastings & northings with leading zeros
e = e.toString().padStart(digits/2, '0');
n = n.toString().padStart(digits/2, '0');
return `${letterPair} ${e} ${n}`;
}
/**
*
* Module exports section, example code below
*
* let geo = require("geotools");
* let os = geo.gpsToOSGrid(fix);
* let ref = geo.gpsToOSMapRef(fix);
*/
// get easting and northings
exports.gpsToOSGrid = function(gps_fix) {
return OsGridRef.latLongToOsGrid(gps_fix);
}
// string with an OS Map grid reference
exports.gpsToOSMapRef = function(gps_fix) {
let os = OsGridRef.latLongToOsGrid(gps_fix);
return to_map_ref(6, os.easting, os.northing);
}

View File

@ -0,0 +1,16 @@
{
"id": "clkinfogps",
"name": "GPS Grid Ref Clockinfo",
"version":"0.01",
"description": "Clockinfo that displays the GPS OS Grid Reference",
"icon": "app.png",
"screenshots": [{"url":"screenshot1.png"}],
"type": "clkinfo",
"tags": "clkinfo,gps",
"supports" : ["BANGLEJS2"],
"readme":"README.md",
"storage": [
{"name":"geotools","url":"geotools.js"},
{"name":"gps.clkinfo.js","url":"clkinfo.js"}
]
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

View File

@ -2,3 +2,4 @@
0.02: Fix mistake preventing game from ending in some cases.
0.03: Update help screen with more details.
0.04: Update cards to draw rounded on newer firmware. Make sure in-game menu can't be pulled up during end of game.
0.05: add confirmation prompt to new game to prevent fat fingering new game during existing one.

View File

@ -2,7 +2,7 @@
"name": "Red 7 Card Game",
"shortName" : "Red 7",
"icon": "icon.png",
"version":"0.04",
"version":"0.05",
"description": "An implementation of the card game Red 7 for your watch. Play against the AI and be the last player still in the game to win!",
"tags": "game",
"supports":["BANGLEJS2"],

View File

@ -814,8 +814,20 @@ function drawMainMenu() {
}
}
menu["New Game"] = function() {
if(startedGame == true) {
E.showPrompt("Discard and start new game?").then(function(v) {
if(v) {
E.showMenu();
resetToNewGame();
} else {
E.showMenu();
drawScreen1();
}
});
} else {
E.showMenu();
resetToNewGame();
}
};
menu["Help"] = function() {
drawScreenHelp();

1
apps/widbatc/ChangeLog Normal file
View File

@ -0,0 +1 @@
0.01: Created

11
apps/widbatc/README.md Normal file
View File

@ -0,0 +1,11 @@
# Yet Another Battery Widget
Shows the current battery level status in the top right in digits using the Lato font
* Works with Bangle 2
* Simple design, no settings
* Uses current colour theme to match clock
![](screenshot.png)
Written by: [Hugh Barney](https://github.com/hughbarney) For support and discussion please post in the [Bangle JS Forum](http://forum.espruino.com/microcosms/1424/)

BIN
apps/widbatc/icon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.1 KiB

View File

@ -0,0 +1,17 @@
{
"id": "widbatc",
"name": "Yet Another Battery Widget",
"shortName":"Battery Level",
"icon": "icon.png",
"screenshots": [{"url":"screenshot.png"}],
"version":"0.01",
"type": "widget",
"supports": ["BANGLEJS", "BANGLEJS2"],
"readme": "README.md",
"description": "Shows the current battery level status in the top right using the Lato Font in digits",
"tags": "widget,battery",
"provides_widgets" : ["battery"],
"storage": [
{"name":"widbatc.wid.js","url":"widget.js"}
]
}

BIN
apps/widbatc/screenshot.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 KiB

25
apps/widbatc/widget.js Normal file
View File

@ -0,0 +1,25 @@
setInterval(()=>WIDGETS["batc"].draw(), 60000);
Bangle.on('lcdPower', function(on) {
if (on) WIDGETS["batc"].draw();
});
WIDGETS["batc"]={area:"tr",sortorder:10,width:48,draw:function() {
g.reset();
// Lato from fonts.google.com, Actual height 17 (17 - 1), Numeric only
g.setFontCustom(atob("AAAAABwAAOAAAgAAHAADwAD4AB8AB8AA+AAeAADAAAAOAAP+AH/8B4DwMAGBgAwMAGBgAwOAOA//gD/4AD4AAAAAAAABgAAcAwDAGAwAwP/+B//wAAGAAAwAAGAAAAAAAAIAwHgOA4DwMA+BgOwMDmBg4wOeGA/gwDwGAAAAAAAAAGAHA8A4DwMAGBhAwMMGBjgwOcOA+/gDj4AAAAABgAAcAAHgADsAA5gAOMAHBgBwMAP/+B//wABgAAMAAAAAAAgD4OB/AwOYGBjAwMYGBjBwMe8Bh/AIHwAAAAAAAAAfAAP8AHxwB8GAdgwPMGBxgwMOOAB/gAH4AAAAAAABgAAMAABgAwMAeBgPgMHwBj4AN8AB+AAPAABAAAAAAAMfAH38B/xwMcGBhgwMMGBjgwP+OA+/gDj4AAAAAAAAOAAH4AA/gQMMGBgzwME8BhvAOPgA/4AD8AAEAAAAAAGAwA4OAHBwAAA="), 46, atob("BAgMDAwMDAwMDAwMBQ=="), 21+(1<<8)+(1<<16));
var bp = "" + E.getBattery().toString();
var text_w = g.stringWidth(bp);
var bw = 7; // battery width
var w = text_w + 3 + bw + 2;
// we need this to be able to shrink or grow on the 3,2,1 digit battery levels
if (w != this.width) {this.width = w; setTimeout(() => Bangle.drawWidgets(),10); return;}
var h = 12; // height
var x = this.x, y = this.y + 4;
g.setColor(g.theme.bg);
g.fillRect(this.x, this.y, this.x + this.width, this.y + 23); // erase background
g.setColor(g.theme.fg);
g.setFontAlign(-1, 0);
g.drawString(bp, this.x, this.y + 12);
x = x + text_w + 3;
g.fillRect(x+2,y,x+5,y+1); // contact
g.fillRect(x,y+2,x+bw,y+2+h); // outer
}};