Skip to content

Commit

Permalink
Merge pull request #3557 from flaparoo/aviatorclk
Browse files Browse the repository at this point in the history
aviatorclk: v1.02 - various improvements
  • Loading branch information
thyttan authored Sep 7, 2024
2 parents e353a4b + 11e5162 commit c43f2c9
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 12 deletions.
5 changes: 5 additions & 0 deletions apps/aviatorclk/ChangeLog
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
1.00: initial release
1.01: added tap event to scroll METAR and toggle seconds display
1.02: continue showing METAR during AVWX updates (show update status next to time)
re-try GPS fix if it takes too long
bug fix
don't attempt to update METAR if Bluetooth is NOT connected
toggle seconds display on front double-taps (if un-locked) to avoid accidential enabling
67 changes: 56 additions & 11 deletions apps/aviatorclk/aviatorclk.app.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const APP_NAME = 'aviatorclk';
const horizontalCenter = g.getWidth()/2;
const mainTimeHeight = 38;
const secondaryFontHeight = 22;
require("Font8x16").add(Graphics); // tertiary font
const dateColour = ( g.theme.dark ? COLOUR_YELLOW : COLOUR_BLUE );
const UTCColour = ( g.theme.dark ? COLOUR_LIGHT_CYAN : COLOUR_DARK_CYAN );
const separatorColour = ( g.theme.dark ? COLOUR_LIGHT_GREY : COLOUR_DARK_GREY );
Expand All @@ -37,6 +38,7 @@ var settings = Object.assign({
var drawTimeout;
var secondsInterval;
var avwxTimeout;
var gpsTimeout;

var AVWXrequest;
var METAR = '';
Expand Down Expand Up @@ -92,29 +94,70 @@ function drawAVWX() {
if (! avwxTimeout) { avwxTimeout = setTimeout(updateAVWX, 5 * 60000); }
}

// show AVWX update status
function showUpdateAVWXstatus(status) {
let y = Bangle.appRect.y + 10;
g.setBgColor(g.theme.bg);
g.clearRect(0, y, horizontalCenter - 54, y + 16);
if (status) {
g.setFontAlign(0, -1).setFont("8x16").setColor( g.theme.dark ? COLOUR_ORANGE : COLOUR_DARK_YELLOW );
g.drawString(status, horizontalCenter - 71, y, true);
}
}

// re-try if the GPS doesn't return a fix in time
function GPStookTooLong() {
Bangle.setGPSPower(false, APP_NAME);
if (gpsTimeout) clearTimeout(gpsTimeout);
gpsTimeout = undefined;

showUpdateAVWXstatus('X');

if (! avwxTimeout) { avwxTimeout = setTimeout(updateAVWX, 5 * 60000); }
}

// update the METAR info
function updateAVWX() {
if (avwxTimeout) clearTimeout(avwxTimeout);
avwxTimeout = undefined;
if (gpsTimeout) clearTimeout(gpsTimeout);
gpsTimeout = undefined;

if (! NRF.getSecurityStatus().connected) {
// if Bluetooth is NOT connected, try again in 5min
showUpdateAVWXstatus('X');
avwxTimeout = setTimeout(updateAVWX, 5 * 60000);
return;
}

METAR = '\nGetting GPS fix';
METARlinesCount = 0; METARscollLines = 0;
METARts = undefined;
showUpdateAVWXstatus('GPS');
if (! METAR) {
METAR = '\nUpdating METAR';
METARlinesCount = 0; METARscollLines = 0;
METARts = undefined;
}
drawAVWX();

gpsTimeout = setTimeout(GPStookTooLong, 30 * 60000);
Bangle.setGPSPower(true, APP_NAME);
Bangle.on('GPS', fix => {
// prevent multiple, simultaneous requests
if (AVWXrequest) { return; }

if ('fix' in fix && fix.fix != 0 && fix.satellites >= 4) {
Bangle.setGPSPower(false, APP_NAME);
if (gpsTimeout) clearTimeout(gpsTimeout);
gpsTimeout = undefined;

let lat = fix.lat;
let lon = fix.lon;

METAR = '\nRequesting METAR';
METARlinesCount = 0; METARscollLines = 0;
METARts = undefined;
showUpdateAVWXstatus('AVWX');
if (! METAR) {
METAR = '\nUpdating METAR';
METARlinesCount = 0; METARscollLines = 0;
METARts = undefined;
}
drawAVWX();

// get latest METAR from nearest airport (via AVWX API)
Expand Down Expand Up @@ -146,6 +189,7 @@ function updateAVWX() {
METARts = undefined;
}

showUpdateAVWXstatus('');
drawAVWX();
AVWXrequest = undefined;

Expand All @@ -155,6 +199,7 @@ function updateAVWX() {
METAR = 'ERR: ' + error;
METARlinesCount = 0; METARscollLines = 0;
METARts = undefined;
showUpdateAVWXstatus('');
drawAVWX();
AVWXrequest = undefined;
});
Expand Down Expand Up @@ -268,10 +313,10 @@ Bangle.on('tap', data => {
case 'bottom':
scrollAVWX(1);
break;
case 'left':
case 'right':
// toggle seconds display on double taps left or right
if (data.double) {
case 'front':
// toggle seconds display on double tap on front/watch-face
// (if watch is un-locked)
if (data.double && ! Bangle.isLocked()) {
if (settings.showSeconds) {
clearInterval(secondsInterval);
let y = Bangle.appRect.y + mainTimeHeight - 3;
Expand All @@ -295,7 +340,7 @@ Bangle.loadWidgets();
Bangle.drawWidgets();

// draw static separator line
y = Bangle.appRect.y + mainTimeHeight + secondaryFontHeight;
let y = Bangle.appRect.y + mainTimeHeight + secondaryFontHeight;
g.setColor(separatorColour);
g.drawLine(0, y, g.getWidth(), y);

Expand Down
2 changes: 1 addition & 1 deletion apps/aviatorclk/metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"id": "aviatorclk",
"name": "Aviator Clock",
"shortName":"AV8R Clock",
"version":"1.01",
"version":"1.02",
"description": "A clock for aviators, with local time and UTC - and the latest METAR for the nearest airport",
"icon": "aviatorclk.png",
"screenshots": [{ "url": "screenshot.png" }, { "url": "screenshot2.png" }],
Expand Down

0 comments on commit c43f2c9

Please sign in to comment.