Solar Clock: fixed memory leak. GPS callbacks being installed for every location change

pull/780/head
adrian w kirk 2021-07-27 01:54:00 +01:00
parent 81a5c0847e
commit e137452baf
2 changed files with 26 additions and 24 deletions

View File

@ -168,7 +168,7 @@ function write_GPS_status(){
return;
var gps_coords = location.getCoordinates();
var gps_coords_msg = [];
var gps_coords_msg;
if(location.isGPSLocation()) {
if(gps_coords == null) {
@ -184,7 +184,7 @@ function write_GPS_status(){
}
}
if(gps_coords_msg.length == 0){
if(gps_coords_msg == null){
gps_coords_msg = ["N:" + Math2.format000_00(gps_coords[1]),
"E:" + Math2.format000_00(gps_coords[0])];
}
@ -283,7 +283,6 @@ function format_offset(){
}
let time_offset = 0;
let last_draw_time = null;
var day_info = null;
var location = LocationUtils.load_locations();
var location_requires_update = true;
@ -364,8 +363,6 @@ function draw_clock(){
write_date(now);
write_offset();
write_twilight_times();
last_draw_time = now;
log_memory_used();
var time_taken = Date.now() - start_time;
console.log("drawing clock:" + now.toISOString() + " time taken:" + time_taken );

View File

@ -7,27 +7,9 @@ class LocationManager {
this.in_use = true;
this.gpsPower = 0;
this.location_info = null;
this.gpsRequested = false;
}
init(){
Bangle.on('GPS', (g) => {
if (!this.in_use)
return;
if (g.fix) {
var loc_info = {
last_update: new Date(),
coordinates: [g.lon, g.lat]
};
console.log("Received gps fixing:" + JSON.stringify(loc_info));
storage.writeJSON("solar_loc.local.json", loc_info);
this.setGPSPower(0);
if(this.isGPSLocation()){
this.location_info = loc_info;
this.notifyUpdate();
}
}
});
try {
this.location_info = storage.readJSON("solar_loc." + this.getName() + ".json");
} catch(e){
@ -40,8 +22,31 @@ class LocationManager {
this.requestGpsUpdate();
}
}
initCallback(){
Bangle.on('GPS', (g) => {
if (!this.in_use)
return;
if (g.fix) {
var loc_info = {
coordinates: [g.lon, g.lat]
};
console.log("Received gps fixing:" + JSON.stringify(loc_info));
storage.writeJSON("solar_loc.local.json", loc_info);
this.setGPSPower(0);
if(this.isGPSLocation()){
this.location_info = loc_info;
this.notifyUpdate();
}
}
});
}
setGPSPower(power){
if(power && !this.gpsRequested){
this.initCallback();
}
this.gpsPower = power;
this.gpsRequested = true;
Bangle.setGPSPower(this.gpsPower);
}
getGPSPower(){return this.gpsPower;}