You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
60 lines
1.4 KiB
60 lines
1.4 KiB
#include "watchos.h"
|
|
#include "Module_UI.h"
|
|
#include "Module_RTC.h"
|
|
|
|
class Task_Clock : public IRunnable, public IDrawable, public Task, public EventListener
|
|
{
|
|
Module_UI* ui = nullptr;
|
|
kernel_handle_t window_handle;
|
|
bool read_rtc = false;
|
|
byte hour, minute;
|
|
|
|
public:
|
|
void start()
|
|
{
|
|
watchos::subscribe(this, WATCHOS_MODULE_RTC, WATCHOS_EVENT_TYPE_RTC_MINUTE);
|
|
|
|
ui = static_cast<Module_UI*>(watchos::module(WATCHOS_MODULE_UI));
|
|
|
|
window_handle = ui->createWindow(this, ui->getRoot());
|
|
ui->setAbsolutePosition(window_handle, 0, 0, 200, 96);
|
|
}
|
|
void tick()
|
|
{
|
|
Event* e;
|
|
while (this->hasEvent())
|
|
{
|
|
e = this->getEvent();
|
|
|
|
if (e->source == WATCHOS_MODULE_RTC && e->event == WATCHOS_EVENT_TYPE_RTC_MINUTE)
|
|
{
|
|
if (!read_rtc || e->param1 != hour || e->param2 != minute)
|
|
{
|
|
hour = e->param1;
|
|
minute = e->param2;
|
|
read_rtc = true;
|
|
ui->setDirty(window_handle);
|
|
}
|
|
}
|
|
|
|
this->popEvent();
|
|
}
|
|
}
|
|
void draw(kernel_handle_t handle)
|
|
{
|
|
if (!read_rtc)
|
|
{
|
|
Module_RTC* rtc = static_cast<Module_RTC*>(watchos::module(WATCHOS_MODULE_RTC));
|
|
hour = rtc->getHour();
|
|
minute = rtc->getMinute();
|
|
read_rtc = true;
|
|
}
|
|
|
|
char time[6];
|
|
sprintf(time, "%02d:%02d", hour, minute);
|
|
|
|
ui->fill(COLOUR_SECONDARY);
|
|
ui->print(0, ui->getHeight() - 8, time, COLOUR_PRIMARY, 1);
|
|
}
|
|
|
|
};
|