Skip to content

Commit 5f248fc

Browse files
committedAug 17, 2021
initialize time and location on reset
1 parent 989693e commit 5f248fc

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed
 

‎src/Screens/main.cpp

+19-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
#include "BuzzScreen.h"
22
#include "CarouselScreen.h"
3-
#include "OptimaLTStd22pt7b.h"
3+
#include "GetLocation.h"
44
#include "GetWeatherScreen.h"
55
#include "IconScreen.h"
66
#include "ImageScreen.h"
77
#include "MenuScreen.h"
8+
#include "OptimaLTStd22pt7b.h"
89
#include "SetLocationScreen.h"
910
#include "SetTimeScreen.h"
1011
#include "SetupWifiScreen.h"
@@ -13,13 +14,17 @@
1314
#include "ShowOrientationScreen.h"
1415
#include "ShowStepsScreen.h"
1516
#include "ShowWifiScreen.h"
17+
#include "SyncTime.h"
1618
#include "SyncTimeScreen.h"
1719
#include "TimeScreen.h"
1820
#include "UpdateFWScreen.h"
1921
#include "Watchy.h"
22+
#include "WatchyErrors.h"
2023
#include "WeatherScreen.h"
2124
#include "icons.h"
2225

26+
#include <time.h>
27+
2328
SetTimeScreen setTimeScreen;
2429
SetupWifiScreen setupWifiScreen;
2530
UpdateFWScreen updateFWScreen;
@@ -66,10 +71,20 @@ CarouselScreen carousel(carouselItems,
6671
sizeof(carouselItems) / sizeof(carouselItems[0]));
6772

6873
void setup() {
69-
#ifdef DEBUG
70-
Serial.begin(115200);
71-
#endif
7274
LOGD(); // fail if debugging macros not defined
75+
76+
// initializing time and location can be a little tricky, because the
77+
// calls can fail for a number of reasons, but you don't want to just
78+
// keep trying because you can't know if the error is transient or
79+
// persistent. So whenever we wake up, try to sync the time and location
80+
// if they haven't ever been synced. If there is a persistent failure
81+
// this can drain your battery...
82+
if (Watchy_SyncTime::lastSyncTimeTS == 0) {
83+
Watchy_SyncTime::syncTime(Watchy_GetLocation::currentLocation.timezone);
84+
}
85+
if (Watchy_GetLocation::lastGetLocationTS == 0) {
86+
Watchy_GetLocation::getLocation();
87+
}
7388
if (Watchy::screen == nullptr) { Watchy::screen = &carousel; }
7489
Watchy::init();
7590
}

0 commit comments

Comments
 (0)
Please sign in to comment.