Compare commits

...

17 Commits

Author SHA1 Message Date
Josh
dfcfe0e4cb Merge branch 'v14' of https://gitea.locker98.com/josh/InfiniTime into v14 2024-05-09 13:50:42 -04:00
Josh
2aefce24f6 Add AcurateWords face to default build in cmake 2024-05-09 13:50:35 -04:00
Josh
c25623ae79 Progress with Accurate words face, but not working yet 2024-05-09 13:50:02 -04:00
Josh
06d93f0b46 Merge branch 'accurate-words-watchface' into v14 2024-05-09 12:45:57 -04:00
Brendan M. Sleight
8084d8784b Missing comma at five to 2022-10-07 11:54:48 +00:00
Brendan M. Sleight
64cd0a6c7a Array[33] 2022-09-17 20:50:27 +00:00
Brendan M. Sleight
bea1d3814f Eliminating null length strings - c++ is harder than python 2022-09-17 20:32:38 +00:00
Brendan M. Sleight
866295676d Clang-format 2022-09-15 19:29:31 +00:00
Brendan M. Sleight
ac93d51090 Correcting ampersand. Update date only on date change 2022-09-15 19:27:55 +00:00
Brendan M. Sleight
4bc27cd593 Use pointers in const char arrays 2022-09-15 19:16:47 +00:00
Brendan M. Sleight
6ae0d47461 clang-format corrections 2022-09-15 16:55:00 +00:00
Brendan M. Sleight
1ca2c2ad34 Specific dates have specific names 2022-09-05 19:55:15 +00:00
Brendan M. Sleight
99785b88a3 Date in words (exlcuding year) 2022-08-28 20:08:25 +00:00
Brendan M. Sleight
0b1bec0ae9 Fixing initial value of hour_adjusted 2022-08-28 13:31:23 +00:00
Brendan M. Sleight
d846cb1b74 Updateing CMakeLists 2022-08-28 13:04:16 +00:00
Brendan M. Sleight
66f70d8af1 WatchFaceAccurateWords - description of current time accurate to a minute 2022-08-28 12:43:55 +00:00
Brendan M. Sleight
4901cc9fd8 Copied exising watch face to new WatchFaceAccurateWords 2022-08-28 11:57:53 +00:00
5 changed files with 354 additions and 1 deletions

View File

