Solar Clock: changed from daily GPS update to GPS update on request because it can take hours to get a GPS fix indoors which will drain the battery. Replaced it with GPS on request of button1

master
adrian w kirk 2021-07-26 22:38:23 +01:00
parent 788e72a5cb
commit 81a5c0847e
2 changed files with 52 additions and 40 deletions

View File

@ -379,13 +379,31 @@ function log_memory_used() {
);
}
var button1pressStart = null;
function button1pressed(){
console.log("button 1 pressed");
if(button1pressStart == null) {
button1pressStart = Date.now();
}
//console.log("button 1 pressed for:" + (Date.now() - button1pressStart));
if(BTN1.read()){
setTimeout(button1pressed,100);
} else {
var buttonPressTime = Date.now() - button1pressStart;
button1pressStart = null;
console.log("button press time=" + buttonPressTime);
if (buttonPressTime < 3000) {
//console.log("offset reset");
time_offset = 0;
clear_sun();
day_info = null;
} else {
//console.log("requesting gps update");
location.requestGpsUpdate();
gps_status_requires_update = true;
}
draw_clock();
}
}
function button3pressed() {
console.log("button 3 pressed");
@ -485,7 +503,7 @@ function button2pressed(){
Bangle.showLauncher();
}
setWatch(button2pressed, BTN2,{repeat:false,edge:"falling"});
setWatch(button1pressed, BTN1,{repeat:true,edge:"falling"});
setWatch(button1pressed, BTN1,{repeat:true,edge:"rising"});
setWatch(button3pressed, BTN3,{repeat:true,edge:"falling"});
setWatch(button4pressed, BTN4,{repeat:true,edge:"rising"});
setWatch(button5pressed, BTN5,{repeat:true,edge:"rising"});

View File

@ -1,44 +1,14 @@
const storage = require("Storage");
const DateUtils = require("solar_date_utils.js");
class LocationManager {
constructor(locations) {
this.idx=0;
this.locations = locations;
this.listeners = [];
this.in_use = true;
this.gps_queried = false;
this.gpsPower = 0;
this.location_info = null;
}
init(){
try {
this.location_info = storage.readJSON("solar_loc." + this.getName() + ".json");
} catch(e){
console.log("failed to load location:" + this.getName())
}
if(this.location_info == null){
this.location_info = {};
}
if (this.isGPSLocation() && !this.gps_queried) {
//console.log("gps location:" + JSON.stringify(this.location_info));
var last_update_str = this.location_info.last_update;
if(last_update_str == null ||
(Date.now() - new Date(last_update_str).getTime() > DateUtils.DAY_MILLIS ) ){
console.log("updating local location last update:" + last_update_str);
this._gpsUpdate();
this.gps_queried = true;
} else {
console.log("gps update not required last update:" + last_update_str);
}
}
}
setGPSPower(power){
this.gpsPower = power;
Bangle.setGPSPower(this.gpsPower);
}
getGPSPower(){return this.gpsPower;}
_gpsUpdate(){
this.setGPSPower(1);
Bangle.on('GPS', (g) => {
if (!this.in_use)
return;
@ -58,6 +28,30 @@ class LocationManager {
}
});
try {
this.location_info = storage.readJSON("solar_loc." + this.getName() + ".json");
} catch(e){
console.log("failed to load location:" + this.getName())
}
if(this.location_info == null){
this.location_info = {};
}
if (this.isGPSLocation() && this.getCoordinates() == null) {
this.requestGpsUpdate();
}
}
setGPSPower(power){
this.gpsPower = power;
Bangle.setGPSPower(this.gpsPower);
}
getGPSPower(){return this.gpsPower;}
requestGpsUpdate(){
if (this.getGPSPower() == 0) {
console.log("updating gps location update");
this.setGPSPower(1);
} else {
console.log("gps already updating");
}
}
isGPSLocation(){return this.getName() == 'local';}
addUpdateListener(listener){this.listeners.push(listener);}