2018-12-08 22:55:55 +00:00
|
|
|
/*
|
|
|
|
* This file is part of the "bluetoothheater" distribution
|
|
|
|
* (https://gitlab.com/mrjones.id.au/bluetoothheater)
|
|
|
|
*
|
|
|
|
* Copyright (C) 2018 Ray Jones <ray@mrjones.id.au>
|
|
|
|
*
|
|
|
|
* 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/>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2019-01-18 07:09:40 +00:00
|
|
|
#include "ClockScreen.h"
|
2018-12-16 07:34:39 +00:00
|
|
|
#include "KeyPad.h"
|
|
|
|
#include "../Protocol/helpers.h"
|
|
|
|
#include "fonts/Tahoma16.h"
|
2019-04-19 11:38:39 +00:00
|
|
|
#include "fonts/Tahoma24.h"
|
2018-12-16 07:34:39 +00:00
|
|
|
#include "../RTC/Clock.h"
|
2018-12-08 22:55:55 +00:00
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
2019-01-18 07:09:40 +00:00
|
|
|
// CClockScreen
|
2018-12-08 22:55:55 +00:00
|
|
|
//
|
|
|
|
// This screen presents a large format clock
|
|
|
|
//
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
2019-01-18 07:09:40 +00:00
|
|
|
CClockScreen::CClockScreen(C128x64_OLED& display, CScreenManager& mgr) : CScreenHeader(display, mgr)
|
2018-12-08 22:55:55 +00:00
|
|
|
{
|
|
|
|
_colon = false;
|
2019-04-09 23:28:46 +00:00
|
|
|
_keyRepeatCount = -1;
|
2018-12-08 22:55:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-01-18 23:06:12 +00:00
|
|
|
bool
|
2019-01-18 07:09:40 +00:00
|
|
|
CClockScreen::show()
|
2018-12-08 22:55:55 +00:00
|
|
|
{
|
|
|
|
CScreenHeader::show();
|
|
|
|
|
|
|
|
const BTCDateTime& now = Clock.get();
|
|
|
|
|
|
|
|
char str[32];
|
|
|
|
// if(now.second() & 0x01)
|
|
|
|
if(_colon)
|
|
|
|
sprintf(str, "%d:%02d", now.hour(), now.minute());
|
|
|
|
else
|
|
|
|
sprintf(str, "%d %02d", now.hour(), now.minute());
|
|
|
|
_colon = !_colon;
|
|
|
|
|
|
|
|
int yPos = 25;
|
|
|
|
{
|
2019-04-19 11:38:39 +00:00
|
|
|
// CTransientFont AF(_display, &tahoma_16ptFontInfo); // temporarily use a large font
|
|
|
|
CTransientFont AF(_display, &tahoma_24ptFontInfo); // temporarily use a large font
|
2018-12-08 22:55:55 +00:00
|
|
|
_printMenuText(_display.xCentre(), yPos, str, false, eCentreJustify);
|
|
|
|
}
|
|
|
|
sprintf(str, "%s %d %s %d", now.dowStr(), now.day(), now.monthStr(), now.year());
|
|
|
|
_printMenuText(_display.xCentre(), 56, str, false, eCentreJustify);
|
2019-01-18 23:06:12 +00:00
|
|
|
|
|
|
|
return true;
|
2018-12-08 22:55:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-01-18 23:06:12 +00:00
|
|
|
bool
|
2019-01-18 07:09:40 +00:00
|
|
|
CClockScreen::keyHandler(uint8_t event)
|
2018-12-08 22:55:55 +00:00
|
|
|
{
|
|
|
|
if(event & keyPressed) {
|
2019-04-09 23:28:46 +00:00
|
|
|
_keyRepeatCount = 0; // unlock tracking of repeat events
|
2019-01-18 07:09:40 +00:00
|
|
|
// press UP
|
|
|
|
if(event & key_Up) {
|
2019-03-16 03:57:37 +00:00
|
|
|
_ScreenManager.selectMenu(CScreenManager::BranchMenu, CScreenManager::SetClockUI); // switch to clock set screen
|
2019-01-18 07:09:40 +00:00
|
|
|
}
|
|
|
|
// press DOWN
|
|
|
|
if(event & key_Down) {
|
2019-03-15 21:43:44 +00:00
|
|
|
_ScreenManager.selectMenu(CScreenManager::TimerMenuLoop); // switch to timer set screen loop
|
2019-01-18 07:09:40 +00:00
|
|
|
}
|
2018-12-08 22:55:55 +00:00
|
|
|
}
|
2019-04-09 23:28:46 +00:00
|
|
|
if(event & keyRepeat) {
|
|
|
|
if(_keyRepeatCount >= 0) {
|
|
|
|
_keyRepeatCount++;
|
|
|
|
// hold LEFT to toggle GPIO output #1
|
|
|
|
if(event & key_Left) {
|
|
|
|
if(_keyRepeatCount > 2) {
|
|
|
|
_keyRepeatCount = -1; // prevent double handling
|
|
|
|
setGPIO(0, !getGPIO(0)); // toggle GPIO output #1
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// hold RIGHT to toggle GPIO output #2
|
|
|
|
if(event & key_Right) {
|
|
|
|
if(_keyRepeatCount > 2) {
|
|
|
|
_keyRepeatCount = -1; // prevent double handling
|
|
|
|
setGPIO(1, !getGPIO(1)); // toggle GPIO output #2
|
|
|
|
}
|
|
|
|
}
|
2019-04-19 23:49:22 +00:00
|
|
|
// hold CENTRE to toggle On/Off state
|
|
|
|
if(event & key_Centre) {
|
|
|
|
int runstate = getHeaterInfo().getRunStateEx();
|
|
|
|
if(runstate) { // running, including cyclic mode idle
|
|
|
|
if(_keyRepeatCount > 5) {
|
|
|
|
_keyRepeatCount = -1;
|
|
|
|
requestOff();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else { // standard idle state
|
|
|
|
// standby, request ON
|
|
|
|
if(_keyRepeatCount > 3) {
|
|
|
|
_keyRepeatCount = -1;
|
|
|
|
requestOn();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-04-09 23:28:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// release event
|
|
|
|
if(event & keyReleased) {
|
|
|
|
if(_keyRepeatCount == 0) { // short Up press - lower target
|
|
|
|
if(event & key_Left) {
|
|
|
|
_ScreenManager.prevMenu();
|
|
|
|
}
|
|
|
|
if(event & key_Right) {
|
|
|
|
_ScreenManager.nextMenu();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_keyRepeatCount = -1;
|
|
|
|
}
|
2019-01-18 23:06:12 +00:00
|
|
|
return true;
|
2018-12-08 22:55:55 +00:00
|
|
|
}
|
|
|
|
|