@ -433,6 +433,7 @@ list(APPEND SOURCE_FILES
displayapp/screens/WatchFacePineTimeStyle.cpp
displayapp/screens/WatchFaceCasioStyleG7710.cpp
displayapp/screens/WatchFaceHorizon.cpp
displayapp/screens/WatchFaceAccurateWords.cpp
##

View File

@ -57,7 +57,8 @@ namespace Pinetime {
Terminal,
Infineat,
CasioStyleG7710,
Horizon
Horizon,
AccurateWords,
};
template <Apps>

View File

@ -31,6 +31,7 @@ else()
set(DEFAULT_WATCHFACE_TYPES "${DEFAULT_WATCHFACE_TYPES}, WatchFace::Infineat")
set(DEFAULT_WATCHFACE_TYPES "${DEFAULT_WATCHFACE_TYPES}, WatchFace::CasioStyleG7710")
set(DEFAULT_WATCHFACE_TYPES "${DEFAULT_WATCHFACE_TYPES}, WatchFace::Horizon")
set(DEFAULT_WATCHFACE_TYPES "${DEFAULT_WATCHFACE_TYPES}, WatchFace::AccurateWords")
set(WATCHFACE_TYPES "${DEFAULT_WATCHFACE_TYPES}" CACHE STRING "List of watch faces to build into the firmware")
endif()

View File

@ -0,0 +1,248 @@
#include "displayapp/screens/WatchFaceAccurateWords.h"
#include <lvgl/lvgl.h>
#include <cstdio>
#include "displayapp/screens/NotificationIcon.h"
#include "displayapp/screens/Symbols.h"
#include "components/battery/BatteryController.h"
#include "components/ble/BleController.h"
#include "components/ble/NotificationManager.h"
#include "components/heartrate/HeartRateController.h"
#include "components/motion/MotionController.h"
#include "components/settings/Settings.h"
using namespace Pinetime::Applications::Screens;
WatchFaceAccurateWords::WatchFaceAccurateWords(Controllers::DateTime& dateTimeController,
const Controllers::Battery& batteryController,
const Controllers::Ble& bleController,
Controllers::NotificationManager& notificatioManager,
Controllers::Settings& settingsController,
Controllers::HeartRateController& heartRateController,
Controllers::MotionController& motionController)
: currentDateTime {{}},
dateTimeController {dateTimeController},
notificatioManager {notificatioManager},
settingsController {settingsController},
heartRateController {heartRateController},
motionController {motionController},
statusIcons(batteryController, bleController) {
statusIcons.Create();
notificationIcon = lv_label_create(lv_scr_act(), nullptr);
lv_obj_set_style_local_text_color(notificationIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_LIME);
lv_label_set_text_static(notificationIcon, NotificationIcon::GetIcon(false));
lv_obj_align(notificationIcon, nullptr, LV_ALIGN_IN_TOP_LEFT, 0, 0);
label_date = lv_label_create(lv_scr_act(), nullptr);
lv_obj_set_style_local_text_color(label_date, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x999999));
lv_label_set_long_mode(label_date, LV_LABEL_LONG_BREAK);
lv_obj_set_width(label_date, LV_HOR_RES - 20);
lv_label_set_align(label_date, LV_LABEL_ALIGN_CENTER);
lv_obj_align(label_date, lv_scr_act(), LV_ALIGN_CENTER, 0, 60);
label_time = lv_label_create(lv_scr_act(), nullptr);
lv_obj_set_style_local_text_font(label_time, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_bold_20);
lv_label_set_long_mode(label_time, LV_LABEL_LONG_BREAK);
lv_obj_set_width(label_time, LV_HOR_RES - 20);
lv_label_set_align(label_time, LV_LABEL_ALIGN_CENTER);
lv_obj_align(label_time, lv_scr_act(), LV_ALIGN_CENTER, 0, 0);
heartbeatIcon = lv_label_create(lv_scr_act(), nullptr);
lv_label_set_text_static(heartbeatIcon, Symbols::heartBeat);
lv_obj_set_style_local_text_color(heartbeatIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0xCE1B1B));
lv_obj_align(heartbeatIcon, lv_scr_act(), LV_ALIGN_IN_BOTTOM_LEFT, 0, 0);
heartbeatValue = lv_label_create(lv_scr_act(), nullptr);
lv_obj_set_style_local_text_color(heartbeatValue, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0xCE1B1B));
lv_label_set_text_static(heartbeatValue, "");
lv_obj_align(heartbeatValue, heartbeatIcon, LV_ALIGN_OUT_RIGHT_MID, 5, 0);
stepValue = lv_label_create(lv_scr_act(), nullptr);
lv_obj_set_style_local_text_color(stepValue, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x00FFE7));
lv_label_set_text_static(stepValue, "0");
lv_obj_align(stepValue, lv_scr_act(), LV_ALIGN_IN_BOTTOM_RIGHT, 0, 0);
stepIcon = lv_label_create(lv_scr_act(), nullptr);
lv_obj_set_style_local_text_color(stepIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x00FFE7));
lv_label_set_text_static(stepIcon, Symbols::shoe);
lv_obj_align(stepIcon, stepValue, LV_ALIGN_OUT_LEFT_MID, -5, 0);
taskRefresh = lv_task_create(RefreshTaskCallback, LV_DISP_DEF_REFR_PERIOD, LV_TASK_PRIO_MID, this);
Refresh();
}
WatchFaceAccurateWords::~WatchFaceAccurateWords() {
lv_task_del(taskRefresh);
lv_obj_clean(lv_scr_act());
}
void WatchFaceAccurateWords::Refresh() {
statusIcons.Update();
notificationState = notificatioManager.AreNewNotificationsAvailable();
if (notificationState.IsUpdated()) {
lv_label_set_text_static(notificationIcon, NotificationIcon::GetIcon(notificationState.Get()));
}
currentDateTime = dateTimeController.CurrentDateTime();
if (currentDateTime.IsUpdated()) {
auto year = dateTimeController.Year();
auto month = dateTimeController.Month();
auto day = dateTimeController.Day();
auto dayOfWeek = dateTimeController.DayOfWeek();
uint8_t hour = dateTimeController.Hours();
uint8_t minute = dateTimeController.Minutes();
uint8_t monthInt = static_cast<uint8_t>(month);
uint8_t dayInt = static_cast<uint8_t>(day);
uint8_t hour_adjusted;
char words[78];
const char* hour_word_array[26] = {"midnight", "one", "two", "three", "four", "five", "six", "seven", "eight",
"nine", "ten", "eleven", "twelve", "one", "two", "three", "four", "five",
"six", "seven", "eight", "nine", "ten", "eleven", "midnight"};
const char* part_day_word_array[9] = {" at night",
" in the early hours",
" in the morning",
" in the morning",
" in the afternoon",
" in the afternoon",
" in the evening",
" at night"};
const char* minutes_rough_array[14] = {"--",
"five past ",
"ten past ",
"quarter past ",
"twenty past ",
"twenty-five past ",
"half past ",
"twenty-five to ",
"twenty to ",
"quarter to ",
"ten to ",
"five to ",
"--"};
const char* minutes_accurate_array[6] = {"--", "just gone ", "a little after ", "coming up to ", "almost "};
const char* days_array[9] = {"--", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"};
const char* months_array[13] =
{"--", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"};
const char* months_numbers_array[33] = {
"zero", "first", "second", "third", "fourth", "fifth", "sixth", "seventh",
"eighth", "ninth", "tenth", "eleventh", "twelfth", "thirteenth", "fourteenth", "fifteenth",
"sixteenth", "seventeenth", "eighteenth", "nineteenth", "twentieth", "twenty-first", "twenty-second", "twenty-third",
"twenty-fourth", "twenty-fifth", "twenty-sixth", "twenty-seventh", "twenty-eighth", "twenty-ninth", "thirtieth", "thirty-first"};
if (displayedHour != hour || displayedMinute != minute) {
displayedHour = hour;
displayedMinute = minute;
// At 33 past the hours we start referign to the next hour
if (minute > 32) {
hour_adjusted = (hour + 1) % 24;
} else {
hour_adjusted = hour;
}
if ((hour_adjusted == 0 || hour_adjusted == 12) && minute == 0) {
// Example 12:00 = Twelve
sprintf(words, "%s", hour_word_array[hour_adjusted]);
} else if ((hour_adjusted == 0 || hour_adjusted == 12) && (((minute + 2) % 60) / 5 == 0)) {
// Example 23:59 = Almost midnight
sprintf(words, "%s%s", minutes_accurate_array[minute % 5], hour_word_array[hour_adjusted]);
} else if ((hour_adjusted == 0 || hour_adjusted == 12) && (minute % 5 == 0)) {
// Example 12:15 = Quarter past twelve
sprintf(words, "%s%s", minutes_rough_array[(minute + 2) / 5], hour_word_array[hour_adjusted]);
} else if (hour_adjusted == 0 || hour_adjusted == 12) {
// Example 00:16 = Just gone quarter past twelve
sprintf(words, "%s%s%s", minutes_accurate_array[minute % 5], minutes_rough_array[(minute + 2) / 5], hour_word_array[hour_adjusted]);
} else if (minute == 0) {
// Example 01:00 = One at night
sprintf(words, "%s%s", hour_word_array[hour_adjusted], part_day_word_array[hour_adjusted / 3]);
} else if (((minute + 2) % 60) / 5 == 0) {
// Example 17:01 = Just gone five in the afternoon
sprintf(words,
"%s%s%s",
minutes_accurate_array[minute % 5],
hour_word_array[hour_adjusted],
part_day_word_array[hour_adjusted / 3]);
} else if (minute % 5 == 0) {
// Example 05:25 = Twenty-five past five in the early hours
sprintf(words,
"%s%s%s",
minutes_rough_array[(minute + 2) / 5],
hour_word_array[hour_adjusted],
part_day_word_array[hour_adjusted / 3]);
} else {
// Example 22:33 = coming up to eleven at night
sprintf(words,
"%s%s%s%s",
minutes_accurate_array[minute % 5],
minutes_rough_array[(minute + 2) / 5],
hour_word_array[hour_adjusted],
part_day_word_array[hour_adjusted / 3]);
}
// Make first letter Uppercase
words[0] = words[0] - 32;
lv_label_set_text_fmt(label_time, "%s", words);
lv_obj_align(label_time, lv_scr_act(), LV_ALIGN_CENTER, 0, -40);
currentDate = std::chrono::time_point_cast<std::chrono::days>(currentDateTime.Get());
if (currentDate.IsUpdated()) {
// Specific dates have specific names
if (year == 1970) {
lv_label_set_text_fmt(label_date, "New Firmware");
} else if (monthInt == 1 && dayInt == 1) {
lv_label_set_text_fmt(label_date, "%s, New Year's Day", days_array[static_cast<uint8_t>(dayOfWeek)]);
} else if (monthInt == 3 && dayInt == 15) {
lv_label_set_text_fmt(label_date, "%s on the Ides of March", days_array[static_cast<uint8_t>(dayOfWeek)]);
} else if (monthInt == 4 && dayInt == 1) {
lv_label_set_text_fmt(label_date, "%s, ERROR C Nonsense in BASIC", days_array[static_cast<uint8_t>(dayOfWeek)]);
} else if (monthInt == 7 && dayInt == 1) {
lv_label_set_text_fmt(label_date, "%s - O'Canada", days_array[static_cast<uint8_t>(dayOfWeek)]);
} else if (monthInt == 10 && dayInt == 31) {
lv_label_set_text_fmt(label_date, "%s on Halloween", days_array[static_cast<uint8_t>(dayOfWeek)]);
} else if (monthInt == 12 && dayInt == 24) {
lv_label_set_text_fmt(label_date, "%s, Christmas Eve", days_array[static_cast<uint8_t>(dayOfWeek)]);
} else if (monthInt == 12 && dayInt == 25) {
lv_label_set_text_fmt(label_date, "%s, Christmas Day", days_array[static_cast<uint8_t>(dayOfWeek)]);
} else if (monthInt == 12 && dayInt == 26) {
lv_label_set_text_fmt(label_date, "%s, Boxing Day", days_array[static_cast<uint8_t>(dayOfWeek)]);
} else if (monthInt == 12 && dayInt == 31) {
lv_label_set_text_fmt(label_date, "%s, New Year's Eve", days_array[static_cast<uint8_t>(dayOfWeek)]);
} else {
lv_label_set_text_fmt(label_date,
"%s, %s of %s",
days_array[static_cast<uint8_t>(dayOfWeek)],
months_numbers_array[dayInt],
months_array[monthInt]);
}
lv_obj_align(label_date, lv_scr_act(), LV_ALIGN_CENTER, 0, 60);
}
}
}
heartbeat = heartRateController.HeartRate();
heartbeatRunning = heartRateController.State() != Controllers::HeartRateController::States::Stopped;
if (heartbeat.IsUpdated() || heartbeatRunning.IsUpdated()) {
if (heartbeatRunning.Get()) {
lv_obj_set_style_local_text_color(heartbeatIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0xCE1B1B));
lv_label_set_text_fmt(heartbeatValue, "%d", heartbeat.Get());
} else {
lv_obj_set_style_local_text_color(heartbeatIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x1B1B1B));
lv_label_set_text_static(heartbeatValue, "");
}
lv_obj_realign(heartbeatIcon);
lv_obj_realign(heartbeatValue);
}
stepCount = motionController.NbSteps();
if (stepCount.IsUpdated() || motionSensorOk.IsUpdated()) {
lv_label_set_text_fmt(stepValue, "%lu", stepCount.Get());
lv_obj_realign(stepValue);
lv_obj_realign(stepIcon);
}
}

