Huge refactoring for C++ and low-power mode
The display currently shows the time, with hours and minutes, and is capable of receiving input with buttons (though does nothing). It sleeps during intervals where nothing is happening. The display task runs once per second, and RTC alarm A is used for periodic alarms to update the system time.
This commit is contained in:
@@ -20,38 +20,98 @@
|
||||
*/
|
||||
|
||||
#include "DisplayTimeTask.h"
|
||||
#include "LowPower.h"
|
||||
|
||||
#include "font-notomono-10.h"
|
||||
#include "SystemTime.h"
|
||||
|
||||
#include "font-notomono-24.h"
|
||||
#include "font-notomono-64.h"
|
||||
|
||||
using Common::ReturnCode;
|
||||
using Common::Time;
|
||||
using Common::Schedule::NextTime;
|
||||
|
||||
static const font &font_large = font_notomono_64;
|
||||
static const font &font_default = font_notomono_24;
|
||||
|
||||
DisplayTimeTask::DisplayTimeTask(BSP::DisplayDriver &driver)
|
||||
: m_driver(driver)
|
||||
, m_y_pos(0)
|
||||
, m_has_cleared(false)
|
||||
, m_last_time()
|
||||
, m_display_seconds(true)
|
||||
{}
|
||||
|
||||
ReturnCode DisplayTimeTask::init() {
|
||||
static char get_char_for_digit(uint8_t bcd_digit)
|
||||
{
|
||||
if (bcd_digit > 9) {
|
||||
return '0';
|
||||
}
|
||||
return bcd_digit + '0';
|
||||
}
|
||||
|
||||
|
||||
ReturnCode DisplayTimeTask::init()
|
||||
{
|
||||
return ReturnCode::OK;
|
||||
}
|
||||
|
||||
NextTime DisplayTimeTask::execute() {
|
||||
//static const char msg_str[] = "Hello world!";
|
||||
void DisplayTimeTask::display_number(uint32_t x, uint32_t y, uint32_t tens, uint32_t ones, const font &f)
|
||||
{
|
||||
char time_str[3] = { 0 };
|
||||
|
||||
int x = 20;
|
||||
time_str[0] = get_char_for_digit(tens);
|
||||
time_str[1] = get_char_for_digit(ones);
|
||||
time_str[2] = '\0';
|
||||
|
||||
m_driver.clear();
|
||||
m_driver.string_at(x, m_y_pos++, "Hello world!", &font_notomono_10);
|
||||
m_driver.refresh();
|
||||
m_driver.string_at(x, y, time_str, &f);
|
||||
}
|
||||
|
||||
if (m_y_pos > 160) {
|
||||
m_y_pos = 0;
|
||||
void DisplayTimeTask::display_time()
|
||||
{
|
||||
uint32_t width = m_driver.get_width();
|
||||
uint32_t height = m_driver.get_height();
|
||||
|
||||
BSP::time_bcd time;
|
||||
BSP::RtcDriver::get_time(time);
|
||||
|
||||
if (!m_has_cleared) {
|
||||
m_driver.clear();
|
||||
}
|
||||
|
||||
BSP::LowPower::stop();
|
||||
int i = 0;
|
||||
|
||||
return NextTime::asap();
|
||||
if (m_last_time.hour_tens != time.hour_tens ||
|
||||
m_last_time.hour_ones != time.hour_ones ||
|
||||
!m_has_cleared) {
|
||||
display_number(0, (i * font_large.size) + (i + 1) * 4, time.hour_tens, time.hour_ones, font_large);
|
||||
}
|
||||
|
||||
i++;
|
||||
if (m_last_time.minute_tens != time.minute_tens ||
|
||||
m_last_time.minute_ones != time.minute_ones ||
|
||||
!m_has_cleared) {
|
||||
display_number(0, (i * font_large.size) + (i + 1) * 4, time.minute_tens, time.minute_ones, font_large);
|
||||
}
|
||||
|
||||
i++;
|
||||
if (m_display_seconds) {
|
||||
if (m_last_time.second_tens != time.second_tens ||
|
||||
m_last_time.second_ones != time.second_ones ||
|
||||
!m_has_cleared) {
|
||||
display_number(0, (i * font_large.size) + (i + 1) * 4, time.second_tens, time.second_ones, font_default);
|
||||
}
|
||||
}
|
||||
|
||||
m_has_cleared = true;
|
||||
m_last_time = time;
|
||||
|
||||
m_driver.refresh();
|
||||
}
|
||||
|
||||
NextTime DisplayTimeTask::execute()
|
||||
{
|
||||
display_time();
|
||||
|
||||
Common::time_t now;
|
||||
BSP::SystemTimer::get_time(now);
|
||||
uint32_t next_secs = Time::to_seconds(now) + 1;
|
||||
return NextTime::at(Time::seconds(next_secs));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user