2019-01-18 07:09:40 +00:00
|
|
|
/*
|
|
|
|
* This file is part of the "bluetoothheater" distribution
|
|
|
|
* (https://gitlab.com/mrjones.id.au/bluetoothheater)
|
|
|
|
*
|
2019-09-08 00:14:36 +00:00
|
|
|
* Copyright (C) 2019 Ray Jones <ray@mrjones.id.au>
|
2019-01-18 07:09:40 +00:00
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// CSetClockScreen
|
|
|
|
//
|
|
|
|
// This screen allows the real time clock to be adjusted
|
|
|
|
//
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#include "SetClockScreen.h"
|
|
|
|
#include "KeyPad.h"
|
|
|
|
#include "fonts/Arial.h"
|
|
|
|
#include "../RTC/Clock.h"
|
2019-06-15 23:09:29 +00:00
|
|
|
#include "../Utility/macros.h"
|
2019-09-08 00:14:36 +00:00
|
|
|
#include "../Utility/NVStorage.h"
|
2019-01-18 07:09:40 +00:00
|
|
|
|
|
|
|
|
2019-11-21 08:25:14 +00:00
|
|
|
CSetClockScreen::CSetClockScreen(C128x64_OLED& display, CScreenManager& mgr) : CUIEditScreen(display, mgr)
|
2019-02-28 08:56:13 +00:00
|
|
|
{
|
|
|
|
_initUI();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CSetClockScreen::onSelect()
|
|
|
|
{
|
2019-07-28 07:40:12 +00:00
|
|
|
CScreen::onSelect();
|
2019-02-28 08:56:13 +00:00
|
|
|
_initUI();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CSetClockScreen::_initUI()
|
2019-01-18 07:09:40 +00:00
|
|
|
{
|
2019-11-21 08:25:14 +00:00
|
|
|
CUIEditScreen::_initUI();
|
2019-01-18 07:09:40 +00:00
|
|
|
_nextT = millis();
|
2019-09-08 00:14:36 +00:00
|
|
|
_12hr = NVstore.getUserSettings().clock12hr;
|
2019-01-18 07:09:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CSetClockScreen::showTime(int)
|
|
|
|
{
|
|
|
|
// override and DO NOTHING!
|
|
|
|
}
|
|
|
|
|
2019-01-18 23:06:12 +00:00
|
|
|
bool
|
2019-01-18 07:09:40 +00:00
|
|
|
CSetClockScreen::show()
|
|
|
|
{
|
2019-11-21 08:25:14 +00:00
|
|
|
|
|
|
|
if(CUIEditScreen::show()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-01-18 07:09:40 +00:00
|
|
|
long deltaT = millis() - _nextT;
|
|
|
|
if(deltaT >= 0) {
|
|
|
|
_nextT += 1000;
|
|
|
|
|
2019-07-28 07:40:12 +00:00
|
|
|
CScreen::show();
|
|
|
|
_display.clearDisplay();
|
2019-01-18 07:09:40 +00:00
|
|
|
|
|
|
|
char str[16];
|
|
|
|
int xPos, yPos;
|
|
|
|
|
2019-07-28 07:40:12 +00:00
|
|
|
_showTitle("Set Clock");
|
2019-01-18 07:09:40 +00:00
|
|
|
|
|
|
|
const BTCDateTime& now = Clock.get();
|
|
|
|
if(_rowSel == 0) {
|
|
|
|
// update printable values
|
2019-09-08 00:14:36 +00:00
|
|
|
_working = now;
|
|
|
|
if(_12hr) {
|
|
|
|
if(_working.hour() < 12)
|
|
|
|
_12hr = 1;
|
|
|
|
else
|
|
|
|
_12hr = 2;
|
|
|
|
}
|
2019-01-18 07:09:40 +00:00
|
|
|
}
|
2019-01-18 20:15:02 +00:00
|
|
|
|
2019-11-21 08:25:14 +00:00
|
|
|
yPos = 20;
|
|
|
|
xPos = 6;
|
|
|
|
// date
|
|
|
|
if(_rowSel==0) {
|
|
|
|
xPos = 18;
|
|
|
|
_printMenuText(xPos, yPos, _working.dowStr());
|
|
|
|
xPos = 20;
|
|
|
|
}
|
|
|
|
|
|
|
|
sprintf(str, "%d", _working.day());
|
|
|
|
xPos += 20 + 12;
|
|
|
|
_printMenuText(xPos, yPos, str, _rowSel==1, eRightJustify);
|
|
|
|
xPos += 4;
|
|
|
|
_printMenuText(xPos, yPos, _working.monthStr(), _rowSel==2);
|
|
|
|
xPos += 22;
|
|
|
|
sprintf(str, "%d", _working.year());
|
|
|
|
_printMenuText(xPos, yPos, str, _rowSel==3);
|
|
|
|
// time
|
|
|
|
yPos = 32;
|
|
|
|
xPos = 8;
|
|
|
|
int hr = _working.hour();
|
|
|
|
if(_12hr) {
|
|
|
|
if(hr == 0)
|
|
|
|
hr = 12;
|
|
|
|
if(hr > 12)
|
|
|
|
hr -= 12;
|
2019-01-18 20:15:02 +00:00
|
|
|
}
|
2019-11-21 08:25:14 +00:00
|
|
|
sprintf(str, "%02d", hr);
|
|
|
|
_printMenuText(xPos, yPos, str, _rowSel==4);
|
|
|
|
xPos += 16;
|
|
|
|
_printMenuText(xPos, yPos, ":");
|
|
|
|
xPos += 8;
|
|
|
|
sprintf(str, "%02d", _working.minute());
|
|
|
|
_printMenuText(xPos, yPos, str, _rowSel==5);
|
|
|
|
xPos += 16;
|
|
|
|
_printMenuText(xPos, yPos, ":");
|
|
|
|
sprintf(str, "%02d", _working.second());
|
|
|
|
xPos += 8;
|
|
|
|
_printMenuText(xPos, yPos, str, _rowSel==6);
|
|
|
|
xPos += 20;
|
|
|
|
const char* annuc = "24hr";
|
|
|
|
switch(_12hr) {
|
|
|
|
case 1: annuc = "AM"; break;
|
|
|
|
case 2: annuc = "PM"; break;
|
|
|
|
}
|
|
|
|
_printMenuText(xPos, yPos, annuc, _rowSel == 7);
|
|
|
|
xPos += 28;
|
|
|
|
if(_rowSel>=1)
|
|
|
|
_printMenuText(_display.width()-border, yPos, "SET", _rowSel==8, eRightJustify);
|
2019-07-28 07:40:12 +00:00
|
|
|
|
2019-11-21 08:25:14 +00:00
|
|
|
// navigation line
|
|
|
|
xPos = _display.xCentre();
|
|
|
|
if(_rowSel == 0) {
|
|
|
|
yPos = 53;
|
|
|
|
_printMenuText(_display.width(), yPos, "\030Edit", false, eRightJustify);
|
|
|
|
_printMenuText(xPos, yPos, " Exit ", true, eCentreJustify);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
_display.drawFastHLine(0, 52, 128, WHITE);
|
|
|
|
_printMenuText(xPos, 56, "\033\032 Sel \030\031 Adj", false, eCentreJustify);
|
|
|
|
if(_rowSel == 8) {
|
|
|
|
_printMenuText(xPos, 56, "Save", false, eCentreJustify);
|
2019-03-17 07:10:01 +00:00
|
|
|
}
|
|
|
|
else {
|
2019-11-21 08:25:14 +00:00
|
|
|
_printMenuText(xPos, 56, "Abort", false, eCentreJustify);
|
2019-03-17 07:10:01 +00:00
|
|
|
}
|
|
|
|
}
|
2019-01-18 07:09:40 +00:00
|
|
|
}
|
2019-01-18 23:06:12 +00:00
|
|
|
return true;
|
2019-01-18 07:09:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-01-18 23:06:12 +00:00
|
|
|
bool
|
2019-01-18 07:09:40 +00:00
|
|
|
CSetClockScreen::keyHandler(uint8_t event)
|
|
|
|
{
|
|
|
|
|
|
|
|
if(event & keyPressed) {
|
|
|
|
// press CENTRE
|
|
|
|
if(event & key_Centre) {
|
|
|
|
if(_rowSel == 0) {
|
2019-03-15 21:43:44 +00:00
|
|
|
_ScreenManager.selectMenu(CScreenManager::RootMenuLoop); // exit, return to clock screen
|
2019-01-18 07:09:40 +00:00
|
|
|
}
|
|
|
|
else {
|
2019-09-08 00:14:36 +00:00
|
|
|
if(_rowSel == 8) { // set the RTC!
|
|
|
|
Clock.set(_working);
|
2019-11-21 08:25:14 +00:00
|
|
|
_enableStoringMessage();
|
2019-01-18 07:09:40 +00:00
|
|
|
}
|
2019-09-08 00:14:36 +00:00
|
|
|
// always save the 12/24hr selection on any OK
|
|
|
|
sUserSettings us = NVstore.getUserSettings();
|
|
|
|
us.clock12hr = _12hr ? 1 : 0;
|
|
|
|
NVstore.setUserSettings(us);
|
|
|
|
NVstore.save();
|
2019-01-18 07:09:40 +00:00
|
|
|
_rowSel = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// press LEFT
|
|
|
|
if(event & key_Left) {
|
|
|
|
if(_rowSel == 0) {
|
2019-03-15 21:43:44 +00:00
|
|
|
_ScreenManager.selectMenu(CScreenManager::RootMenuLoop); // exit, return to clock screen
|
2019-01-18 07:09:40 +00:00
|
|
|
}
|
|
|
|
else {
|
2019-03-17 07:10:01 +00:00
|
|
|
_rowSel--;
|
2019-09-08 00:14:36 +00:00
|
|
|
WRAPLOWERLIMIT(_rowSel, 1, 8);
|
2019-01-18 07:09:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// press RIGHT
|
|
|
|
if(event & key_Right) {
|
|
|
|
if(_rowSel == 0) {
|
2019-03-15 21:43:44 +00:00
|
|
|
_ScreenManager.selectMenu(CScreenManager::RootMenuLoop); // exit, return to clock screen
|
2019-01-18 07:09:40 +00:00
|
|
|
}
|
|
|
|
else {
|
2019-03-17 07:10:01 +00:00
|
|
|
_rowSel++;
|
2019-09-08 00:14:36 +00:00
|
|
|
WRAPUPPERLIMIT(_rowSel, 8, 1);
|
2019-01-18 07:09:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// press UP
|
|
|
|
if(event & key_Up) {
|
2019-04-18 11:02:39 +00:00
|
|
|
if(_rowSel == 0) {
|
2019-09-08 00:14:36 +00:00
|
|
|
_rowSel = 7;
|
2019-04-18 11:02:39 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
_adjTimeDate(+1);
|
|
|
|
}
|
2019-01-18 07:09:40 +00:00
|
|
|
}
|
|
|
|
// press DOWN
|
|
|
|
if(event & key_Down) {
|
|
|
|
if(_rowSel == 0) {
|
2019-03-15 21:43:44 +00:00
|
|
|
_ScreenManager.selectMenu(CScreenManager::RootMenuLoop); // exit, return to clock screen
|
2019-01-18 07:09:40 +00:00
|
|
|
} else {
|
2019-03-17 07:10:01 +00:00
|
|
|
_adjTimeDate(-1);
|
2019-01-18 07:09:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-03-17 07:10:01 +00:00
|
|
|
|
2019-01-18 07:09:40 +00:00
|
|
|
if(event & keyRepeat) {
|
2019-03-17 07:10:01 +00:00
|
|
|
if(_rowSel >= 1) {
|
2019-01-18 07:09:40 +00:00
|
|
|
// hold RIGHT
|
2019-03-17 07:10:01 +00:00
|
|
|
if(event & key_Up) {
|
2019-02-28 08:56:13 +00:00
|
|
|
_adjTimeDate(+1);
|
2019-01-18 07:09:40 +00:00
|
|
|
}
|
|
|
|
// hold LEFT
|
2019-03-17 07:10:01 +00:00
|
|
|
if(event & key_Down) {
|
2019-02-28 08:56:13 +00:00
|
|
|
_adjTimeDate(-1);
|
2019-01-18 07:09:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
_nextT = millis();
|
|
|
|
_ScreenManager.reqUpdate();
|
2019-01-18 23:06:12 +00:00
|
|
|
return true;
|
2019-01-18 07:09:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2019-02-28 08:56:13 +00:00
|
|
|
CSetClockScreen::_adjTimeDate(int dir)
|
2019-01-18 07:09:40 +00:00
|
|
|
{
|
|
|
|
switch(_rowSel) {
|
|
|
|
case 1:
|
2019-09-08 00:14:36 +00:00
|
|
|
_working.adjustDay(dir);
|
2019-01-18 07:09:40 +00:00
|
|
|
break;
|
|
|
|
case 2:
|
2019-09-08 00:14:36 +00:00
|
|
|
_working.adjustMonth(dir);
|
2019-01-18 07:09:40 +00:00
|
|
|
break;
|
|
|
|
case 3:
|
2019-09-08 00:14:36 +00:00
|
|
|
_working.adjustYear(dir);
|
2019-01-18 07:09:40 +00:00
|
|
|
break;
|
|
|
|
case 4:
|
2019-09-08 00:14:36 +00:00
|
|
|
_working.adjustHour(dir);
|
|
|
|
if(_12hr == 1 && _working.hour() >= 12)
|
|
|
|
_12hr = 2;
|
|
|
|
if(_12hr == 2 && _working.hour() < 12)
|
|
|
|
_12hr = 1;
|
2019-01-18 07:09:40 +00:00
|
|
|
break;
|
|
|
|
case 5:
|
2019-09-08 00:14:36 +00:00
|
|
|
_working.adjustMinute(dir);
|
2019-01-18 07:09:40 +00:00
|
|
|
break;
|
|
|
|
case 6:
|
2019-09-08 00:14:36 +00:00
|
|
|
_working.adjustSecond(dir);
|
|
|
|
break;
|
|
|
|
case 7:
|
|
|
|
DebugPort.printf("hr1=%d ", _working.hour());
|
|
|
|
_12hr += dir;
|
|
|
|
WRAPLIMITS(_12hr, 0, 2);
|
|
|
|
if(_12hr == 1 && _working.hour() >= 12)
|
|
|
|
_working.adjustHour12();
|
|
|
|
if(_12hr == 2 && _working.hour() < 12)
|
|
|
|
_working.adjustHour12();
|
|
|
|
DebugPort.printf("hr2=%d ", _working.hour());
|
|
|
|
DebugPort.printf("_12hr=%d\r\n", _12hr);
|
2019-01-18 07:09:40 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|