View File

@ -0,0 +1,102 @@
#pragma once
#include <lvgl/src/lv_core/lv_obj.h>
#include <chrono>
#include <cstdint>
#include <memory>
#include "displayapp/screens/Screen.h"
#include "components/datetime/DateTimeController.h"
#include "components/ble/BleController.h"
#include "displayapp/widgets/StatusIcons.h"
#include "displayapp/apps/Apps.h"
#include "utility/DirtyValue.h"
namespace Pinetime {
namespace Controllers {
class Settings;
class Battery;
class Ble;
class NotificationManager;
class HeartRateController;
class MotionController;
}
namespace Applications {
namespace Screens {
class WatchFaceAccurateWords : public Screen {
public:
WatchFaceAccurateWords(Controllers::DateTime& dateTimeController,
const Controllers::Battery& batteryController,
const Controllers::Ble& bleController,
Controllers::NotificationManager& notificatioManager,
Controllers::Settings& settingsController,
Controllers::HeartRateController& heartRateController,
Controllers::MotionController& motionController);
~WatchFaceAccurateWords() override;
void Refresh() override;
private:
uint8_t displayedHour = -1;
uint8_t displayedMinute = -1;
uint16_t currentYear = 1970;
Controllers::DateTime::Months currentMonth = Pinetime::Controllers::DateTime::Months::Unknown;
Controllers::DateTime::Days currentDayOfWeek = Pinetime::Controllers::DateTime::Days::Unknown;
uint8_t currentDay = 0;
Utility::DirtyValue<uint8_t> batteryPercentRemaining {};
Utility::DirtyValue<bool> powerPresent {};
Utility::DirtyValue<bool> bleState {};
Utility::DirtyValue<bool> bleRadioEnabled {};
Utility::DirtyValue<std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds>> currentDateTime {};
Utility::DirtyValue<bool> motionSensorOk {};
Utility::DirtyValue<uint32_t> stepCount {};
Utility::DirtyValue<uint8_t> heartbeat {};
Utility::DirtyValue<bool> heartbeatRunning {};
Utility::DirtyValue<bool> notificationState {};
Utility::DirtyValue<std::chrono::time_point<std::chrono::system_clock, std::chrono::days>> currentDate;
lv_obj_t* label_time;
lv_obj_t* label_time_ampm;
lv_obj_t* label_date;
lv_obj_t* heartbeatIcon;
lv_obj_t* heartbeatValue;
lv_obj_t* stepIcon;
lv_obj_t* stepValue;
lv_obj_t* notificationIcon;
Controllers::DateTime& dateTimeController;
Controllers::NotificationManager& notificatioManager;
Controllers::Settings& settingsController;
Controllers::HeartRateController& heartRateController;
Controllers::MotionController& motionController;
lv_task_t* taskRefresh;
Widgets::StatusIcons statusIcons;
};
}
template <>
struct WatchFaceTraits<WatchFace::AccurateWords> {
static constexpr WatchFace watchFace = WatchFace::AccurateWords;
static constexpr const char* name = "AccurateWords";
static Screens::Screen* Create(AppControllers& controllers) {
return new Screens::WatchFaceAccurateWords (controllers.dateTimeController,
controllers.batteryController,
controllers.bleController,
controllers.notificationManager,
controllers.settingsController,
controllers.heartRateController,
controllers.motionController);
};
static bool IsAvailable(Pinetime::Controllers::FS& ) {
return true;
}
};
}
}