Skip to content

Commit

Permalink
t Merge branch 'main' of github.com:headblockhead/InfiniTime
Browse files Browse the repository at this point in the history
  • Loading branch information
headblockhead committed Oct 4, 2024
2 parents bc34111 + e84de3d commit f58c36a
Show file tree
Hide file tree
Showing 29 changed files with 537 additions and 292 deletions.
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,7 @@ list(APPEND SOURCE_FILES
displayapp/screens/settings/SettingTimeFormat.cpp
displayapp/screens/settings/SettingWeatherFormat.cpp
displayapp/screens/settings/SettingWakeUp.cpp
displayapp/screens/settings/SettingWidgets.cpp
displayapp/screens/settings/SettingDisplay.cpp
displayapp/screens/settings/SettingSteps.cpp
displayapp/screens/settings/SettingSetDateTime.cpp
Expand Down
2 changes: 2 additions & 0 deletions src/components/ble/MusicService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
#include "components/ble/MusicService.h"
#include "components/ble/NimbleController.h"
#include <cstring>
#include <FreeRTOS.h>
#include <task.h>

namespace {
// 0000yyxx-78fc-48fe-8e23-433b3a1942d0
Expand Down
1 change: 1 addition & 0 deletions src/components/ble/MusicService.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <host/ble_uuid.h>
#undef max
#undef min
#include <FreeRTOS.h>

namespace Pinetime {
namespace Controllers {
Expand Down
29 changes: 17 additions & 12 deletions src/components/settings/Settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ namespace Pinetime {
enum class Notification : uint8_t { On, Off, Sleep };
enum class ChimesOption : uint8_t { None, Hours, HalfHours };
enum class WakeUpMode : uint8_t { SingleTap = 0, DoubleTap = 1, RaiseWrist = 2, Shake = 3, LowerWrist = 4 };
enum class Widget : uint8_t { HeartRate = 0, Steps = 1, Weather = 2 };
enum class Colors : uint8_t {
White,
Silver,
Expand All @@ -35,14 +36,12 @@ namespace Pinetime {
Pink
};
enum class PTSGaugeStyle : uint8_t { Full, Half, Numeric };
enum class PTSWeather : uint8_t { On, Off };

struct PineTimeStyle {
Colors ColorTime = Colors::Teal;
Colors ColorBar = Colors::Teal;
Colors ColorBG = Colors::Black;
PTSGaugeStyle gaugeStyle = PTSGaugeStyle::Full;
PTSWeather weatherEnable = PTSWeather::Off;
};

struct WatchFaceInfineat {
Expand Down Expand Up @@ -144,16 +143,6 @@ namespace Pinetime {
return settings.PTS.gaugeStyle;
};

void SetPTSWeather(PTSWeather weatherEnable) {
if (weatherEnable != settings.PTS.weatherEnable)
settingsChanged = true;
settings.PTS.weatherEnable = weatherEnable;
};

PTSWeather GetPTSWeather() const {
return settings.PTS.weatherEnable;
};

void SetAppMenu(uint8_t menu) {
appMenu = menu;
};
Expand Down Expand Up @@ -192,6 +181,21 @@ namespace Pinetime {
return settings.weatherFormat;
};

void SetWidget(Widget widget, bool enabled) {
if (enabled != IsWidgetOn(widget)) {
settingsChanged = true;
}
settings.widgets.set(static_cast<size_t>(widget), enabled);
}

std::bitset<3> GetWidgets() const {
return settings.widgets;
}

bool IsWidgetOn(const Widget widget) const {
return GetWidgets()[static_cast<size_t>(widget)];
}

void SetNotificationStatus(Notification status) {
if (status != settings.notificationStatus) {
settingsChanged = true;
Expand Down Expand Up @@ -321,6 +325,7 @@ namespace Pinetime {

WatchFaceInfineat watchFaceInfineat;

std::bitset<3> widgets {0b111}; // Set all 3 widgets to enabled by default
std::bitset<5> wakeUpMode {0};
uint16_t shakeWakeThreshold = 150;

Expand Down
6 changes: 5 additions & 1 deletion src/displayapp/DisplayApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
#include "displayapp/screens/settings/SettingTimeFormat.h"
#include "displayapp/screens/settings/SettingWeatherFormat.h"
#include "displayapp/screens/settings/SettingWakeUp.h"
#include "displayapp/screens/settings/SettingWidgets.h"
#include "displayapp/screens/settings/SettingDisplay.h"
#include "displayapp/screens/settings/SettingSteps.h"
#include "displayapp/screens/settings/SettingSetDateTime.h"
Expand Down Expand Up @@ -600,8 +601,11 @@ void DisplayApp::LoadScreen(Apps app, DisplayApp::FullRefreshDirections directio
case Apps::SettingWakeUp:
currentScreen = std::make_unique<Screens::SettingWakeUp>(settingsController);
break;
case Apps::SettingWidgets:
currentScreen = std::make_unique<Screens::SettingWidgets>(settingsController);
break;
case Apps::SettingDisplay:
currentScreen = std::make_unique<Screens::SettingDisplay>(this, settingsController);
currentScreen = std::make_unique<Screens::SettingDisplay>(settingsController);
break;
case Apps::SettingSteps:
currentScreen = std::make_unique<Screens::SettingSteps>(settingsController);
Expand Down
1 change: 1 addition & 0 deletions src/displayapp/apps/Apps.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ namespace Pinetime {
SettingWeatherFormat,
SettingDisplay,
SettingWakeUp,
SettingWidgets,
SettingSteps,
SettingSetDateTime,
SettingChimes,
Expand Down
2 changes: 1 addition & 1 deletion src/displayapp/fonts/fonts.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
},
{
"file": "FontAwesome5-Solid+Brands+Regular.woff",
"range": "0xf294, 0xf242, 0xf54b, 0xf21e, 0xf1e6, 0xf017, 0xf129, 0xf03a, 0xf185, 0xf560, 0xf001, 0xf3fd, 0xf1fc, 0xf45d, 0xf59f, 0xf5a0, 0xf027, 0xf028, 0xf6a9, 0xf04b, 0xf04c, 0xf048, 0xf051, 0xf095, 0xf3dd, 0xf04d, 0xf2f2, 0xf024, 0xf252, 0xf569, 0xf06e, 0xf015, 0xf00c, 0xf0f3, 0xf522, 0xf743"
"range": "0xf294, 0xf242, 0xf54b, 0xf21e, 0xf1e6, 0xf017, 0xf129, 0xf03a, 0xf185, 0xf560, 0xf001, 0xf3fd, 0xf1fc, 0xf45d, 0xf59f, 0xf5a0, 0xf027, 0xf028, 0xf6a9, 0xf04b, 0xf04c, 0xf048, 0xf051, 0xf095, 0xf3dd, 0xf04d, 0xf2f2, 0xf024, 0xf252, 0xf569, 0xf06e, 0xf015, 0xf00c, 0xf0f3, 0xf522, 0xf743, 0xf0ad"
}
],
"bpp": 1,
Expand Down
15 changes: 6 additions & 9 deletions src/displayapp/screens/BatteryIcon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,12 @@ void BatteryIcon::SetBatteryPercentage(uint8_t percentage) {
lv_obj_set_height(batteryJuice, percentage * 14 / 100);
lv_obj_realign(batteryJuice);
if (colorOnLowBattery) {
static constexpr int lowBatteryThreshold = 15;
static constexpr int criticalBatteryThreshold = 5;
if (percentage > lowBatteryThreshold) {
SetColor(LV_COLOR_WHITE);
} else if (percentage > criticalBatteryThreshold) {
SetColor(LV_COLOR_ORANGE);
} else {
SetColor(Colors::deepOrange);
}
// HSV color model has red at 0° and green at 120°.
// We lock satuation and brightness at 100% and traverse the cilinder
// between red and green, thus avoiding the darker RGB on medium battery
// charges and giving us a much nicer color range.
uint8_t hue = percentage * 120 / 100;
SetColor(lv_color_hsv_to_rgb(hue, 100, 100));
}
}

Expand Down
18 changes: 16 additions & 2 deletions src/displayapp/screens/Notifications.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ Notifications::NotificationItem::NotificationItem(const char* title,
lv_label_set_text_fmt(alert_count, "%i/%i", notifNr, notifNb);
lv_obj_align(alert_count, nullptr, LV_ALIGN_IN_TOP_RIGHT, 0, 16);

lv_obj_t* alert_type = lv_label_create(container, nullptr);
alert_type = lv_label_create(container, nullptr);
lv_obj_set_style_local_text_color(alert_type, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, Colors::orange);
if (title == nullptr) {
lv_label_set_text_static(alert_type, "Notification");
Expand All @@ -299,7 +299,7 @@ Notifications::NotificationItem::NotificationItem(const char* title,
}
lv_label_refr_text(alert_type);
}
lv_label_set_long_mode(alert_type, LV_LABEL_LONG_SROLL_CIRC);
lv_label_set_long_mode(alert_type, LV_LABEL_LONG_CROP);
lv_obj_set_width(alert_type, 180);
lv_obj_align(alert_type, nullptr, LV_ALIGN_IN_TOP_LEFT, 0, 16);

Expand Down Expand Up @@ -349,6 +349,15 @@ Notifications::NotificationItem::NotificationItem(const char* title,
lv_obj_set_style_local_bg_color(bt_mute, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, Colors::lightGray);
} break;
}
refreshTask = lv_task_create(Notifications::NotificationItem::Refresh, 1000, LV_TASK_PRIO_MID, this);
//lv_task_once(refreshTask); // The documentation says it exists, but I was unable to compile
}

void Notifications::NotificationItem::Refresh(lv_task_t* tsk) {
static_cast<Notifications::NotificationItem*>(tsk->user_data)->StartTitleScroll();
lv_task_del(tsk); // This substitutes the call to lv_task_once
// This method can be updated in the future for implementing other features.
// For now it is executed one single time after 1 second and then deleted.
}

void Notifications::NotificationItem::OnCallButtonEvent(lv_obj_t* obj, lv_event_t event) {
Expand All @@ -371,4 +380,9 @@ void Notifications::NotificationItem::OnCallButtonEvent(lv_obj_t* obj, lv_event_

Notifications::NotificationItem::~NotificationItem() {
lv_obj_clean(lv_scr_act());
lv_task_del(refreshTask);
}

void Notifications::NotificationItem::StartTitleScroll(){
lv_label_set_long_mode(this->alert_type, LV_LABEL_LONG_SROLL_CIRC);
}
6 changes: 6 additions & 0 deletions src/displayapp/screens/Notifications.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ namespace Pinetime {
}

void OnCallButtonEvent(lv_obj_t*, lv_event_t event);
static void Refresh(lv_task_t* tsk);

private:
lv_obj_t* container;
Expand All @@ -63,6 +64,11 @@ namespace Pinetime {
lv_obj_t* label_accept;
lv_obj_t* label_mute;
lv_obj_t* label_reject;
lv_obj_t* alert_type;

void StartTitleScroll();
lv_task_t* refreshTask;

Pinetime::Controllers::AlertNotificationService& alertNotificationService;
Pinetime::Controllers::MotorController& motorController;

Expand Down
1 change: 1 addition & 0 deletions src/displayapp/screens/Symbols.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ namespace Pinetime {
static constexpr const char* eye = "\xEF\x81\xAE";
static constexpr const char* home = "\xEF\x80\x95";
static constexpr const char* sleep = "\xEE\xBD\x84";
static constexpr const char* wrench = "\xEF\x82\xAD";

// fontawesome_weathericons.c
// static constexpr const char* sun = "\xEF\x86\x85";
Expand Down
3 changes: 1 addition & 2 deletions src/displayapp/screens/SystemInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ SystemInfo::SystemInfo(Pinetime::Applications::DisplayApp* app,
Pinetime::Controllers::MotionController& motionController,
const Pinetime::Drivers::Cst816S& touchPanel,
const Pinetime::Drivers::SpiNorFlash& spiNorFlash)
: app {app},
dateTimeController {dateTimeController},
: dateTimeController {dateTimeController},
batteryController {batteryController},
brightnessController {brightnessController},
bleController {bleController},
Expand Down
1 change: 0 additions & 1 deletion src/displayapp/screens/SystemInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ namespace Pinetime {
bool OnTouchEvent(TouchEvents event) override;

private:
DisplayApp* app;
Pinetime::Controllers::DateTime& dateTimeController;
const Pinetime::Controllers::Battery& batteryController;
Pinetime::Controllers::BrightnessController& brightnessController;
Expand Down
101 changes: 98 additions & 3 deletions src/displayapp/screens/WatchFaceAnalog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
#include "displayapp/screens/BleIcon.h"
#include "displayapp/screens/Symbols.h"
#include "displayapp/screens/NotificationIcon.h"
#include "displayapp/screens/WeatherSymbols.h"
#include "components/ble/SimpleWeatherService.h"
#include "components/heartrate/HeartRateController.h"
#include "components/motion/MotionController.h"
#include "components/settings/Settings.h"
#include "displayapp/InfiniTimeTheme.h"

Expand Down Expand Up @@ -45,14 +49,20 @@ WatchFaceAnalog::WatchFaceAnalog(Controllers::DateTime& dateTimeController,
const Controllers::Battery& batteryController,
const Controllers::Ble& bleController,
Controllers::NotificationManager& notificationManager,
Controllers::Settings& settingsController)
Controllers::Settings& settingsController,
Controllers::HeartRateController& heartRateController,
Controllers::MotionController& motionController,
Controllers::SimpleWeatherService& weatherService)
: currentDateTime {{}},
batteryIcon(true),
dateTimeController {dateTimeController},
batteryController {batteryController},
bleController {bleController},
notificationManager {notificationManager},
settingsController {settingsController} {
settingsController {settingsController},
heartRateController {heartRateController},
motionController {motionController},
weatherService {weatherService} {

sHour = 99;
sMinute = 99;
Expand Down Expand Up @@ -111,13 +121,25 @@ WatchFaceAnalog::WatchFaceAnalog(Controllers::DateTime& dateTimeController,
lv_obj_align(notificationIcon, nullptr, LV_ALIGN_IN_TOP_LEFT, 0, 0);

// Date - Day / Week day

label_date_day = lv_label_create(lv_scr_act(), nullptr);
lv_obj_set_style_local_text_color(label_date_day, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, Colors::orange);
lv_label_set_text_fmt(label_date_day, "%s\n%02i", dateTimeController.DayOfWeekShortToString(), dateTimeController.Day());
lv_label_set_align(label_date_day, LV_LABEL_ALIGN_CENTER);
lv_obj_align(label_date_day, nullptr, LV_ALIGN_CENTER, 50, 0);

if (settingsController.IsWidgetOn(Pinetime::Controllers::Settings::Widget::Weather)) {
weatherIcon = lv_label_create(lv_scr_act(), nullptr);
lv_obj_set_style_local_text_color(weatherIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, Colors::lightGray);
lv_obj_set_style_local_text_font(weatherIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &fontawesome_weathericons);
lv_label_set_text(weatherIcon, "");
lv_obj_align(weatherIcon, nullptr, LV_ALIGN_CENTER, -50, -12);

temperature = lv_label_create(lv_scr_act(), nullptr);
lv_obj_set_style_local_text_color(temperature, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, Colors::lightGray);
lv_label_set_text(temperature, "");
lv_obj_align(temperature, nullptr, LV_ALIGN_CENTER, -50, 12);
}

minute_body = lv_line_create(lv_scr_act(), nullptr);
minute_body_trace = lv_line_create(lv_scr_act(), nullptr);
hour_body = lv_line_create(lv_scr_act(), nullptr);
Expand Down Expand Up @@ -154,6 +176,30 @@ WatchFaceAnalog::WatchFaceAnalog(Controllers::DateTime& dateTimeController,
lv_style_set_line_rounded(&hour_line_style_trace, LV_STATE_DEFAULT, false);
lv_obj_add_style(hour_body_trace, LV_LINE_PART_MAIN, &hour_line_style_trace);

if (settingsController.IsWidgetOn(Pinetime::Controllers::Settings::Widget::HeartRate)) {
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);
}

if (settingsController.IsWidgetOn(Pinetime::Controllers::Settings::Widget::Steps)) {
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();
Expand Down Expand Up @@ -261,4 +307,53 @@ void WatchFaceAnalog::Refresh() {
lv_label_set_text_fmt(label_date_day, "%s\n%02i", dateTimeController.DayOfWeekShortToString(), dateTimeController.Day());
}
}

if (settingsController.IsWidgetOn(Pinetime::Controllers::Settings::Widget::HeartRate)) {
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);
}
}

if (settingsController.IsWidgetOn(Pinetime::Controllers::Settings::Widget::Steps)) {
stepCount = motionController.NbSteps();
if (stepCount.IsUpdated()) {
lv_label_set_text_fmt(stepValue, "%lu", stepCount.Get());
lv_obj_realign(stepValue);
lv_obj_realign(stepIcon);
}
}

if (settingsController.IsWidgetOn(Pinetime::Controllers::Settings::Widget::Weather)) {
currentWeather = weatherService.Current();
if (currentWeather.IsUpdated()) {
auto optCurrentWeather = currentWeather.Get();
if (optCurrentWeather) {
int16_t temp = optCurrentWeather->temperature;
char tempUnit = 'C';
if (settingsController.GetWeatherFormat() == Controllers::Settings::WeatherFormat::Imperial) {
temp = Controllers::SimpleWeatherService::CelsiusToFahrenheit(temp);
tempUnit = 'F';
}
temp = temp / 100 + (temp % 100 >= 50 ? 1 : 0);
lv_label_set_text_fmt(temperature, "%d°%c", temp, tempUnit);
lv_label_set_text(weatherIcon, Symbols::GetSymbol(optCurrentWeather->iconId));
} else {
lv_label_set_text_static(temperature, "");
lv_label_set_text(weatherIcon, "");
}
lv_obj_realign(temperature);
lv_obj_realign(weatherIcon);
}
}
}
Loading

0 comments on commit f58c36a

Please sign in to comment.