Merge branch 'develop' into infineat-external-resources
# Conflicts: # src/displayapp/screens/Symbols.h # src/displayapp/screens/settings/SettingWatchFace.cpp # src/displayapp/screens/settings/SettingWatchFace.h
This commit is contained in:
@@ -2,19 +2,29 @@
|
||||
#include "displayapp/DisplayApp.h"
|
||||
#include "displayapp/screens/Symbols.h"
|
||||
#include "displayapp/screens/BatteryIcon.h"
|
||||
#include "components/ble/BleController.h"
|
||||
#include "displayapp/InfiniTimeTheme.h"
|
||||
|
||||
using namespace Pinetime::Applications::Screens;
|
||||
|
||||
namespace {
|
||||
void ButtonEventHandler(lv_obj_t* obj, lv_event_t event) {
|
||||
auto* screen = static_cast<QuickSettings*>(obj->user_data);
|
||||
screen->OnButtonEvent(obj, event);
|
||||
if (event == LV_EVENT_CLICKED) {
|
||||
screen->OnButtonEvent(obj);
|
||||
}
|
||||
}
|
||||
|
||||
void lv_update_task(struct _lv_task_t* task) {
|
||||
auto* user_data = static_cast<QuickSettings*>(task->user_data);
|
||||
user_data->UpdateScreen();
|
||||
}
|
||||
|
||||
enum class ButtonState : lv_state_t {
|
||||
NotificationsOn = LV_STATE_CHECKED,
|
||||
NotificationsOff = LV_STATE_DEFAULT,
|
||||
Sleep = 0x40,
|
||||
};
|
||||
}
|
||||
|
||||
QuickSettings::QuickSettings(Pinetime::Applications::DisplayApp* app,
|
||||
@@ -22,13 +32,16 @@ QuickSettings::QuickSettings(Pinetime::Applications::DisplayApp* app,
|
||||
Controllers::DateTime& dateTimeController,
|
||||
Controllers::BrightnessController& brightness,
|
||||
Controllers::MotorController& motorController,
|
||||
Pinetime::Controllers::Settings& settingsController)
|
||||
Pinetime::Controllers::Settings& settingsController,
|
||||
Controllers::Ble& bleController)
|
||||
: Screen(app),
|
||||
batteryController {batteryController},
|
||||
dateTimeController {dateTimeController},
|
||||
brightness {brightness},
|
||||
motorController {motorController},
|
||||
settingsController {settingsController} {
|
||||
settingsController {settingsController},
|
||||
statusIcons(batteryController, bleController) {
|
||||
|
||||
statusIcons.Create();
|
||||
|
||||
// This is the distance (padding) between all objects on this screen.
|
||||
static constexpr uint8_t innerDistance = 10;
|
||||
@@ -38,9 +51,6 @@ QuickSettings::QuickSettings(Pinetime::Applications::DisplayApp* app,
|
||||
lv_label_set_align(label_time, LV_LABEL_ALIGN_CENTER);
|
||||
lv_obj_align(label_time, lv_scr_act(), LV_ALIGN_IN_TOP_LEFT, 0, 0);
|
||||
|
||||
batteryIcon.Create(lv_scr_act());
|
||||
lv_obj_align(batteryIcon.GetObject(), nullptr, LV_ALIGN_IN_TOP_RIGHT, 0, 0);
|
||||
|
||||
static constexpr uint8_t barHeight = 20 + innerDistance;
|
||||
static constexpr uint8_t buttonHeight = (LV_VER_RES_MAX - barHeight - innerDistance) / 2;
|
||||
static constexpr uint8_t buttonWidth = (LV_HOR_RES_MAX - innerDistance) / 2; // wide buttons
|
||||
@@ -49,7 +59,7 @@ QuickSettings::QuickSettings(Pinetime::Applications::DisplayApp* app,
|
||||
|
||||
lv_style_init(&btn_style);
|
||||
lv_style_set_radius(&btn_style, LV_STATE_DEFAULT, buttonHeight / 4);
|
||||
lv_style_set_bg_color(&btn_style, LV_STATE_DEFAULT, LV_COLOR_MAKE(0x38, 0x38, 0x38));
|
||||
lv_style_set_bg_color(&btn_style, LV_STATE_DEFAULT, Colors::bgAlt);
|
||||
|
||||
btn1 = lv_btn_create(lv_scr_act(), nullptr);
|
||||
btn1->user_data = this;
|
||||
@@ -72,25 +82,29 @@ QuickSettings::QuickSettings(Pinetime::Applications::DisplayApp* app,
|
||||
lv_obj_t* lbl_btn;
|
||||
lbl_btn = lv_label_create(btn2, nullptr);
|
||||
lv_obj_set_style_local_text_font(lbl_btn, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &lv_font_sys_48);
|
||||
lv_label_set_text_static(lbl_btn, Symbols::highlight);
|
||||
lv_label_set_text_static(lbl_btn, Symbols::flashlight);
|
||||
|
||||
btn3 = lv_btn_create(lv_scr_act(), nullptr);
|
||||
btn3->user_data = this;
|
||||
lv_obj_set_event_cb(btn3, ButtonEventHandler);
|
||||
lv_btn_set_checkable(btn3, true);
|
||||
lv_obj_add_style(btn3, LV_BTN_PART_MAIN, &btn_style);
|
||||
lv_obj_set_style_local_bg_color(btn3, LV_BTN_PART_MAIN, LV_STATE_CHECKED, LV_COLOR_MAKE(0x0, 0xb0, 0x0));
|
||||
lv_obj_set_style_local_bg_color(btn3, LV_BTN_PART_MAIN, static_cast<lv_state_t>(ButtonState::NotificationsOff), LV_COLOR_RED);
|
||||
static constexpr lv_color_t violet = LV_COLOR_MAKE(0x60, 0x00, 0xff);
|
||||
lv_obj_set_style_local_bg_color(btn3, LV_BTN_PART_MAIN, static_cast<lv_state_t>(ButtonState::Sleep), violet);
|
||||
lv_obj_set_size(btn3, buttonWidth, buttonHeight);
|
||||
lv_obj_align(btn3, nullptr, LV_ALIGN_IN_BOTTOM_LEFT, buttonXOffset, 0);
|
||||
|
||||
btn3_lvl = lv_label_create(btn3, nullptr);
|
||||
lv_obj_set_style_local_text_font(btn3_lvl, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &lv_font_sys_48);
|
||||
|
||||
if (settingsController.GetNotificationStatus() == Controllers::Settings::Notification::ON) {
|
||||
lv_obj_add_state(btn3, LV_STATE_CHECKED);
|
||||
if (settingsController.GetNotificationStatus() == Controllers::Settings::Notification::On) {
|
||||
lv_label_set_text_static(btn3_lvl, Symbols::notificationsOn);
|
||||
} else {
|
||||
lv_obj_set_state(btn3, static_cast<lv_state_t>(ButtonState::NotificationsOn));
|
||||
} else if (settingsController.GetNotificationStatus() == Controllers::Settings::Notification::Off) {
|
||||
lv_label_set_text_static(btn3_lvl, Symbols::notificationsOff);
|
||||
} else {
|
||||
lv_label_set_text_static(btn3_lvl, Symbols::sleep);
|
||||
lv_obj_set_state(btn3, static_cast<lv_state_t>(ButtonState::Sleep));
|
||||
}
|
||||
|
||||
btn4 = lv_btn_create(lv_scr_act(), nullptr);
|
||||
@@ -118,34 +132,36 @@ QuickSettings::~QuickSettings() {
|
||||
|
||||
void QuickSettings::UpdateScreen() {
|
||||
lv_label_set_text(label_time, dateTimeController.FormattedTime().c_str());
|
||||
batteryIcon.SetBatteryPercentage(batteryController.PercentRemaining());
|
||||
statusIcons.Update();
|
||||
}
|
||||
|
||||
void QuickSettings::OnButtonEvent(lv_obj_t* object, lv_event_t event) {
|
||||
if (object == btn2 && event == LV_EVENT_CLICKED) {
|
||||
|
||||
running = false;
|
||||
void QuickSettings::OnButtonEvent(lv_obj_t* object) {
|
||||
if (object == btn2) {
|
||||
app->StartApp(Apps::FlashLight, DisplayApp::FullRefreshDirections::Up);
|
||||
|
||||
} else if (object == btn1 && event == LV_EVENT_CLICKED) {
|
||||
} else if (object == btn1) {
|
||||
|
||||
brightness.Step();
|
||||
lv_label_set_text_static(btn1_lvl, brightness.GetIcon());
|
||||
settingsController.SetBrightness(brightness.Level());
|
||||
|
||||
} else if (object == btn3 && event == LV_EVENT_VALUE_CHANGED) {
|
||||
} else if (object == btn3) {
|
||||
|
||||
if (lv_obj_get_state(btn3, LV_BTN_PART_MAIN) & LV_STATE_CHECKED) {
|
||||
settingsController.SetNotificationStatus(Controllers::Settings::Notification::ON);
|
||||
motorController.RunForDuration(35);
|
||||
lv_label_set_text_static(btn3_lvl, Symbols::notificationsOn);
|
||||
} else {
|
||||
settingsController.SetNotificationStatus(Controllers::Settings::Notification::OFF);
|
||||
if (settingsController.GetNotificationStatus() == Controllers::Settings::Notification::On) {
|
||||
settingsController.SetNotificationStatus(Controllers::Settings::Notification::Off);
|
||||
lv_label_set_text_static(btn3_lvl, Symbols::notificationsOff);
|
||||
lv_obj_set_state(btn3, static_cast<lv_state_t>(ButtonState::NotificationsOff));
|
||||
} else if (settingsController.GetNotificationStatus() == Controllers::Settings::Notification::Off) {
|
||||
settingsController.SetNotificationStatus(Controllers::Settings::Notification::Sleep);
|
||||
lv_label_set_text_static(btn3_lvl, Symbols::sleep);
|
||||
lv_obj_set_state(btn3, static_cast<lv_state_t>(ButtonState::Sleep));
|
||||
} else {
|
||||
settingsController.SetNotificationStatus(Controllers::Settings::Notification::On);
|
||||
lv_label_set_text_static(btn3_lvl, Symbols::notificationsOn);
|
||||
lv_obj_set_state(btn3, static_cast<lv_state_t>(ButtonState::NotificationsOn));
|
||||
motorController.RunForDuration(35);
|
||||
}
|
||||
|
||||
} else if (object == btn4 && event == LV_EVENT_CLICKED) {
|
||||
running = false;
|
||||
} else if (object == btn4) {
|
||||
settingsController.SetSettingsMenu(0);
|
||||
app->StartApp(Apps::Settings, DisplayApp::FullRefreshDirections::Up);
|
||||
}
|
||||
|
@@ -8,7 +8,7 @@
|
||||
#include "components/motor/MotorController.h"
|
||||
#include "components/settings/Settings.h"
|
||||
#include "components/battery/BatteryController.h"
|
||||
#include <displayapp/screens/BatteryIcon.h>
|
||||
#include "displayapp/widgets/StatusIcons.h"
|
||||
|
||||
namespace Pinetime {
|
||||
|
||||
@@ -22,16 +22,16 @@ namespace Pinetime {
|
||||
Controllers::DateTime& dateTimeController,
|
||||
Controllers::BrightnessController& brightness,
|
||||
Controllers::MotorController& motorController,
|
||||
Pinetime::Controllers::Settings& settingsController);
|
||||
Pinetime::Controllers::Settings& settingsController,
|
||||
Controllers::Ble& bleController);
|
||||
|
||||
~QuickSettings() override;
|
||||
|
||||
void OnButtonEvent(lv_obj_t* object, lv_event_t event);
|
||||
void OnButtonEvent(lv_obj_t* object);
|
||||
|
||||
void UpdateScreen();
|
||||
|
||||
private:
|
||||
Pinetime::Controllers::Battery& batteryController;
|
||||
Controllers::DateTime& dateTimeController;
|
||||
Controllers::BrightnessController& brightness;
|
||||
Controllers::MotorController& motorController;
|
||||
@@ -49,7 +49,7 @@ namespace Pinetime {
|
||||
lv_obj_t* btn3_lvl;
|
||||
lv_obj_t* btn4;
|
||||
|
||||
BatteryIcon batteryIcon;
|
||||
Widgets::StatusIcons statusIcons;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@@ -14,6 +14,8 @@ namespace {
|
||||
}
|
||||
}
|
||||
|
||||
constexpr std::array<SettingChimes::Option, 3> SettingChimes::options;
|
||||
|
||||
SettingChimes::SettingChimes(Pinetime::Applications::DisplayApp* app, Pinetime::Controllers::Settings& settingsController)
|
||||
: Screen(app), settingsController {settingsController} {
|
||||
|
||||
@@ -40,37 +42,16 @@ SettingChimes::SettingChimes(Pinetime::Applications::DisplayApp* app, Pinetime::
|
||||
lv_label_set_align(icon, LV_LABEL_ALIGN_CENTER);
|
||||
lv_obj_align(icon, title, LV_ALIGN_OUT_LEFT_MID, -10, 0);
|
||||
|
||||
optionsTotal = 0;
|
||||
cbOption[optionsTotal] = lv_checkbox_create(container1, nullptr);
|
||||
lv_checkbox_set_text_static(cbOption[optionsTotal], " Off");
|
||||
cbOption[optionsTotal]->user_data = this;
|
||||
lv_obj_set_event_cb(cbOption[optionsTotal], event_handler);
|
||||
SetRadioButtonStyle(cbOption[optionsTotal]);
|
||||
if (settingsController.GetChimeOption() == Controllers::Settings::ChimesOption::None) {
|
||||
lv_checkbox_set_checked(cbOption[optionsTotal], true);
|
||||
for (unsigned int i = 0; i < options.size(); i++) {
|
||||
cbOption[i] = lv_checkbox_create(container1, nullptr);
|
||||
lv_checkbox_set_text(cbOption[i], options[i].name);
|
||||
if (settingsController.GetChimeOption() == options[i].chimesOption) {
|
||||
lv_checkbox_set_checked(cbOption[i], true);
|
||||
}
|
||||
cbOption[i]->user_data = this;
|
||||
lv_obj_set_event_cb(cbOption[i], event_handler);
|
||||
SetRadioButtonStyle(cbOption[i]);
|
||||
}
|
||||
|
||||
optionsTotal++;
|
||||
cbOption[optionsTotal] = lv_checkbox_create(container1, nullptr);
|
||||
lv_checkbox_set_text_static(cbOption[optionsTotal], " Every hour");
|
||||
cbOption[optionsTotal]->user_data = this;
|
||||
lv_obj_set_event_cb(cbOption[optionsTotal], event_handler);
|
||||
SetRadioButtonStyle(cbOption[optionsTotal]);
|
||||
if (settingsController.GetChimeOption() == Controllers::Settings::ChimesOption::Hours) {
|
||||
lv_checkbox_set_checked(cbOption[optionsTotal], true);
|
||||
}
|
||||
|
||||
optionsTotal++;
|
||||
cbOption[optionsTotal] = lv_checkbox_create(container1, nullptr);
|
||||
lv_checkbox_set_text_static(cbOption[optionsTotal], " Every 30 mins");
|
||||
cbOption[optionsTotal]->user_data = this;
|
||||
lv_obj_set_event_cb(cbOption[optionsTotal], event_handler);
|
||||
SetRadioButtonStyle(cbOption[optionsTotal]);
|
||||
if (settingsController.GetChimeOption() == Controllers::Settings::ChimesOption::HalfHours) {
|
||||
lv_checkbox_set_checked(cbOption[optionsTotal], true);
|
||||
}
|
||||
|
||||
optionsTotal++;
|
||||
}
|
||||
|
||||
SettingChimes::~SettingChimes() {
|
||||
@@ -80,18 +61,10 @@ SettingChimes::~SettingChimes() {
|
||||
|
||||
void SettingChimes::UpdateSelected(lv_obj_t* object, lv_event_t event) {
|
||||
if (event == LV_EVENT_VALUE_CHANGED) {
|
||||
for (uint8_t i = 0; i < optionsTotal; i++) {
|
||||
for (uint8_t i = 0; i < options.size(); i++) {
|
||||
if (object == cbOption[i]) {
|
||||
lv_checkbox_set_checked(cbOption[i], true);
|
||||
if (i == 0) {
|
||||
settingsController.SetChimeOption(Controllers::Settings::ChimesOption::None);
|
||||
}
|
||||
if (i == 1) {
|
||||
settingsController.SetChimeOption(Controllers::Settings::ChimesOption::Hours);
|
||||
}
|
||||
if (i == 2) {
|
||||
settingsController.SetChimeOption(Controllers::Settings::ChimesOption::HalfHours);
|
||||
}
|
||||
settingsController.SetChimeOption(options[i].chimesOption);
|
||||
} else {
|
||||
lv_checkbox_set_checked(cbOption[i], false);
|
||||
}
|
||||
|
@@ -4,6 +4,7 @@
|
||||
#include <lvgl/lvgl.h>
|
||||
#include "components/settings/Settings.h"
|
||||
#include "displayapp/screens/Screen.h"
|
||||
#include <array>
|
||||
|
||||
namespace Pinetime {
|
||||
|
||||
@@ -18,9 +19,19 @@ namespace Pinetime {
|
||||
void UpdateSelected(lv_obj_t* object, lv_event_t event);
|
||||
|
||||
private:
|
||||
struct Option {
|
||||
Controllers::Settings::ChimesOption chimesOption;
|
||||
const char* name;
|
||||
};
|
||||
static constexpr std::array<Option, 3> options = {{
|
||||
{Controllers::Settings::ChimesOption::None, " Off"},
|
||||
{Controllers::Settings::ChimesOption::Hours, " Every hour"},
|
||||
{Controllers::Settings::ChimesOption::HalfHours, " Every 30 mins"}
|
||||
}};
|
||||
|
||||
std::array<lv_obj_t*, options.size()> cbOption;
|
||||
|
||||
Controllers::Settings& settingsController;
|
||||
uint8_t optionsTotal;
|
||||
lv_obj_t* cbOption[3];
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@@ -15,7 +15,7 @@ namespace {
|
||||
}
|
||||
}
|
||||
|
||||
constexpr std::array<uint16_t, 4> SettingDisplay::options;
|
||||
constexpr std::array<uint16_t, 6> SettingDisplay::options;
|
||||
|
||||
SettingDisplay::SettingDisplay(Pinetime::Applications::DisplayApp* app, Pinetime::Controllers::Settings& settingsController)
|
||||
: Screen(app), settingsController {settingsController} {
|
||||
@@ -30,7 +30,7 @@ SettingDisplay::SettingDisplay(Pinetime::Applications::DisplayApp* app, Pinetime
|
||||
lv_obj_set_pos(container1, 10, 60);
|
||||
lv_obj_set_width(container1, LV_HOR_RES - 20);
|
||||
lv_obj_set_height(container1, LV_VER_RES - 50);
|
||||
lv_cont_set_layout(container1, LV_LAYOUT_COLUMN_LEFT);
|
||||
lv_cont_set_layout(container1, LV_LAYOUT_PRETTY_TOP);
|
||||
|
||||
lv_obj_t* title = lv_label_create(lv_scr_act(), nullptr);
|
||||
lv_label_set_text_static(title, "Display timeout");
|
||||
@@ -46,7 +46,7 @@ SettingDisplay::SettingDisplay(Pinetime::Applications::DisplayApp* app, Pinetime
|
||||
char buffer[12];
|
||||
for (unsigned int i = 0; i < options.size(); i++) {
|
||||
cbOption[i] = lv_checkbox_create(container1, nullptr);
|
||||
sprintf(buffer, "%3d seconds", options[i] / 1000);
|
||||
sprintf(buffer, "%2ds", options[i] / 1000);
|
||||
lv_checkbox_set_text(cbOption[i], buffer);
|
||||
cbOption[i]->user_data = this;
|
||||
lv_obj_set_event_cb(cbOption[i], event_handler);
|
||||
|
@@ -20,7 +20,7 @@ namespace Pinetime {
|
||||
void UpdateSelected(lv_obj_t* object, lv_event_t event);
|
||||
|
||||
private:
|
||||
static constexpr std::array<uint16_t, 4> options = {5000, 15000, 20000, 30000};
|
||||
static constexpr std::array<uint16_t, 6> options = {5000, 7000, 10000, 15000, 20000, 30000};
|
||||
|
||||
Controllers::Settings& settingsController;
|
||||
lv_obj_t* cbOption[options.size()];
|
||||
|
@@ -11,13 +11,36 @@ namespace {
|
||||
constexpr int16_t POS_X_DAY = -72;
|
||||
constexpr int16_t POS_X_MONTH = 0;
|
||||
constexpr int16_t POS_X_YEAR = 72;
|
||||
constexpr int16_t POS_Y_PLUS = -50;
|
||||
constexpr int16_t POS_Y_TEXT = -6;
|
||||
constexpr int16_t POS_Y_MINUS = 40;
|
||||
|
||||
void event_handler(lv_obj_t* obj, lv_event_t event) {
|
||||
auto* screen = static_cast<SettingSetDate*>(obj->user_data);
|
||||
screen->HandleButtonPress(obj, event);
|
||||
if (event == LV_EVENT_CLICKED) {
|
||||
screen->HandleButtonPress();
|
||||
}
|
||||
}
|
||||
|
||||
void ValueChangedHandler(void* userData) {
|
||||
auto* screen = static_cast<SettingSetDate*>(userData);
|
||||
screen->CheckDay();
|
||||
}
|
||||
|
||||
int MaximumDayOfMonth(uint8_t month, uint16_t year) {
|
||||
switch (month) {
|
||||
case 2: {
|
||||
if ((((year % 4) == 0) && ((year % 100) != 0)) || ((year % 400) == 0)) {
|
||||
return 29;
|
||||
}
|
||||
return 28;
|
||||
}
|
||||
case 4:
|
||||
case 6:
|
||||
case 9:
|
||||
case 11:
|
||||
return 30;
|
||||
default:
|
||||
return 31;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,164 +58,54 @@ SettingSetDate::SettingSetDate(Pinetime::Applications::DisplayApp* app, Pinetime
|
||||
lv_label_set_align(icon, LV_LABEL_ALIGN_CENTER);
|
||||
lv_obj_align(icon, title, LV_ALIGN_OUT_LEFT_MID, -10, 0);
|
||||
|
||||
dayValue = static_cast<int>(dateTimeController.Day());
|
||||
lblDay = lv_label_create(lv_scr_act(), nullptr);
|
||||
lv_label_set_text_fmt(lblDay, "%d", dayValue);
|
||||
lv_label_set_align(lblDay, LV_LABEL_ALIGN_CENTER);
|
||||
lv_obj_align(lblDay, lv_scr_act(), LV_ALIGN_CENTER, POS_X_DAY, POS_Y_TEXT);
|
||||
lv_obj_set_auto_realign(lblDay, true);
|
||||
dayCounter.SetValueChangedEventCallback(this, ValueChangedHandler);
|
||||
dayCounter.Create();
|
||||
dayCounter.SetValue(dateTimeController.Day());
|
||||
lv_obj_align(dayCounter.GetObject(), nullptr, LV_ALIGN_CENTER, POS_X_DAY, POS_Y_TEXT);
|
||||
|
||||
monthValue = static_cast<int>(dateTimeController.Month());
|
||||
lblMonth = lv_label_create(lv_scr_act(), nullptr);
|
||||
UpdateMonthLabel();
|
||||
lv_label_set_align(lblMonth, LV_LABEL_ALIGN_CENTER);
|
||||
lv_obj_align(lblMonth, lv_scr_act(), LV_ALIGN_CENTER, POS_X_MONTH, POS_Y_TEXT);
|
||||
lv_obj_set_auto_realign(lblMonth, true);
|
||||
monthCounter.EnableMonthMode();
|
||||
monthCounter.SetValueChangedEventCallback(this, ValueChangedHandler);
|
||||
monthCounter.Create();
|
||||
monthCounter.SetValue(static_cast<int>(dateTimeController.Month()));
|
||||
lv_obj_align(monthCounter.GetObject(), nullptr, LV_ALIGN_CENTER, POS_X_MONTH, POS_Y_TEXT);
|
||||
|
||||
yearValue = static_cast<int>(dateTimeController.Year());
|
||||
if (yearValue < 2021)
|
||||
yearValue = 2021;
|
||||
lblYear = lv_label_create(lv_scr_act(), nullptr);
|
||||
lv_label_set_text_fmt(lblYear, "%d", yearValue);
|
||||
lv_label_set_align(lblYear, LV_LABEL_ALIGN_CENTER);
|
||||
lv_obj_align(lblYear, lv_scr_act(), LV_ALIGN_CENTER, POS_X_YEAR, POS_Y_TEXT);
|
||||
lv_obj_set_auto_realign(lblYear, true);
|
||||
|
||||
btnDayPlus = lv_btn_create(lv_scr_act(), nullptr);
|
||||
btnDayPlus->user_data = this;
|
||||
lv_obj_set_size(btnDayPlus, 50, 40);
|
||||
lv_obj_align(btnDayPlus, lv_scr_act(), LV_ALIGN_CENTER, POS_X_DAY, POS_Y_PLUS);
|
||||
lv_obj_set_style_local_value_str(btnDayPlus, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, "+");
|
||||
lv_obj_set_event_cb(btnDayPlus, event_handler);
|
||||
|
||||
btnDayMinus = lv_btn_create(lv_scr_act(), nullptr);
|
||||
btnDayMinus->user_data = this;
|
||||
lv_obj_set_size(btnDayMinus, 50, 40);
|
||||
lv_obj_align(btnDayMinus, lv_scr_act(), LV_ALIGN_CENTER, POS_X_DAY, POS_Y_MINUS);
|
||||
lv_obj_set_style_local_value_str(btnDayMinus, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, "-");
|
||||
lv_obj_set_event_cb(btnDayMinus, event_handler);
|
||||
|
||||
btnMonthPlus = lv_btn_create(lv_scr_act(), nullptr);
|
||||
btnMonthPlus->user_data = this;
|
||||
lv_obj_set_size(btnMonthPlus, 50, 40);
|
||||
lv_obj_align(btnMonthPlus, lv_scr_act(), LV_ALIGN_CENTER, POS_X_MONTH, POS_Y_PLUS);
|
||||
lv_obj_set_style_local_value_str(btnMonthPlus, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, "+");
|
||||
lv_obj_set_event_cb(btnMonthPlus, event_handler);
|
||||
|
||||
btnMonthMinus = lv_btn_create(lv_scr_act(), nullptr);
|
||||
btnMonthMinus->user_data = this;
|
||||
lv_obj_set_size(btnMonthMinus, 50, 40);
|
||||
lv_obj_align(btnMonthMinus, lv_scr_act(), LV_ALIGN_CENTER, POS_X_MONTH, POS_Y_MINUS);
|
||||
lv_obj_set_style_local_value_str(btnMonthMinus, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, "-");
|
||||
lv_obj_set_event_cb(btnMonthMinus, event_handler);
|
||||
|
||||
btnYearPlus = lv_btn_create(lv_scr_act(), nullptr);
|
||||
btnYearPlus->user_data = this;
|
||||
lv_obj_set_size(btnYearPlus, 50, 40);
|
||||
lv_obj_align(btnYearPlus, lv_scr_act(), LV_ALIGN_CENTER, POS_X_YEAR, POS_Y_PLUS);
|
||||
lv_obj_set_style_local_value_str(btnYearPlus, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, "+");
|
||||
lv_obj_set_event_cb(btnYearPlus, event_handler);
|
||||
|
||||
btnYearMinus = lv_btn_create(lv_scr_act(), nullptr);
|
||||
btnYearMinus->user_data = this;
|
||||
lv_obj_set_size(btnYearMinus, 50, 40);
|
||||
lv_obj_align(btnYearMinus, lv_scr_act(), LV_ALIGN_CENTER, POS_X_YEAR, POS_Y_MINUS);
|
||||
lv_obj_set_style_local_value_str(btnYearMinus, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, "-");
|
||||
lv_obj_set_event_cb(btnYearMinus, event_handler);
|
||||
yearCounter.SetValueChangedEventCallback(this, ValueChangedHandler);
|
||||
yearCounter.Create();
|
||||
yearCounter.SetValue(dateTimeController.Year());
|
||||
lv_obj_align(yearCounter.GetObject(), nullptr, LV_ALIGN_CENTER, POS_X_YEAR, POS_Y_TEXT);
|
||||
|
||||
btnSetTime = lv_btn_create(lv_scr_act(), nullptr);
|
||||
btnSetTime->user_data = this;
|
||||
lv_obj_set_size(btnSetTime, 120, 48);
|
||||
lv_obj_align(btnSetTime, lv_scr_act(), LV_ALIGN_IN_BOTTOM_MID, 0, 0);
|
||||
lv_obj_set_style_local_bg_color(btnSetTime, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_MAKE(0x38, 0x38, 0x38));
|
||||
lv_obj_set_style_local_value_str(btnSetTime, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, "Set");
|
||||
lv_obj_set_event_cb(btnSetTime, event_handler);
|
||||
lv_btn_set_state(btnSetTime, LV_BTN_STATE_DISABLED);
|
||||
}
|
||||
|
||||
SettingSetDate::~SettingSetDate() {
|
||||
lv_obj_clean(lv_scr_act());
|
||||
}
|
||||
|
||||
void SettingSetDate::HandleButtonPress(lv_obj_t* object, lv_event_t event) {
|
||||
if (event != LV_EVENT_CLICKED)
|
||||
return;
|
||||
|
||||
if (object == btnDayPlus) {
|
||||
dayValue++;
|
||||
if (dayValue > MaximumDayOfMonth())
|
||||
dayValue = 1;
|
||||
lv_label_set_text_fmt(lblDay, "%d", dayValue);
|
||||
lv_btn_set_state(btnSetTime, LV_BTN_STATE_RELEASED);
|
||||
} else if (object == btnDayMinus) {
|
||||
dayValue--;
|
||||
if (dayValue < 1)
|
||||
dayValue = MaximumDayOfMonth();
|
||||
lv_label_set_text_fmt(lblDay, "%d", dayValue);
|
||||
lv_btn_set_state(btnSetTime, LV_BTN_STATE_RELEASED);
|
||||
} else if (object == btnMonthPlus) {
|
||||
monthValue++;
|
||||
if (monthValue > 12)
|
||||
monthValue = 1;
|
||||
UpdateMonthLabel();
|
||||
lv_btn_set_state(btnSetTime, LV_BTN_STATE_RELEASED);
|
||||
CheckDay();
|
||||
} else if (object == btnMonthMinus) {
|
||||
monthValue--;
|
||||
if (monthValue < 1)
|
||||
monthValue = 12;
|
||||
UpdateMonthLabel();
|
||||
lv_btn_set_state(btnSetTime, LV_BTN_STATE_RELEASED);
|
||||
CheckDay();
|
||||
} else if (object == btnYearPlus) {
|
||||
yearValue++;
|
||||
lv_label_set_text_fmt(lblYear, "%d", yearValue);
|
||||
lv_btn_set_state(btnSetTime, LV_BTN_STATE_RELEASED);
|
||||
CheckDay();
|
||||
} else if (object == btnYearMinus) {
|
||||
yearValue--;
|
||||
lv_label_set_text_fmt(lblYear, "%d", yearValue);
|
||||
lv_btn_set_state(btnSetTime, LV_BTN_STATE_RELEASED);
|
||||
CheckDay();
|
||||
} else if (object == btnSetTime) {
|
||||
NRF_LOG_INFO("Setting date (manually) to %04d-%02d-%02d", yearValue, monthValue, dayValue);
|
||||
dateTimeController.SetTime(static_cast<uint16_t>(yearValue),
|
||||
static_cast<uint8_t>(monthValue),
|
||||
static_cast<uint8_t>(dayValue),
|
||||
0,
|
||||
dateTimeController.Hours(),
|
||||
dateTimeController.Minutes(),
|
||||
dateTimeController.Seconds(),
|
||||
nrf_rtc_counter_get(portNRF_RTC_REG));
|
||||
lv_btn_set_state(btnSetTime, LV_BTN_STATE_DISABLED);
|
||||
}
|
||||
}
|
||||
|
||||
int SettingSetDate::MaximumDayOfMonth() const {
|
||||
switch (monthValue) {
|
||||
case 2:
|
||||
if ((((yearValue % 4) == 0) && ((yearValue % 100) != 0)) || ((yearValue % 400) == 0))
|
||||
return 29;
|
||||
return 28;
|
||||
case 4:
|
||||
case 6:
|
||||
case 9:
|
||||
case 11:
|
||||
return 30;
|
||||
default:
|
||||
return 31;
|
||||
}
|
||||
void SettingSetDate::HandleButtonPress() {
|
||||
const uint16_t yearValue = yearCounter.GetValue();
|
||||
const uint8_t monthValue = monthCounter.GetValue();
|
||||
const uint8_t dayValue = dayCounter.GetValue();
|
||||
NRF_LOG_INFO("Setting date (manually) to %04d-%02d-%02d", yearValue, monthValue, dayValue);
|
||||
dateTimeController.SetTime(yearValue,
|
||||
monthValue,
|
||||
dayValue,
|
||||
0,
|
||||
dateTimeController.Hours(),
|
||||
dateTimeController.Minutes(),
|
||||
dateTimeController.Seconds(),
|
||||
nrf_rtc_counter_get(portNRF_RTC_REG));
|
||||
lv_btn_set_state(btnSetTime, LV_BTN_STATE_DISABLED);
|
||||
}
|
||||
|
||||
void SettingSetDate::CheckDay() {
|
||||
int maxDay = MaximumDayOfMonth();
|
||||
if (dayValue > maxDay) {
|
||||
dayValue = maxDay;
|
||||
lv_label_set_text_fmt(lblDay, "%d", dayValue);
|
||||
lv_obj_align(lblDay, lv_scr_act(), LV_ALIGN_CENTER, POS_X_DAY, POS_Y_TEXT);
|
||||
}
|
||||
}
|
||||
|
||||
void SettingSetDate::UpdateMonthLabel() {
|
||||
lv_label_set_text_static(
|
||||
lblMonth,
|
||||
Pinetime::Controllers::DateTime::MonthShortToStringLow(static_cast<Pinetime::Controllers::DateTime::Months>(monthValue)));
|
||||
const int maxDay = MaximumDayOfMonth(monthCounter.GetValue(), yearCounter.GetValue());
|
||||
dayCounter.SetMax(maxDay);
|
||||
lv_btn_set_state(btnSetTime, LV_BTN_STATE_RELEASED);
|
||||
}
|
||||
|
@@ -4,6 +4,7 @@
|
||||
#include <lvgl/lvgl.h>
|
||||
#include "components/datetime/DateTimeController.h"
|
||||
#include "displayapp/screens/Screen.h"
|
||||
#include "displayapp/widgets/Counter.h"
|
||||
|
||||
namespace Pinetime {
|
||||
namespace Applications {
|
||||
@@ -13,28 +14,17 @@ namespace Pinetime {
|
||||
SettingSetDate(DisplayApp* app, Pinetime::Controllers::DateTime& dateTimeController);
|
||||
~SettingSetDate() override;
|
||||
|
||||
void HandleButtonPress(lv_obj_t* object, lv_event_t event);
|
||||
void HandleButtonPress();
|
||||
void CheckDay();
|
||||
|
||||
private:
|
||||
Controllers::DateTime& dateTimeController;
|
||||
|
||||
int dayValue;
|
||||
int monthValue;
|
||||
int yearValue;
|
||||
lv_obj_t* lblDay;
|
||||
lv_obj_t* lblMonth;
|
||||
lv_obj_t* lblYear;
|
||||
lv_obj_t* btnDayPlus;
|
||||
lv_obj_t* btnDayMinus;
|
||||
lv_obj_t* btnMonthPlus;
|
||||
lv_obj_t* btnMonthMinus;
|
||||
lv_obj_t* btnYearPlus;
|
||||
lv_obj_t* btnYearMinus;
|
||||
lv_obj_t* btnSetTime;
|
||||
|
||||
int MaximumDayOfMonth() const;
|
||||
void CheckDay();
|
||||
void UpdateMonthLabel();
|
||||
Widgets::Counter dayCounter = Widgets::Counter(1, 31, jetbrains_mono_bold_20);
|
||||
Widgets::Counter monthCounter = Widgets::Counter(1, 12, jetbrains_mono_bold_20);
|
||||
Widgets::Counter yearCounter = Widgets::Counter(1970, 9999, jetbrains_mono_bold_20);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@@ -5,21 +5,22 @@
|
||||
#include "displayapp/DisplayApp.h"
|
||||
#include "displayapp/screens/Symbols.h"
|
||||
#include "components/settings/Settings.h"
|
||||
#include "displayapp/InfiniTimeTheme.h"
|
||||
|
||||
using namespace Pinetime::Applications::Screens;
|
||||
|
||||
namespace {
|
||||
constexpr int16_t POS_X_HOURS = -72;
|
||||
constexpr int16_t POS_X_MINUTES = 0;
|
||||
constexpr int16_t POS_X_SECONDS = 72;
|
||||
constexpr int16_t POS_Y_PLUS = -50;
|
||||
constexpr int16_t POS_Y_TEXT = -6;
|
||||
constexpr int16_t POS_Y_MINUS = 40;
|
||||
constexpr int16_t OFS_Y_COLON = -2;
|
||||
constexpr int16_t POS_Y_TEXT = -7;
|
||||
|
||||
void event_handler(lv_obj_t* obj, lv_event_t event) {
|
||||
void SetTimeEventHandler(lv_obj_t* obj, lv_event_t event) {
|
||||
auto* screen = static_cast<SettingSetTime*>(obj->user_data);
|
||||
screen->HandleButtonPress(obj, event);
|
||||
if (event == LV_EVENT_CLICKED) {
|
||||
screen->SetTime();
|
||||
}
|
||||
}
|
||||
void ValueChangedHandler(void* userData) {
|
||||
auto* screen = static_cast<SettingSetTime*>(userData);
|
||||
screen->UpdateScreen();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,6 +28,7 @@ SettingSetTime::SettingSetTime(Pinetime::Applications::DisplayApp* app,
|
||||
Pinetime::Controllers::DateTime& dateTimeController,
|
||||
Pinetime::Controllers::Settings& settingsController)
|
||||
: Screen(app), dateTimeController {dateTimeController}, settingsController {settingsController} {
|
||||
|
||||
lv_obj_t* title = lv_label_create(lv_scr_act(), nullptr);
|
||||
lv_label_set_text_static(title, "Set current time");
|
||||
lv_label_set_align(title, LV_LABEL_ALIGN_CENTER);
|
||||
@@ -34,160 +36,72 @@ SettingSetTime::SettingSetTime(Pinetime::Applications::DisplayApp* app,
|
||||
|
||||
lv_obj_t* icon = lv_label_create(lv_scr_act(), nullptr);
|
||||
lv_obj_set_style_local_text_color(icon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_ORANGE);
|
||||
|
||||
lv_label_set_text_static(icon, Symbols::clock);
|
||||
lv_label_set_align(icon, LV_LABEL_ALIGN_CENTER);
|
||||
lv_obj_align(icon, title, LV_ALIGN_OUT_LEFT_MID, -10, 0);
|
||||
|
||||
hoursValue = static_cast<int>(dateTimeController.Hours());
|
||||
lblHours = lv_label_create(lv_scr_act(), nullptr);
|
||||
lv_obj_set_style_local_text_font(lblHours, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_42);
|
||||
lv_label_set_text_fmt(lblHours, "%02d", hoursValue);
|
||||
lv_label_set_align(lblHours, LV_LABEL_ALIGN_CENTER);
|
||||
lv_obj_align(lblHours, lv_scr_act(), LV_ALIGN_CENTER, POS_X_HOURS, POS_Y_TEXT);
|
||||
lv_obj_set_auto_realign(lblHours, true);
|
||||
lv_obj_t* staticLabel = lv_label_create(lv_scr_act(), nullptr);
|
||||
lv_obj_set_style_local_text_font(staticLabel, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_42);
|
||||
lv_label_set_text_static(staticLabel, "00:00:00");
|
||||
lv_obj_align(staticLabel, lv_scr_act(), LV_ALIGN_CENTER, 0, POS_Y_TEXT);
|
||||
|
||||
lv_obj_t* lblColon1 = lv_label_create(lv_scr_act(), nullptr);
|
||||
lv_obj_set_style_local_text_font(lblColon1, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_42);
|
||||
lv_label_set_text_static(lblColon1, ":");
|
||||
lv_label_set_align(lblColon1, LV_LABEL_ALIGN_CENTER);
|
||||
lv_obj_align(lblColon1, lv_scr_act(), LV_ALIGN_CENTER, (POS_X_HOURS + POS_X_MINUTES) / 2, POS_Y_TEXT + OFS_Y_COLON);
|
||||
hourCounter.Create();
|
||||
if (settingsController.GetClockType() == Controllers::Settings::ClockType::H12) {
|
||||
hourCounter.EnableTwelveHourMode();
|
||||
}
|
||||
hourCounter.SetValue(dateTimeController.Hours());
|
||||
lv_obj_align(hourCounter.GetObject(), nullptr, LV_ALIGN_CENTER, -75, POS_Y_TEXT);
|
||||
hourCounter.SetValueChangedEventCallback(this, ValueChangedHandler);
|
||||
|
||||
minutesValue = static_cast<int>(dateTimeController.Minutes());
|
||||
lblMinutes = lv_label_create(lv_scr_act(), nullptr);
|
||||
lv_obj_set_style_local_text_font(lblMinutes, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_42);
|
||||
lv_label_set_text_fmt(lblMinutes, "%02d", minutesValue);
|
||||
lv_label_set_align(lblMinutes, LV_LABEL_ALIGN_CENTER);
|
||||
lv_obj_align(lblMinutes, lv_scr_act(), LV_ALIGN_CENTER, POS_X_MINUTES, POS_Y_TEXT);
|
||||
lv_obj_set_auto_realign(lblMinutes, true);
|
||||
|
||||
lv_obj_t* lblColon2 = lv_label_create(lv_scr_act(), nullptr);
|
||||
lv_obj_set_style_local_text_font(lblColon2, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_42);
|
||||
lv_label_set_text_static(lblColon2, ":");
|
||||
lv_label_set_align(lblColon2, LV_LABEL_ALIGN_CENTER);
|
||||
lv_obj_align(lblColon2, lv_scr_act(), LV_ALIGN_CENTER, (POS_X_MINUTES + POS_X_SECONDS) / 2, POS_Y_TEXT + OFS_Y_COLON);
|
||||
|
||||
lv_obj_t* lblSeconds = lv_label_create(lv_scr_act(), nullptr);
|
||||
lv_obj_set_style_local_text_font(lblSeconds, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_42);
|
||||
lv_label_set_text_static(lblSeconds, "00");
|
||||
lv_label_set_align(lblSeconds, LV_LABEL_ALIGN_CENTER);
|
||||
lv_obj_align(lblSeconds, lv_scr_act(), LV_ALIGN_CENTER, POS_X_SECONDS, POS_Y_TEXT);
|
||||
minuteCounter.Create();
|
||||
minuteCounter.SetValue(dateTimeController.Minutes());
|
||||
lv_obj_align(minuteCounter.GetObject(), nullptr, LV_ALIGN_CENTER, 0, POS_Y_TEXT);
|
||||
minuteCounter.SetValueChangedEventCallback(this, ValueChangedHandler);
|
||||
|
||||
lblampm = lv_label_create(lv_scr_act(), nullptr);
|
||||
lv_obj_set_style_local_text_font(lblampm, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_bold_20);
|
||||
lv_label_set_text_static(lblampm, " ");
|
||||
lv_label_set_align(lblampm, LV_LABEL_ALIGN_CENTER);
|
||||
lv_obj_align(lblampm, lv_scr_act(), LV_ALIGN_CENTER, POS_X_SECONDS, POS_Y_PLUS);
|
||||
|
||||
btnHoursPlus = lv_btn_create(lv_scr_act(), nullptr);
|
||||
btnHoursPlus->user_data = this;
|
||||
lv_obj_set_size(btnHoursPlus, 50, 40);
|
||||
lv_obj_align(btnHoursPlus, lv_scr_act(), LV_ALIGN_CENTER, -72, -50);
|
||||
lv_obj_set_style_local_value_str(btnHoursPlus, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, "+");
|
||||
lv_obj_set_event_cb(btnHoursPlus, event_handler);
|
||||
|
||||
btnHoursMinus = lv_btn_create(lv_scr_act(), nullptr);
|
||||
btnHoursMinus->user_data = this;
|
||||
lv_obj_set_size(btnHoursMinus, 50, 40);
|
||||
lv_obj_align(btnHoursMinus, lv_scr_act(), LV_ALIGN_CENTER, -72, 40);
|
||||
lv_obj_set_style_local_value_str(btnHoursMinus, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, "-");
|
||||
lv_obj_set_event_cb(btnHoursMinus, event_handler);
|
||||
|
||||
btnMinutesPlus = lv_btn_create(lv_scr_act(), nullptr);
|
||||
btnMinutesPlus->user_data = this;
|
||||
lv_obj_set_size(btnMinutesPlus, 50, 40);
|
||||
lv_obj_align(btnMinutesPlus, lv_scr_act(), LV_ALIGN_CENTER, 0, -50);
|
||||
lv_obj_set_style_local_value_str(btnMinutesPlus, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, "+");
|
||||
lv_obj_set_event_cb(btnMinutesPlus, event_handler);
|
||||
|
||||
btnMinutesMinus = lv_btn_create(lv_scr_act(), nullptr);
|
||||
btnMinutesMinus->user_data = this;
|
||||
lv_obj_set_size(btnMinutesMinus, 50, 40);
|
||||
lv_obj_align(btnMinutesMinus, lv_scr_act(), LV_ALIGN_CENTER, 0, 40);
|
||||
lv_obj_set_style_local_value_str(btnMinutesMinus, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, "-");
|
||||
lv_obj_set_event_cb(btnMinutesMinus, event_handler);
|
||||
lv_obj_align(lblampm, lv_scr_act(), LV_ALIGN_CENTER, 75, -50);
|
||||
|
||||
btnSetTime = lv_btn_create(lv_scr_act(), nullptr);
|
||||
btnSetTime->user_data = this;
|
||||
lv_obj_set_size(btnSetTime, 120, 48);
|
||||
lv_obj_set_size(btnSetTime, 120, 50);
|
||||
lv_obj_align(btnSetTime, lv_scr_act(), LV_ALIGN_IN_BOTTOM_MID, 0, 0);
|
||||
lv_obj_set_style_local_value_str(btnSetTime, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, "Set");
|
||||
lv_obj_set_event_cb(btnSetTime, event_handler);
|
||||
lv_obj_set_style_local_bg_color(btnSetTime, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, Colors::bgAlt);
|
||||
lv_obj_set_style_local_value_color(btnSetTime, LV_BTN_PART_MAIN, LV_STATE_DISABLED, LV_COLOR_GRAY);
|
||||
lv_obj_set_event_cb(btnSetTime, SetTimeEventHandler);
|
||||
|
||||
SetHourLabels();
|
||||
UpdateScreen();
|
||||
lv_obj_set_state(btnSetTime, LV_STATE_DISABLED);
|
||||
}
|
||||
|
||||
SettingSetTime::~SettingSetTime() {
|
||||
lv_obj_clean(lv_scr_act());
|
||||
}
|
||||
|
||||
void SettingSetTime::SetHourLabels() {
|
||||
void SettingSetTime::UpdateScreen() {
|
||||
if (settingsController.GetClockType() == Controllers::Settings::ClockType::H12) {
|
||||
switch (hoursValue) {
|
||||
case 0:
|
||||
lv_label_set_text_static(lblHours, "12");
|
||||
lv_label_set_text_static(lblampm, "AM");
|
||||
break;
|
||||
case 1 ... 11:
|
||||
lv_label_set_text_fmt(lblHours, "%02d", hoursValue);
|
||||
lv_label_set_text_static(lblampm, "AM");
|
||||
break;
|
||||
case 12:
|
||||
lv_label_set_text_static(lblHours, "12");
|
||||
lv_label_set_text_static(lblampm, "PM");
|
||||
break;
|
||||
case 13 ... 23:
|
||||
lv_label_set_text_fmt(lblHours, "%02d", hoursValue - 12);
|
||||
lv_label_set_text_static(lblampm, "PM");
|
||||
break;
|
||||
if (hourCounter.GetValue() >= 12) {
|
||||
lv_label_set_text_static(lblampm, "PM");
|
||||
} else {
|
||||
lv_label_set_text_static(lblampm, "AM");
|
||||
}
|
||||
} else {
|
||||
lv_label_set_text_fmt(lblHours, "%02d", hoursValue);
|
||||
}
|
||||
lv_obj_set_state(btnSetTime, LV_STATE_DEFAULT);
|
||||
}
|
||||
|
||||
void SettingSetTime::HandleButtonPress(lv_obj_t* object, lv_event_t event) {
|
||||
if (event != LV_EVENT_CLICKED)
|
||||
return;
|
||||
|
||||
if (object == btnHoursPlus) {
|
||||
hoursValue++;
|
||||
if (hoursValue > 23) {
|
||||
hoursValue = 0;
|
||||
}
|
||||
SetHourLabels();
|
||||
lv_btn_set_state(btnSetTime, LV_BTN_STATE_RELEASED);
|
||||
} else if (object == btnHoursMinus) {
|
||||
hoursValue--;
|
||||
if (hoursValue < 0) {
|
||||
hoursValue = 23;
|
||||
}
|
||||
SetHourLabels();
|
||||
lv_btn_set_state(btnSetTime, LV_BTN_STATE_RELEASED);
|
||||
} else if (object == btnMinutesPlus) {
|
||||
minutesValue++;
|
||||
if (minutesValue > 59) {
|
||||
minutesValue = 0;
|
||||
}
|
||||
lv_label_set_text_fmt(lblMinutes, "%02d", minutesValue);
|
||||
lv_btn_set_state(btnSetTime, LV_BTN_STATE_RELEASED);
|
||||
} else if (object == btnMinutesMinus) {
|
||||
minutesValue--;
|
||||
if (minutesValue < 0) {
|
||||
minutesValue = 59;
|
||||
}
|
||||
lv_label_set_text_fmt(lblMinutes, "%02d", minutesValue);
|
||||
lv_btn_set_state(btnSetTime, LV_BTN_STATE_RELEASED);
|
||||
} else if (object == btnSetTime) {
|
||||
NRF_LOG_INFO("Setting time (manually) to %02d:%02d:00", hoursValue, minutesValue);
|
||||
dateTimeController.SetTime(dateTimeController.Year(),
|
||||
static_cast<uint8_t>(dateTimeController.Month()),
|
||||
dateTimeController.Day(),
|
||||
static_cast<uint8_t>(dateTimeController.DayOfWeek()),
|
||||
static_cast<uint8_t>(hoursValue),
|
||||
static_cast<uint8_t>(minutesValue),
|
||||
0,
|
||||
nrf_rtc_counter_get(portNRF_RTC_REG));
|
||||
lv_btn_set_state(btnSetTime, LV_BTN_STATE_DISABLED);
|
||||
}
|
||||
void SettingSetTime::SetTime() {
|
||||
const int hoursValue = hourCounter.GetValue();
|
||||
const int minutesValue = minuteCounter.GetValue();
|
||||
NRF_LOG_INFO("Setting time (manually) to %02d:%02d:00", hoursValue, minutesValue);
|
||||
dateTimeController.SetTime(dateTimeController.Year(),
|
||||
static_cast<uint8_t>(dateTimeController.Month()),
|
||||
dateTimeController.Day(),
|
||||
static_cast<uint8_t>(dateTimeController.DayOfWeek()),
|
||||
static_cast<uint8_t>(hoursValue),
|
||||
static_cast<uint8_t>(minutesValue),
|
||||
0,
|
||||
nrf_rtc_counter_get(portNRF_RTC_REG));
|
||||
lv_obj_set_state(btnSetTime, LV_STATE_DISABLED);
|
||||
}
|
||||
|
@@ -4,6 +4,7 @@
|
||||
#include <lvgl/lvgl.h>
|
||||
#include "components/datetime/DateTimeController.h"
|
||||
#include "components/settings/Settings.h"
|
||||
#include "displayapp/widgets/Counter.h"
|
||||
#include "displayapp/screens/Screen.h"
|
||||
|
||||
namespace Pinetime {
|
||||
@@ -16,24 +17,17 @@ namespace Pinetime {
|
||||
Pinetime::Controllers::Settings& settingsController);
|
||||
~SettingSetTime() override;
|
||||
|
||||
void HandleButtonPress(lv_obj_t* object, lv_event_t event);
|
||||
void SetTime();
|
||||
void UpdateScreen();
|
||||
|
||||
private:
|
||||
Controllers::DateTime& dateTimeController;
|
||||
Controllers::Settings& settingsController;
|
||||
|
||||
void SetHourLabels();
|
||||
|
||||
int hoursValue;
|
||||
int minutesValue;
|
||||
lv_obj_t* lblHours;
|
||||
lv_obj_t* lblMinutes;
|
||||
lv_obj_t* lblampm;
|
||||
lv_obj_t* btnHoursPlus;
|
||||
lv_obj_t* btnHoursMinus;
|
||||
lv_obj_t* btnMinutesPlus;
|
||||
lv_obj_t* btnMinutesMinus;
|
||||
lv_obj_t* btnSetTime;
|
||||
Widgets::Counter hourCounter = Widgets::Counter(0, 23, jetbrains_mono_42);
|
||||
Widgets::Counter minuteCounter = Widgets::Counter(0, 59, jetbrains_mono_42);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@@ -3,6 +3,7 @@
|
||||
#include "displayapp/DisplayApp.h"
|
||||
#include "displayapp/screens/Screen.h"
|
||||
#include "displayapp/screens/Symbols.h"
|
||||
#include "displayapp/InfiniTimeTheme.h"
|
||||
|
||||
using namespace Pinetime::Applications::Screens;
|
||||
|
||||
@@ -123,8 +124,7 @@ void SettingShakeThreshold::UpdateSelected(lv_obj_t* object, lv_event_t event) {
|
||||
vCalTime = xTaskGetTickCount();
|
||||
lv_label_set_text_static(calLabel, "Ready!");
|
||||
lv_obj_set_click(positionArc, false);
|
||||
lv_obj_set_style_local_bg_color(calButton, LV_BTN_PART_MAIN, LV_STATE_CHECKED, LV_COLOR_MAKE(0x0, 0xb0, 0x0));
|
||||
lv_obj_set_style_local_bg_color(calButton, LV_BTN_PART_MAIN, LV_STATE_CHECKED, LV_COLOR_MAKE(0x0, 0xb0, 0x0));
|
||||
lv_obj_set_style_local_bg_color(calButton, LV_BTN_PART_MAIN, LV_STATE_CHECKED, Colors::highlight);
|
||||
} else if (lv_btn_get_state(calButton) == LV_BTN_STATE_RELEASED) {
|
||||
calibrating = 0;
|
||||
lv_obj_set_click(positionArc, true);
|
||||
|
@@ -17,7 +17,6 @@ SettingSteps::SettingSteps(Pinetime::Applications::DisplayApp* app, Pinetime::Co
|
||||
|
||||
lv_obj_t* container1 = lv_cont_create(lv_scr_act(), nullptr);
|
||||
|
||||
// lv_obj_set_style_local_bg_color(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x111111));
|
||||
lv_obj_set_style_local_bg_opa(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, LV_OPA_TRANSP);
|
||||
lv_obj_set_style_local_pad_all(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, 10);
|
||||
lv_obj_set_style_local_pad_inner(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, 5);
|
||||
|
@@ -20,7 +20,7 @@ namespace Pinetime {
|
||||
void UpdateSelected(lv_obj_t* object, lv_event_t event);
|
||||
|
||||
private:
|
||||
static constexpr std::array<const char*, 2> options = {" 12-hour", " 24-hour"};
|
||||
static constexpr std::array<const char*, 2> options = {"12-hour", "24-hour"};
|
||||
Controllers::Settings& settingsController;
|
||||
lv_obj_t* cbOption[options.size()];
|
||||
};
|
||||
|
@@ -42,7 +42,7 @@ SettingWakeUp::SettingWakeUp(Pinetime::Applications::DisplayApp* app, Pinetime::
|
||||
|
||||
optionsTotal = 0;
|
||||
cbOption[optionsTotal] = lv_checkbox_create(container1, nullptr);
|
||||
lv_checkbox_set_text_static(cbOption[optionsTotal], " Single Tap");
|
||||
lv_checkbox_set_text_static(cbOption[optionsTotal], "Single Tap");
|
||||
cbOption[optionsTotal]->user_data = this;
|
||||
lv_obj_set_event_cb(cbOption[optionsTotal], event_handler);
|
||||
if (settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::SingleTap)) {
|
||||
@@ -50,7 +50,7 @@ SettingWakeUp::SettingWakeUp(Pinetime::Applications::DisplayApp* app, Pinetime::
|
||||
}
|
||||
optionsTotal++;
|
||||
cbOption[optionsTotal] = lv_checkbox_create(container1, nullptr);
|
||||
lv_checkbox_set_text_static(cbOption[optionsTotal], " Double Tap");
|
||||
lv_checkbox_set_text_static(cbOption[optionsTotal], "Double Tap");
|
||||
cbOption[optionsTotal]->user_data = this;
|
||||
lv_obj_set_event_cb(cbOption[optionsTotal], event_handler);
|
||||
if (settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::DoubleTap)) {
|
||||
@@ -58,7 +58,7 @@ SettingWakeUp::SettingWakeUp(Pinetime::Applications::DisplayApp* app, Pinetime::
|
||||
}
|
||||
optionsTotal++;
|
||||
cbOption[optionsTotal] = lv_checkbox_create(container1, nullptr);
|
||||
lv_checkbox_set_text_static(cbOption[optionsTotal], " Raise Wrist");
|
||||
lv_checkbox_set_text_static(cbOption[optionsTotal], "Raise Wrist");
|
||||
cbOption[optionsTotal]->user_data = this;
|
||||
lv_obj_set_event_cb(cbOption[optionsTotal], event_handler);
|
||||
if (settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::RaiseWrist)) {
|
||||
@@ -66,7 +66,7 @@ SettingWakeUp::SettingWakeUp(Pinetime::Applications::DisplayApp* app, Pinetime::
|
||||
}
|
||||
optionsTotal++;
|
||||
cbOption[optionsTotal] = lv_checkbox_create(container1, nullptr);
|
||||
lv_checkbox_set_text_static(cbOption[optionsTotal], " Shake Wake");
|
||||
lv_checkbox_set_text_static(cbOption[optionsTotal], "Shake Wake");
|
||||
cbOption[optionsTotal]->user_data = this;
|
||||
lv_obj_set_event_cb(cbOption[optionsTotal], event_handler);
|
||||
if (settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::Shake)) {
|
||||
|
@@ -38,7 +38,7 @@ bool SettingWatchFace::OnTouchEvent(Pinetime::Applications::TouchEvents event) {
|
||||
}
|
||||
|
||||
std::unique_ptr<Screen> SettingWatchFace::CreateScreen1() {
|
||||
std::array<const char*, 4> watchfaces {" Digital face", " Analog face", " PineTimeStyle", " Terminal"};
|
||||
std::array<const char*, 4> watchfaces {"Digital face", "Analog face", "PineTimeStyle", "Terminal"};
|
||||
return std::make_unique<Screens::CheckboxList>(0, 2, app, settingsController, title,
|
||||
symbol, &Controllers::Settings::SetClockFace,
|
||||
&Controllers::Settings::GetClockFace,
|
||||
@@ -46,7 +46,7 @@ std::unique_ptr<Screen> SettingWatchFace::CreateScreen1() {
|
||||
}
|
||||
|
||||
std::unique_ptr<Screen> SettingWatchFace::CreateScreen2() {
|
||||
std::array<const char*, 4> watchfaces {" Infineat face", "", "", ""};
|
||||
std::array<const char*, 4> watchfaces {"Infineat face", "", "", ""};
|
||||
return std::make_unique<Screens::CheckboxList>(1, 2, app, settingsController, title,
|
||||
symbol, &Controllers::Settings::SetClockFace,
|
||||
&Controllers::Settings::GetClockFace,
|
||||
|
@@ -1,33 +1,27 @@
|
||||
#include "displayapp/screens/settings/Settings.h"
|
||||
#include <lvgl/lvgl.h>
|
||||
#include <array>
|
||||
#include "displayapp/screens/List.h"
|
||||
#include <functional>
|
||||
#include "displayapp/Apps.h"
|
||||
#include "displayapp/DisplayApp.h"
|
||||
#include "displayapp/screens/Symbols.h"
|
||||
|
||||
using namespace Pinetime::Applications::Screens;
|
||||
|
||||
constexpr std::array<List::Applications, Settings::entries.size()> Settings::entries;
|
||||
|
||||
auto Settings::CreateScreenList() const {
|
||||
std::array<std::function<std::unique_ptr<Screen>()>, nScreens> screens;
|
||||
for (size_t i = 0; i < screens.size(); i++) {
|
||||
screens[i] = [this, i]() -> std::unique_ptr<Screen> {
|
||||
return CreateScreen(i);
|
||||
};
|
||||
}
|
||||
return screens;
|
||||
}
|
||||
|
||||
Settings::Settings(Pinetime::Applications::DisplayApp* app, Pinetime::Controllers::Settings& settingsController)
|
||||
: Screen(app),
|
||||
settingsController {settingsController},
|
||||
screens {app,
|
||||
settingsController.GetSettingsMenu(),
|
||||
{
|
||||
[this]() -> std::unique_ptr<Screen> {
|
||||
return CreateScreen1();
|
||||
},
|
||||
[this]() -> std::unique_ptr<Screen> {
|
||||
return CreateScreen2();
|
||||
},
|
||||
[this]() -> std::unique_ptr<Screen> {
|
||||
return CreateScreen3();
|
||||
},
|
||||
[this]() -> std::unique_ptr<Screen> {
|
||||
return CreateScreen4();
|
||||
},
|
||||
},
|
||||
Screens::ScreenListModes::UpDown} {
|
||||
screens {app, settingsController.GetSettingsMenu(), CreateScreenList(), Screens::ScreenListModes::UpDown} {
|
||||
}
|
||||
|
||||
Settings::~Settings() {
|
||||
@@ -38,48 +32,11 @@ bool Settings::OnTouchEvent(Pinetime::Applications::TouchEvents event) {
|
||||
return screens.OnTouchEvent(event);
|
||||
}
|
||||
|
||||
std::unique_ptr<Screen> Settings::CreateScreen1() {
|
||||
std::array<Screens::List::Applications, 4> applications {{
|
||||
{Symbols::sun, "Display", Apps::SettingDisplay},
|
||||
{Symbols::eye, "Wake Up", Apps::SettingWakeUp},
|
||||
{Symbols::clock, "Time format", Apps::SettingTimeFormat},
|
||||
{Symbols::home, "Watch face", Apps::SettingWatchFace},
|
||||
}};
|
||||
std::unique_ptr<Screen> Settings::CreateScreen(unsigned int screenNum) const {
|
||||
std::array<List::Applications, entriesPerScreen> screens;
|
||||
for (int i = 0; i < entriesPerScreen; i++) {
|
||||
screens[i] = entries[screenNum * entriesPerScreen + i];
|
||||
}
|
||||
|
||||
return std::make_unique<Screens::List>(0, 4, app, settingsController, applications);
|
||||
}
|
||||
|
||||
std::unique_ptr<Screen> Settings::CreateScreen2() {
|
||||
std::array<Screens::List::Applications, 4> applications {{
|
||||
{Symbols::shoe, "Steps", Apps::SettingSteps},
|
||||
{Symbols::clock, "Set date", Apps::SettingSetDate},
|
||||
{Symbols::clock, "Set time", Apps::SettingSetTime},
|
||||
{Symbols::batteryHalf, "Battery", Apps::BatteryInfo},
|
||||
}};
|
||||
|
||||
return std::make_unique<Screens::List>(1, 4, app, settingsController, applications);
|
||||
}
|
||||
|
||||
std::unique_ptr<Screen> Settings::CreateScreen3() {
|
||||
|
||||
std::array<Screens::List::Applications, 4> applications {{
|
||||
{Symbols::clock, "Chimes", Apps::SettingChimes},
|
||||
{Symbols::tachometer, "Shake Calib.", Apps::SettingShakeThreshold},
|
||||
{Symbols::check, "Firmware", Apps::FirmwareValidation},
|
||||
{Symbols::bluetooth, "Bluetooth", Apps::SettingBluetooth},
|
||||
}};
|
||||
|
||||
return std::make_unique<Screens::List>(2, 4, app, settingsController, applications);
|
||||
}
|
||||
|
||||
std::unique_ptr<Screen> Settings::CreateScreen4() {
|
||||
|
||||
std::array<Screens::List::Applications, 4> applications {{
|
||||
{Symbols::list, "About", Apps::SysInfo},
|
||||
{Symbols::none, "None", Apps::None},
|
||||
{Symbols::none, "None", Apps::None},
|
||||
{Symbols::none, "None", Apps::None},
|
||||
}};
|
||||
|
||||
return std::make_unique<Screens::List>(3, 4, app, settingsController, applications);
|
||||
return std::make_unique<Screens::List>(screenNum, nScreens, app, settingsController, screens);
|
||||
}
|
||||
|
@@ -1,8 +1,11 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <array>
|
||||
#include <memory>
|
||||
#include "displayapp/screens/Screen.h"
|
||||
#include "displayapp/screens/ScreenList.h"
|
||||
#include "displayapp/screens/Symbols.h"
|
||||
#include "displayapp/screens/List.h"
|
||||
|
||||
namespace Pinetime {
|
||||
|
||||
@@ -17,14 +20,38 @@ namespace Pinetime {
|
||||
bool OnTouchEvent(Pinetime::Applications::TouchEvents event) override;
|
||||
|
||||
private:
|
||||
auto CreateScreenList() const;
|
||||
std::unique_ptr<Screen> CreateScreen(unsigned int screenNum) const;
|
||||
|
||||
Controllers::Settings& settingsController;
|
||||
|
||||
ScreenList<4> screens;
|
||||
static constexpr int entriesPerScreen = 4;
|
||||
|
||||
std::unique_ptr<Screen> CreateScreen1();
|
||||
std::unique_ptr<Screen> CreateScreen2();
|
||||
std::unique_ptr<Screen> CreateScreen3();
|
||||
std::unique_ptr<Screen> CreateScreen4();
|
||||
// Increment this when more space is needed
|
||||
static constexpr int nScreens = 4;
|
||||
|
||||
static constexpr std::array<List::Applications, entriesPerScreen * nScreens> entries {{
|
||||
{Symbols::sun, "Display", Apps::SettingDisplay},
|
||||
{Symbols::eye, "Wake Up", Apps::SettingWakeUp},
|
||||
{Symbols::clock, "Time format", Apps::SettingTimeFormat},
|
||||
{Symbols::home, "Watch face", Apps::SettingWatchFace},
|
||||
|
||||
{Symbols::shoe, "Steps", Apps::SettingSteps},
|
||||
{Symbols::clock, "Set date", Apps::SettingSetDate},
|
||||
{Symbols::clock, "Set time", Apps::SettingSetTime},
|
||||
{Symbols::batteryHalf, "Battery", Apps::BatteryInfo},
|
||||
|
||||
{Symbols::clock, "Chimes", Apps::SettingChimes},
|
||||
{Symbols::tachometer, "Shake Calib.", Apps::SettingShakeThreshold},
|
||||
{Symbols::check, "Firmware", Apps::FirmwareValidation},
|
||||
{Symbols::bluetooth, "Bluetooth", Apps::SettingBluetooth},
|
||||
|
||||
{Symbols::list, "About", Apps::SysInfo},
|
||||
{Symbols::none, "None", Apps::None},
|
||||
{Symbols::none, "None", Apps::None},
|
||||
{Symbols::none, "None", Apps::None},
|
||||
}};
|
||||
ScreenList<nScreens> screens;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user