From 19e9fa8361d6643a9e278653db544c36ee83ecf0 Mon Sep 17 00:00:00 2001 From: Pavel Machek Date: Sat, 20 Jul 2024 22:17:36 +0200 Subject: [PATCH 01/36] sixths: fix issues in emulator, a bit bigger font --- apps/sixths/sixths.app.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/apps/sixths/sixths.app.js b/apps/sixths/sixths.app.js index c5fb3b9cf8..a0ea2c101b 100644 --- a/apps/sixths/sixths.app.js +++ b/apps/sixths/sixths.app.js @@ -547,7 +547,9 @@ function draw() { msg = gpsHandle(); } else { let o = Bangle.getOptions(); - msg = o.seaLevelPressure.toFixed(1) + "hPa"; + let pr = o.seaLevelPressure; + if (pr) + msg = pr.toFixed(1) + "hPa"; if (note != "") { msg = note; } @@ -563,7 +565,8 @@ function draw() { //let km = 0.001 * 0.719 * Bangle.getHealthStatus("day").steps; g.setFontAlign(-1, 1); - g.setFont('Vector', 26); + // 33 still fits + g.setFont('Vector', 30); const weekday = ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"]; @@ -585,7 +588,10 @@ function draw() { o.seaLevelPressure = o.seaLevelPressure + a; Bangle.setOptions(o); } - msg = o.seaLevelPressure.toFixed(1) + "hPa"; + let pr = o.seaLevelPressure; + msg = "emu?"; + if (pr) + msg = pr.toFixed(1) + "hPa"; } else { msg = fmtAlt(cur_altitude); } From 661bf324fd40a27b00f1261af555072f6728c4c3 Mon Sep 17 00:00:00 2001 From: Pavel Machek Date: Sat, 20 Jul 2024 22:39:31 +0200 Subject: [PATCH 02/36] sixths: Refactor info printing, so we can scroll down less important stuff --- apps/sixths/sixths.app.js | 51 +++++++++++++++++++++------------------ 1 file changed, 27 insertions(+), 24 deletions(-) diff --git a/apps/sixths/sixths.app.js b/apps/sixths/sixths.app.js index a0ea2c101b..09ba8679e7 100644 --- a/apps/sixths/sixths.app.js +++ b/apps/sixths/sixths.app.js @@ -542,18 +542,6 @@ function draw() { g.setColor(0.25, 1, 1); g.fillPoly([ W/2, 24, W, 80, 0, 80 ]); } - let msg = ""; - if (gps_on) { - msg = gpsHandle(); - } else { - let o = Bangle.getOptions(); - let pr = o.seaLevelPressure; - if (pr) - msg = pr.toFixed(1) + "hPa"; - if (note != "") { - msg = note; - } - } drawBackground(); let now = new Date(); @@ -564,16 +552,21 @@ function draw() { //let km = 0.001 * 0.719 * Bangle.getHealthStatus("day").steps; - g.setFontAlign(-1, 1); // 33 still fits g.setFont('Vector', 30); const weekday = ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"]; + + msg = weekday[now.getDay()] + "" + now.getDate() + ". " + + fmtSteps(Bangle.getHealthStatus("day").steps) + "\n"; - g.drawString(weekday[now.getDay()] + "" + now.getDate() + ". " - + fmtSteps(Bangle.getHealthStatus("day").steps), 10, 115); - - g.drawString(msg, 10, 145); + if (gps_on) { + msg += gpsHandle() + "\n"; + } + + if (cur_mark) { + msg += markHandle() + "\n"; + } if (getTime() - last_active > 15*60) { let alt_adjust = cur_altitude - rest_altitude; @@ -589,17 +582,27 @@ function draw() { Bangle.setOptions(o); } let pr = o.seaLevelPressure; - msg = "emu?"; if (pr) - msg = pr.toFixed(1) + "hPa"; + msg += pr.toFixed(1) + "hPa"; + else + msg += "emu?"; } else { - msg = fmtAlt(cur_altitude); + msg += fmtAlt(cur_altitude); } - msg = msg + " " + cur_temperature.toFixed(1)+icon_c; - if (cur_mark) { - msg = markHandle(); + msg = msg + " " + cur_temperature.toFixed(1)+icon_c + "\n"; + + if (note != "") + msg += note + "\n"; + + { + let o = Bangle.getOptions(); + let pr = o.seaLevelPressure; + + if (pr) + msg += pr.toFixed(1) + "hPa\n"; } - g.drawString(msg, 10, 175); + g.setFontAlign(-1, -1); + g.drawString(msg, 10, 85); if (disp_mode == 1) { g.drawString(debug, 10, 45); From 490f37f7c6b354db91c90d2baac78a379c5f5d7e Mon Sep 17 00:00:00 2001 From: Pavel Machek Date: Sat, 20 Jul 2024 22:49:29 +0200 Subject: [PATCH 03/36] siths: Acknowledge commands. --- apps/sixths/sixths.app.js | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/apps/sixths/sixths.app.js b/apps/sixths/sixths.app.js index 09ba8679e7..f5ac5ef0b6 100644 --- a/apps/sixths/sixths.app.js +++ b/apps/sixths/sixths.app.js @@ -154,7 +154,7 @@ function gpsHandle() { msg = "L"+ fmtTimeDiff(getTime()-last_fix); else { msg = "N"+ fmtTimeDiff(getTime()-gps_on); - if (fix) { + if (0 && fix) { msg += " " + fix.satellites + "sats"; } } @@ -238,6 +238,10 @@ function selectWP(i) { show("WP:"+wp.name, 60); print("Select waypoint: ", cur_mark); } +function ack(cmd) { + show(cmd, 3); + doBuzz(' .'); +} function inputHandler(s) { print("Ascii: ", s, s[0], s[1]); if (s[0] == '^') { @@ -265,22 +269,23 @@ function inputHandler(s) { show("Bat "+bat+"%", 60); break; } - case 'D': selectWP(1); break; - case 'F': gpsOff(); show("GPS off", 3); break; - case 'G': gpsOn(); gps_limit = getTime() + 60*60*4; show("GPS on", 3); break; + case 'D': doBuzz(' .'); selectWP(1); break; + case 'F': gpsOff(); ack("GPS off"); break; + case 'T': gpsOn(); gps_limit = getTime() + 60*60*4; ack("GPS on"); break; case 'I': + doBuzz(' .'); disp_mode += 1; if (disp_mode == 2) { disp_mode = 0; } break; case 'L': aload("altimeter.app.js"); break; - case 'M': mode = 2; show("M>", 10); cur_mark = markNew(); mode_time = getTime(); break; - case 'N': mode = 1; show(">", 10); mode_time = getTime(); break; + case 'M': doBuzz(' .'); mode = 2; show("M>", 10); cur_mark = markNew(); mode_time = getTime(); break; + case 'N': doBuzz(' .'); mode = 1; show(">", 10); mode_time = getTime(); break; case 'O': aload("orloj.app.js"); break; case 'R': aload("runplus.app.js"); break; - case 'S': gpsOn(); gps_limit = getTime() + 60*30; gps_speed_limit = gps_limit; show("GPS on", 3); break; - case 'T': { + case 'S': gpsOn(); gps_limit = getTime() + 60*30; gps_speed_limit = gps_limit; ack("GPS speed"); break; + case 'G': { s = ' T'; let d = new Date(); s += d.getHours() % 10; @@ -288,8 +293,9 @@ function inputHandler(s) { doBuzz(toMorse(s)); break; } - case 'U': selectWP(-1); break; - case 'Y': doBuzz(buzz); Bangle.resetCompass(); break; + case 'U': doBuzz(' .'); selectWP(-1); break; + case 'Y': ack('Compass reset'); Bangle.resetCompass(); break; + default: doBuzz(' ..'); show("Unknown "+s, 5); break; } } const morseDict = { From 2e8a52198ddbfb8afa51dfaff95c1359146116f3 Mon Sep 17 00:00:00 2001 From: Pavel Machek Date: Sat, 20 Jul 2024 23:01:08 +0200 Subject: [PATCH 04/36] sixths: fix docs, adjust times for keeping the gps fix. --- apps/sixths/README.md | 6 +++--- apps/sixths/sixths.app.js | 10 ++++++++-- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/apps/sixths/README.md b/apps/sixths/README.md index 18aa85bebb..6f66386668 100644 --- a/apps/sixths/README.md +++ b/apps/sixths/README.md @@ -26,8 +26,8 @@ Useful gestures: B -- "Battery", show/buzz battery info D -- "Down", previous waypoint -F -- "oFf", disable GPS. -G -- "Gps", enable GPS for 4 hours in low power mode. +F -- "turn oFf gps", disable GPS. +T -- "Turn on gps", enable GPS for 4 hours in low power mode. I -- "Info", toggle info display L -- "aLtimeter", load altimeter app M -- "Mark", create mark from current position @@ -35,7 +35,7 @@ N -- "Note", take a note and write it to the log. O -- "Orloj", run orloj app R -- "Run", run "runplus" app S -- "Speed", enable GPS for 30 minutes in high power mode. - T -- "Time", buzz current time + G -- "Get time", buzz current time U -- "Up", next waypoint Y -- "compass", reset compass diff --git a/apps/sixths/sixths.app.js b/apps/sixths/sixths.app.js index f5ac5ef0b6..93145db5bb 100644 --- a/apps/sixths/sixths.app.js +++ b/apps/sixths/sixths.app.js @@ -22,7 +22,8 @@ var gps_on = 0, // time GPS was turned on last_restart = 0, last_pause = 0, last_fstart = 0; // utime var gps_needed = 0, // how long to wait for a fix gps_limit = 0, // timeout -- when to stop recording - gps_speed_limit = 0; + gps_speed_limit = 0, + keep_fix_for = 10; var prev_fix = null; var gps_dist = 0; @@ -148,6 +149,11 @@ function gpsHandle() { if (!last_fstart) last_fstart = getTime(); last_fix = getTime(); + keep_fix_for = gps_needed / 3; + if (keep_fix_for < 10) + keep_fix_for = 10; + if (keep_fix_for > 3*60) + keep_fix_for = 3*60; gps_needed = 60; } else { if (last_fix) @@ -164,7 +170,7 @@ function gpsHandle() { let d2 = (getTime()-last_fstart); print("gps on, restarted ", d, gps_needed, d2, fix.lat); if (getTime() > gps_speed_limit && - (d > gps_needed || (last_fstart && d2 > 10))) { + (d > gps_needed || (last_fstart && d2 > keep_fix_for))) { gpsPause(); gps_needed = gps_needed * 1.5; print("Pausing, next try", gps_needed); From a06e73b31681876d9f226926b0188f24f912af76 Mon Sep 17 00:00:00 2001 From: Pavel Machek Date: Fri, 26 Jul 2024 16:24:34 +0200 Subject: [PATCH 05/36] sixths: Allow keeping distances over restarts, better debug display implementation --- apps/sixths/sixths.app.js | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/apps/sixths/sixths.app.js b/apps/sixths/sixths.app.js index 93145db5bb..a9a5558b57 100644 --- a/apps/sixths/sixths.app.js +++ b/apps/sixths/sixths.app.js @@ -12,14 +12,15 @@ var buzz = "", /* Set this to transmit morse via vibrations */ inm = "", l = "", /* For incoming morse handling */ in_str = "", note = "", - debug = "v0.04.1", debug2 = "(otherdb)", debug3 = "(short)"; + debug = "v0.05.1", debug2 = "(otherdb)", debug3 = "(short)"; var mode = 0, mode_time = 0; // 0 .. normal, 1 .. note, 2.. mark name var disp_mode = 0; // 0 .. normal, 1 .. small time // GPS handling var gps_on = 0, // time GPS was turned on last_fix = 0, // time of last fix - last_restart = 0, last_pause = 0, last_fstart = 0; // utime + last_restart = 0, last_pause = 0; // utime + last_fstart = 0; // utime, time of start of last fix var gps_needed = 0, // how long to wait for a fix gps_limit = 0, // timeout -- when to stop recording gps_speed_limit = 0, @@ -85,12 +86,14 @@ function gpsPause() { last_restart = 0; last_pause = getTime(); } +function gpsReset() { + prev_fix = null; + gps_dist = 0; +} function gpsOn() { gps_on = getTime(); gps_needed = 1000; last_fix = 0; - prev_fix = null; - gps_dist = 0; gpsRestart(); } function gpsOff() { @@ -128,6 +131,8 @@ function gpsHandleFix(fix) { } function gpsHandle() { let msg = ""; + debug2 = "Ne" + gps_needed; + debug3 = "Ke" + keep_fix_for; if (!last_restart) { let d = (getTime()-last_pause); if (last_fix) @@ -149,11 +154,11 @@ function gpsHandle() { if (!last_fstart) last_fstart = getTime(); last_fix = getTime(); - keep_fix_for = gps_needed / 3; + keep_fix_for = gps_needed / 1.5; if (keep_fix_for < 10) keep_fix_for = 10; - if (keep_fix_for > 3*60) - keep_fix_for = 3*60; + if (keep_fix_for > 4*60) + keep_fix_for = 4*60; gps_needed = 60; } else { if (last_fix) @@ -289,7 +294,8 @@ function inputHandler(s) { case 'M': doBuzz(' .'); mode = 2; show("M>", 10); cur_mark = markNew(); mode_time = getTime(); break; case 'N': doBuzz(' .'); mode = 1; show(">", 10); mode_time = getTime(); break; case 'O': aload("orloj.app.js"); break; - case 'R': aload("runplus.app.js"); break; + case 'R': gpsReset(); ack("GPS reset"); break; + case 'P': aload("runplus.app.js"); break; case 'S': gpsOn(); gps_limit = getTime() + 60*30; gps_speed_limit = gps_limit; ack("GPS speed"); break; case 'G': { s = ' T'; @@ -617,9 +623,8 @@ function draw() { g.drawString(msg, 10, 85); if (disp_mode == 1) { - g.drawString(debug, 10, 45); - g.drawString(debug2, 10, 65); - g.drawString(debug3, 10, 85); + g.setFont('Vector', 21); + g.drawString(debug + "\n" + debug2 + "\n" + debug3, 10, 20); } queueDraw(); From 8d6c4f70caab1a4a1eafd26e954f501959276bdd Mon Sep 17 00:00:00 2001 From: Pavel Machek Date: Fri, 26 Jul 2024 17:21:21 +0200 Subject: [PATCH 06/36] sixths: This should fix keep_fix_for logic --- apps/sixths/sixths.app.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/apps/sixths/sixths.app.js b/apps/sixths/sixths.app.js index a9a5558b57..86c6241be2 100644 --- a/apps/sixths/sixths.app.js +++ b/apps/sixths/sixths.app.js @@ -115,7 +115,8 @@ function gpsHandleFix(fix) { doBuzz(" ."); prev_fix = fix; } - if (1) { + if (0) { + /* Display error between GPS and system time */ let now1 = Date(); let now2 = fix.time; let n1 = now1.getMinutes() * 60 + now1.getSeconds(); @@ -154,7 +155,7 @@ function gpsHandle() { if (!last_fstart) last_fstart = getTime(); last_fix = getTime(); - keep_fix_for = gps_needed / 1.5; + keep_fix_for = (last_fstart - last_restart) / 2; if (keep_fix_for < 10) keep_fix_for = 10; if (keep_fix_for > 4*60) @@ -175,7 +176,7 @@ function gpsHandle() { let d2 = (getTime()-last_fstart); print("gps on, restarted ", d, gps_needed, d2, fix.lat); if (getTime() > gps_speed_limit && - (d > gps_needed || (last_fstart && d2 > keep_fix_for))) { + ((d > gps_needed && !last_fstart) || (last_fstart && d2 > keep_fix_for))) { gpsPause(); gps_needed = gps_needed * 1.5; print("Pausing, next try", gps_needed); From 23d2766bf130fe98f185578d4a4830bee65195f0 Mon Sep 17 00:00:00 2001 From: Pavel Machek Date: Fri, 26 Jul 2024 17:37:08 +0200 Subject: [PATCH 07/36] sixths: This should keep power with GPS on --- apps/sixths/README.md | 11 ----------- apps/sixths/sixths.app.js | 3 ++- 2 files changed, 2 insertions(+), 12 deletions(-) diff --git a/apps/sixths/README.md b/apps/sixths/README.md index 6f66386668..9c5d25b363 100644 --- a/apps/sixths/README.md +++ b/apps/sixths/README.md @@ -73,9 +73,6 @@ Todo: *) only turn on compass when needed -*) only warn about battery low when it crosses thresholds, update -battery low message - *) rename "show" to something else -- it collides with built-in *) adjust clock according to GPS @@ -84,16 +81,8 @@ battery low message *) hide messages after timeout. -*) show route lengths after the fact - *) implement longer recording than "G". -*) Probably T should be G. - -*) sum gps distances for a day - *) allow setting up home altitude, or at least disable auto-calibration *) show time-to-sunset / sunrise? - -*) one-second updates when gps is active \ No newline at end of file diff --git a/apps/sixths/sixths.app.js b/apps/sixths/sixths.app.js index 86c6241be2..56b616846e 100644 --- a/apps/sixths/sixths.app.js +++ b/apps/sixths/sixths.app.js @@ -754,7 +754,8 @@ function lockHandler(locked) { function queueDraw() { let next; - if (getTime() - last_unlocked > 3*60) + if ((getTime() - last_unlocked > 3*60) && + (getTime() > gps_limit)) next = 60000; else next = 1000; From d9fa77f8183ba7457f40128522707490c876e4cc Mon Sep 17 00:00:00 2001 From: Pavel Machek Date: Fri, 26 Jul 2024 17:42:50 +0200 Subject: [PATCH 08/36] sixths: Implement hiding info after timeout --- apps/sixths/sixths.app.js | 37 ++++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/apps/sixths/sixths.app.js b/apps/sixths/sixths.app.js index 56b616846e..e779c08f12 100644 --- a/apps/sixths/sixths.app.js +++ b/apps/sixths/sixths.app.js @@ -13,6 +13,7 @@ var buzz = "", /* Set this to transmit morse via vibrations */ in_str = "", note = "", debug = "v0.05.1", debug2 = "(otherdb)", debug3 = "(short)"; +var note_limit = 0; var mode = 0, mode_time = 0; // 0 .. normal, 1 .. note, 2.. mark name var disp_mode = 0; // 0 .. normal, 1 .. small time @@ -111,7 +112,7 @@ function fmtTimeDiff(d) { } function gpsHandleFix(fix) { if (!prev_fix) { - show("GPS acquired", 10); + showMsg("GPS acquired", 10); doBuzz(" ."); prev_fix = fix; } @@ -213,7 +214,7 @@ function markHandle() { return msg; } function entryDone() { - show(":" + in_str); + showMsg(":" + in_str); doBuzz(" ."); switch (mode) { case 1: logstamp(">" + in_str); break; @@ -237,7 +238,7 @@ function selectWP(i) { if (sel_wp >= waypoints.length) sel_wp = waypoints.length - 1; if (sel_wp < 0) { - show("No WPs", 60); + showMsg("No WPs", 60); } let wp = waypoints[sel_wp]; cur_mark = {}; @@ -247,11 +248,11 @@ function selectWP(i) { cur_mark.fix.fix = 1; cur_mark.fix.lat = wp.lat; cur_mark.fix.lon = wp.lon; - show("WP:"+wp.name, 60); + showMsg("WP:"+wp.name, 60); print("Select waypoint: ", cur_mark); } function ack(cmd) { - show(cmd, 3); + showMsg(cmd, 3); doBuzz(' .'); } function inputHandler(s) { @@ -265,7 +266,7 @@ function inputHandler(s) { } if ((mode == 1) || (mode == 2)){ in_str = in_str + s; - show(">"+in_str, 10); + showMsg(">"+in_str, 10); mode_time = getTime(); return; } @@ -278,7 +279,7 @@ function inputHandler(s) { else s = s+(bat/5); doBuzz(toMorse(s)); - show("Bat "+bat+"%", 60); + showMsg("Bat "+bat+"%", 60); break; } case 'D': doBuzz(' .'); selectWP(1); break; @@ -292,8 +293,8 @@ function inputHandler(s) { } break; case 'L': aload("altimeter.app.js"); break; - case 'M': doBuzz(' .'); mode = 2; show("M>", 10); cur_mark = markNew(); mode_time = getTime(); break; - case 'N': doBuzz(' .'); mode = 1; show(">", 10); mode_time = getTime(); break; + case 'M': doBuzz(' .'); mode = 2; showMsg("M>", 10); cur_mark = markNew(); mode_time = getTime(); break; + case 'N': doBuzz(' .'); mode = 1; showMsg(">", 10); mode_time = getTime(); break; case 'O': aload("orloj.app.js"); break; case 'R': gpsReset(); ack("GPS reset"); break; case 'P': aload("runplus.app.js"); break; @@ -308,7 +309,7 @@ function inputHandler(s) { } case 'U': doBuzz(' .'); selectWP(-1); break; case 'Y': ack('Compass reset'); Bangle.resetCompass(); break; - default: doBuzz(' ..'); show("Unknown "+s, 5); break; + default: doBuzz(' ..'); showMsg("Unknown "+s, 5); break; } } const morseDict = { @@ -429,13 +430,14 @@ function hourly() { let bat = E.getBattery(); if (bat < 25) { s = ' B'; - show("Bat "+bat+"%", 60); + showMsg("Bat "+bat+"%", 60); } if (is_active) doBuzz(toMorse(s)); //logstamp(""); } -function show(msg, timeout) { +function showMsg(msg, timeout) { + note_limit = getTime() + timeout; note = msg; } function fivemin() { @@ -587,6 +589,13 @@ function draw() { msg += markHandle() + "\n"; } + if (note != "") { + if (getTime() > note_limit) + note = ""; + else + msg += note + "\n"; + } + if (getTime() - last_active > 15*60) { let alt_adjust = cur_altitude - rest_altitude; let abs = Math.abs(alt_adjust); @@ -608,10 +617,8 @@ function draw() { } else { msg += fmtAlt(cur_altitude); } - msg = msg + " " + cur_temperature.toFixed(1)+icon_c + "\n"; - if (note != "") - msg += note + "\n"; + msg = msg + " " + cur_temperature.toFixed(1)+icon_c + "\n"; { let o = Bangle.getOptions(); From fda027fa18c107f11f158bc7c097000b5f0cd04e Mon Sep 17 00:00:00 2001 From: Pavel Machek Date: Sat, 27 Jul 2024 19:06:35 +0200 Subject: [PATCH 09/36] sixths: Get my location from... mylocation. --- apps/sixths/README.md | 12 +++--------- apps/sixths/sixths.app.js | 10 +++++----- 2 files changed, 8 insertions(+), 14 deletions(-) diff --git a/apps/sixths/README.md b/apps/sixths/README.md index 9c5d25b363..939d162e6e 100644 --- a/apps/sixths/README.md +++ b/apps/sixths/README.md @@ -33,7 +33,8 @@ I -- "Info", toggle info display M -- "Mark", create mark from current position N -- "Note", take a note and write it to the log. O -- "Orloj", run orloj app - R -- "Run", run "runplus" app + P -- "runPlus", run "runplus" app +R -- "Reset" daily statistics S -- "Speed", enable GPS for 30 minutes in high power mode. G -- "Get time", buzz current time U -- "Up", next waypoint @@ -44,6 +45,7 @@ to communicate back to the user. B -- battery low. E -- acknowledge, gesture understood. +I -- unknown gesture. T -- start of new hour. Three colored dots may appear on display. North is on the 12 o'clock @@ -73,14 +75,6 @@ Todo: *) only turn on compass when needed -*) rename "show" to something else -- it collides with built-in - -*) adjust clock according to GPS - -*) show something more reasonable than (NOTEHERE). - -*) hide messages after timeout. - *) implement longer recording than "G". *) allow setting up home altitude, or at least disable auto-calibration diff --git a/apps/sixths/sixths.app.js b/apps/sixths/sixths.app.js index e779c08f12..83631522fe 100644 --- a/apps/sixths/sixths.app.js +++ b/apps/sixths/sixths.app.js @@ -1,8 +1,7 @@ // Sixth sense /* eslint-disable no-unused-vars */ -// Options you'll want to edit -const rest_altitude = 354; +var location; const W = g.getWidth(); const H = g.getHeight(); @@ -12,7 +11,7 @@ var buzz = "", /* Set this to transmit morse via vibrations */ inm = "", l = "", /* For incoming morse handling */ in_str = "", note = "", - debug = "v0.05.1", debug2 = "(otherdb)", debug3 = "(short)"; + debug = "v0.05.2", debug2 = "(otherdb)", debug3 = "(short)"; var note_limit = 0; var mode = 0, mode_time = 0; // 0 .. normal, 1 .. note, 2.. mark name var disp_mode = 0; // 0 .. normal, 1 .. small time @@ -597,14 +596,14 @@ function draw() { } if (getTime() - last_active > 15*60) { - let alt_adjust = cur_altitude - rest_altitude; + let alt_adjust = cur_altitude - location.alt; let abs = Math.abs(alt_adjust); print("adj", alt_adjust); let o = Bangle.getOptions(); if (abs > 10 && abs < 150) { let a = 0.01; // FIXME: draw is called often compared to alt reading - if (cur_altitude > rest_altitude) + if (cur_altitude > location.alt) a = -a; o.seaLevelPressure = o.seaLevelPressure + a; Bangle.setOptions(o); @@ -789,6 +788,7 @@ function start() { } draw(); + location = require("Storage").readJSON("mylocation.json",1)||{"lat":50,"lon":14.45,"alt":354,"location":"Woods"}; loadWPs(); buzzTask(); if (0) From 522a53c5b73497ee2067f26e35f68e880e49b533 Mon Sep 17 00:00:00 2001 From: Pavel Machek Date: Sat, 27 Jul 2024 19:27:41 +0200 Subject: [PATCH 10/36] sixths: move state into struct so we can save it --- apps/sixths/sixths.app.js | 82 ++++++++++++++++++++------------------- 1 file changed, 43 insertions(+), 39 deletions(-) diff --git a/apps/sixths/sixths.app.js b/apps/sixths/sixths.app.js index 83631522fe..99588f5f3e 100644 --- a/apps/sixths/sixths.app.js +++ b/apps/sixths/sixths.app.js @@ -16,17 +16,23 @@ var note_limit = 0; var mode = 0, mode_time = 0; // 0 .. normal, 1 .. note, 2.. mark name var disp_mode = 0; // 0 .. normal, 1 .. small time +var state = { + gps_limit: 0, // timeout -- when to stop recording + gps_speed_limit: 0, + prev_fix: null, + gps_dist: 0, + + // Marks + cur_mark: null, +}; + // GPS handling var gps_on = 0, // time GPS was turned on last_fix = 0, // time of last fix last_restart = 0, last_pause = 0; // utime last_fstart = 0; // utime, time of start of last fix var gps_needed = 0, // how long to wait for a fix - gps_limit = 0, // timeout -- when to stop recording - gps_speed_limit = 0, keep_fix_for = 10; -var prev_fix = null; -var gps_dist = 0; var mark_heading = -1; @@ -39,9 +45,6 @@ var is_level = false; var cur_altitude = 0; var cur_temperature = 0; -// Marks -var cur_mark = null; - // Icons var icon_alt = "\0\x08\x1a\1\x00\x00\x00\x20\x30\x78\x7C\xFE\xFF\x00\xC3\xE7\xFF\xDB\xC3\xC3\xC3\xC3\x00\x00\x00\x00\x00\x00\x00\x00"; @@ -87,8 +90,8 @@ function gpsPause() { last_pause = getTime(); } function gpsReset() { - prev_fix = null; - gps_dist = 0; + state.prev_fix = null; + state.gps_dist = 0; } function gpsOn() { gps_on = getTime(); @@ -110,10 +113,10 @@ function fmtTimeDiff(d) { return ""+d.toFixed(0)+"m"; } function gpsHandleFix(fix) { - if (!prev_fix) { + if (!state.prev_fix) { showMsg("GPS acquired", 10); doBuzz(" ."); - prev_fix = fix; + state.prev_fix = fix; } if (0) { /* Display error between GPS and system time */ @@ -124,10 +127,10 @@ function gpsHandleFix(fix) { debug2 = "te "+(n2-n1)+"s"; } loggps(fix); - let d = calcDistance(fix, prev_fix); + let d = calcDistance(fix, state.prev_fix); if (d > 30) { - prev_fix = fix; - gps_dist += d/1000; + state.prev_fix = fix; + state.gps_dist += d/1000; } } function gpsHandle() { @@ -182,33 +185,33 @@ function gpsHandle() { print("Pausing, next try", gps_needed); } } - msg += " "+gps_dist.toFixed(1)+icon_km; + msg += " "+state.gps_dist.toFixed(1)+icon_km; return msg; } function markNew() { let r = {}; r.time = getTime(); - r.fix = prev_fix; + r.fix = state.prev_fix; r.steps = Bangle.getHealthStatus("day").steps; - r.gps_dist = gps_dist; + r.gps_dist = state.gps_dist; r.altitude = cur_altitude; r.name = "auto"; return r; } function markHandle() { - let m = cur_mark; + let m = state.cur_mark; let msg = m.name + ">"; if (m.time) { msg += fmtTimeDiff(getTime()- m.time); } - if (prev_fix && prev_fix.fix && m.fix && m.fix.fix) { - let s = fmtDist(calcDistance(m.fix, prev_fix)/1000) + icon_km; + if (state.prev_fix && state.prev_fix.fix && m.fix && m.fix.fix) { + let s = fmtDist(calcDistance(m.fix, state.prev_fix)/1000) + icon_km; msg += " " + s; debug = "wp>" + s; - mark_heading = 180 + calcBearing(m.fix, prev_fix); + mark_heading = 180 + calcBearing(m.fix, state.prev_fix); debug2 = "wp>" + mark_heading; } else { - msg += " w" + fmtDist(gps_dist - m.gps_dist); + msg += " w" + fmtDist(state.gps_dist - m.gps_dist); } return msg; } @@ -217,7 +220,7 @@ function entryDone() { doBuzz(" ."); switch (mode) { case 1: logstamp(">" + in_str); break; - case 2: cur_mark.name = in_str; break; + case 2: state.cur_mark.name = in_str; break; } in_str = 0; mode = 0; @@ -240,15 +243,15 @@ function selectWP(i) { showMsg("No WPs", 60); } let wp = waypoints[sel_wp]; - cur_mark = {}; - cur_mark.name = wp.name; - cur_mark.gps_dist = 0; /* HACK */ - cur_mark.fix = {}; - cur_mark.fix.fix = 1; - cur_mark.fix.lat = wp.lat; - cur_mark.fix.lon = wp.lon; + state.cur_mark = {}; + state.cur_mark.name = wp.name; + state.cur_mark.gps_dist = 0; /* HACK */ + state.cur_mark.fix = {}; + state.cur_mark.fix.fix = 1; + state.cur_mark.fix.lat = wp.lat; + state.cur_mark.fix.lon = wp.lon; showMsg("WP:"+wp.name, 60); - print("Select waypoint: ", cur_mark); + print("Select waypoint: ", state.cur_mark); } function ack(cmd) { showMsg(cmd, 3); @@ -283,7 +286,7 @@ function inputHandler(s) { } case 'D': doBuzz(' .'); selectWP(1); break; case 'F': gpsOff(); ack("GPS off"); break; - case 'T': gpsOn(); gps_limit = getTime() + 60*60*4; ack("GPS on"); break; + case 'T': gpsOn(); state.gps_limit = getTime() + 60*60*4; ack("GPS on"); break; case 'I': doBuzz(' .'); disp_mode += 1; @@ -292,12 +295,12 @@ function inputHandler(s) { } break; case 'L': aload("altimeter.app.js"); break; - case 'M': doBuzz(' .'); mode = 2; showMsg("M>", 10); cur_mark = markNew(); mode_time = getTime(); break; + case 'M': doBuzz(' .'); mode = 2; showMsg("M>", 10); state.cur_mark = markNew(); mode_time = getTime(); break; case 'N': doBuzz(' .'); mode = 1; showMsg(">", 10); mode_time = getTime(); break; case 'O': aload("orloj.app.js"); break; case 'R': gpsReset(); ack("GPS reset"); break; case 'P': aload("runplus.app.js"); break; - case 'S': gpsOn(); gps_limit = getTime() + 60*30; gps_speed_limit = gps_limit; ack("GPS speed"); break; + case 'S': gpsOn(); state.gps_limit = getTime() + 60*30; state.gps_speed_limit = state.gps_limit; ack("GPS speed"); break; case 'G': { s = ' T'; let d = new Date(); @@ -458,7 +461,7 @@ function every(now) { } mode = 0; } - if (gps_on && getTime() > gps_limit && getTime() > gps_speed_limit) { + if (gps_on && getTime() > state.gps_limit && getTime() > state.gps_speed_limit) { Bangle.setGPSPower(0, "sixths"); gps_on = 0; } @@ -529,9 +532,9 @@ function drawBackground() { drawDot(h, 0.7, 10); } } - if (prev_fix && prev_fix.fix) { + if (state.prev_fix && state.prev_fix.fix) { g.setColor(0.5, 1, 0.5); - drawDot(prev_fix.course, 0.5, 6); + drawDot(state.prev_fix.course, 0.5, 6); } if (mark_heading != -1) { g.setColor(1, 0.5, 0.5); @@ -584,7 +587,7 @@ function draw() { msg += gpsHandle() + "\n"; } - if (cur_mark) { + if (state.cur_mark) { msg += markHandle() + "\n"; } @@ -761,7 +764,7 @@ function lockHandler(locked) { function queueDraw() { let next; if ((getTime() - last_unlocked > 3*60) && - (getTime() > gps_limit)) + (getTime() > state.gps_limit)) next = 60000; else next = 1000; @@ -789,6 +792,7 @@ function start() { draw(); location = require("Storage").readJSON("mylocation.json",1)||{"lat":50,"lon":14.45,"alt":354,"location":"Woods"}; + state = require("Storage").readJSON("sixths.json",1)||state; loadWPs(); buzzTask(); if (0) From ee934d5bb55171dc482e14caeb963789e8c2c5e0 Mon Sep 17 00:00:00 2001 From: Pavel Machek Date: Sat, 27 Jul 2024 21:04:47 +0200 Subject: [PATCH 11/36] sixths: fixup moving to struct. --- apps/sixths/sixths.app.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/sixths/sixths.app.js b/apps/sixths/sixths.app.js index 99588f5f3e..ee2128a0a1 100644 --- a/apps/sixths/sixths.app.js +++ b/apps/sixths/sixths.app.js @@ -11,7 +11,7 @@ var buzz = "", /* Set this to transmit morse via vibrations */ inm = "", l = "", /* For incoming morse handling */ in_str = "", note = "", - debug = "v0.05.2", debug2 = "(otherdb)", debug3 = "(short)"; + debug = "v0.05.3", debug2 = "(otherdb)", debug3 = "(short)"; var note_limit = 0; var mode = 0, mode_time = 0; // 0 .. normal, 1 .. note, 2.. mark name var disp_mode = 0; // 0 .. normal, 1 .. small time @@ -178,7 +178,7 @@ function gpsHandle() { let d = (getTime()-last_restart); let d2 = (getTime()-last_fstart); print("gps on, restarted ", d, gps_needed, d2, fix.lat); - if (getTime() > gps_speed_limit && + if (getTime() > state.gps_speed_limit && ((d > gps_needed && !last_fstart) || (last_fstart && d2 > keep_fix_for))) { gpsPause(); gps_needed = gps_needed * 1.5; From 1498c501d9e75185d82613ad5bf94ee4161052f9 Mon Sep 17 00:00:00 2001 From: Pavel Machek Date: Wed, 14 Aug 2024 21:21:59 +0200 Subject: [PATCH 12/36] sixths: start using fmt library. --- apps/sixths/README.md | 16 +++ apps/sixths/sixths.app.js | 244 +++++++++++++++++++++++++++++--------- 2 files changed, 205 insertions(+), 55 deletions(-) diff --git a/apps/sixths/README.md b/apps/sixths/README.md index 939d162e6e..2fe7ad484a 100644 --- a/apps/sixths/README.md +++ b/apps/sixths/README.md @@ -80,3 +80,19 @@ Todo: *) allow setting up home altitude, or at least disable auto-calibration *) show time-to-sunset / sunrise? + +*) "myprofile" to read step length + +*) +-3.5hPa 1012hPa + +*) keep GPS on longer + +*) display gps alt + offset to baro + +*) start logging altitudes, baro pressure + +*) compute climb/descent + +*) switch to compensated compass + +*) only accept gps fix when altitude matches baro \ No newline at end of file diff --git a/apps/sixths/sixths.app.js b/apps/sixths/sixths.app.js index ee2128a0a1..9ce647ec6c 100644 --- a/apps/sixths/sixths.app.js +++ b/apps/sixths/sixths.app.js @@ -1,6 +1,176 @@ // Sixth sense /* eslint-disable no-unused-vars */ +/* fmt library v0.2.2 */ +let fmt = { + icon_alt : "\0\x08\x1a\1\x00\x00\x00\x20\x30\x78\x7C\xFE\xFF\x00\xC3\xE7\xFF\xDB\xC3\xC3\xC3\xC3\x00\x00\x00\x00\x00\x00\x00\x00", + icon_m : "\0\x08\x1a\1\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xC3\xE7\xFF\xDB\xC3\xC3\xC3\xC3\x00\x00\x00\x00\x00\x00\x00\x00", + icon_km : "\0\x08\x1a\1\xC3\xC6\xCC\xD8\xF0\xD8\xCC\xC6\xC3\x00\xC3\xE7\xFF\xDB\xC3\xC3\xC3\xC3\x00\x00\x00\x00\x00\x00\x00\x00", + icon_kph : "\0\x08\x1a\1\xC3\xC6\xCC\xD8\xF0\xD8\xCC\xC6\xC3\x00\xC3\xE7\xFF\xDB\xC3\xC3\xC3\xC3\x00\xFF\x00\xC3\xC3\xFF\xC3\xC3", + icon_c : "\0\x08\x1a\1\x00\x00\x60\x90\x90\x60\x00\x7F\xFF\xC0\xC0\xC0\xC0\xC0\xFF\x7F\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", + + /* 0 .. DD.ddddd + 1 .. DD MM.mmm' + 2 .. DD MM'ss" + */ + geo_mode : 1, + + init: function() {}, + fmtDist: function(km) { + if (km >= 1.0) return km.toFixed(1) + this.icon_km; + return (km*1000).toFixed(0) + this.icon_m; + }, + fmtSteps: function(n) { return this.fmtDist(0.001 * 0.719 * n); }, + fmtAlt: function(m) { return m.toFixed(0) + this.icon_alt; }, + draw_dot : 1, + add0: function(i) { + if (i > 9) { + return ""+i; + } else { + return "0"+i; + } + }, + fmtTOD: function(now) { + this.draw_dot = !this.draw_dot; + let dot = ":"; + if (!this.draw_dot) + dot = "."; + return now.getHours() + dot + this.add0(now.getMinutes()); + }, + fmtNow: function() { return this.fmtTOD(new Date()); }, + fmtTimeDiff: function(d) { + if (d < 180) + return ""+d.toFixed(0); + d = d/60; + return ""+d.toFixed(0)+"m"; + }, + fmtAngle: function(x) { + switch (this.geo_mode) { + case 0: + return "" + x; + case 1: { + let d = Math.floor(x); + let m = x - d; + m = m*60; + return "" + d + " " + m.toFixed(3) + "'"; + } + case 2: { + let d = Math.floor(x); + let m = x - d; + m = m*60; + let mf = Math.floor(m); + let s = m - mf; + s = s*60; + return "" + d + " " + mf + "'" + s.toFixed(0) + '"'; + } + } + return "bad mode?"; + }, + fmtPos: function(pos) { + let x = pos.lat; + let c = "N"; + if (x<0) { + c = "S"; + x = -x; + } + let s = c+this.fmtAngle(x) + "\n"; + c = "E"; + if (x<0) { + c = "W"; + x = -x; + } + return s + c + this.fmtAngle(x); + }, + fmtFix: function(fix, t) { + if (fix && fix.fix && fix.lat) { + return this.fmtSpeed(fix.speed) + " " + + this.fmtAlt(fix.alt); + } else { + return "N/FIX " + this.fmtTimeDiff(t); + } + }, + fmtSpeed: function(kph) { + return kph.toFixed(1) + this.icon_kph; + }, + radians: function(a) { return a*Math.PI/180; }, + degrees: function(a) { return a*180/Math.PI; }, + // distance between 2 lat and lons, in meters, Mean Earth Radius = 6371km + // https://www.movable-type.co.uk/scripts/latlong.html + // (Equirectangular approximation) + // returns value in meters + distance: function(a,b) { + var x = this.radians(b.lon-a.lon) * Math.cos(this.radians((a.lat+b.lat)/2)); + var y = this.radians(b.lat-a.lat); + return Math.sqrt(x*x + y*y) * 6371000; + }, + // thanks to waypointer + bearing: function(a,b) { + var delta = this.radians(b.lon-a.lon); + var alat = this.radians(a.lat); + var blat = this.radians(b.lat); + var y = Math.sin(delta) * Math.cos(blat); + var x = Math.cos(alat) * Math.sin(blat) - + Math.sin(alat)*Math.cos(blat)*Math.cos(delta); + return Math.round(this.degrees(Math.atan2(y, x))); + }, +}; + +/* gps library v0.1.2 */ +let gps = { + emulator: -1, + init: function(x) { + this.emulator = (process.env.BOARD=="EMSCRIPTEN" + || process.env.BOARD=="EMSCRIPTEN2")?1:0; + }, + state: {}, + on_gps: function(f) { + let fix = this.getGPSFix(); + f(fix); + + /* + "lat": number, // Latitude in degrees + "lon": number, // Longitude in degrees + "alt": number, // altitude in M + "speed": number, // Speed in kph + "course": number, // Course in degrees + "time": Date, // Current Time (or undefined if not known) + "satellites": 7, // Number of satellites + "fix": 1 // NMEA Fix state - 0 is no fix + "hdop": number, // Horizontal Dilution of Precision + */ + this.state.timeout = setTimeout(this.on_gps, 1000, f); + }, + off_gps: function() { + clearTimeout(this.state.timeout); + }, + getGPSFix: function() { + if (!this.emulator) + return Bangle.getGPSFix(); + let fix = {}; + fix.fix = 1; + fix.lat = 50; + fix.lon = 14-(getTime()-this.gps_start) / 1000; /* Go West! */ + fix.alt = 200; + fix.speed = 5; + fix.course = 30; + fix.time = Date(); + fix.satellites = 5; + fix.hdop = 12; + return fix; + }, + gps_start : -1, + start_gps: function() { + Bangle.setGPSPower(1, "libgps"); + this.gps_start = getTime(); + }, + stop_gps: function() { + Bangle.setGPSPower(0, "libgps"); + }, +}; + +fmt.init(); +gps.init(); + var location; const W = g.getWidth(); @@ -11,7 +181,7 @@ var buzz = "", /* Set this to transmit morse via vibrations */ inm = "", l = "", /* For incoming morse handling */ in_str = "", note = "", - debug = "v0.05.3", debug2 = "(otherdb)", debug3 = "(short)"; + debug = "v0.6.0", debug2 = "(otherdb)", debug3 = "(short)"; var note_limit = 0; var mode = 0, mode_time = 0; // 0 .. normal, 1 .. note, 2.. mark name var disp_mode = 0; // 0 .. normal, 1 .. small time @@ -103,15 +273,6 @@ function gpsOff() { Bangle.setGPSPower(0, "sixths"); gps_on = 0; } -function fmtDist(km) { return km.toFixed(1) + icon_km; } -function fmtSteps(n) { return fmtDist(0.001 * 0.719 * n); } -function fmtAlt(m) { return m.toFixed(0) + icon_alt; } -function fmtTimeDiff(d) { - if (d < 180) - return ""+d.toFixed(0); - d = d/60; - return ""+d.toFixed(0)+"m"; -} function gpsHandleFix(fix) { if (!state.prev_fix) { showMsg("GPS acquired", 10); @@ -140,9 +301,9 @@ function gpsHandle() { if (!last_restart) { let d = (getTime()-last_pause); if (last_fix) - msg = "PL"+ fmtTimeDiff(getTime()-last_fix); + msg = "PL"+ fmt.fmtTimeDiff(getTime()-last_fix); else - msg = "PN"+ fmtTimeDiff(getTime()-gps_on); + msg = "PN"+ fmt.fmtTimeDiff(getTime()-gps_on); print("gps on, paused ", d, gps_needed); if (d > gps_needed * 2) { @@ -166,9 +327,9 @@ function gpsHandle() { gps_needed = 60; } else { if (last_fix) - msg = "L"+ fmtTimeDiff(getTime()-last_fix); + msg = "L"+ fmt.fmtTimeDiff(getTime()-last_fix); else { - msg = "N"+ fmtTimeDiff(getTime()-gps_on); + msg = "N"+ fmt.fmtTimeDiff(getTime()-gps_on); if (0 && fix) { msg += " " + fix.satellites + "sats"; } @@ -177,7 +338,7 @@ function gpsHandle() { let d = (getTime()-last_restart); let d2 = (getTime()-last_fstart); - print("gps on, restarted ", d, gps_needed, d2, fix.lat); + print("gps on, restarted ", d, gps_needed, d2); if (getTime() > state.gps_speed_limit && ((d > gps_needed && !last_fstart) || (last_fstart && d2 > keep_fix_for))) { gpsPause(); @@ -202,16 +363,16 @@ function markHandle() { let m = state.cur_mark; let msg = m.name + ">"; if (m.time) { - msg += fmtTimeDiff(getTime()- m.time); + msg += fmt.fmtTimeDiff(getTime()- m.time); } if (state.prev_fix && state.prev_fix.fix && m.fix && m.fix.fix) { - let s = fmtDist(calcDistance(m.fix, state.prev_fix)/1000) + icon_km; + let s = fmt.fmtDist(fmt.distance(m.fix, state.prev_fix)/1000) + icon_km; msg += " " + s; debug = "wp>" + s; - mark_heading = 180 + calcBearing(m.fix, state.prev_fix); + mark_heading = 180 + fmt.bearing(m.fix, state.prev_fix); debug2 = "wp>" + mark_heading; } else { - msg += " w" + fmtDist(state.gps_dist - m.gps_dist); + msg += " w" + fmt.fmtDist(state.gps_dist - m.gps_dist); } return msg; } @@ -249,7 +410,7 @@ function selectWP(i) { state.cur_mark.fix = {}; state.cur_mark.fix.fix = 1; state.cur_mark.fix.lat = wp.lat; - state.cur_mark.fix.lon = wp.lon; + state.cur_mark.fix.lon = wp.lon; showMsg("WP:"+wp.name, 60); print("Select waypoint: ", state.cur_mark); } @@ -305,7 +466,7 @@ function inputHandler(s) { s = ' T'; let d = new Date(); s += d.getHours() % 10; - s += add0(d.getMinutes()); + s += fmt.add0(d.getMinutes()); doBuzz(toMorse(s)); break; } @@ -411,13 +572,6 @@ function touchHandler(d) { //print(inm, "drag:", d); } -function add0(i) { - if (i > 9) { - return ""+i; - } else { - return "0"+i; - } -} var lastHour = -1, lastMin = -1; function logstamp(s) { logfile.write("utime=" + getTime() + " " + s + "\n"); @@ -477,31 +631,11 @@ function every(now) { } -function radians(a) { return a*Math.PI/180; } -function degrees(a) { return a*180/Math.PI; } -// distance between 2 lat and lons, in meters, Mean Earth Radius = 6371km -// https://www.movable-type.co.uk/scripts/latlong.html -// (Equirectangular approximation) -function calcDistance(a,b) { - var x = radians(b.lon-a.lon) * Math.cos(radians((a.lat+b.lat)/2)); - var y = radians(b.lat-a.lat); - return Math.sqrt(x*x + y*y) * 6371000; -} -// thanks to waypointer -function calcBearing(a,b){ - var delta = radians(b.lon-a.lon); - var alat = radians(a.lat); - var blat = radians(b.lat); - var y = Math.sin(delta) * Math.cos(blat); - var x = Math.cos(alat)*Math.sin(blat) - - Math.sin(alat)*Math.cos(blat)*Math.cos(delta); - return Math.round(degrees(Math.atan2(y, x))); -} function testBearing() { let p1 = {}, p2 = {}; p1.lat = 40; p2.lat = 50; p1.lon = 14; p2.lon = 14; - print("bearing = ", calcBearing(p1, p2)); + print("bearing = ", fmt.bearing(p1, p2)); } function radA(p) { return p*(Math.PI*2); } @@ -551,7 +685,7 @@ function drawTime(now) { let dot = ":"; if (!draw_dot) dot = "."; - g.drawString(now.getHours() + dot + add0(now.getMinutes()), W, 90); + g.drawString(now.getHours() + dot + fmt.add0(now.getMinutes()), W, 90); } function draw() { if (disp_mode == 2) { @@ -579,14 +713,14 @@ function draw() { g.setFont('Vector', 30); const weekday = ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"]; - + msg = weekday[now.getDay()] + "" + now.getDate() + ". " - + fmtSteps(Bangle.getHealthStatus("day").steps) + "\n"; + + fmt.fmtSteps(Bangle.getHealthStatus("day").steps) + "\n"; if (gps_on) { msg += gpsHandle() + "\n"; } - + if (state.cur_mark) { msg += markHandle() + "\n"; } @@ -617,7 +751,7 @@ function draw() { else msg += "emu?"; } else { - msg += fmtAlt(cur_altitude); + msg += fmt.fmtAlt(cur_altitude); } msg = msg + " " + cur_temperature.toFixed(1)+icon_c + "\n"; @@ -647,7 +781,7 @@ function draw_all() { g.setColor(1, 1, 1); g.setFontAlign(-1, 1); let now = new Date(); - g.drawString(now.getHours() + ":" + add0(now.getMinutes()) + ":" + add0(now.getSeconds()), 10, 40); + g.drawString(now.getHours() + ":" + fmt.add0(now.getMinutes()) + ":" + fmt.add0(now.getSeconds()), 10, 40); let acc = Bangle.getAccel(); let ax = 0 + acc.x, ay = 0.75 + acc.y, az = 0.75 + acc.y; From bc98682aa9e4542d2bd483cfce29e14348d7e441 Mon Sep 17 00:00:00 2001 From: Pavel Machek Date: Wed, 14 Aug 2024 21:26:31 +0200 Subject: [PATCH 13/36] sixths: use icons from library. --- apps/sixths/sixths.app.js | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/apps/sixths/sixths.app.js b/apps/sixths/sixths.app.js index 9ce647ec6c..75f7ede3fc 100644 --- a/apps/sixths/sixths.app.js +++ b/apps/sixths/sixths.app.js @@ -215,14 +215,6 @@ var is_level = false; var cur_altitude = 0; var cur_temperature = 0; -// Icons - -var icon_alt = "\0\x08\x1a\1\x00\x00\x00\x20\x30\x78\x7C\xFE\xFF\x00\xC3\xE7\xFF\xDB\xC3\xC3\xC3\xC3\x00\x00\x00\x00\x00\x00\x00\x00"; -//var icon_m = "\0\x08\x1a\1\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xC3\xE7\xFF\xDB\xC3\xC3\xC3\xC3\x00\x00\x00\x00\x00\x00\x00\x00"; -var icon_km = "\0\x08\x1a\1\xC3\xC6\xCC\xD8\xF0\xD8\xCC\xC6\xC3\x00\xC3\xE7\xFF\xDB\xC3\xC3\xC3\xC3\x00\x00\x00\x00\x00\x00\x00\x00"; -var icon_kph = "\0\x08\x1a\1\xC3\xC6\xCC\xD8\xF0\xD8\xCC\xC6\xC3\x00\xC3\xE7\xFF\xDB\xC3\xC3\xC3\xC3\x00\xFF\x00\xC3\xC3\xFF\xC3\xC3"; -var icon_c = "\0\x08\x1a\1\x00\x00\x60\x90\x90\x60\x00\x7F\xFF\xC0\xC0\xC0\xC0\xC0\xFF\x7F\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"; - function toMorse(x) { let r = ""; for (var i = 0; i < x.length; i++) { @@ -313,7 +305,7 @@ function gpsHandle() { let fix = Bangle.getGPSFix(); if (fix && fix.fix && fix.lat) { gpsHandleFix(fix); - msg = fix.speed.toFixed(1) + icon_kph; + msg = fmt.fmtSpeed(fix.speed); print("GPS FIX", msg); if (!last_fstart) @@ -346,7 +338,7 @@ function gpsHandle() { print("Pausing, next try", gps_needed); } } - msg += " "+state.gps_dist.toFixed(1)+icon_km; + msg += " "+fmt.fmtDist(state.gps_dist); return msg; } function markNew() { @@ -366,7 +358,7 @@ function markHandle() { msg += fmt.fmtTimeDiff(getTime()- m.time); } if (state.prev_fix && state.prev_fix.fix && m.fix && m.fix.fix) { - let s = fmt.fmtDist(fmt.distance(m.fix, state.prev_fix)/1000) + icon_km; + let s = fmt.fmtDist(fmt.distance(m.fix, state.prev_fix)/1000) + fmt.icon_km; msg += " " + s; debug = "wp>" + s; mark_heading = 180 + fmt.bearing(m.fix, state.prev_fix); @@ -754,7 +746,7 @@ function draw() { msg += fmt.fmtAlt(cur_altitude); } - msg = msg + " " + cur_temperature.toFixed(1)+icon_c + "\n"; + msg = msg + " " + cur_temperature.toFixed(1)+fmt.icon_c + "\n"; { let o = Bangle.getOptions(); From 8d19a3585395aa359b4b01adf3bfe9b0e1ff964d Mon Sep 17 00:00:00 2001 From: Pavel Machek Date: Wed, 14 Aug 2024 21:40:46 +0200 Subject: [PATCH 14/36] sixths: add pressure formatting. --- apps/sixths/sixths.app.js | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/apps/sixths/sixths.app.js b/apps/sixths/sixths.app.js index 75f7ede3fc..ee190a7195 100644 --- a/apps/sixths/sixths.app.js +++ b/apps/sixths/sixths.app.js @@ -8,6 +8,9 @@ let fmt = { icon_km : "\0\x08\x1a\1\xC3\xC6\xCC\xD8\xF0\xD8\xCC\xC6\xC3\x00\xC3\xE7\xFF\xDB\xC3\xC3\xC3\xC3\x00\x00\x00\x00\x00\x00\x00\x00", icon_kph : "\0\x08\x1a\1\xC3\xC6\xCC\xD8\xF0\xD8\xCC\xC6\xC3\x00\xC3\xE7\xFF\xDB\xC3\xC3\xC3\xC3\x00\xFF\x00\xC3\xC3\xFF\xC3\xC3", icon_c : "\0\x08\x1a\1\x00\x00\x60\x90\x90\x60\x00\x7F\xFF\xC0\xC0\xC0\xC0\xC0\xFF\x7F\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", + icon_hpa : "\x00\x08\x16\x01\x00\x80\xb0\xc8\x88\x88\x88\x00\xf0\x88\x84\x84\x88\xf0\x80\x8c\x92\x22\x25\x19\x00\x00", + icon_9 : "\x00\x08\x16\x01\x00\x00\x00\x00\x38\x44\x44\x4c\x34\x04\x04\x38\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", + icon_10 : "\x00\x08\x16\x01\x00\x08\x18\x28\x08\x08\x08\x00\x00\x18\x24\x24\x24\x24\x18\x00\x00\x00\x00\x00\x00\x00", /* 0 .. DD.ddddd 1 .. DD MM.mmm' @@ -22,6 +25,17 @@ let fmt = { }, fmtSteps: function(n) { return this.fmtDist(0.001 * 0.719 * n); }, fmtAlt: function(m) { return m.toFixed(0) + this.icon_alt; }, + fmtTemp: function(c) { return c.toFixed(1) + this.icon_c; }, + fmtPress: function(p) { + if (p < 900 || p > 1100) + return p.toFixed(1) + this.icon_hpa; + if (p < 1000) { + p -= 900; + return this.icon_9 + p.toFixed(1) + this.icon_hpa; + } + p -= 1000; + return this.icon_10 + p.toFixed(1) + this.icon_hpa; + }, draw_dot : 1, add0: function(i) { if (i > 9) { @@ -739,21 +753,21 @@ function draw() { } let pr = o.seaLevelPressure; if (pr) - msg += pr.toFixed(1) + "hPa"; + msg += fmt.fmtPress(pr); else msg += "emu?"; } else { msg += fmt.fmtAlt(cur_altitude); } - msg = msg + " " + cur_temperature.toFixed(1)+fmt.icon_c + "\n"; + msg = msg + " " + fmt.fmtTemp(cur_temperature) + "\n"; { let o = Bangle.getOptions(); let pr = o.seaLevelPressure; if (pr) - msg += pr.toFixed(1) + "hPa\n"; + msg += fmt.fmtPress(pr) + "\n"; } g.setFontAlign(-1, -1); g.drawString(msg, 10, 85); From 6c04da4c01578fc6645f9168d78dc2c53ac9365e Mon Sep 17 00:00:00 2001 From: Pavel Machek Date: Wed, 14 Aug 2024 21:44:08 +0200 Subject: [PATCH 15/36] sixths: Keep GPS on for longer. --- apps/sixths/README.md | 2 -- apps/sixths/sixths.app.js | 12 ++++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/apps/sixths/README.md b/apps/sixths/README.md index 2fe7ad484a..4b826ca92f 100644 --- a/apps/sixths/README.md +++ b/apps/sixths/README.md @@ -85,8 +85,6 @@ Todo: *) +-3.5hPa 1012hPa -*) keep GPS on longer - *) display gps alt + offset to baro *) start logging altitudes, baro pressure diff --git a/apps/sixths/sixths.app.js b/apps/sixths/sixths.app.js index ee190a7195..7adc59d452 100644 --- a/apps/sixths/sixths.app.js +++ b/apps/sixths/sixths.app.js @@ -216,7 +216,7 @@ var gps_on = 0, // time GPS was turned on last_restart = 0, last_pause = 0; // utime last_fstart = 0; // utime, time of start of last fix var gps_needed = 0, // how long to wait for a fix - keep_fix_for = 10; + keep_fix_for = 30; var mark_heading = -1; @@ -325,11 +325,11 @@ function gpsHandle() { if (!last_fstart) last_fstart = getTime(); last_fix = getTime(); - keep_fix_for = (last_fstart - last_restart) / 2; - if (keep_fix_for < 10) - keep_fix_for = 10; - if (keep_fix_for > 4*60) - keep_fix_for = 4*60; + keep_fix_for = (last_fstart - last_restart) / 1.5; + if (keep_fix_for < 20) + keep_fix_for = 20; + if (keep_fix_for > 6*60) + keep_fix_for = 6*60; gps_needed = 60; } else { if (last_fix) From 543e51846bbfdb2ec83ad833729ea9d920c67f37 Mon Sep 17 00:00:00 2001 From: Pavel Machek Date: Wed, 14 Aug 2024 22:01:13 +0200 Subject: [PATCH 16/36] sixhts: Warn when GPS altitude does not match baro. --- apps/sixths/sixths.app.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/apps/sixths/sixths.app.js b/apps/sixths/sixths.app.js index 7adc59d452..9f88a8fea4 100644 --- a/apps/sixths/sixths.app.js +++ b/apps/sixths/sixths.app.js @@ -294,7 +294,7 @@ function gpsHandleFix(fix) { debug2 = "te "+(n2-n1)+"s"; } loggps(fix); - let d = calcDistance(fix, state.prev_fix); + let d = fmt.distance(fix, state.prev_fix); if (d > 30) { state.prev_fix = fix; state.gps_dist += d/1000; @@ -316,11 +316,13 @@ function gpsHandle() { gpsRestart(); } } else { - let fix = Bangle.getGPSFix(); + let fix = gps.getGPSFix(); if (fix && fix.fix && fix.lat) { gpsHandleFix(fix); - msg = fmt.fmtSpeed(fix.speed); - print("GPS FIX", msg); + msg = ""; + if (Math.abs(fix.alt - cur_altitude) > 20) + msg += "!"; + msg += fmt.fmtSpeed(fix.speed); if (!last_fstart) last_fstart = getTime(); From 08870ec31a3a4dd4ce1741de702d826dd73ebb17 Mon Sep 17 00:00:00 2001 From: Pavel Machek Date: Wed, 14 Aug 2024 22:10:27 +0200 Subject: [PATCH 17/36] sixths: start logging more data. --- apps/sixths/README.md | 6 ++---- apps/sixths/sixths.app.js | 7 +++++-- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/apps/sixths/README.md b/apps/sixths/README.md index 4b826ca92f..8a7d2185a6 100644 --- a/apps/sixths/README.md +++ b/apps/sixths/README.md @@ -85,12 +85,10 @@ Todo: *) +-3.5hPa 1012hPa -*) display gps alt + offset to baro +?) display gps alt + offset to baro -*) start logging altitudes, baro pressure +?) start logging baro pressure *) compute climb/descent *) switch to compensated compass - -*) only accept gps fix when altitude matches baro \ No newline at end of file diff --git a/apps/sixths/sixths.app.js b/apps/sixths/sixths.app.js index 9f88a8fea4..f9901f8b44 100644 --- a/apps/sixths/sixths.app.js +++ b/apps/sixths/sixths.app.js @@ -582,10 +582,13 @@ function touchHandler(d) { } var lastHour = -1, lastMin = -1; function logstamp(s) { - logfile.write("utime=" + getTime() + " " + s + "\n"); + logfile.write("utime=" + getTime() + + " bele=" + cur_altitude + + " batperc=" + E.getBattery() + + " " + s + "\n"); } function loggps(fix) { - logfile.write(fix.lat + " " + fix.lon + " "); + logfile.write(fix.lat + " " + fix.lon + " ele=" + fix.alt + " "); logstamp(""); } function hourly() { From a27f40c9f6cbb77ade83f95b3c01e1c5df5c603b Mon Sep 17 00:00:00 2001 From: Pavel Machek Date: Wed, 14 Aug 2024 22:29:26 +0200 Subject: [PATCH 18/36] sixths: save night pressure to watch trend. --- apps/sixths/sixths.app.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/apps/sixths/sixths.app.js b/apps/sixths/sixths.app.js index f9901f8b44..49a209a9ae 100644 --- a/apps/sixths/sixths.app.js +++ b/apps/sixths/sixths.app.js @@ -28,13 +28,13 @@ let fmt = { fmtTemp: function(c) { return c.toFixed(1) + this.icon_c; }, fmtPress: function(p) { if (p < 900 || p > 1100) - return p.toFixed(1) + this.icon_hpa; + return p.toFixed(0) + this.icon_hpa; if (p < 1000) { p -= 900; - return this.icon_9 + p.toFixed(1) + this.icon_hpa; + return this.icon_9 + p.toFixed(0) + this.icon_hpa; } p -= 1000; - return this.icon_10 + p.toFixed(1) + this.icon_hpa; + return this.icon_10 + p.toFixed(0) + this.icon_hpa; }, draw_dot : 1, add0: function(i) { @@ -228,6 +228,7 @@ var is_level = false; // For altitude handling. var cur_altitude = 0; var cur_temperature = 0; +var night_pressure = 0; function toMorse(x) { let r = ""; @@ -771,6 +772,10 @@ function draw() { let o = Bangle.getOptions(); let pr = o.seaLevelPressure; + if (now.hour < 6) + night_pressure = pr; + if (night_pressure) + msg += (pr-night_pressure).toFixed(1) + fmt.icon_hpa + " "; if (pr) msg += fmt.fmtPress(pr) + "\n"; } From e6f864d44181b09db50b3867b40317aab2893401 Mon Sep 17 00:00:00 2001 From: Pavel Machek Date: Thu, 15 Aug 2024 09:53:47 +0200 Subject: [PATCH 19/36] sixths: Fix pressure change handling. --- apps/sixths/README.md | 2 -- apps/sixths/sixths.app.js | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/apps/sixths/README.md b/apps/sixths/README.md index 8a7d2185a6..9fd7631f9e 100644 --- a/apps/sixths/README.md +++ b/apps/sixths/README.md @@ -83,8 +83,6 @@ Todo: *) "myprofile" to read step length -*) +-3.5hPa 1012hPa - ?) display gps alt + offset to baro ?) start logging baro pressure diff --git a/apps/sixths/sixths.app.js b/apps/sixths/sixths.app.js index 49a209a9ae..ea9943fdd5 100644 --- a/apps/sixths/sixths.app.js +++ b/apps/sixths/sixths.app.js @@ -772,7 +772,7 @@ function draw() { let o = Bangle.getOptions(); let pr = o.seaLevelPressure; - if (now.hour < 6) + if (now.getHours() < 10) night_pressure = pr; if (night_pressure) msg += (pr-night_pressure).toFixed(1) + fmt.icon_hpa + " "; From f61a98d1b97105f07bc7bb00e1e21048d218c0dd Mon Sep 17 00:00:00 2001 From: Pavel Machek Date: Thu, 15 Aug 2024 10:42:16 +0200 Subject: [PATCH 20/36] sixths: start implementing climb/descent. --- apps/sixths/sixths.app.js | 51 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 48 insertions(+), 3 deletions(-) diff --git a/apps/sixths/sixths.app.js b/apps/sixths/sixths.app.js index ea9943fdd5..eeba5eb6f8 100644 --- a/apps/sixths/sixths.app.js +++ b/apps/sixths/sixths.app.js @@ -226,7 +226,7 @@ var draw_dot = false; var is_level = false; // For altitude handling. -var cur_altitude = 0; +var cur_altitude = -1; var cur_temperature = 0; var night_pressure = 0; @@ -608,6 +608,9 @@ function showMsg(msg, timeout) { note_limit = getTime() + timeout; note = msg; } + +var prev_step = -1, this_step = -1; + function fivemin() { print("fivemin"); let s = ' B'; @@ -618,7 +621,8 @@ function fivemin() { } catch (e) { print("Altimeter error", e); } - + prev_step = this_step; + this_step = Bangle.getStepCount(); } function every(now) { if ((mode > 0) && (getTime() - mode_time > 10)) { @@ -699,6 +703,45 @@ function drawTime(now) { dot = "."; g.drawString(now.getHours() + dot + fmt.add0(now.getMinutes()), W, 90); } + +var base_alt = -1, ext_alt = -1, tot_down = 0, tot_up = 0; + +function walkHandle() { + let msg = ""; + let step = Bangle.getStepCount(); + let cur = cur_altitude; + if (base_alt == -1) { + base_alt = cur; + ext_alt = cur; + } + if (this_step - prev_step > 100 + || 1 + || step - this_step > 100) { + msg += fmt.fmtSteps((this_step - prev_step) * 12); + + let dir = cur > base_alt; /* 1.. climb */ + if (!dir) dir = -1; + let hyst = 6; + if (Math.abs(cur - base_alt) > hyst) { + if (cur > ext_alt) { //f + ext_alt = cur; + } + if (cur < ext_alt - hyst) { //f + let diff = ext_alt - base_alt; + if (1) { + tot_up += diff; + } + base_alt = cur; + ext_alt = cur; + } + } + msg += fmt.fmtAlt(cur-base_alt) + fmt.fmtAlt(tot_down) + fmt.fmtAlt(tot_up); + + return msg + "\n"; + } + return ""; +} + function draw() { if (disp_mode == 2) { draw_all(); @@ -743,6 +786,8 @@ function draw() { else msg += note + "\n"; } + + msg += walkHandle(); if (getTime() - last_active > 15*60) { let alt_adjust = cur_altitude - location.alt; @@ -772,7 +817,7 @@ function draw() { let o = Bangle.getOptions(); let pr = o.seaLevelPressure; - if (now.getHours() < 10) + if (now.getHours() < 10) // FIXME night_pressure = pr; if (night_pressure) msg += (pr-night_pressure).toFixed(1) + fmt.icon_hpa + " "; From ba21c2ba7b6606a376ef5b2abe4883b498c27d69 Mon Sep 17 00:00:00 2001 From: Pavel Machek Date: Thu, 15 Aug 2024 10:48:09 +0200 Subject: [PATCH 21/36] sixths: Tweak settings for easier debugging. --- apps/sixths/sixths.app.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/apps/sixths/sixths.app.js b/apps/sixths/sixths.app.js index eeba5eb6f8..2e3f1de0d2 100644 --- a/apps/sixths/sixths.app.js +++ b/apps/sixths/sixths.app.js @@ -195,7 +195,7 @@ var buzz = "", /* Set this to transmit morse via vibrations */ inm = "", l = "", /* For incoming morse handling */ in_str = "", note = "", - debug = "v0.6.0", debug2 = "(otherdb)", debug3 = "(short)"; + debug = "v0.5.10", debug2 = "(otherdb)", debug3 = "(short)"; var note_limit = 0; var mode = 0, mode_time = 0; // 0 .. normal, 1 .. note, 2.. mark name var disp_mode = 0; // 0 .. normal, 1 .. small time @@ -721,7 +721,7 @@ function walkHandle() { let dir = cur > base_alt; /* 1.. climb */ if (!dir) dir = -1; - let hyst = 6; + let hyst = 2; if (Math.abs(cur - base_alt) > hyst) { if (cur > ext_alt) { //f ext_alt = cur; @@ -817,7 +817,7 @@ function draw() { let o = Bangle.getOptions(); let pr = o.seaLevelPressure; - if (now.getHours() < 10) // FIXME + if (now.getHours() < 12) // FIXME night_pressure = pr; if (night_pressure) msg += (pr-night_pressure).toFixed(1) + fmt.icon_hpa + " "; From 462dc3827be4b4874b64e6ebda05540642b317ed Mon Sep 17 00:00:00 2001 From: Pavel Machek Date: Thu, 15 Aug 2024 11:57:26 +0200 Subject: [PATCH 22/36] sixths: fixup altitude totals. Still not fully correct. --- apps/sixths/sixths.app.js | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/apps/sixths/sixths.app.js b/apps/sixths/sixths.app.js index 2e3f1de0d2..4f8cfdeb9e 100644 --- a/apps/sixths/sixths.app.js +++ b/apps/sixths/sixths.app.js @@ -722,17 +722,22 @@ function walkHandle() { let dir = cur > base_alt; /* 1.. climb */ if (!dir) dir = -1; let hyst = 2; + // This is not fully correct; it fails + // to add totals for sequence such as 100, 200, 100, 200. if (Math.abs(cur - base_alt) > hyst) { - if (cur > ext_alt) { //f + if (cur*dir > ext_alt*dir) { ext_alt = cur; } - if (cur < ext_alt - hyst) { //f + if (cur*dir < (ext_alt - hyst*dir)*dir) { let diff = ext_alt - base_alt; - if (1) { + if (1 == dir) { tot_up += diff; } - base_alt = cur; - ext_alt = cur; + if (-1 == dir) { + tot_down += -diff; + } + base_alt = ext_alt; + ext_alt = ext_alt; } } msg += fmt.fmtAlt(cur-base_alt) + fmt.fmtAlt(tot_down) + fmt.fmtAlt(tot_up); From 64cfbeb157d4c2c3054173c6bc9d291e2305b2bf Mon Sep 17 00:00:00 2001 From: Pavel Machek Date: Thu, 15 Aug 2024 12:20:01 +0200 Subject: [PATCH 23/36] sixths: more altitude fixups, hopefully correct --- apps/sixths/sixths.app.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/apps/sixths/sixths.app.js b/apps/sixths/sixths.app.js index 4f8cfdeb9e..138a1b5c23 100644 --- a/apps/sixths/sixths.app.js +++ b/apps/sixths/sixths.app.js @@ -719,15 +719,14 @@ function walkHandle() { || step - this_step > 100) { msg += fmt.fmtSteps((this_step - prev_step) * 12); - let dir = cur > base_alt; /* 1.. climb */ + let dir = ext_alt > base_alt; /* 1.. climb */ if (!dir) dir = -1; let hyst = 2; - // This is not fully correct; it fails - // to add totals for sequence such as 100, 200, 100, 200. if (Math.abs(cur - base_alt) > hyst) { if (cur*dir > ext_alt*dir) { ext_alt = cur; } + } if (cur*dir < (ext_alt - hyst*dir)*dir) { let diff = ext_alt - base_alt; if (1 == dir) { @@ -737,9 +736,9 @@ function walkHandle() { tot_down += -diff; } base_alt = ext_alt; - ext_alt = ext_alt; + ext_alt = cur; } - } + msg += fmt.fmtAlt(cur-base_alt) + fmt.fmtAlt(tot_down) + fmt.fmtAlt(tot_up); return msg + "\n"; From 6b201ceb7f26f556ad15bb971e082daaa79b04a6 Mon Sep 17 00:00:00 2001 From: Pavel Machek Date: Fri, 16 Aug 2024 21:31:28 +0200 Subject: [PATCH 24/36] sixths: simplify climb/descent display, scalable altitude warnings. --- apps/sixths/sixths.app.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/apps/sixths/sixths.app.js b/apps/sixths/sixths.app.js index 138a1b5c23..160847020e 100644 --- a/apps/sixths/sixths.app.js +++ b/apps/sixths/sixths.app.js @@ -323,6 +323,10 @@ function gpsHandle() { msg = ""; if (Math.abs(fix.alt - cur_altitude) > 20) msg += "!"; + if (Math.abs(fix.alt - cur_altitude) > 80) + msg += "!"; + if (Math.abs(fix.alt - cur_altitude) > 320) + msg += "!"; msg += fmt.fmtSpeed(fix.speed); if (!last_fstart) @@ -738,8 +742,8 @@ function walkHandle() { base_alt = ext_alt; ext_alt = cur; } - - msg += fmt.fmtAlt(cur-base_alt) + fmt.fmtAlt(tot_down) + fmt.fmtAlt(tot_up); + + msg += " " + fmt.fmtAlt(tot_down-cur+base_alt) + " " + fmt.fmtAlt(tot_up+cur-base_alt); return msg + "\n"; } From 099e504d3f4fc554ef32f0378a6e2e68fe46f5e9 Mon Sep 17 00:00:00 2001 From: Pavel Machek Date: Fri, 16 Aug 2024 21:58:34 +0200 Subject: [PATCH 25/36] sixths: fix alt up/down counts. --- apps/sixths/sixths.app.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/apps/sixths/sixths.app.js b/apps/sixths/sixths.app.js index 160847020e..10c18255f2 100644 --- a/apps/sixths/sixths.app.js +++ b/apps/sixths/sixths.app.js @@ -721,7 +721,7 @@ function walkHandle() { if (this_step - prev_step > 100 || 1 || step - this_step > 100) { - msg += fmt.fmtSteps((this_step - prev_step) * 12); + //msg += fmt.fmtSteps((this_step - prev_step) * 12); let dir = ext_alt > base_alt; /* 1.. climb */ if (!dir) dir = -1; @@ -731,8 +731,8 @@ function walkHandle() { ext_alt = cur; } } + let diff = ext_alt - base_alt; if (cur*dir < (ext_alt - hyst*dir)*dir) { - let diff = ext_alt - base_alt; if (1 == dir) { tot_up += diff; } @@ -742,8 +742,15 @@ function walkHandle() { base_alt = ext_alt; ext_alt = cur; } + let tmp_down = tot_down, tmp_up = tot_up; + if (1 == dir) { + tmp_up += diff; + } + if (-1 == dir) { + tmp_down += -diff; + } - msg += " " + fmt.fmtAlt(tot_down-cur+base_alt) + " " + fmt.fmtAlt(tot_up+cur-base_alt); + msg += " " + fmt.fmtAlt(tmp_down) + " " + fmt.fmtAlt(tmp_up); return msg + "\n"; } From bc0a490bea58616a081ef0416b66da87d85a7792 Mon Sep 17 00:00:00 2001 From: Pavel Machek Date: Sun, 18 Aug 2024 20:42:53 +0200 Subject: [PATCH 26/36] sixths: better implementation of "info". --- apps/sixths/sixths.app.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/apps/sixths/sixths.app.js b/apps/sixths/sixths.app.js index 10c18255f2..b491faa8d8 100644 --- a/apps/sixths/sixths.app.js +++ b/apps/sixths/sixths.app.js @@ -700,12 +700,12 @@ function drawTime(now) { g.setFont('Vector', 60); else g.setFont('Vector', 26); - g.setFontAlign(1, 1); + g.setFontAlign(1, -1); draw_dot = !draw_dot; let dot = ":"; if (!draw_dot) dot = "."; - g.drawString(now.getHours() + dot + fmt.add0(now.getMinutes()), W, 90); + g.drawString(now.getHours() + dot + fmt.add0(now.getMinutes()), W, 28); } var base_alt = -1, ext_alt = -1, tot_down = 0, tot_up = 0; @@ -840,9 +840,12 @@ function draw() { msg += fmt.fmtPress(pr) + "\n"; } g.setFontAlign(-1, -1); - g.drawString(msg, 10, 85); + if (disp_mode == 0) + g.drawString(msg, 10, 85); + else + g.drawString(msg, 10, 60); - if (disp_mode == 1) { + if (0 && disp_mode == 1) { g.setFont('Vector', 21); g.drawString(debug + "\n" + debug2 + "\n" + debug3, 10, 20); } From 7057b34e6fd4e01fd3ee0ac039488dc952cf2a32 Mon Sep 17 00:00:00 2001 From: Pavel Machek Date: Sun, 18 Aug 2024 21:55:54 +0200 Subject: [PATCH 27/36] sixths: fix hPa formatting. --- apps/sixths/sixths.app.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/sixths/sixths.app.js b/apps/sixths/sixths.app.js index b491faa8d8..90bf17ded7 100644 --- a/apps/sixths/sixths.app.js +++ b/apps/sixths/sixths.app.js @@ -31,10 +31,10 @@ let fmt = { return p.toFixed(0) + this.icon_hpa; if (p < 1000) { p -= 900; - return this.icon_9 + p.toFixed(0) + this.icon_hpa; + return this.icon_9 + this.add0(p.toFixed(0)) + this.icon_hpa; } p -= 1000; - return this.icon_10 + p.toFixed(0) + this.icon_hpa; + return this.icon_10 + this.add0(p.toFixed(0)) + this.icon_hpa; }, draw_dot : 1, add0: function(i) { From 5c77834a6bd533b3900f765d5bdff6663f7f3966 Mon Sep 17 00:00:00 2001 From: Pavel Machek Date: Mon, 19 Aug 2024 13:32:34 +0200 Subject: [PATCH 28/36] sixths: Activate delta pressure measurement --- apps/sixths/sixths.app.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/sixths/sixths.app.js b/apps/sixths/sixths.app.js index 90bf17ded7..af6e984f13 100644 --- a/apps/sixths/sixths.app.js +++ b/apps/sixths/sixths.app.js @@ -832,7 +832,7 @@ function draw() { let o = Bangle.getOptions(); let pr = o.seaLevelPressure; - if (now.getHours() < 12) // FIXME + if (now.getHours() < 6) night_pressure = pr; if (night_pressure) msg += (pr-night_pressure).toFixed(1) + fmt.icon_hpa + " "; From 68ae86361c332475eef39da91af606fbab17315e Mon Sep 17 00:00:00 2001 From: Pavel Machek Date: Mon, 19 Aug 2024 22:12:51 +0200 Subject: [PATCH 29/36] sixths: start importing suncalc. --- apps/sixths/sixths.app.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/apps/sixths/sixths.app.js b/apps/sixths/sixths.app.js index af6e984f13..857adc564a 100644 --- a/apps/sixths/sixths.app.js +++ b/apps/sixths/sixths.app.js @@ -182,6 +182,21 @@ let gps = { }, }; +/* sun version 0.0.1 */ +let sun = { + SunCalc: null, + init: function() { + try { + this.SunCalc = require("suncalc"); // from modules folder + } catch (e) { + print("Require error", e); + } + + print("Have suncalc: ", this.SunCalc); + } +}; + +sun.init(); fmt.init(); gps.init(); From d25b643c49e086108e24558c572b9eed536bb843 Mon Sep 17 00:00:00 2001 From: Pavel Machek Date: Mon, 19 Aug 2024 22:33:39 +0200 Subject: [PATCH 30/36] sixths: start testing Sun time/pos --- apps/sixths/sixths.app.js | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/apps/sixths/sixths.app.js b/apps/sixths/sixths.app.js index 857adc564a..c6fe4234f5 100644 --- a/apps/sixths/sixths.app.js +++ b/apps/sixths/sixths.app.js @@ -185,6 +185,8 @@ let gps = { /* sun version 0.0.1 */ let sun = { SunCalc: null, + lat: 50, + lon: 14, init: function() { try { this.SunCalc = require("suncalc"); // from modules folder @@ -193,10 +195,24 @@ let sun = { } print("Have suncalc: ", this.SunCalc); - } + }, + get_sun_pos: function() { + let d = new Date(); + let sun = this.SunCalc.getPosition(d, this.lat, this.lon); + print(sun.azimuth, sun.altitude); + return sun; + }, + get_sun_time: function() { + let d = new Date(); + let sun = this.SunCalc.getTimes(d, this.lat, this.lon); + print(sun.sunrise, sun.sunrise.getHour()); + return sun; + }, }; sun.init(); +sun.get_sun_pos(); +sun.get_sun_time(); fmt.init(); gps.init(); From a104f12f7ee115f5fad6c8cb115604679c474e2c Mon Sep 17 00:00:00 2001 From: Pavel Machek Date: Mon, 19 Aug 2024 22:37:01 +0200 Subject: [PATCH 31/36] sixths: show version on info --- apps/sixths/sixths.app.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/apps/sixths/sixths.app.js b/apps/sixths/sixths.app.js index c6fe4234f5..8e716a5be7 100644 --- a/apps/sixths/sixths.app.js +++ b/apps/sixths/sixths.app.js @@ -226,7 +226,7 @@ var buzz = "", /* Set this to transmit morse via vibrations */ inm = "", l = "", /* For incoming morse handling */ in_str = "", note = "", - debug = "v0.5.10", debug2 = "(otherdb)", debug3 = "(short)"; + debug = "v0.5.11", debug2 = "(otherdb)", debug3 = "(short)"; var note_limit = 0; var mode = 0, mode_time = 0; // 0 .. normal, 1 .. note, 2.. mark name var disp_mode = 0; // 0 .. normal, 1 .. small time @@ -736,7 +736,10 @@ function drawTime(now) { let dot = ":"; if (!draw_dot) dot = "."; - g.drawString(now.getHours() + dot + fmt.add0(now.getMinutes()), W, 28); + let s = ""; + if (disp_mode == 1) + s = debug; + g.drawString(s + now.getHours() + dot + fmt.add0(now.getMinutes()), W, 28); } var base_alt = -1, ext_alt = -1, tot_down = 0, tot_up = 0; From 942ff4aaf892f03a2bf11c5ea016f9fd5420a1e2 Mon Sep 17 00:00:00 2001 From: Pavel Machek Date: Mon, 19 Aug 2024 22:44:51 +0200 Subject: [PATCH 32/36] sixths: gethour was not available, try this --- apps/sixths/sixths.app.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/sixths/sixths.app.js b/apps/sixths/sixths.app.js index 8e716a5be7..5740c95096 100644 --- a/apps/sixths/sixths.app.js +++ b/apps/sixths/sixths.app.js @@ -205,7 +205,7 @@ let sun = { get_sun_time: function() { let d = new Date(); let sun = this.SunCalc.getTimes(d, this.lat, this.lon); - print(sun.sunrise, sun.sunrise.getHour()); + print(sun.sunrise, sun.sunset); return sun; }, }; From 1b40897ea287ca6a75d04b4945cd301f201894a8 Mon Sep 17 00:00:00 2001 From: Pavel Machek Date: Thu, 22 Aug 2024 14:49:00 +0200 Subject: [PATCH 33/36] sixths: add fixme. --- apps/sixths/sixths.app.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/apps/sixths/sixths.app.js b/apps/sixths/sixths.app.js index 5740c95096..761ddee76d 100644 --- a/apps/sixths/sixths.app.js +++ b/apps/sixths/sixths.app.js @@ -675,11 +675,10 @@ function every(now) { lastHour = now.getHours(); hourly(); } - if (lastMin / 5 != now.getMinutes() / 5) { + if (lastMin / 5 != now.getMinutes() / 5) { // fixme, trunc? lastMin = now.getMinutes(); fivemin(); } - } function testBearing() { From cfcfe8e9855b3db7d2eed22a676fa93843456b79 Mon Sep 17 00:00:00 2001 From: Pavel Machek Date: Thu, 29 Aug 2024 09:36:05 +0200 Subject: [PATCH 34/36] sixths: Increase version --- apps/sixths/ChangeLog | 8 ++++++++ apps/sixths/metadata.json | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/apps/sixths/ChangeLog b/apps/sixths/ChangeLog index 510748fb31..2da2201428 100644 --- a/apps/sixths/ChangeLog +++ b/apps/sixths/ChangeLog @@ -3,3 +3,11 @@ 0.03: minor code improvements 0.04: make height auto-calibration useful and slow ticks to save power 0.05: add ability to navigate to waypoints, better documentation +0.1: lots of updates + acknowledge commands by vibration and message + ui tweaks -- bigger font, compressing uninteresting info + display meters up/down + display pressure trend + adjust GPS on/off algorithm for more reliable fix + display warnings when GPS altitude does not match baro + diff --git a/apps/sixths/metadata.json b/apps/sixths/metadata.json index 585f23170e..9aab1ee8b0 100644 --- a/apps/sixths/metadata.json +++ b/apps/sixths/metadata.json @@ -1,6 +1,6 @@ { "id": "sixths", "name": "Sixth sense", - "version": "0.05", + "version": "0.1", "description": "Clock for outdoor use with GPS support", "icon": "app.png", "readme": "README.md", From 468f55950d560a2472a7c457052dbc839059153d Mon Sep 17 00:00:00 2001 From: Pavel Machek Date: Thu, 29 Aug 2024 09:38:47 +0200 Subject: [PATCH 35/36] sixths: fix warnings --- apps/sixths/sixths.app.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/sixths/sixths.app.js b/apps/sixths/sixths.app.js index 761ddee76d..c8d2e668eb 100644 --- a/apps/sixths/sixths.app.js +++ b/apps/sixths/sixths.app.js @@ -244,7 +244,7 @@ var state = { // GPS handling var gps_on = 0, // time GPS was turned on last_fix = 0, // time of last fix - last_restart = 0, last_pause = 0; // utime + last_restart = 0, last_pause = 0, // utime last_fstart = 0; // utime, time of start of last fix var gps_needed = 0, // how long to wait for a fix keep_fix_for = 30; @@ -817,7 +817,7 @@ function draw() { const weekday = ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"]; - msg = weekday[now.getDay()] + "" + now.getDate() + ". " + let msg = weekday[now.getDay()] + "" + now.getDate() + ". " + fmt.fmtSteps(Bangle.getHealthStatus("day").steps) + "\n"; if (gps_on) { From e521b67d59693feb63a2abdcc79d21173765ab1e Mon Sep 17 00:00:00 2001 From: Pavel Machek Date: Thu, 29 Aug 2024 11:32:50 +0200 Subject: [PATCH 36/36] sixths: Mark version as 0.10 for consistency with other apps. --- apps/sixths/ChangeLog | 2 +- apps/sixths/metadata.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/sixths/ChangeLog b/apps/sixths/ChangeLog index 2da2201428..bff499d30b 100644 --- a/apps/sixths/ChangeLog +++ b/apps/sixths/ChangeLog @@ -3,7 +3,7 @@ 0.03: minor code improvements 0.04: make height auto-calibration useful and slow ticks to save power 0.05: add ability to navigate to waypoints, better documentation -0.1: lots of updates +0.10: lots of updates acknowledge commands by vibration and message ui tweaks -- bigger font, compressing uninteresting info display meters up/down diff --git a/apps/sixths/metadata.json b/apps/sixths/metadata.json index 9aab1ee8b0..03a9aa1d9d 100644 --- a/apps/sixths/metadata.json +++ b/apps/sixths/metadata.json @@ -1,6 +1,6 @@ { "id": "sixths", "name": "Sixth sense", - "version": "0.1", + "version": "0.10", "description": "Clock for outdoor use with GPS support", "icon": "app.png", "readme": "README.md",