Skip to content

Commit

Permalink
gps lock
Browse files Browse the repository at this point in the history
  • Loading branch information
strukturart committed Jul 21, 2023
1 parent 5473aae commit a5b2b79
Show file tree
Hide file tree
Showing 8 changed files with 96 additions and 92 deletions.
12 changes: 6 additions & 6 deletions application/assets/js/keepalive.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,16 +115,16 @@ const keepalive = (() => {

//reset alarm or stop loop
navigator.mozSetMessageHandler("alarm", function (message) {
let k = JSON.parse(localStorage.getItem("status"));

remove_alarm();
//stop alarm when tracking is not active
let k = JSON.parse(localStorage.getItem("status"));
if (k.tracking_running === false) return false;

let f = Math.round(Date.now() / 1000) - k.gps_data_received;
//module.pushLocalNotification("O.map", String(f));
if (k.tracking_running && k.closedByUser === false) {
m();
} else if (k.tracking_running && f > 360) {
m();
//let f = Math.round(Date.now() / 1000) - k.gps_data_received;
//something is wrong
if (k.tracking_running && k.closedByUser == false) {
module.pushLocalNotification(
"O.map",
"Attention the tracking was aborted unexpectedly"
Expand Down
19 changes: 11 additions & 8 deletions application/assets/js/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,10 @@ const module = (() => {
gpx_group.eachLayer(function (l) {
if (l.getBounds()) gpx_selection.push(l);
});
if (gpx_selection.length == 0) {
helper.side_toaster("no gpx file to select", 2000);
return false;
}

if (gpx_selection_count > gpx_selection.length - 1) gpx_selection_count = 0;
map.fitBounds(gpx_selection[gpx_selection_count].getBounds());
Expand All @@ -400,6 +404,7 @@ const module = (() => {

gpx_selection_info.name = gpx_selection[gpx_selection_count]._info.name;
update_gpx_info();
status.select_gpx = true;
};

let update_gpx_info = function () {
Expand Down Expand Up @@ -430,8 +435,6 @@ const module = (() => {

let k = L.GeometryUtil.closest(map, m, latlng, true);

// L.marker(k).addTo(map);

let f = calc_distance(
mainmarker.device_lat,
mainmarker.device_lng,
Expand All @@ -446,7 +449,6 @@ const module = (() => {
if (mainmarker.accuracy < 22) {
// Add the current value of f to the closest_average array
closest_average.push(f);
console.log(closest_average);
}

// Calculate the average of the closest_average array if it has more than 48 elements
Expand All @@ -468,10 +470,11 @@ const module = (() => {

// If the average is above 0.5, trigger a vibration and show a toaster message
if (result > 0.5) {
helper.side_toaster("Too far " + result, 3000);

try {
navigator.vibrate([1000, 500, 1000]);
module.pushLocalNotification(
"O.map",
"Attention you have left the path"
);
} catch (e) {}
}
}
Expand Down Expand Up @@ -650,7 +653,7 @@ const module = (() => {
let tracking_latlngs = [];
let tracking_interval;
let tracking_cache = [];
let gps_lock;
//let gps_lock;
let tracking_altitude = [];
let calc = 0;

Expand Down Expand Up @@ -702,7 +705,7 @@ const module = (() => {
status.tracking_running = true;

if ("requestWakeLock" in navigator) {
gps_lock = window.navigator.requestWakeLock("gps");
// gps_lock = window.navigator.requestWakeLock("gps");
if (setting.tracking_screenlock) screenWakeLock("lock", "screen");
}

Expand Down
15 changes: 7 additions & 8 deletions application/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -467,19 +467,19 @@ <h2>Export</h2>
</div>
<!--GPX-->
<div class="panel menu-box" id="gpx-file-info" name="GPX File-Info">
<section>
<div class="item" id="gpx-name"></div>
<section class="item">
<div id="gpx-name"></div>
</section>
<section>
<section class="item">
<strong><u>Distance</u></strong>
<div class="item" id="gpx-distance"></div>
<div id="gpx-distance"></div>
</section>
<section>
<section class="item">
<strong><u>Evolution</u></strong>
<div class="item" id="gpx-evo-up"><span></span></div>
<div class="item" id="gpx-evo-down"><span></span></div>
</section>
<section>
<section class="item">
<strong><u>Time</u></strong>
<div class="item" id="gpx-time">duration <span></span></div>
</section>
Expand All @@ -504,8 +504,7 @@ <h2>Export</h2>
id="routing-profile"
data-map="startrouting"
>
activates warning if you are too far off the path
</button>
Follow path </button>
<button
class="item"

Expand Down
48 changes: 24 additions & 24 deletions application/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ let gpx_selection_info = {};
let tilesLayer = "";
let n;

let gps_lock;

const days = ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"];

let routing = {
Expand Down Expand Up @@ -96,9 +98,9 @@ let status = {
marker_selection: false,
path_selection: false,
windowOpen: "map",
sub_status: "",
selected_marker: "",
appOpendByUser: true,
closedByUser: false,
live_track_file_created: false,
tracking_backupup_at: new Date().getTime() / 1000,
tracking_paused: false,
Expand All @@ -111,6 +113,10 @@ if (!navigator.geolocation) {
helper.toaster("Your device does't support geolocation!", 2000);
}

if ("requestWakeLock" in navigator) {
gps_lock = window.navigator.requestWakeLock("gps");
}

if ("b2g" in Navigator) {
try {
if ("serviceWorker" in navigator) {
Expand Down Expand Up @@ -1219,11 +1225,6 @@ document.addEventListener("DOMContentLoaded", function () {
myMarker.setIcon(maps.follow_icon);
}

//routing calc distance to closest point
if (crd != null || crd != "") {
//rs.instructions();
}

let j = localStorage.getItem("last_location");

//store location as fallout
Expand Down Expand Up @@ -1254,12 +1255,11 @@ document.addEventListener("DOMContentLoaded", function () {
//distances

if (routing.active && routing.auto_routing == false) {
alert("calc");
module.get_closest_point(routing.coordinates);
}

if (status.follow_path == true) {
module.get_closest_point(gpx_selection_latlng);
module.get_closest_point(general.gpx_selection_latlng);
}

distance_to_target();
Expand Down Expand Up @@ -1604,13 +1604,19 @@ document.addEventListener("DOMContentLoaded", function () {
);
return false;
}
status.follow_path = true;
document.querySelector("div#finder").style.display = "none";
status.windowOpen = "map";
helper.side_toaster(
"you will get a warning if you are too far off the path",
3000
);

if (status.follow_path == false) {
status.follow_path = true;
document.querySelector("div#finder").style.display = "none";
status.windowOpen = "map";
helper.side_toaster(
"you will get a warning if you are too far off the path",
3000
);
} else {
status.follow_path = false;
helper.side_toaster("off", 3000);
}
}

if (item_value === "startrouting") {
Expand Down Expand Up @@ -1905,7 +1911,7 @@ document.addEventListener("DOMContentLoaded", function () {
finder_panels = finder_panels.filter((e) => e.id != "weather");
}

if (gpx_group.length == 0) {
if (status.select_gpx == true) {
finder_panels = finder_panels.filter((e) => e.id != "gpx-file-info");
}

Expand Down Expand Up @@ -2188,7 +2194,6 @@ document.addEventListener("DOMContentLoaded", function () {
status.closedByUser = true;
status.appOpendByUser = false;
status.tracking_running = false;
localStorage.setItem("status", status);
window.close();
break;

Expand All @@ -2211,7 +2216,6 @@ document.addEventListener("DOMContentLoaded", function () {
status.live_track = true;
module.measure_distance("tracking");
status.tracking_running = true;
localStorage.setItem("status", JSON.stringify(status));

var d = new Date();
d.setMinutes(d.getMinutes() + 1);
Expand Down Expand Up @@ -2295,7 +2299,6 @@ document.addEventListener("DOMContentLoaded", function () {
case "EndCall":
localStorage.setItem("app_closed", "by_user");
status.closedByUser = true;
localStorage.setItem("status", status);
window.close();
break;

Expand Down Expand Up @@ -2650,7 +2653,6 @@ document.addEventListener("DOMContentLoaded", function () {
module.user_input("open", "", "Save as GPX file");
bottom_bar("cancel", "don't save", "save");

localStorage.setItem("status", JSON.stringify(status));
keepalive.remove_alarm();
status.tracking_running = false;
status.tracking_paused = true;
Expand All @@ -2659,8 +2661,6 @@ document.addEventListener("DOMContentLoaded", function () {
let t = new Date().getTime() / 1000;
t = t + 320;
status.tracking_backupup_at = t;

localStorage.setItem("status", JSON.stringify(status));
keepalive.remove_alarm();

return true;
Expand All @@ -2678,7 +2678,6 @@ document.addEventListener("DOMContentLoaded", function () {
);
module.measure_distance("tracking");
status.tracking_running = true;
localStorage.setItem("status", JSON.stringify(status));

var d = new Date();
d.setMinutes(d.getMinutes() + 1);
Expand Down Expand Up @@ -2744,7 +2743,6 @@ document.addEventListener("DOMContentLoaded", function () {
case "*":
if (status.intro) return false;
mainmarker.selected_marker = module.select_marker();

break;

case "#":
Expand Down Expand Up @@ -2796,6 +2794,8 @@ document.addEventListener("DOMContentLoaded", function () {
////////////////////////////////

function handleKeyDown(evt) {
localStorage.setItem("status", JSON.stringify(status));

if (status.visible === "hidden") return false;
if (evt.key === "Backspace" && status.windowOpen !== "map") {
evt.preventDefault();
Expand Down
12 changes: 6 additions & 6 deletions docs/assets/js/keepalive.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,16 +115,16 @@ const keepalive = (() => {

//reset alarm or stop loop
navigator.mozSetMessageHandler("alarm", function (message) {
let k = JSON.parse(localStorage.getItem("status"));

remove_alarm();
//stop alarm when tracking is not active
let k = JSON.parse(localStorage.getItem("status"));
if (k.tracking_running === false) return false;

let f = Math.round(Date.now() / 1000) - k.gps_data_received;
//module.pushLocalNotification("O.map", String(f));
if (k.tracking_running && k.closedByUser === false) {
m();
} else if (k.tracking_running && f > 360) {
m();
//let f = Math.round(Date.now() / 1000) - k.gps_data_received;
//something is wrong
if (k.tracking_running && k.closedByUser == false) {
module.pushLocalNotification(
"O.map",
"Attention the tracking was aborted unexpectedly"
Expand Down
19 changes: 11 additions & 8 deletions docs/assets/js/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,10 @@ const module = (() => {
gpx_group.eachLayer(function (l) {
if (l.getBounds()) gpx_selection.push(l);
});
if (gpx_selection.length == 0) {
helper.side_toaster("no gpx file to select", 2000);
return false;
}

if (gpx_selection_count > gpx_selection.length - 1) gpx_selection_count = 0;
map.fitBounds(gpx_selection[gpx_selection_count].getBounds());
Expand All @@ -400,6 +404,7 @@ const module = (() => {

gpx_selection_info.name = gpx_selection[gpx_selection_count]._info.name;
update_gpx_info();
status.select_gpx = true;
};

let update_gpx_info = function () {
Expand Down Expand Up @@ -430,8 +435,6 @@ const module = (() => {

let k = L.GeometryUtil.closest(map, m, latlng, true);

// L.marker(k).addTo(map);

let f = calc_distance(
mainmarker.device_lat,
mainmarker.device_lng,
Expand All @@ -446,7 +449,6 @@ const module = (() => {
if (mainmarker.accuracy < 22) {
// Add the current value of f to the closest_average array
closest_average.push(f);
console.log(closest_average);
}

// Calculate the average of the closest_average array if it has more than 48 elements
Expand All @@ -468,10 +470,11 @@ const module = (() => {

// If the average is above 0.5, trigger a vibration and show a toaster message
if (result > 0.5) {
helper.side_toaster("Too far " + result, 3000);

try {
navigator.vibrate([1000, 500, 1000]);
module.pushLocalNotification(
"O.map",
"Attention you have left the path"
);
} catch (e) {}
}
}
Expand Down Expand Up @@ -650,7 +653,7 @@ const module = (() => {
let tracking_latlngs = [];
let tracking_interval;
let tracking_cache = [];
let gps_lock;
//let gps_lock;
let tracking_altitude = [];
let calc = 0;

Expand Down Expand Up @@ -702,7 +705,7 @@ const module = (() => {
status.tracking_running = true;

if ("requestWakeLock" in navigator) {
gps_lock = window.navigator.requestWakeLock("gps");
// gps_lock = window.navigator.requestWakeLock("gps");
if (setting.tracking_screenlock) screenWakeLock("lock", "screen");
}

Expand Down
Loading

0 comments on commit a5b2b79

Please sign in to comment.