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
parent
788e72a5cb
commit
81a5c0847e
|
|
@ -379,15 +379,33 @@ function log_memory_used() {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var button1pressStart = null;
|
||||||
function button1pressed(){
|
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;
|
time_offset = 0;
|
||||||
clear_sun();
|
clear_sun();
|
||||||
day_info = null;
|
day_info = null;
|
||||||
|
} else {
|
||||||
|
//console.log("requesting gps update");
|
||||||
|
location.requestGpsUpdate();
|
||||||
|
gps_status_requires_update = true;
|
||||||
|
}
|
||||||
draw_clock();
|
draw_clock();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function button3pressed(){
|
function button3pressed() {
|
||||||
console.log("button 3 pressed");
|
console.log("button 3 pressed");
|
||||||
time_offset = 0;
|
time_offset = 0;
|
||||||
location.nextLocation();
|
location.nextLocation();
|
||||||
|
|
@ -485,7 +503,7 @@ function button2pressed(){
|
||||||
Bangle.showLauncher();
|
Bangle.showLauncher();
|
||||||
}
|
}
|
||||||
setWatch(button2pressed, BTN2,{repeat:false,edge:"falling"});
|
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(button3pressed, BTN3,{repeat:true,edge:"falling"});
|
||||||
setWatch(button4pressed, BTN4,{repeat:true,edge:"rising"});
|
setWatch(button4pressed, BTN4,{repeat:true,edge:"rising"});
|
||||||
setWatch(button5pressed, BTN5,{repeat:true,edge:"rising"});
|
setWatch(button5pressed, BTN5,{repeat:true,edge:"rising"});
|
||||||
|
|
@ -1,44 +1,14 @@
|
||||||
const storage = require("Storage");
|
const storage = require("Storage");
|
||||||
const DateUtils = require("solar_date_utils.js");
|
|
||||||
class LocationManager {
|
class LocationManager {
|
||||||
constructor(locations) {
|
constructor(locations) {
|
||||||
this.idx=0;
|
this.idx=0;
|
||||||
this.locations = locations;
|
this.locations = locations;
|
||||||
this.listeners = [];
|
this.listeners = [];
|
||||||
this.in_use = true;
|
this.in_use = true;
|
||||||
this.gps_queried = false;
|
|
||||||
this.gpsPower = 0;
|
this.gpsPower = 0;
|
||||||
this.location_info = null;
|
this.location_info = null;
|
||||||
}
|
}
|
||||||
init(){
|
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) => {
|
Bangle.on('GPS', (g) => {
|
||||||
if (!this.in_use)
|
if (!this.in_use)
|
||||||
return;
|
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';}
|
isGPSLocation(){return this.getName() == 'local';}
|
||||||
addUpdateListener(listener){this.listeners.push(listener);}
|
addUpdateListener(listener){this.listeners.push(listener);}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue