mirror of https://github.com/sqfmi/Watchy.git
add NTP to menu
parent
12915a48e6
commit
a454e65ba2
|
@ -91,6 +91,9 @@ void Watchy::handleButtonPress(){
|
||||||
case 5:
|
case 5:
|
||||||
showUpdateFW();
|
showUpdateFW();
|
||||||
break;
|
break;
|
||||||
|
case 6:
|
||||||
|
syncNTP();
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -170,6 +173,9 @@ void Watchy::handleButtonPress(){
|
||||||
case 5:
|
case 5:
|
||||||
showUpdateFW();
|
showUpdateFW();
|
||||||
break;
|
break;
|
||||||
|
case 6:
|
||||||
|
syncNTP();
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -219,9 +225,9 @@ void Watchy::showMenu(byte menuIndex, bool partialRefresh){
|
||||||
uint16_t w, h;
|
uint16_t w, h;
|
||||||
int16_t yPos;
|
int16_t yPos;
|
||||||
|
|
||||||
const char *menuItems[] = {"Check Battery", "Vibrate Motor", "Show Accelerometer", "Set Time", "Setup WiFi", "Update Firmware"};
|
const char *menuItems[] = {"Check Battery", "Vibrate Motor", "Show Accelerometer", "Set Time", "Setup WiFi", "Update Firmware", "Sync NTP"};
|
||||||
for(int i=0; i<MENU_LENGTH; i++){
|
for(int i=0; i<MENU_LENGTH; i++){
|
||||||
yPos = 30+(MENU_HEIGHT*i);
|
yPos = MENU_HEIGHT+(MENU_HEIGHT*i);
|
||||||
display.setCursor(0, yPos);
|
display.setCursor(0, yPos);
|
||||||
if(i == menuIndex){
|
if(i == menuIndex){
|
||||||
display.getTextBounds(menuItems[i], 0, yPos, &x1, &y1, &w, &h);
|
display.getTextBounds(menuItems[i], 0, yPos, &x1, &y1, &w, &h);
|
||||||
|
@ -248,9 +254,9 @@ void Watchy::showFastMenu(byte menuIndex){
|
||||||
uint16_t w, h;
|
uint16_t w, h;
|
||||||
int16_t yPos;
|
int16_t yPos;
|
||||||
|
|
||||||
const char *menuItems[] = {"Check Battery", "Vibrate Motor", "Show Accelerometer", "Set Time", "Setup WiFi", "Update Firmware"};
|
const char *menuItems[] = {"Check Battery", "Vibrate Motor", "Show Accelerometer", "Set Time", "Setup WiFi", "Update Firmware", "Sync NTP"};
|
||||||
for(int i=0; i<MENU_LENGTH; i++){
|
for(int i=0; i<MENU_LENGTH; i++){
|
||||||
yPos = 30+(MENU_HEIGHT*i);
|
yPos = MENU_HEIGHT+(MENU_HEIGHT*i);
|
||||||
display.setCursor(0, yPos);
|
display.setCursor(0, yPos);
|
||||||
if(i == menuIndex){
|
if(i == menuIndex){
|
||||||
display.getTextBounds(menuItems[i], 0, yPos, &x1, &y1, &w, &h);
|
display.getTextBounds(menuItems[i], 0, yPos, &x1, &y1, &w, &h);
|
||||||
|
@ -557,7 +563,6 @@ void Watchy::drawWatchFace(){
|
||||||
weatherData Watchy::getWeatherData(){
|
weatherData Watchy::getWeatherData(){
|
||||||
if(weatherIntervalCounter >= WEATHER_UPDATE_INTERVAL){ //only update if WEATHER_UPDATE_INTERVAL has elapsed i.e. 30 minutes
|
if(weatherIntervalCounter >= WEATHER_UPDATE_INTERVAL){ //only update if WEATHER_UPDATE_INTERVAL has elapsed i.e. 30 minutes
|
||||||
if(connectWiFi()){
|
if(connectWiFi()){
|
||||||
RTC.syncNtpTime(); //Sync NTP
|
|
||||||
HTTPClient http; //Use Weather API for live data if WiFi is connected
|
HTTPClient http; //Use Weather API for live data if WiFi is connected
|
||||||
http.setConnectTimeout(3000);//3 second max timeout
|
http.setConnectTimeout(3000);//3 second max timeout
|
||||||
String weatherQueryURL = String(OPENWEATHERMAP_URL) + String(CITY_NAME) + String(",") + String(COUNTRY_CODE) + String("&units=") + String(TEMP_UNIT) + String("&appid=") + String(OPENWEATHERMAP_APIKEY);
|
String weatherQueryURL = String(OPENWEATHERMAP_URL) + String(CITY_NAME) + String(",") + String(COUNTRY_CODE) + String("&units=") + String(TEMP_UNIT) + String("&appid=") + String(OPENWEATHERMAP_APIKEY);
|
||||||
|
@ -729,7 +734,6 @@ void Watchy::setupWifi(){
|
||||||
display.println("Setup failed &");
|
display.println("Setup failed &");
|
||||||
display.println("timed out!");
|
display.println("timed out!");
|
||||||
}else{
|
}else{
|
||||||
RTC.syncNtpTime(); //sync ntp
|
|
||||||
display.println("Connected to");
|
display.println("Connected to");
|
||||||
display.println(WiFi.SSID());
|
display.println(WiFi.SSID());
|
||||||
}
|
}
|
||||||
|
@ -877,6 +881,28 @@ void Watchy::updateFWBegin(){
|
||||||
showMenu(menuIndex, false);
|
showMenu(menuIndex, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Watchy::syncNTP(){
|
||||||
|
display.setFullWindow();
|
||||||
|
display.fillScreen(GxEPD_BLACK);
|
||||||
|
display.setFont(&FreeMonoBold9pt7b);
|
||||||
|
display.setTextColor(GxEPD_WHITE);
|
||||||
|
display.setCursor(0, 30);
|
||||||
|
display.println("Syncing NTP... ");
|
||||||
|
display.display(false); //full refresh
|
||||||
|
if(connectWiFi()){
|
||||||
|
if(RTC.syncNtpTime()){
|
||||||
|
display.println("NTP Sync Success");
|
||||||
|
}else{
|
||||||
|
display.println("NTP Sync Failed");
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
display.println("WiFi Not Configured");
|
||||||
|
}
|
||||||
|
display.display(true); //full refresh
|
||||||
|
delay(1000);
|
||||||
|
showMenu(menuIndex, false);
|
||||||
|
}
|
||||||
|
|
||||||
// time_t compileTime()
|
// time_t compileTime()
|
||||||
// {
|
// {
|
||||||
// const time_t FUDGE(10); //fudge factor to allow for upload time, etc. (seconds, YMMV)
|
// const time_t FUDGE(10); //fudge factor to allow for upload time, etc. (seconds, YMMV)
|
||||||
|
|
|
@ -40,6 +40,7 @@ class Watchy {
|
||||||
void showAccelerometer();
|
void showAccelerometer();
|
||||||
void showUpdateFW();
|
void showUpdateFW();
|
||||||
void setTime();
|
void setTime();
|
||||||
|
void syncNTP();
|
||||||
void setupWifi();
|
void setupWifi();
|
||||||
bool connectWiFi();
|
bool connectWiFi();
|
||||||
weatherData getWeatherData();
|
weatherData getWeatherData();
|
||||||
|
|
|
@ -115,11 +115,11 @@ void WatchyRTC::_PCFConfig(String datetime){ //String datetime is YYYY:MM:DD:HH:
|
||||||
clearAlarm();
|
clearAlarm();
|
||||||
}
|
}
|
||||||
|
|
||||||
void WatchyRTC::syncNtpTime(){ //NTP sync - call after connecting to WiFi and remember to turn it back off
|
bool WatchyRTC::syncNtpTime(){ //NTP sync - call after connecting to WiFi and remember to turn it back off
|
||||||
configTime(GMT_OFFSET_SEC, DST_OFFSET_SEC, NTP_SERVER);
|
configTime(GMT_OFFSET_SEC, DST_OFFSET_SEC, NTP_SERVER);
|
||||||
struct tm timeinfo;
|
struct tm timeinfo;
|
||||||
if(!getLocalTime(&timeinfo)){
|
if(!getLocalTime(&timeinfo)){
|
||||||
return; //NTP sync failed
|
return false; //NTP sync failed
|
||||||
}
|
}
|
||||||
/****************************************************
|
/****************************************************
|
||||||
struct tm
|
struct tm
|
||||||
|
@ -143,6 +143,7 @@ void WatchyRTC::syncNtpTime(){ //NTP sync - call after connecting to WiFi and re
|
||||||
tm.Minute = timeinfo.tm_min;
|
tm.Minute = timeinfo.tm_min;
|
||||||
tm.Second = timeinfo.tm_sec;
|
tm.Second = timeinfo.tm_sec;
|
||||||
set(tm);
|
set(tm);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
String WatchyRTC::_getValue(String data, char separator, int index)
|
String WatchyRTC::_getValue(String data, char separator, int index)
|
||||||
|
|
|
@ -25,7 +25,7 @@ class WatchyRTC {
|
||||||
void clearAlarm();
|
void clearAlarm();
|
||||||
void read(tmElements_t &tm);
|
void read(tmElements_t &tm);
|
||||||
void set(tmElements_t tm);
|
void set(tmElements_t tm);
|
||||||
void syncNtpTime();
|
bool syncNtpTime();
|
||||||
uint8_t temperature();
|
uint8_t temperature();
|
||||||
private:
|
private:
|
||||||
void _DSConfig(String datetime);
|
void _DSConfig(String datetime);
|
||||||
|
|
|
@ -40,8 +40,8 @@
|
||||||
#define MAIN_MENU_STATE 0
|
#define MAIN_MENU_STATE 0
|
||||||
#define APP_STATE 1
|
#define APP_STATE 1
|
||||||
#define FW_UPDATE_STATE 2
|
#define FW_UPDATE_STATE 2
|
||||||
#define MENU_HEIGHT 30
|
#define MENU_HEIGHT 25
|
||||||
#define MENU_LENGTH 6
|
#define MENU_LENGTH 7
|
||||||
//set time
|
//set time
|
||||||
#define SET_HOUR 0
|
#define SET_HOUR 0
|
||||||
#define SET_MINUTE 1
|
#define SET_MINUTE 1
|
||||||
|
|
Loading…
Reference in New Issue