| 819 | } |
| 820 | |
| 821 | fetchTime() { |
| 822 | if (this.rtc.valid) |
| 823 | this.setTime(this.rtc.seconds); |
| 824 | |
| 825 | if (!this.connectionWasEstablished) |
| 826 | return; |
| 827 | |
| 828 | trace(`fetchTime\n`); |
| 829 | if (undefined !== this.upToDateTimer) { |
| 830 | Timer.schedule(this.upToDateTimer, 100, RESET_TIME_INTERVAL); |
| 831 | return; |
| 832 | } |
| 833 | |
| 834 | this.upToDateTimer = Timer.set(id => { |
| 835 | let hosts = Object.assign([], ntpHosts); |
| 836 | let sntp = new SNTP({host: hosts.shift()}, function(message, value) { |
| 837 | switch (message) { |
| 838 | case 1: // success! |
| 839 | this.clock.setTime(value, 1); |
| 840 | this.clock.display.showTime(this.clock.currentStyle); |
| 841 | global.needsReboot = 0; |
| 842 | break; |
| 843 | case -1: |
| 844 | if (hosts.length) |
| 845 | return hosts.shift(); |
| 846 | break; |
| 847 | } |
| 848 | }); |
| 849 | sntp.clock = this; |
| 850 | }, 100, RESET_TIME_INTERVAL); |
| 851 | } |
| 852 | |
| 853 | /* |
| 854 | buttonPressed() { |