Skip to content

Commit

Permalink
tracking altitude
Browse files Browse the repository at this point in the history
  • Loading branch information
strukturart committed Sep 19, 2023
1 parent 5d3eb4f commit 2d94e04
Show file tree
Hide file tree
Showing 10 changed files with 82 additions and 20 deletions.
1 change: 1 addition & 0 deletions application/assets/css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ body {

body.screenOff {
filter: brightness(0);
overflow: hidden;
}

kbd {
Expand Down
Binary file added application/assets/image/battery.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
43 changes: 37 additions & 6 deletions application/assets/js/module.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,31 @@
const module = (() => {
if (navigator.getBattery) {
let battery_memory = 1;
navigator.getBattery().then(function (battery) {
battery.addEventListener("levelchange", function () {
if (battery_memory < battery.level) return false;
if (battery.level <= 0.3) {
module.pushLocalNotification(
"battery is weak",
"",
"/assets/image/battery.png"
);

battery_memory = battery.level;
}
});
});
}

let uniqueId =
Date.now().toString(36) + Math.random().toString(36).substring(2);

let pushLocalNotification = function (title, text) {
let kk = "/assets/image/battery.png";
let pushLocalNotification = function (title, text, icon) {
window.Notification.requestPermission().then((result) => {
const options = {
body: text,
icon: icon,
mozbehavior: {
vibrationPattern: [30, 200, 30],
},
Expand Down Expand Up @@ -814,6 +834,15 @@ const module = (() => {
// Only record data if accuracy is high enough
if (mainmarker.accuracy > 10000) return false;

//only record when movment
if (
tracking_cache.length > 0 &&
tracking_cache[tracking_cache.length - 1].lat ==
mainmarker.device_lat &&
tracking_cache[tracking_cache.length - 1].lng == mainmarker.device_lng
)
return false;

//store time
let ts = new Date();
tracking_timestamp.push(ts.toISOString());
Expand Down Expand Up @@ -849,7 +878,7 @@ const module = (() => {
JSON.stringify(tracking_cache)
);

const { gain, loss } = calculateGainAndLoss(tracking_altitude, 100);
const { gain, loss } = calculateGainAndLoss(tracking_altitude, 50);

//get tracking data to display in view
new L.GPX(toGPX(), { async: true }).on("loaded", function (e) {
Expand All @@ -861,11 +890,11 @@ const module = (() => {
tracking.distance = a.toFixed(2) + general.measurement_unit;

//gain
let b = e.target._info.elevation.gain;
let b = gain;
tracking.gain = gain;

//loss
let c = e.target._info.elevation.loss;
let c = loss;
tracking.loss = loss;
//alt

Expand All @@ -883,11 +912,13 @@ const module = (() => {
tracking.distance = a.toFixed(2) + general.measurement_unit;

//gain
let b = e.target.get_elevation_gain_imp();
let b = gain;
b = b * 3.280839895;
tracking.gain = b.toFixed(2);

//loss
let c = e.target.get_elevation_loss_imp();
let c = loss;
c = c * 3.280839895;
tracking.loss = c.toFixed(2);

//alt
Expand Down
3 changes: 1 addition & 2 deletions application/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ document.addEventListener("DOMContentLoaded", function () {
);
//load gpx file on start
if (e.name.substring(0, 1) == "_") {
module.loadGPX(fileinfo.path + "/" + fileinfo.name);
module.loadGPX(e.path + "/" + e.name);
}
});
});
Expand Down Expand Up @@ -2741,7 +2741,6 @@ document.addEventListener("DOMContentLoaded", function () {
case "5":
// maps.export_db();
//maps.import_db();

if (status.tracking_running) {
document.getElementById("tracking-view").style.display = "flex";
status.windowOpen = "trackingView";
Expand Down
4 changes: 2 additions & 2 deletions application/manifest.webapp
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"version": "1.9.717",
"version": "1.9.72",
"version_name": "together we are strong",
"name": "o.map",
"description": "O.map, your ultimate navigation companion for KaiOS-powered devices. O.map is a lightweight and feature-rich map application designed specifically for KaiOS, enabling you to explore and navigate the world with ease. Whether you're a local resident, a tourist, or an adventurer, O.map is here to enhance your journey and keep you on the right track.",
"launch_path": "/index.html",
"type": "privileged",
"fullscreen": "true",
"priority": "high",
"userAgentInfo": "o.map / 1.9.717 written by strukturart@gmail.com",
"userAgentInfo": "o.map / 1.9.718 written by strukturart@gmail.com",
"icons": {
"56": "/assets/icons/icon-56-56.png",
"112": "/assets/icons/icon-112-112.png"
Expand Down
1 change: 1 addition & 0 deletions docs/assets/css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ body {

body.screenOff {
filter: brightness(0);
overflow: hidden;
}

kbd {
Expand Down
Binary file added docs/assets/image/battery.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
43 changes: 37 additions & 6 deletions docs/assets/js/module.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,31 @@
const module = (() => {
if (navigator.getBattery) {
let battery_memory = 1;
navigator.getBattery().then(function (battery) {
battery.addEventListener("levelchange", function () {
if (battery_memory < battery.level) return false;
if (battery.level <= 0.3) {
module.pushLocalNotification(
"battery is weak",
"",
"/assets/image/battery.png"
);

battery_memory = battery.level;
}
});
});
}

let uniqueId =
Date.now().toString(36) + Math.random().toString(36).substring(2);

let pushLocalNotification = function (title, text) {
let kk = "/assets/image/battery.png";
let pushLocalNotification = function (title, text, icon) {
window.Notification.requestPermission().then((result) => {
const options = {
body: text,
icon: icon,
mozbehavior: {
vibrationPattern: [30, 200, 30],
},
Expand Down Expand Up @@ -814,6 +834,15 @@ const module = (() => {
// Only record data if accuracy is high enough
if (mainmarker.accuracy > 10000) return false;

//only record when movment
if (
tracking_cache.length > 0 &&
tracking_cache[tracking_cache.length - 1].lat ==
mainmarker.device_lat &&
tracking_cache[tracking_cache.length - 1].lng == mainmarker.device_lng
)
return false;

//store time
let ts = new Date();
tracking_timestamp.push(ts.toISOString());
Expand Down Expand Up @@ -849,7 +878,7 @@ const module = (() => {
JSON.stringify(tracking_cache)
);

const { gain, loss } = calculateGainAndLoss(tracking_altitude, 100);
const { gain, loss } = calculateGainAndLoss(tracking_altitude, 50);

//get tracking data to display in view
new L.GPX(toGPX(), { async: true }).on("loaded", function (e) {
Expand All @@ -861,11 +890,11 @@ const module = (() => {
tracking.distance = a.toFixed(2) + general.measurement_unit;

//gain
let b = e.target._info.elevation.gain;
let b = gain;
tracking.gain = gain;

//loss
let c = e.target._info.elevation.loss;
let c = loss;
tracking.loss = loss;
//alt

Expand All @@ -883,11 +912,13 @@ const module = (() => {
tracking.distance = a.toFixed(2) + general.measurement_unit;

//gain
let b = e.target.get_elevation_gain_imp();
let b = gain;
b = b * 3.280839895;
tracking.gain = b.toFixed(2);

//loss
let c = e.target.get_elevation_loss_imp();
let c = loss;
c = c * 3.280839895;
tracking.loss = c.toFixed(2);

//alt
Expand Down
3 changes: 1 addition & 2 deletions docs/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ document.addEventListener("DOMContentLoaded", function () {
);
//load gpx file on start
if (e.name.substring(0, 1) == "_") {
module.loadGPX(fileinfo.path + "/" + fileinfo.name);
module.loadGPX(e.path + "/" + e.name);
}
});
});
Expand Down Expand Up @@ -2741,7 +2741,6 @@ document.addEventListener("DOMContentLoaded", function () {
case "5":
// maps.export_db();
//maps.import_db();

if (status.tracking_running) {
document.getElementById("tracking-view").style.display = "flex";
status.windowOpen = "trackingView";
Expand Down
4 changes: 2 additions & 2 deletions docs/manifest.webapp
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"version": "1.9.717",
"version": "1.9.72",
"version_name": "together we are strong",
"name": "o.map",
"description": "O.map, your ultimate navigation companion for KaiOS-powered devices. O.map is a lightweight and feature-rich map application designed specifically for KaiOS, enabling you to explore and navigate the world with ease. Whether you're a local resident, a tourist, or an adventurer, O.map is here to enhance your journey and keep you on the right track.",
"launch_path": "/index.html",
"type": "privileged",
"fullscreen": "true",
"priority": "high",
"userAgentInfo": "o.map / 1.9.717 written by strukturart@gmail.com",
"userAgentInfo": "o.map / 1.9.718 written by strukturart@gmail.com",
"icons": {
"56": "/assets/icons/icon-56-56.png",
"112": "/assets/icons/icon-112-112.png"
Expand Down

0 comments on commit 2d94e04

Please sign in to comment.