2020-01-18 12:17:52 -05:00
|
|
|
#include <cstdio>
|
2020-10-02 15:16:48 -04:00
|
|
|
|
2020-01-18 12:17:52 -05:00
|
|
|
#include <libs/date/includes/date/date.h>
|
2020-10-02 15:16:48 -04:00
|
|
|
#include "components/datetime/DateTimeController.h"
|
2020-02-10 15:05:33 -05:00
|
|
|
#include <libs/lvgl/lvgl.h>
|
2020-01-18 12:17:52 -05:00
|
|
|
#include "Clock.h"
|
2020-02-16 12:32:36 -05:00
|
|
|
#include "../DisplayApp.h"
|
2020-03-14 11:33:47 -04:00
|
|
|
#include "BatteryIcon.h"
|
|
|
|
#include "BleIcon.h"
|
2020-07-04 07:58:15 -04:00
|
|
|
#include "Symbols.h"
|
2020-01-18 12:17:52 -05:00
|
|
|
using namespace Pinetime::Applications::Screens;
|
2020-03-01 13:09:59 -05:00
|
|
|
extern lv_font_t jetbrains_mono_extrabold_compressed;
|
2020-02-10 15:05:33 -05:00
|
|
|
extern lv_font_t jetbrains_mono_bold_20;
|
2020-07-03 15:37:40 -04:00
|
|
|
extern lv_style_t* LabelBigStyle;
|
2020-03-14 11:33:47 -04:00
|
|
|
|
2020-02-16 12:32:36 -05:00
|
|
|
static void event_handler(lv_obj_t * obj, lv_event_t event) {
|
|
|
|
Clock* screen = static_cast<Clock *>(obj->user_data);
|
|
|
|
screen->OnObjectEvent(obj, event);
|
|
|
|
}
|
|
|
|
|
2020-02-23 10:14:03 -05:00
|
|
|
Clock::Clock(DisplayApp* app,
|
|
|
|
Controllers::DateTime& dateTimeController,
|
|
|
|
Controllers::Battery& batteryController,
|
2020-07-04 07:58:15 -04:00
|
|
|
Controllers::Ble& bleController) : Screen(app), currentDateTime{{}},
|
2020-02-23 10:14:03 -05:00
|
|
|
dateTimeController{dateTimeController}, batteryController{batteryController}, bleController{bleController} {
|
2020-02-16 12:32:36 -05:00
|
|
|
displayedChar[0] = 0;
|
|
|
|
displayedChar[1] = 0;
|
|
|
|
displayedChar[2] = 0;
|
|
|
|
displayedChar[3] = 0;
|
|
|
|
displayedChar[4] = 0;
|
|
|
|
|
2020-07-04 07:58:15 -04:00
|
|
|
batteryIcon = lv_label_create(lv_scr_act(), NULL);
|
|
|
|
lv_label_set_text(batteryIcon, Symbols::batteryFull);
|
|
|
|
lv_obj_align(batteryIcon, lv_scr_act(), LV_ALIGN_IN_TOP_RIGHT, -5, 2);
|
|
|
|
|
|
|
|
batteryPlug = lv_label_create(lv_scr_act(), NULL);
|
|
|
|
lv_label_set_text(batteryPlug, Symbols::plug);
|
|
|
|
lv_obj_align(batteryPlug, batteryIcon, LV_ALIGN_OUT_LEFT_MID, -5, 0);
|
|
|
|
|
|
|
|
bleIcon = lv_label_create(lv_scr_act(), NULL);
|
|
|
|
lv_label_set_text(bleIcon, Symbols::bluetooth);
|
|
|
|
lv_obj_align(bleIcon, batteryPlug, LV_ALIGN_OUT_LEFT_MID, -5, 0);
|
2020-03-14 11:33:47 -04:00
|
|
|
|
|
|
|
|
|
|
|
label_date = lv_label_create(lv_scr_act(), NULL);
|
|
|
|
|
|
|
|
lv_obj_align(label_date, lv_scr_act(), LV_ALIGN_IN_LEFT_MID, 0, 60);
|
|
|
|
|
2020-02-10 15:05:33 -05:00
|
|
|
label_time = lv_label_create(lv_scr_act(), NULL);
|
2020-07-03 15:37:40 -04:00
|
|
|
lv_label_set_style(label_time, LV_LABEL_STYLE_MAIN, LabelBigStyle);
|
2020-02-10 15:05:33 -05:00
|
|
|
lv_obj_align(label_time, lv_scr_act(), LV_ALIGN_IN_LEFT_MID, 0, 0);
|
|
|
|
|
2020-02-16 12:32:36 -05:00
|
|
|
backgroundLabel = lv_label_create(lv_scr_act(), NULL);
|
|
|
|
backgroundLabel->user_data = this;
|
|
|
|
lv_obj_set_click(backgroundLabel, true);
|
|
|
|
lv_obj_set_event_cb(backgroundLabel, event_handler);
|
|
|
|
lv_label_set_long_mode(backgroundLabel, LV_LABEL_LONG_CROP);
|
|
|
|
lv_obj_set_size(backgroundLabel, 240, 240);
|
|
|
|
lv_obj_set_pos(backgroundLabel, 0, 0);
|
|
|
|
lv_label_set_text(backgroundLabel, "");
|
2020-07-04 07:58:15 -04:00
|
|
|
|
|
|
|
|
|
|
|
heartbeatIcon = lv_label_create(lv_scr_act(), NULL);
|
|
|
|
lv_label_set_text(heartbeatIcon, Symbols::heartBeat);
|
|
|
|
lv_obj_align(heartbeatIcon, lv_scr_act(), LV_ALIGN_IN_BOTTOM_LEFT, 5, -2);
|
|
|
|
|
|
|
|
heartbeatValue = lv_label_create(lv_scr_act(), NULL);
|
|
|
|
lv_label_set_text(heartbeatValue, "0");
|
|
|
|
lv_obj_align(heartbeatValue, heartbeatIcon, LV_ALIGN_OUT_RIGHT_MID, 5, 0);
|
|
|
|
|
|
|
|
heartbeatBpm = lv_label_create(lv_scr_act(), NULL);
|
|
|
|
lv_label_set_text(heartbeatBpm, "BPM");
|
|
|
|
lv_obj_align(heartbeatBpm, heartbeatValue, LV_ALIGN_OUT_RIGHT_MID, 5, 0);
|
|
|
|
|
|
|
|
stepValue = lv_label_create(lv_scr_act(), NULL);
|
|
|
|
lv_label_set_text(stepValue, "0");
|
|
|
|
lv_obj_align(stepValue, lv_scr_act(), LV_ALIGN_IN_BOTTOM_RIGHT, -5, -2);
|
|
|
|
|
|
|
|
stepIcon = lv_label_create(lv_scr_act(), NULL);
|
|
|
|
lv_label_set_text(stepIcon, Symbols::shoe);
|
|
|
|
lv_obj_align(stepIcon, stepValue, LV_ALIGN_OUT_LEFT_MID, -5, 0);
|
2020-02-16 12:32:36 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
Clock::~Clock() {
|
|
|
|
lv_obj_clean(lv_scr_act());
|
2020-02-10 15:05:33 -05:00
|
|
|
}
|
2020-01-18 12:17:52 -05:00
|
|
|
|
2020-02-23 10:14:03 -05:00
|
|
|
bool Clock::Refresh() {
|
|
|
|
batteryPercentRemaining = batteryController.PercentRemaining();
|
|
|
|
if (batteryPercentRemaining.IsUpdated()) {
|
2020-03-14 11:33:47 -04:00
|
|
|
auto batteryPercent = batteryPercentRemaining.Get();
|
2020-07-04 07:58:15 -04:00
|
|
|
lv_label_set_text(batteryIcon, BatteryIcon::GetBatteryIcon(batteryPercent));
|
|
|
|
auto isCharging = batteryController.IsCharging() || batteryController.IsPowerPresent();
|
|
|
|
lv_label_set_text(batteryPlug, BatteryIcon::GetPlugIcon(isCharging));
|
2020-01-18 12:17:52 -05:00
|
|
|
}
|
|
|
|
|
2020-02-23 10:14:03 -05:00
|
|
|
bleState = bleController.IsConnected();
|
|
|
|
if (bleState.IsUpdated()) {
|
|
|
|
if(bleState.Get() == true) {
|
2020-07-04 07:58:15 -04:00
|
|
|
lv_label_set_text(bleIcon, BleIcon::GetIcon(true));
|
2020-02-20 12:17:53 -05:00
|
|
|
} else {
|
2020-07-04 07:58:15 -04:00
|
|
|
lv_label_set_text(bleIcon, BleIcon::GetIcon(false));
|
2020-02-20 12:17:53 -05:00
|
|
|
}
|
2020-01-18 12:17:52 -05:00
|
|
|
}
|
2020-07-04 07:58:15 -04:00
|
|
|
lv_obj_align(batteryIcon, lv_scr_act(), LV_ALIGN_IN_TOP_RIGHT, -5, 5);
|
|
|
|
lv_obj_align(batteryPlug, batteryIcon, LV_ALIGN_OUT_LEFT_MID, -5, 0);
|
|
|
|
lv_obj_align(bleIcon, batteryPlug, LV_ALIGN_OUT_LEFT_MID, -5, 0);
|
2020-01-18 12:17:52 -05:00
|
|
|
|
2020-02-16 12:32:36 -05:00
|
|
|
currentDateTime = dateTimeController.CurrentDateTime();
|
|
|
|
|
2020-02-23 10:14:03 -05:00
|
|
|
if(currentDateTime.IsUpdated()) {
|
2020-01-18 12:17:52 -05:00
|
|
|
auto newDateTime = currentDateTime.Get();
|
|
|
|
|
|
|
|
auto dp = date::floor<date::days>(newDateTime);
|
|
|
|
auto time = date::make_time(newDateTime-dp);
|
|
|
|
auto yearMonthDay = date::year_month_day(dp);
|
|
|
|
|
|
|
|
auto year = (int)yearMonthDay.year();
|
|
|
|
auto month = static_cast<Pinetime::Controllers::DateTime::Months>((unsigned)yearMonthDay.month());
|
|
|
|
auto day = (unsigned)yearMonthDay.day();
|
|
|
|
auto dayOfWeek = static_cast<Pinetime::Controllers::DateTime::Days>(date::weekday(yearMonthDay).iso_encoding());
|
|
|
|
|
|
|
|
auto hour = time.hours().count();
|
|
|
|
auto minute = time.minutes().count();
|
|
|
|
|
|
|
|
char minutesChar[3];
|
2020-08-17 10:31:00 -04:00
|
|
|
sprintf(minutesChar, "%02d", static_cast<int>(minute));
|
2020-01-18 12:17:52 -05:00
|
|
|
|
|
|
|
char hoursChar[3];
|
2020-08-17 10:31:00 -04:00
|
|
|
sprintf(hoursChar, "%02d", static_cast<int>(hour));
|
2020-01-18 12:17:52 -05:00
|
|
|
|
2020-02-10 15:05:33 -05:00
|
|
|
char timeStr[6];
|
|
|
|
sprintf(timeStr, "%c%c:%c%c", hoursChar[0],hoursChar[1],minutesChar[0], minutesChar[1]);
|
2020-02-16 12:32:36 -05:00
|
|
|
|
|
|
|
if(hoursChar[0] != displayedChar[0] || hoursChar[1] != displayedChar[1] || minutesChar[0] != displayedChar[2] || minutesChar[1] != displayedChar[3]) {
|
|
|
|
displayedChar[0] = hoursChar[0];
|
|
|
|
displayedChar[1] = hoursChar[1];
|
|
|
|
displayedChar[2] = minutesChar[0];
|
|
|
|
displayedChar[3] = minutesChar[1];
|
|
|
|
|
|
|
|
lv_label_set_text(label_time, timeStr);
|
|
|
|
}
|
2020-01-18 12:17:52 -05:00
|
|
|
|
|
|
|
if ((year != currentYear) || (month != currentMonth) || (dayOfWeek != currentDayOfWeek) || (day != currentDay)) {
|
|
|
|
char dateStr[22];
|
|
|
|
sprintf(dateStr, "%s %d %s %d", DayOfWeekToString(dayOfWeek), day, MonthToString(month), year);
|
2020-02-10 15:05:33 -05:00
|
|
|
lv_label_set_text(label_date, dateStr);
|
|
|
|
|
2020-01-18 12:17:52 -05:00
|
|
|
|
|
|
|
currentYear = year;
|
|
|
|
currentMonth = month;
|
|
|
|
currentDayOfWeek = dayOfWeek;
|
|
|
|
currentDay = day;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-04 07:58:15 -04:00
|
|
|
// TODO heartbeat = heartBeatController.GetValue();
|
|
|
|
if(heartbeat.IsUpdated()) {
|
|
|
|
char heartbeatBuffer[4];
|
|
|
|
sprintf(heartbeatBuffer, "%d", heartbeat.Get());
|
|
|
|
lv_label_set_text(heartbeatValue, heartbeatBuffer);
|
|
|
|
lv_obj_align(heartbeatIcon, lv_scr_act(), LV_ALIGN_IN_BOTTOM_LEFT, 5, -2);
|
|
|
|
lv_obj_align(heartbeatValue, heartbeatIcon, LV_ALIGN_OUT_RIGHT_MID, 5, 0);
|
|
|
|
lv_obj_align(heartbeatBpm, heartbeatValue, LV_ALIGN_OUT_RIGHT_MID, 5, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO stepCount = stepController.GetValue();
|
|
|
|
if(stepCount.IsUpdated()) {
|
|
|
|
char stepBuffer[5];
|
|
|
|
sprintf(stepBuffer, "%lu", stepCount.Get());
|
|
|
|
lv_label_set_text(stepValue, stepBuffer);
|
|
|
|
lv_obj_align(stepValue, lv_scr_act(), LV_ALIGN_IN_BOTTOM_RIGHT, -5, -2);
|
|
|
|
lv_obj_align(stepIcon, stepValue, LV_ALIGN_OUT_LEFT_MID, -5, 0);
|
|
|
|
}
|
|
|
|
|
2020-02-23 07:44:39 -05:00
|
|
|
return running;
|
2020-01-18 12:17:52 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
const char *Clock::MonthToString(Pinetime::Controllers::DateTime::Months month) {
|
|
|
|
return Clock::MonthsString[static_cast<uint8_t>(month)];
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *Clock::DayOfWeekToString(Pinetime::Controllers::DateTime::Days dayOfWeek) {
|
|
|
|
return Clock::DaysString[static_cast<uint8_t>(dayOfWeek)];
|
|
|
|
}
|
|
|
|
|
|
|
|
char const *Clock::DaysString[] = {
|
|
|
|
"",
|
|
|
|
"MONDAY",
|
|
|
|
"TUESDAY",
|
|
|
|
"WEDNESDAY",
|
|
|
|
"THURSDAY",
|
|
|
|
"FRIDAY",
|
|
|
|
"SATURDAY",
|
|
|
|
"SUNDAY"
|
|
|
|
};
|
|
|
|
|
|
|
|
char const *Clock::MonthsString[] = {
|
|
|
|
"",
|
|
|
|
"JAN",
|
|
|
|
"FEB",
|
|
|
|
"MAR",
|
|
|
|
"APR",
|
|
|
|
"MAY",
|
|
|
|
"JUN",
|
|
|
|
"JUL",
|
|
|
|
"AUG",
|
|
|
|
"SEP",
|
|
|
|
"OCT",
|
|
|
|
"NOV",
|
|
|
|
"DEC"
|
|
|
|
};
|
2020-02-10 15:05:33 -05:00
|
|
|
|
2020-02-16 12:32:36 -05:00
|
|
|
void Clock::OnObjectEvent(lv_obj_t *obj, lv_event_t event) {
|
|
|
|
if(obj == backgroundLabel) {
|
|
|
|
if (event == LV_EVENT_CLICKED) {
|
2020-02-23 07:44:39 -05:00
|
|
|
|
|
|
|
running = false;
|
2020-02-16 12:32:36 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-23 07:44:39 -05:00
|
|
|
bool Clock::OnButtonPushed() {
|
2020-03-09 16:29:12 -04:00
|
|
|
running = false;
|
|
|
|
return false;
|
2020-02-23 07:44:39 -05:00
|
|
|
}
|
|
|
|
|
2020-02-10 15:05:33 -05:00
|
|
|
|