Add menu for setting timezone
This commit is contained in:
parent
15838abd5a
commit
a3aaacf5e7
4 changed files with 66 additions and 22 deletions
18
src/Menu.cpp
18
src/Menu.cpp
|
@ -76,6 +76,7 @@ void Menu::HandleButtonPress(uint64_t buttonMask)
|
|||
|
||||
m_currentPage = m_pages[m_currentPage].menuItems[m_currentMenuItem].pageNum;
|
||||
m_currentMenuItem = 0;
|
||||
m_numMenuItemsinCurrentPage = m_pages[m_currentPage].menuItems.size();
|
||||
|
||||
Redraw(false);
|
||||
|
||||
|
@ -85,6 +86,7 @@ void Menu::HandleButtonPress(uint64_t buttonMask)
|
|||
if (buttonMask & BACK_BTN_MASK) {
|
||||
m_currentPage = m_pages[m_currentPage].backPageNum;
|
||||
m_currentMenuItem = 0;
|
||||
m_numMenuItemsinCurrentPage = m_pages[m_currentPage].menuItems.size();
|
||||
|
||||
Redraw(false);
|
||||
return;
|
||||
|
@ -93,20 +95,6 @@ void Menu::HandleButtonPress(uint64_t buttonMask)
|
|||
|
||||
void Menu::SetPages(const std::vector<MenuPage> & pages)
|
||||
{
|
||||
// If the number of pages has changed, reset the current page and menu item.
|
||||
if (pages.size() != m_numPages) {
|
||||
Serial.println("Resetting current page");
|
||||
m_currentPage = 0;
|
||||
m_currentMenuItem = 0;
|
||||
}
|
||||
|
||||
// If the number of menu items has changed, reset the current menu item.
|
||||
if (pages.size() > 0 && pages[m_currentMenuItem].menuItems.size() != m_numMenuItemsinCurrentPage) {
|
||||
Serial.println("Resetting current menu item");
|
||||
m_currentMenuItem = 0;
|
||||
m_numMenuItemsinCurrentPage = pages[m_currentPage].menuItems.size();
|
||||
}
|
||||
|
||||
m_pages = pages;
|
||||
m_numPages = pages.size();
|
||||
}
|
||||
|
@ -179,7 +167,7 @@ void Menu::Redraw(bool partialRefresh)
|
|||
for (uint8_t i = 0; i < m_numMenuItemsinCurrentPage; i++) {
|
||||
int16_t x, y;
|
||||
uint16_t w, h;
|
||||
m_display->getTextBounds(m_pages[m_currentPage].menuItems[m_currentMenuItem].title.c_str(), 5, top, &x, &y, &w, &h);
|
||||
m_display->getTextBounds(m_pages[m_currentPage].menuItems[i].title.c_str(), 5, top, &x, &y, &w, &h);
|
||||
|
||||
if (i == m_currentMenuItem) {
|
||||
m_display->fillRect(5, top, m_display->width() - 15, h + 6, GxEPD_BLACK);
|
||||
|
|
|
@ -4,16 +4,21 @@
|
|||
|
||||
RTC_DATA_ATTR bool WatchFace::m_menuSetup = false;
|
||||
RTC_DATA_ATTR bool WatchFace::m_inMenu = false;
|
||||
RTC_DATA_ATTR int WatchFace::m_tzOffset = TZ_OFFSET;
|
||||
Menu WatchFace::m_menu;
|
||||
|
||||
void WatchFace::Setup() // Called after hardware is set up
|
||||
{
|
||||
if (!m_menuSetup) {
|
||||
m_menuSetup = true;
|
||||
m_menu.Init(m_display);
|
||||
}
|
||||
|
||||
SetupVolatileMenuStuff();
|
||||
|
||||
if (!m_menuSetup) {
|
||||
m_menu.Reset();
|
||||
m_menuSetup = true;
|
||||
}
|
||||
}
|
||||
|
||||
void WatchFace::HandleButtonPress(uint64_t buttonMask)
|
||||
|
@ -44,7 +49,7 @@ void WatchFace::DrawWatchFace(bool partialRefresh)
|
|||
DrawBatteryIcon();
|
||||
|
||||
tmElements_t currentTime;
|
||||
m_RTC.read(currentTime, TZ_OFFSET);
|
||||
m_RTC.read(currentTime, m_tzOffset);
|
||||
SevenSegment sevenSegment(30, 60, 6, 5, 5);
|
||||
|
||||
if (currentTime.Hour < 10) {
|
||||
|
@ -99,6 +104,11 @@ void WatchFace::SetupVolatileMenuStuff()
|
|||
nullptr, // callback
|
||||
1 // pageNum
|
||||
},
|
||||
{
|
||||
"Set TZ", // title
|
||||
nullptr, // callback
|
||||
2 // pageNum
|
||||
},
|
||||
{
|
||||
"Back", // title
|
||||
nullptr, // callback
|
||||
|
@ -124,6 +134,39 @@ void WatchFace::SetupVolatileMenuStuff()
|
|||
}
|
||||
},
|
||||
},
|
||||
{
|
||||
0, // backPageNum
|
||||
"TIMEZONE", // title
|
||||
ALIGNMENT_CENTER, // titleAlignment
|
||||
"", // body
|
||||
{ // Menu items
|
||||
{
|
||||
"+0", // title
|
||||
std::bind(&WatchFace::MenuTimeZoneSelected, this, 0), // callback
|
||||
0 // pageNum
|
||||
},
|
||||
{
|
||||
"+1", // title
|
||||
std::bind(&WatchFace::MenuTimeZoneSelected, this, 3600), // callback
|
||||
0 // pageNum
|
||||
},
|
||||
{
|
||||
"+2", // title
|
||||
std::bind(&WatchFace::MenuTimeZoneSelected, this, 7200), // callback
|
||||
0 // pageNum
|
||||
},
|
||||
{
|
||||
"+3", // title
|
||||
std::bind(&WatchFace::MenuTimeZoneSelected, this, 10800), // callback
|
||||
0 // pageNum
|
||||
},
|
||||
{
|
||||
"Back", // title
|
||||
nullptr, // callback
|
||||
0 // pageNum
|
||||
}
|
||||
},
|
||||
}
|
||||
};
|
||||
|
||||
m_menu.SetPages(menuPages);
|
||||
|
@ -150,3 +193,14 @@ void WatchFace::MenuNTPSyncSelected()
|
|||
DrawWatchFace(false);
|
||||
}
|
||||
}
|
||||
|
||||
void WatchFace::MenuTimeZoneSelected(int tzOffset)
|
||||
{
|
||||
m_tzOffset = tzOffset;
|
||||
|
||||
if (m_inMenu) {
|
||||
m_inMenu = false;
|
||||
m_menu.Reset();
|
||||
DrawWatchFace(false);
|
||||
}
|
||||
}
|
|
@ -14,9 +14,11 @@ private:
|
|||
RTC_DATA_ATTR static bool m_menuSetup;
|
||||
RTC_DATA_ATTR static bool m_inMenu;
|
||||
RTC_DATA_ATTR static Menu m_menu;
|
||||
RTC_DATA_ATTR static int m_tzOffset;
|
||||
|
||||
void SetupVolatileMenuStuff();
|
||||
void DrawBatteryIcon();
|
||||
void MenuExited();
|
||||
void MenuNTPSyncSelected();
|
||||
void MenuTimeZoneSelected(int tzOffset);
|
||||
};
|
|
@ -65,15 +65,15 @@ void Watchy::DeepSleep()
|
|||
// Set GPIOs 0-39 to input to avoid power leaking out
|
||||
const uint64_t ignore = 0b11110001000000110000100111000010; // Ignore some GPIOs due to resets
|
||||
for (int i = 0; i < GPIO_NUM_MAX; i++) {
|
||||
if ((ignore >> i) & 0b1)
|
||||
if ((ignore >> i) & 0b1) {
|
||||
continue;
|
||||
}
|
||||
pinMode(i, INPUT);
|
||||
}
|
||||
esp_sleep_enable_ext0_wakeup((gpio_num_t)RTC_INT_PIN,
|
||||
0); // enable deep sleep wake on RTC interrupt
|
||||
esp_sleep_enable_ext0_wakeup((gpio_num_t)RTC_INT_PIN, 0); // enable deep sleep wake on RTC interrupt
|
||||
esp_sleep_enable_ext1_wakeup(
|
||||
BTN_PIN_MASK,
|
||||
ESP_EXT1_WAKEUP_ANY_HIGH); // enable deep sleep wake on button press
|
||||
ESP_EXT1_WAKEUP_ANY_HIGH);
|
||||
esp_deep_sleep_start();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue