Enable buttons and the display.
Kind-of-sort-of usable-ish.
This commit is contained in:
140
DisplayTimeScreen.cpp
Normal file
140
DisplayTimeScreen.cpp
Normal file
@@ -0,0 +1,140 @@
|
||||
/*
|
||||
* Copyright (C) 2019 Max Regan
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "DisplayTimeScreen.h"
|
||||
#include "RtcDriver.h"
|
||||
#include "SystemTime.h"
|
||||
|
||||
#include "font-notomono-29.h"
|
||||
#include "font-notomono-68.h"
|
||||
|
||||
using Common::ReturnCode;
|
||||
using Common::Time;
|
||||
using Common::Schedule::NextTime;
|
||||
|
||||
static const struct font &font = font_notomono_68;
|
||||
|
||||
DisplayTimeScreen::DisplayTimeScreen(BSP::DisplayDriver &driver,
|
||||
ScreenManager &manager,
|
||||
Screen &menu_screen)
|
||||
: m_driver(driver)
|
||||
, m_last_time()
|
||||
, m_manager(manager)
|
||||
, m_menu_screen(menu_screen)
|
||||
, m_display_seconds(false)
|
||||
{}
|
||||
|
||||
static char get_char_for_digit(uint8_t bcd_digit)
|
||||
{
|
||||
if (bcd_digit > 9) {
|
||||
return '0';
|
||||
}
|
||||
return bcd_digit + '0';
|
||||
}
|
||||
|
||||
ReturnCode DisplayTimeScreen::init()
|
||||
{
|
||||
SET_TO(GPIOA->MODER, GPIO_MODER_MODE0, 1u << GPIO_MODER_MODE1_Pos);
|
||||
|
||||
GPIOA->OTYPER &= ~GPIO_OTYPER_OT_1;
|
||||
GPIOA->PUPDR &= ~GPIO_PUPDR_PUPD1;
|
||||
GPIOA->PUPDR |= 2u << GPIO_PUPDR_PUPD1_Pos;
|
||||
|
||||
return ReturnCode::OK;
|
||||
}
|
||||
|
||||
void DisplayTimeScreen::display_number(uint32_t *x, uint32_t y, uint32_t tens, uint32_t ones, const struct font &f)
|
||||
{
|
||||
char time_str[3] = { 0 };
|
||||
|
||||
time_str[0] = get_char_for_digit(tens);
|
||||
time_str[1] = get_char_for_digit(ones);
|
||||
time_str[2] = '\0';
|
||||
|
||||
m_driver.string_at(x, y, time_str, &f);
|
||||
}
|
||||
|
||||
void DisplayTimeScreen::display_time()
|
||||
{
|
||||
Common::WallClockTime time;
|
||||
BSP::RtcDriver::get_time(time);
|
||||
|
||||
// FIXME: Don't clear every redraw. Something is broken on screen
|
||||
// switching. enable/disable not called?
|
||||
m_driver.clear();
|
||||
|
||||
uint32_t x = 0;
|
||||
const uint32_t y_space = (m_driver.get_height() - (2 * font.size)) / 3;
|
||||
const uint32_t x_space = (m_driver.get_width() - (2 * 54)) / 2;
|
||||
|
||||
if (m_last_time.get_hours_24() != time.get_hours_24()) {
|
||||
x = x_space;
|
||||
display_number(&x, y_space,
|
||||
time.get_hours_12_tens(), time.get_hours_12_ones(), font);
|
||||
}
|
||||
|
||||
if (m_last_time.get_minutes() != time.get_minutes()) {
|
||||
x = x_space;
|
||||
display_number(&x, y_space * 2 + font.size,
|
||||
time.get_minutes_tens(), time.get_minutes_ones(), font);
|
||||
}
|
||||
|
||||
if (m_display_seconds) {
|
||||
// display_number(&x, y,
|
||||
// time.get_seconds_tens(), time.get_seconds_ones(), font_default);
|
||||
}
|
||||
|
||||
m_last_time = time;
|
||||
m_driver.refresh();
|
||||
}
|
||||
|
||||
NextTime DisplayTimeScreen::execute()
|
||||
{
|
||||
display_time();
|
||||
|
||||
Common::time_t now;
|
||||
BSP::SystemTimer::get_time(now);
|
||||
uint32_t next_secs = Time::to_seconds(now) + (m_display_seconds ? 1 : 60);
|
||||
return NextTime::at(Time::seconds(next_secs));
|
||||
}
|
||||
|
||||
|
||||
void DisplayTimeScreen::enable() {
|
||||
m_driver.clear();
|
||||
m_last_time = {};
|
||||
}
|
||||
|
||||
void DisplayTimeScreen::disable() {
|
||||
m_driver.clear();
|
||||
}
|
||||
|
||||
void DisplayTimeScreen::notify_up_button() {
|
||||
/* TODO: This should open a menu first */
|
||||
m_manager.push_screen(m_menu_screen);
|
||||
}
|
||||
|
||||
void DisplayTimeScreen::notify_middle_button() {
|
||||
|
||||
}
|
||||
|
||||
void DisplayTimeScreen::notify_down_button() {
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user