mirror of https://github.com/sqfmi/Watchy.git
Added Moon Phase menu app.
parent
c515c75811
commit
0422175d12
|
@ -27,6 +27,7 @@ RTC_DATA_ATTR bool USB_PLUGGED_IN = false;
|
||||||
RTC_DATA_ATTR tmElements_t bootTime;
|
RTC_DATA_ATTR tmElements_t bootTime;
|
||||||
RTC_DATA_ATTR uint32_t lastIPAddress;
|
RTC_DATA_ATTR uint32_t lastIPAddress;
|
||||||
RTC_DATA_ATTR char lastSSID[30];
|
RTC_DATA_ATTR char lastSSID[30];
|
||||||
|
RTC_DATA_ATTR MoonPhase mp;
|
||||||
|
|
||||||
void Watchy::init(String datetime) {
|
void Watchy::init(String datetime) {
|
||||||
esp_sleep_wakeup_cause_t wakeup_reason;
|
esp_sleep_wakeup_cause_t wakeup_reason;
|
||||||
|
@ -39,7 +40,7 @@ void Watchy::init(String datetime) {
|
||||||
RTC.init();
|
RTC.init();
|
||||||
// Init the display since is almost sure we will use it
|
// Init the display since is almost sure we will use it
|
||||||
display.epd2.initWatchy();
|
display.epd2.initWatchy();
|
||||||
|
mp = MoonPhase();
|
||||||
switch (wakeup_reason) {
|
switch (wakeup_reason) {
|
||||||
#ifdef ARDUINO_ESP32S3_DEV
|
#ifdef ARDUINO_ESP32S3_DEV
|
||||||
case ESP_SLEEP_WAKEUP_TIMER: // RTC Alarm
|
case ESP_SLEEP_WAKEUP_TIMER: // RTC Alarm
|
||||||
|
@ -97,6 +98,9 @@ void Watchy::init(String datetime) {
|
||||||
esp_sleep_disable_wakeup_source(ESP_SLEEP_WAKEUP_ALL);
|
esp_sleep_disable_wakeup_source(ESP_SLEEP_WAKEUP_ALL);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
time_t epoch = makeTime(currentTime);
|
||||||
|
mp.calculate(epoch);
|
||||||
deepSleep();
|
deepSleep();
|
||||||
}
|
}
|
||||||
void Watchy::deepSleep() {
|
void Watchy::deepSleep() {
|
||||||
|
@ -167,6 +171,8 @@ void Watchy::handleButtonPress() {
|
||||||
case 6:
|
case 6:
|
||||||
showSyncNTP();
|
showSyncNTP();
|
||||||
break;
|
break;
|
||||||
|
case 7:
|
||||||
|
showMoonPhase();
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -249,6 +255,8 @@ void Watchy::handleButtonPress() {
|
||||||
case 6:
|
case 6:
|
||||||
showSyncNTP();
|
showSyncNTP();
|
||||||
break;
|
break;
|
||||||
|
case 7:
|
||||||
|
showMoonPhase();
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -302,9 +310,9 @@ void Watchy::showMenu(byte menuIndex, bool partialRefresh) {
|
||||||
const char *menuItems[] = {
|
const char *menuItems[] = {
|
||||||
"About Watchy", "Vibrate Motor", "Show Accelerometer",
|
"About Watchy", "Vibrate Motor", "Show Accelerometer",
|
||||||
"Set Time", "Setup WiFi", "Update Firmware",
|
"Set Time", "Setup WiFi", "Update Firmware",
|
||||||
"Sync NTP"};
|
"Sync NTP", "Moon Phase"};
|
||||||
for (int i = 0; i < MENU_LENGTH; i++) {
|
for (int i = 0; i < MENU_LENGTH; i++) {
|
||||||
yPos = MENU_HEIGHT + (MENU_HEIGHT * i);
|
yPos = MENU_HEIGHT/2 + (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);
|
||||||
|
@ -335,9 +343,9 @@ void Watchy::showFastMenu(byte menuIndex) {
|
||||||
const char *menuItems[] = {
|
const char *menuItems[] = {
|
||||||
"About Watchy", "Vibrate Motor", "Show Accelerometer",
|
"About Watchy", "Vibrate Motor", "Show Accelerometer",
|
||||||
"Set Time", "Setup WiFi", "Update Firmware",
|
"Set Time", "Setup WiFi", "Update Firmware",
|
||||||
"Sync NTP"};
|
"Sync NTP", "Moon Phase"};
|
||||||
for (int i = 0; i < MENU_LENGTH; i++) {
|
for (int i = 0; i < MENU_LENGTH; i++) {
|
||||||
yPos = MENU_HEIGHT + (MENU_HEIGHT * i);
|
yPos = MENU_HEIGHT/2 + (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);
|
||||||
|
@ -404,6 +412,57 @@ void Watchy::showAbout() {
|
||||||
guiState = APP_STATE;
|
guiState = APP_STATE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Watchy::showMoonPhase() {
|
||||||
|
|
||||||
|
RTC.read(currentTime);
|
||||||
|
time_t epoch = makeTime(currentTime);
|
||||||
|
mp.calculate(epoch);
|
||||||
|
|
||||||
|
display.setFullWindow();
|
||||||
|
display.fillScreen(GxEPD_BLACK);
|
||||||
|
display.setFont(&FreeMonoBold9pt7b);
|
||||||
|
display.setTextColor(GxEPD_WHITE);
|
||||||
|
display.setCursor(0, 10);
|
||||||
|
|
||||||
|
display.setCursor(0, MENU_HEIGHT);
|
||||||
|
|
||||||
|
display.print("Date: ");
|
||||||
|
display.println(mp.jDate);
|
||||||
|
|
||||||
|
display.print("Phase: ");
|
||||||
|
display.println(mp.phase);
|
||||||
|
|
||||||
|
display.print("Age: ");
|
||||||
|
display.print(mp.age);
|
||||||
|
display.println(" days");
|
||||||
|
|
||||||
|
display.print("Visibility: ");
|
||||||
|
display.print(mp.fraction);
|
||||||
|
display.println("%");
|
||||||
|
|
||||||
|
display.print("Distance: ");
|
||||||
|
display.print(mp.distance);
|
||||||
|
display.println(" er");
|
||||||
|
|
||||||
|
display.print("Latitude: ");
|
||||||
|
display.print(mp.latitude);
|
||||||
|
display.println("°");
|
||||||
|
|
||||||
|
display.print("Longitude: ");
|
||||||
|
display.print(mp.longitude);
|
||||||
|
display.println("°");
|
||||||
|
|
||||||
|
display.print("Ph.: ");
|
||||||
|
display.println(mp.phaseName);
|
||||||
|
|
||||||
|
display.print("Zodiac: ");
|
||||||
|
display.println(mp.zodiacName);
|
||||||
|
|
||||||
|
display.display(true); // full refresh
|
||||||
|
|
||||||
|
guiState = APP_STATE;
|
||||||
|
}
|
||||||
|
|
||||||
void Watchy::showBuzz() {
|
void Watchy::showBuzz() {
|
||||||
display.setFullWindow();
|
display.setFullWindow();
|
||||||
display.fillScreen(GxEPD_BLACK);
|
display.fillScreen(GxEPD_BLACK);
|
||||||
|
@ -443,7 +502,7 @@ void Watchy::setTime() {
|
||||||
int8_t hour = currentTime.Hour;
|
int8_t hour = currentTime.Hour;
|
||||||
int8_t day = currentTime.Day;
|
int8_t day = currentTime.Day;
|
||||||
int8_t month = currentTime.Month;
|
int8_t month = currentTime.Month;
|
||||||
int8_t year = currentTime.Year; //tmYearToY2k(currentTime.Year);
|
int8_t year = tmYearToY2k(currentTime.Year);
|
||||||
#endif
|
#endif
|
||||||
int8_t gmt = gmtOffset / 3600;
|
int8_t gmt = gmtOffset / 3600;
|
||||||
|
|
||||||
|
@ -580,7 +639,7 @@ void Watchy::setTime() {
|
||||||
if (setIndex == SET_YEAR) { // blink minute digits
|
if (setIndex == SET_YEAR) { // blink minute digits
|
||||||
display.setTextColor(blink ? GxEPD_WHITE : GxEPD_BLACK);
|
display.setTextColor(blink ? GxEPD_WHITE : GxEPD_BLACK);
|
||||||
}
|
}
|
||||||
display.print(year);
|
display.print(1970 + year);
|
||||||
|
|
||||||
display.setTextColor(GxEPD_WHITE);
|
display.setTextColor(GxEPD_WHITE);
|
||||||
display.print("/");
|
display.print("/");
|
||||||
|
@ -613,7 +672,7 @@ void Watchy::setTime() {
|
||||||
#ifdef ARDUINO_ESP32S3_DEV
|
#ifdef ARDUINO_ESP32S3_DEV
|
||||||
tm.Year = year;
|
tm.Year = year;
|
||||||
#else
|
#else
|
||||||
tm.Year = year; //y2kYearToTm(year);
|
tm.Year = y2kYearToTm(year);
|
||||||
#endif
|
#endif
|
||||||
tm.Hour = hour;
|
tm.Hour = hour;
|
||||||
tm.Minute = minute;
|
tm.Minute = minute;
|
||||||
|
@ -1200,5 +1259,9 @@ bool Watchy::syncNTP(long gmt, String ntpServer) {
|
||||||
tmElements_t tm;
|
tmElements_t tm;
|
||||||
breakTime((time_t)timeClient.getEpochTime(), tm);
|
breakTime((time_t)timeClient.getEpochTime(), tm);
|
||||||
RTC.set(tm);
|
RTC.set(tm);
|
||||||
|
//Update also moon calendar.
|
||||||
|
RTC.read(currentTime);
|
||||||
|
time_t epoch = makeTime(currentTime);
|
||||||
|
mp.calculate(epoch);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "esp_chip_info.h"
|
#include "esp_chip_info.h"
|
||||||
#include "TimezonesGMT.h"
|
#include "TimezonesGMT.h"
|
||||||
|
#include "MoonPhase.h"
|
||||||
#ifdef ARDUINO_ESP32S3_DEV
|
#ifdef ARDUINO_ESP32S3_DEV
|
||||||
#include "Watchy32KRTC.h"
|
#include "Watchy32KRTC.h"
|
||||||
#include "soc/rtc.h"
|
#include "soc/rtc.h"
|
||||||
|
@ -86,6 +87,7 @@ public:
|
||||||
void showMenu(byte menuIndex, bool partialRefresh);
|
void showMenu(byte menuIndex, bool partialRefresh);
|
||||||
void showFastMenu(byte menuIndex);
|
void showFastMenu(byte menuIndex);
|
||||||
void showAbout();
|
void showAbout();
|
||||||
|
void showMoonPhase();
|
||||||
void showBuzz();
|
void showBuzz();
|
||||||
void showAccelerometer();
|
void showAccelerometer();
|
||||||
void showUpdateFW();
|
void showUpdateFW();
|
||||||
|
|
|
@ -99,8 +99,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 25
|
#define MENU_HEIGHT 24
|
||||||
#define MENU_LENGTH 7
|
#define MENU_LENGTH 8
|
||||||
// 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