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-07-28 07:40:12 +00:00
|
|
|
CSetClockScreen::CSetClockScreen(C128x64_OLED& display, CScreenManager& mgr) : CScreen(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
|
|
|
{
|
|
|
|
_rowSel = 0;
|
|
|
|
_nextT = millis();
|
2019-01-18 20:15:02 +00:00
|
|
|
_SaveTime = 0;
|
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()
|
|
|
|
{
|
|
|
|
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
|
|
|
|
|
|
|
if(_SaveTime) {
|
2019-07-27 23:07:29 +00:00
|
|
|
_showStoringMessage();
|
2019-01-18 20:15:02 +00:00
|
|
|
long tDelta = millis() - _SaveTime;
|
2019-07-27 23:07:29 +00:00
|
|
|
if(tDelta > 0) {
|
2019-01-18 20:15:02 +00:00
|
|
|
_SaveTime = 0;
|
2019-07-27 23:07:29 +00:00
|
|
|
}
|
2019-01-18 20:15:02 +00:00
|
|
|
}
|
|
|
|
else {
|
2019-07-28 07:40:12 +00:00
|
|
|
yPos = 20;
|
2019-01-18 20:15:02 +00:00
|
|
|
xPos = 6;
|
|
|
|
// date
|
|
|
|
if(_rowSel==0) {
|
2019-07-28 07:40:12 +00:00
|
|
|
xPos = 18;
|
2019-09-08 00:14:36 +00:00
|
|
|
_printMenuText(xPos, yPos, _working.dowStr());
|
2019-07-28 07:40:12 +00:00
|
|
|
xPos = 20;
|
2019-01-18 20:15:02 +00:00
|
|
|
}
|
|
|
|
|
2019-09-08 00:14:36 +00:00
|
|
|
sprintf(str, "%d", _working.day());
|
2019-01-18 20:15:02 +00:00
|
|
|
xPos += 20 + 12;
|
|
|
|
_printMenuText(xPos, yPos, str, _rowSel==1, eRightJustify);
|
|
|
|
xPos += 4;
|
2019-09-08 00:14:36 +00:00
|
|
|
_printMenuText(xPos, yPos, _working.monthStr(), _rowSel==2);
|
2019-01-18 20:15:02 +00:00
|
|
|
xPos += 22;
|
2019-09-08 00:14:36 +00:00
|
|
|
sprintf(str, "%d", _working.year());
|
2019-01-18 20:15:02 +00:00
|
|
|
_printMenuText(xPos, yPos, str, _rowSel==3);
|
|
|
|
// time
|
2019-07-28 07:40:12 +00:00
|
|
|
yPos = 32;
|
2019-09-08 00:14:36 +00:00
|
|
|
xPos = 8;
|
|
|
|
int hr = _working.hour();
|
|
|
|
if(_12hr) {
|
|
|
|
if(hr == 0)
|
|
|
|
hr = 12;
|
|
|
|
if(hr > 12)
|
|
|
|
hr -= 12;
|
|
|
|
}
|
|
|
|
sprintf(str, "%02d", hr);
|
2019-01-18 20:15:02 +00:00
|
|
|
_printMenuText(xPos, yPos, str, _rowSel==4);
|
|
|
|
xPos += 16;
|
|
|
|
_printMenuText(xPos, yPos, ":");
|
|
|
|
xPos += 8;
|
2019-09-08 00:14:36 +00:00
|
|
|
sprintf(str, "%02d", _working.minute());
|
2019-01-18 20:15:02 +00:00
|
|
|
_printMenuText(xPos, yPos, str, _rowSel==5);
|
|
|
|
xPos += 16;
|
|
|
|
_printMenuText(xPos, yPos, ":");
|
2019-09-08 00:14:36 +00:00
|
|
|
sprintf(str, "%02d", _working.second());
|
2019-01-18 20:15:02 +00:00
|
|
|
xPos += 8;
|
|
|
|
_printMenuText(xPos, yPos, str, _rowSel==6);
|
2019-09-08 00:14:36 +00:00
|
|
|
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;
|
2019-01-18 20:15:02 +00:00
|
|
|
if(_rowSel>=1)
|
2019-09-08 00:14:36 +00:00
|
|
|
_printMenuText(_display.width()-border, yPos, "SET", _rowSel==8, eRightJustify);
|
2019-07-28 07:40:12 +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);
|
2019-03-17 07:10:01 +00:00
|
|
|
}
|
|
|
|
else {
|
2019-07-28 07:40:12 +00:00
|
|
|
_display.drawFastHLine(0, 52, 128, WHITE);
|
|
|
|
_printMenuText(xPos, 56, "\033\032 Sel \030\031 Adj", false, eCentreJustify);
|
2019-09-08 00:14:36 +00:00
|
|
|
if(_rowSel == 8) {
|
2019-07-28 07:40:12 +00:00
|
|
|
_printMenuText(xPos, 56, "Save", false, eCentreJustify);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
_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-01-18 20:15:02 +00:00
|
|
|
_SaveTime = millis() + 1500;
|
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;
|
|
|
|
}
|
|
|
|
}
|