Merge remote-tracking branch 'upstream/develop' into pts-settings
This commit is contained in:
@@ -31,7 +31,10 @@ namespace Pinetime {
|
||||
SettingTimeFormat,
|
||||
SettingDisplay,
|
||||
SettingWakeUp,
|
||||
SettingSteps
|
||||
SettingSteps,
|
||||
SettingSetDate,
|
||||
SettingSetTime,
|
||||
Error,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@@ -29,6 +29,7 @@
|
||||
#include "displayapp/screens/FlashLight.h"
|
||||
#include "displayapp/screens/BatteryInfo.h"
|
||||
#include "displayapp/screens/Steps.h"
|
||||
#include "displayapp/screens/Error.h"
|
||||
|
||||
#include "drivers/Cst816s.h"
|
||||
#include "drivers/St7789.h"
|
||||
@@ -43,6 +44,8 @@
|
||||
#include "displayapp/screens/settings/SettingWakeUp.h"
|
||||
#include "displayapp/screens/settings/SettingDisplay.h"
|
||||
#include "displayapp/screens/settings/SettingSteps.h"
|
||||
#include "displayapp/screens/settings/SettingSetDate.h"
|
||||
#include "displayapp/screens/settings/SettingSetTime.h"
|
||||
|
||||
#include "libs/lv_conf.h"
|
||||
|
||||
@@ -109,11 +112,16 @@ DisplayApp::DisplayApp(Drivers::St7789& lcd,
|
||||
touchHandler {touchHandler} {
|
||||
}
|
||||
|
||||
void DisplayApp::Start() {
|
||||
void DisplayApp::Start(System::BootErrors error) {
|
||||
msgQueue = xQueueCreate(queueSize, itemSize);
|
||||
|
||||
// Start clock when smartwatch boots
|
||||
LoadApp(Apps::Clock, DisplayApp::FullRefreshDirections::None);
|
||||
bootError = error;
|
||||
|
||||
if (error == System::BootErrors::TouchController) {
|
||||
LoadApp(Apps::Error, DisplayApp::FullRefreshDirections::None);
|
||||
} else {
|
||||
LoadApp(Apps::Clock, DisplayApp::FullRefreshDirections::None);
|
||||
}
|
||||
|
||||
if (pdPASS != xTaskCreate(DisplayApp::Process, "displayapp", 800, this, 0, &taskHandle)) {
|
||||
APP_ERROR_HANDLER(NRF_ERROR_NO_MEM);
|
||||
@@ -308,6 +316,11 @@ void DisplayApp::LoadApp(Apps app, DisplayApp::FullRefreshDirections direction)
|
||||
motionController);
|
||||
break;
|
||||
|
||||
case Apps::Error:
|
||||
currentScreen = std::make_unique<Screens::Error>(this, bootError);
|
||||
ReturnApp(Apps::Clock, FullRefreshDirections::Down, TouchEvents::None);
|
||||
break;
|
||||
|
||||
case Apps::FirmwareValidation:
|
||||
currentScreen = std::make_unique<Screens::FirmwareValidation>(this, validator);
|
||||
ReturnApp(Apps::Settings, FullRefreshDirections::Down, TouchEvents::SwipeDown);
|
||||
@@ -364,13 +377,21 @@ void DisplayApp::LoadApp(Apps app, DisplayApp::FullRefreshDirections direction)
|
||||
currentScreen = std::make_unique<Screens::SettingSteps>(this, settingsController);
|
||||
ReturnApp(Apps::Settings, FullRefreshDirections::Down, TouchEvents::SwipeDown);
|
||||
break;
|
||||
case Apps::SettingSetDate:
|
||||
currentScreen = std::make_unique<Screens::SettingSetDate>(this, dateTimeController);
|
||||
ReturnApp(Apps::Settings, FullRefreshDirections::Down, TouchEvents::SwipeDown);
|
||||
break;
|
||||
case Apps::SettingSetTime:
|
||||
currentScreen = std::make_unique<Screens::SettingSetTime>(this, dateTimeController);
|
||||
ReturnApp(Apps::Settings, FullRefreshDirections::Down, TouchEvents::SwipeDown);
|
||||
break;
|
||||
case Apps::BatteryInfo:
|
||||
currentScreen = std::make_unique<Screens::BatteryInfo>(this, batteryController);
|
||||
ReturnApp(Apps::Settings, FullRefreshDirections::Down, TouchEvents::SwipeDown);
|
||||
break;
|
||||
case Apps::SysInfo:
|
||||
currentScreen = std::make_unique<Screens::SystemInfo>(
|
||||
this, dateTimeController, batteryController, brightnessController, bleController, watchdog, motionController);
|
||||
this, dateTimeController, batteryController, brightnessController, bleController, watchdog, motionController, touchPanel);
|
||||
ReturnApp(Apps::Settings, FullRefreshDirections::Down, TouchEvents::SwipeDown);
|
||||
break;
|
||||
case Apps::FlashLight:
|
||||
|
@@ -18,6 +18,7 @@
|
||||
#include "touchhandler/TouchHandler.h"
|
||||
|
||||
#include "Messages.h"
|
||||
#include "BootErrors.h"
|
||||
|
||||
namespace Pinetime {
|
||||
|
||||
@@ -61,7 +62,7 @@ namespace Pinetime {
|
||||
Pinetime::Controllers::TimerController& timerController,
|
||||
Pinetime::Controllers::AlarmController& alarmController,
|
||||
Pinetime::Controllers::TouchHandler& touchHandler);
|
||||
void Start();
|
||||
void Start(System::BootErrors error);
|
||||
void PushMessage(Display::Messages msg);
|
||||
|
||||
void StartApp(Apps app, DisplayApp::FullRefreshDirections direction);
|
||||
@@ -116,6 +117,7 @@ namespace Pinetime {
|
||||
|
||||
Apps nextApp = Apps::None;
|
||||
DisplayApp::FullRefreshDirections nextDirection;
|
||||
System::BootErrors bootError;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@@ -10,6 +10,7 @@
|
||||
#include <date/date.h>
|
||||
#include <drivers/Watchdog.h>
|
||||
#include <components/motor/MotorController.h>
|
||||
#include <BootErrors.h>
|
||||
#include "TouchEvents.h"
|
||||
#include "Apps.h"
|
||||
#include "Messages.h"
|
||||
@@ -58,6 +59,7 @@ namespace Pinetime {
|
||||
Pinetime::Controllers::AlarmController& alarmController,
|
||||
Pinetime::Controllers::TouchHandler& touchHandler);
|
||||
void Start();
|
||||
void Start(Pinetime::System::BootErrors){ Start(); };
|
||||
void PushMessage(Pinetime::Applications::Display::Messages msg);
|
||||
void Register(Pinetime::System::SystemTask* systemTask);
|
||||
|
||||
|
@@ -120,10 +120,7 @@ void Alarm::OnButtonEvent(lv_obj_t* obj, lv_event_t event) {
|
||||
return;
|
||||
}
|
||||
if (obj == btnMessage) {
|
||||
lv_obj_del(txtMessage);
|
||||
lv_obj_del(btnMessage);
|
||||
txtMessage = nullptr;
|
||||
btnMessage = nullptr;
|
||||
HideInfo();
|
||||
return;
|
||||
}
|
||||
// If any other button was pressed, disable the alarm
|
||||
@@ -174,6 +171,14 @@ void Alarm::OnButtonEvent(lv_obj_t* obj, lv_event_t event) {
|
||||
}
|
||||
}
|
||||
|
||||
bool Alarm::OnButtonPushed() {
|
||||
if (txtMessage != nullptr && btnMessage != nullptr) {
|
||||
HideInfo();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void Alarm::UpdateAlarmTime() {
|
||||
lv_label_set_text_fmt(time, "%02d:%02d", alarmHours, alarmMinutes);
|
||||
alarmController.SetAlarmTime(alarmHours, alarmMinutes);
|
||||
@@ -224,6 +229,12 @@ void Alarm::ShowInfo() {
|
||||
}
|
||||
}
|
||||
|
||||
void Alarm::HideInfo() {
|
||||
lv_obj_del(btnMessage);
|
||||
txtMessage = nullptr;
|
||||
btnMessage = nullptr;
|
||||
}
|
||||
|
||||
void Alarm::SetRecurButtonState() {
|
||||
using Pinetime::Controllers::AlarmController;
|
||||
switch (alarmController.Recurrence()) {
|
||||
|
@@ -31,6 +31,7 @@ namespace Pinetime {
|
||||
~Alarm() override;
|
||||
void SetAlerting();
|
||||
void OnButtonEvent(lv_obj_t* obj, lv_event_t event);
|
||||
bool OnButtonPushed() override;
|
||||
|
||||
private:
|
||||
bool running;
|
||||
@@ -46,6 +47,7 @@ namespace Pinetime {
|
||||
void SetRecurButtonState();
|
||||
void SetAlarm();
|
||||
void ShowInfo();
|
||||
void HideInfo();
|
||||
void ToggleRecurrence();
|
||||
void UpdateAlarmTime();
|
||||
};
|
||||
|
50
src/displayapp/screens/Error.cpp
Normal file
50
src/displayapp/screens/Error.cpp
Normal file
@@ -0,0 +1,50 @@
|
||||
#include "Error.h"
|
||||
|
||||
using namespace Pinetime::Applications::Screens;
|
||||
|
||||
namespace {
|
||||
void ButtonEventCallback(lv_obj_t* obj, lv_event_t /*event*/) {
|
||||
auto* errorScreen = static_cast<Error*>(obj->user_data);
|
||||
errorScreen->ButtonEventHandler();
|
||||
}
|
||||
}
|
||||
|
||||
Error::Error(Pinetime::Applications::DisplayApp* app, System::BootErrors error)
|
||||
: Screen(app) {
|
||||
|
||||
lv_obj_t* warningLabel = lv_label_create(lv_scr_act(), nullptr);
|
||||
lv_obj_set_style_local_text_color(warningLabel, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_ORANGE);
|
||||
lv_label_set_text_static(warningLabel, "Warning");
|
||||
lv_obj_align(warningLabel, nullptr, LV_ALIGN_IN_TOP_MID, 0, 0);
|
||||
|
||||
lv_obj_t* causeLabel = lv_label_create(lv_scr_act(), nullptr);
|
||||
lv_label_set_long_mode(causeLabel, LV_LABEL_LONG_BREAK);
|
||||
lv_obj_set_width(causeLabel, LV_HOR_RES);
|
||||
lv_obj_align(causeLabel, warningLabel, LV_ALIGN_OUT_BOTTOM_MID, 0, 0);
|
||||
|
||||
if (error == System::BootErrors::TouchController) {
|
||||
lv_label_set_text_static(causeLabel, "Touch controller error detected.");
|
||||
}
|
||||
|
||||
lv_obj_t* tipLabel = lv_label_create(lv_scr_act(), nullptr);
|
||||
lv_label_set_long_mode(tipLabel, LV_LABEL_LONG_BREAK);
|
||||
lv_obj_set_width(tipLabel, LV_HOR_RES);
|
||||
lv_label_set_text_static(tipLabel, "If you encounter problems and your device is under warranty, contact the devices seller.");
|
||||
lv_obj_align(tipLabel, causeLabel, LV_ALIGN_OUT_BOTTOM_MID, 0, 0);
|
||||
|
||||
btnOk = lv_btn_create(lv_scr_act(), nullptr);
|
||||
btnOk->user_data = this;
|
||||
lv_obj_set_event_cb(btnOk, ButtonEventCallback);
|
||||
lv_obj_set_size(btnOk, LV_HOR_RES, 50);
|
||||
lv_obj_align(btnOk, lv_scr_act(), LV_ALIGN_IN_BOTTOM_MID, 0, 0);
|
||||
lv_obj_set_style_local_value_str(btnOk, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, "Proceed");
|
||||
lv_obj_set_style_local_bg_color(btnOk, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_ORANGE);
|
||||
}
|
||||
|
||||
void Error::ButtonEventHandler() {
|
||||
running = false;
|
||||
}
|
||||
|
||||
Error::~Error() {
|
||||
lv_obj_clean(lv_scr_act());
|
||||
}
|
21
src/displayapp/screens/Error.h
Normal file
21
src/displayapp/screens/Error.h
Normal file
@@ -0,0 +1,21 @@
|
||||
#pragma once
|
||||
|
||||
#include "Screen.h"
|
||||
#include "BootErrors.h"
|
||||
#include <lvgl/lvgl.h>
|
||||
|
||||
namespace Pinetime {
|
||||
namespace Applications {
|
||||
namespace Screens {
|
||||
class Error : public Screen {
|
||||
public:
|
||||
Error(DisplayApp* app, System::BootErrors error);
|
||||
~Error() override;
|
||||
|
||||
void ButtonEventHandler();
|
||||
private:
|
||||
lv_obj_t* btnOk;
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
@@ -47,8 +47,8 @@ void Paddle::Refresh() {
|
||||
dy *= -1;
|
||||
}
|
||||
|
||||
// checks if it has touched the side (left side)
|
||||
if (ballX >= LV_VER_RES - ballSize - 1) {
|
||||
// checks if it has touched the side (right side)
|
||||
if (ballX >= LV_HOR_RES - ballSize - 1) {
|
||||
dx *= -1;
|
||||
}
|
||||
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* This file is part of the Infinitime distribution (https://github.com/JF002/Infinitime).
|
||||
* This file is part of the Infinitime distribution (https://github.com/InfiniTimeOrg/Infinitime).
|
||||
* Copyright (c) 2021 Kieran Cawthray.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
|
@@ -33,7 +33,8 @@ SystemInfo::SystemInfo(Pinetime::Applications::DisplayApp* app,
|
||||
Pinetime::Controllers::BrightnessController& brightnessController,
|
||||
Pinetime::Controllers::Ble& bleController,
|
||||
Pinetime::Drivers::WatchdogView& watchdog,
|
||||
Pinetime::Controllers::MotionController& motionController)
|
||||
Pinetime::Controllers::MotionController& motionController,
|
||||
Pinetime::Drivers::Cst816S& touchPanel)
|
||||
: Screen(app),
|
||||
dateTimeController {dateTimeController},
|
||||
batteryController {batteryController},
|
||||
@@ -41,6 +42,7 @@ SystemInfo::SystemInfo(Pinetime::Applications::DisplayApp* app,
|
||||
bleController {bleController},
|
||||
watchdog {watchdog},
|
||||
motionController{motionController},
|
||||
touchPanel{touchPanel},
|
||||
screens {app,
|
||||
0,
|
||||
{[this]() -> std::unique_ptr<Screen> {
|
||||
@@ -141,7 +143,8 @@ std::unique_ptr<Screen> SystemInfo::CreateScreen2() {
|
||||
"#444444 Battery# %d%%/%03imV\n"
|
||||
"#444444 Backlight# %s\n"
|
||||
"#444444 Last reset# %s\n"
|
||||
"#444444 Accel.# %s\n",
|
||||
"#444444 Accel.# %s\n"
|
||||
"#444444 Touch.# %x.%x.%x\n",
|
||||
dateTimeController.Day(),
|
||||
static_cast<uint8_t>(dateTimeController.Month()),
|
||||
dateTimeController.Year(),
|
||||
@@ -156,7 +159,10 @@ std::unique_ptr<Screen> SystemInfo::CreateScreen2() {
|
||||
batteryController.Voltage(),
|
||||
brightnessController.ToString(),
|
||||
resetReason,
|
||||
ToString(motionController.DeviceType()));
|
||||
ToString(motionController.DeviceType()),
|
||||
touchPanel.GetChipId(),
|
||||
touchPanel.GetVendorId(),
|
||||
touchPanel.GetFwVersion());
|
||||
lv_obj_align(label, lv_scr_act(), LV_ALIGN_CENTER, 0, 0);
|
||||
return std::make_unique<Screens::Label>(1, 5, app, label);
|
||||
}
|
||||
@@ -200,11 +206,14 @@ bool SystemInfo::sortById(const TaskStatus_t& lhs, const TaskStatus_t& rhs) {
|
||||
}
|
||||
|
||||
std::unique_ptr<Screen> SystemInfo::CreateScreen4() {
|
||||
TaskStatus_t tasksStatus[10];
|
||||
static constexpr uint8_t maxTaskCount = 9;
|
||||
TaskStatus_t tasksStatus[maxTaskCount];
|
||||
|
||||
lv_obj_t* infoTask = lv_table_create(lv_scr_act(), NULL);
|
||||
lv_table_set_col_cnt(infoTask, 4);
|
||||
lv_table_set_row_cnt(infoTask, 8);
|
||||
lv_obj_set_pos(infoTask, 0, 10);
|
||||
lv_table_set_row_cnt(infoTask, maxTaskCount + 1);
|
||||
lv_obj_set_style_local_pad_all(infoTask, LV_TABLE_PART_CELL1, LV_STATE_DEFAULT, 0);
|
||||
lv_obj_set_style_local_border_color(infoTask, LV_TABLE_PART_CELL1, LV_STATE_DEFAULT, LV_COLOR_GRAY);
|
||||
|
||||
lv_table_set_cell_value(infoTask, 0, 0, "#");
|
||||
lv_table_set_col_width(infoTask, 0, 30);
|
||||
@@ -215,9 +224,9 @@ std::unique_ptr<Screen> SystemInfo::CreateScreen4() {
|
||||
lv_table_set_cell_value(infoTask, 0, 3, "Free");
|
||||
lv_table_set_col_width(infoTask, 3, 90);
|
||||
|
||||
auto nb = uxTaskGetSystemState(tasksStatus, sizeof(tasksStatus) / sizeof(tasksStatus[0]), nullptr);
|
||||
auto nb = uxTaskGetSystemState(tasksStatus, maxTaskCount, nullptr);
|
||||
std::sort(tasksStatus, tasksStatus + nb, sortById);
|
||||
for (uint8_t i = 0; i < nb && i < 7; i++) {
|
||||
for (uint8_t i = 0; i < nb && i < maxTaskCount; i++) {
|
||||
|
||||
lv_table_set_cell_value(infoTask, i + 1, 0, std::to_string(tasksStatus[i].xTaskNumber).c_str());
|
||||
char state[2] = {0};
|
||||
@@ -261,7 +270,8 @@ std::unique_ptr<Screen> SystemInfo::CreateScreen5() {
|
||||
"Public License v3\n"
|
||||
"#444444 Source code#\n"
|
||||
"#FFFF00 https://github.com/#\n"
|
||||
"#FFFF00 JF002/InfiniTime#");
|
||||
"#FFFF00 InfiniTimeOrg/#\n"
|
||||
"#FFFF00 InfiniTime#");
|
||||
lv_label_set_align(label, LV_LABEL_ALIGN_CENTER);
|
||||
lv_obj_align(label, lv_scr_act(), LV_ALIGN_CENTER, 0, 0);
|
||||
return std::make_unique<Screens::Label>(4, 5, app, label);
|
||||
|
@@ -28,7 +28,8 @@ namespace Pinetime {
|
||||
Pinetime::Controllers::BrightnessController& brightnessController,
|
||||
Pinetime::Controllers::Ble& bleController,
|
||||
Pinetime::Drivers::WatchdogView& watchdog,
|
||||
Pinetime::Controllers::MotionController& motionController);
|
||||
Pinetime::Controllers::MotionController& motionController,
|
||||
Pinetime::Drivers::Cst816S& touchPanel);
|
||||
~SystemInfo() override;
|
||||
bool OnTouchEvent(TouchEvents event) override;
|
||||
|
||||
@@ -39,6 +40,7 @@ namespace Pinetime {
|
||||
Pinetime::Controllers::Ble& bleController;
|
||||
Pinetime::Drivers::WatchdogView& watchdog;
|
||||
Pinetime::Controllers::MotionController& motionController;
|
||||
Pinetime::Drivers::Cst816S& touchPanel;
|
||||
|
||||
ScreenList<5> screens;
|
||||
|
||||
|
198
src/displayapp/screens/settings/SettingSetDate.cpp
Normal file
198
src/displayapp/screens/settings/SettingSetDate.cpp
Normal file
@@ -0,0 +1,198 @@
|
||||
#include "SettingSetDate.h"
|
||||
#include <lvgl/lvgl.h>
|
||||
#include <hal/nrf_rtc.h>
|
||||
#include <nrf_log.h>
|
||||
#include "displayapp/DisplayApp.h"
|
||||
#include "displayapp/screens/Symbols.h"
|
||||
|
||||
using namespace Pinetime::Applications::Screens;
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
SettingSetDate::SettingSetDate(Pinetime::Applications::DisplayApp *app, Pinetime::Controllers::DateTime &dateTimeController) :
|
||||
Screen(app),
|
||||
dateTimeController {dateTimeController} {
|
||||
lv_obj_t * title = lv_label_create(lv_scr_act(), nullptr);
|
||||
lv_label_set_text_static(title, "Set current date");
|
||||
lv_label_set_align(title, LV_LABEL_ALIGN_CENTER);
|
||||
lv_obj_align(title, lv_scr_act(), LV_ALIGN_IN_TOP_MID, 15, 15);
|
||||
|
||||
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);
|
||||
|
||||
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);
|
||||
|
||||
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);
|
||||
|
||||
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);
|
||||
|
||||
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_value_str(btnSetTime, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, "Set");
|
||||
lv_obj_set_event_cb(btnSetTime, event_handler);
|
||||
}
|
||||
|
||||
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::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)));
|
||||
}
|
41
src/displayapp/screens/settings/SettingSetDate.h
Normal file
41
src/displayapp/screens/settings/SettingSetDate.h
Normal file
@@ -0,0 +1,41 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <lvgl/lvgl.h>
|
||||
#include "components/datetime/DateTimeController.h"
|
||||
#include "displayapp/screens/Screen.h"
|
||||
|
||||
namespace Pinetime {
|
||||
namespace Applications {
|
||||
namespace Screens {
|
||||
class SettingSetDate : public Screen{
|
||||
public:
|
||||
SettingSetDate(DisplayApp* app, Pinetime::Controllers::DateTime &dateTimeController);
|
||||
~SettingSetDate() override;
|
||||
|
||||
void HandleButtonPress(lv_obj_t *object, lv_event_t event);
|
||||
|
||||
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();
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
154
src/displayapp/screens/settings/SettingSetTime.cpp
Normal file
154
src/displayapp/screens/settings/SettingSetTime.cpp
Normal file
@@ -0,0 +1,154 @@
|
||||
#include "SettingSetTime.h"
|
||||
#include <lvgl/lvgl.h>
|
||||
#include <hal/nrf_rtc.h>
|
||||
#include <nrf_log.h>
|
||||
#include "displayapp/DisplayApp.h"
|
||||
#include "displayapp/screens/Symbols.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;
|
||||
|
||||
void event_handler(lv_obj_t * obj, lv_event_t event) {
|
||||
auto* screen = static_cast<SettingSetTime *>(obj->user_data);
|
||||
screen->HandleButtonPress(obj, event);
|
||||
}
|
||||
}
|
||||
|
||||
SettingSetTime::SettingSetTime(Pinetime::Applications::DisplayApp *app, Pinetime::Controllers::DateTime &dateTimeController) :
|
||||
Screen(app),
|
||||
dateTimeController {dateTimeController} {
|
||||
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);
|
||||
lv_obj_align(title, lv_scr_act(), LV_ALIGN_IN_TOP_MID, 15, 15);
|
||||
|
||||
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 * 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);
|
||||
|
||||
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);
|
||||
|
||||
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);
|
||||
|
||||
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_value_str(btnSetTime, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, "Set");
|
||||
lv_obj_set_event_cb(btnSetTime, event_handler);
|
||||
}
|
||||
|
||||
SettingSetTime::~SettingSetTime() {
|
||||
lv_obj_clean(lv_scr_act());
|
||||
}
|
||||
|
||||
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;
|
||||
lv_label_set_text_fmt(lblHours, "%02d", hoursValue);
|
||||
lv_btn_set_state(btnSetTime, LV_BTN_STATE_RELEASED);
|
||||
} else if (object == btnHoursMinus) {
|
||||
hoursValue--;
|
||||
if (hoursValue < 0)
|
||||
hoursValue = 23;
|
||||
lv_label_set_text_fmt(lblHours, "%02d", hoursValue);
|
||||
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);
|
||||
}
|
||||
}
|
33
src/displayapp/screens/settings/SettingSetTime.h
Normal file
33
src/displayapp/screens/settings/SettingSetTime.h
Normal file
@@ -0,0 +1,33 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <lvgl/lvgl.h>
|
||||
#include "components/datetime/DateTimeController.h"
|
||||
#include "displayapp/screens/Screen.h"
|
||||
|
||||
namespace Pinetime {
|
||||
namespace Applications {
|
||||
namespace Screens {
|
||||
class SettingSetTime : public Screen{
|
||||
public:
|
||||
SettingSetTime(DisplayApp* app, Pinetime::Controllers::DateTime &dateTimeController);
|
||||
~SettingSetTime() override;
|
||||
|
||||
void HandleButtonPress(lv_obj_t *object, lv_event_t event);
|
||||
|
||||
private:
|
||||
Controllers::DateTime& dateTimeController;
|
||||
|
||||
int hoursValue;
|
||||
int minutesValue;
|
||||
lv_obj_t * lblHours;
|
||||
lv_obj_t * lblMinutes;
|
||||
lv_obj_t * btnHoursPlus;
|
||||
lv_obj_t * btnHoursMinus;
|
||||
lv_obj_t * btnMinutesPlus;
|
||||
lv_obj_t * btnMinutesMinus;
|
||||
lv_obj_t * btnSetTime;
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
@@ -47,8 +47,20 @@ std::unique_ptr<Screen> Settings::CreateScreen2() {
|
||||
std::array<Screens::List::Applications, 4> applications {{
|
||||
{Symbols::shoe, "Steps", Apps::SettingSteps},
|
||||
{Symbols::batteryHalf, "Battery", Apps::BatteryInfo},
|
||||
{Symbols::clock, "Set date", Apps::SettingSetDate},
|
||||
{Symbols::clock, "Set time", Apps::SettingSetTime}
|
||||
}};
|
||||
|
||||
return std::make_unique<Screens::List>(1, 3, app, settingsController, applications);
|
||||
}
|
||||
|
||||
std::unique_ptr<Screen> Settings::CreateScreen3() {
|
||||
|
||||
std::array<Screens::List::Applications, 4> applications {{
|
||||
{Symbols::check, "Firmware", Apps::FirmwareValidation},
|
||||
{Symbols::list, "About", Apps::SysInfo},
|
||||
{Symbols::none, "None", Apps::None},
|
||||
{Symbols::none, "None", Apps::None}
|
||||
}};
|
||||
|
||||
return std::make_unique<Screens::List>(1, 2, app, settingsController, applications);
|
||||
|
Reference in New Issue
Block a user