diff --git a/apps/solarclock/solar_clock.js b/apps/solarclock/solar_clock.js index 3ab05cee2..8ba042a23 100644 --- a/apps/solarclock/solar_clock.js +++ b/apps/solarclock/solar_clock.js @@ -379,18 +379,36 @@ function log_memory_used() { ); } +var button1pressStart = null; function button1pressed(){ - console.log("button 1 pressed"); - time_offset = 0; - clear_sun(); - day_info = null; - draw_clock(); + 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"); - time_offset = 0; - location.nextLocation(); +function button3pressed() { + console.log("button 3 pressed"); + time_offset = 0; + location.nextLocation(); } function button4pressed(){ @@ -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"}); \ No newline at end of file diff --git a/apps/solarclock/solar_location.js b/apps/solarclock/solar_location.js index 8d2d1a7fc..3384d14d1 100644 --- a/apps/solarclock/solar_location.js +++ b/apps/solarclock/solar_location.js @@ -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);}