diff --git a/apps.json b/apps.json index abdfcbd3c..e5195ec02 100644 --- a/apps.json +++ b/apps.json @@ -296,10 +296,9 @@ {"name":"solar_graphic_utils.js","url":"solar_graphic_utils.js"}, {"name":"solar_location.js","url":"solar_location.js"}, {"name":"solar_math_utils.js","url":"solar_math_utils.js"}, - {"name":"solar_loc.Iceland.json","url":"solar_loc.Iceland.json"}, - {"name":"solar_loc.Kauai.json","url":"solar_loc.Kauai.json"}, + {"name":"solar_loc.Reykjavik.json","url":"solar_loc.Reykjavik.json"}, + {"name":"solar_loc.Honolulu.json","url":"solar_loc.Honolulu.json"}, {"name":"solar_loc.Tokyo.json","url":"solar_loc.Tokyo.json"}, - {"name":"solar_loc.local.json","url":"solar_loc.local.json"}, {"name":"solar_locations.json","url":"solar_locations.json"} ] }, diff --git a/apps/solarclock/solar_clock.js b/apps/solarclock/solar_clock.js index 43a4f564b..279f7f664 100644 --- a/apps/solarclock/solar_clock.js +++ b/apps/solarclock/solar_clock.js @@ -199,15 +199,18 @@ function write_GPS_status(){ } const TWILIGHT_X_COORD = 200; +const NO_TIME = "--:--"; var twilight_times_requires_update = true; function write_twilight_times(){ if(!twilight_times_requires_update) return; - var twilight_msg=[]; + var twilight_msg; if(day_info != null) { twilight_msg = [format_time(day_info.sunrise_date), format_time(day_info.sunset_date)]; + } else { + twilight_msg = [NO_TIME,NO_TIME]; } g.setColor(screen_info.screen_bg_color[0],screen_info.screen_bg_color[1],screen_info.screen_bg_color[2]); g.fillRect(TWILIGHT_X_COORD,INFO_PANEL_LINE_Y1,240,INFO_PANEL_LINE_Y2 + 13); diff --git a/apps/solarclock/solar_loc.local.json b/apps/solarclock/solar_loc.local.json deleted file mode 100644 index c1b2c7d33..000000000 --- a/apps/solarclock/solar_loc.local.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "coordinates": [-0.12574, 51.50853] -} \ No newline at end of file diff --git a/apps/solarclock/solar_location.js b/apps/solarclock/solar_location.js index 2af73746d..dbe5a5cbe 100644 --- a/apps/solarclock/solar_location.js +++ b/apps/solarclock/solar_location.js @@ -1,4 +1,5 @@ const storage = require("Storage"); +const DateUtils = require("solar_date_utils.js"); class LocationManager { constructor(locations) { this.idx=0; @@ -10,12 +11,26 @@ class LocationManager { this.location_info = null; } init(){ - this.location_info = storage.readJSON("solar_loc." + this.getName() + ".json"); - if(this.isGPSLocation() && !this.gps_queried) { - console.log("updating local location"); - this._gpsUpdate(); - this.gps_queried = true; - } + 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;