Merge branch 'mruss77-statusBarTimeFormat' into develop
This commit is contained in:
commit
e332be0d7c
6 changed files with 38 additions and 10 deletions
|
@ -11,6 +11,9 @@ namespace {
|
|||
char const* MonthsStringLow[] = {"--", "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
|
||||
}
|
||||
|
||||
DateTime::DateTime(Controllers::Settings& settingsController) : settingsController {settingsController} {
|
||||
}
|
||||
|
||||
void DateTime::SetCurrentTime(std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds> t) {
|
||||
this->currentDateTime = t;
|
||||
UpdateTime(previousSystickCounter); // Update internal state without updating the time
|
||||
|
@ -120,3 +123,24 @@ const char* DateTime::MonthShortToStringLow(Months month) {
|
|||
void DateTime::Register(Pinetime::System::SystemTask* systemTask) {
|
||||
this->systemTask = systemTask;
|
||||
}
|
||||
|
||||
using ClockType = Pinetime::Controllers::Settings::ClockType;
|
||||
std::string DateTime::FormattedTime() {
|
||||
// Return time as a string in 12- or 24-hour format
|
||||
char buff[9];
|
||||
if (settingsController.GetClockType() == ClockType::H12) {
|
||||
uint8_t hour12;
|
||||
const char* amPmStr;
|
||||
if (hour < 12) {
|
||||
hour12 = (hour == 0) ? 12 : hour;
|
||||
amPmStr = "AM";
|
||||
} else {
|
||||
hour12 = (hour == 12) ? 12 : hour - 12;
|
||||
amPmStr = "PM";
|
||||
}
|
||||
sprintf(buff, "%i:%02i %s", hour12, minute, amPmStr);
|
||||
} else {
|
||||
sprintf(buff, "%02i:%02i", hour, minute);
|
||||
}
|
||||
return std::string(buff);
|
||||
}
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
#include <cstdint>
|
||||
#include <chrono>
|
||||
#include <string>
|
||||
#include "components/settings/Settings.h"
|
||||
|
||||
namespace Pinetime {
|
||||
namespace System {
|
||||
|
@ -10,6 +12,7 @@ namespace Pinetime {
|
|||
namespace Controllers {
|
||||
class DateTime {
|
||||
public:
|
||||
DateTime(Controllers::Settings& settingsController);
|
||||
enum class Days : uint8_t { Unknown, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday };
|
||||
enum class Months : uint8_t {
|
||||
Unknown,
|
||||
|
@ -71,6 +74,7 @@ namespace Pinetime {
|
|||
|
||||
void Register(System::SystemTask* systemTask);
|
||||
void SetCurrentTime(std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds> t);
|
||||
std::string FormattedTime();
|
||||
|
||||
private:
|
||||
uint16_t year = 0;
|
||||
|
@ -89,6 +93,7 @@ namespace Pinetime {
|
|||
bool isHourAlreadyNotified = true;
|
||||
bool isHalfHourAlreadyNotified = true;
|
||||
System::SystemTask* systemTask = nullptr;
|
||||
Controllers::Settings& settingsController;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
#pragma once
|
||||
#include <cstdint>
|
||||
#include <bitset>
|
||||
#include "components/datetime/DateTimeController.h"
|
||||
#include "components/brightness/BrightnessController.h"
|
||||
#include "components/fs/FS.h"
|
||||
|
||||
|
|
|
@ -33,7 +33,7 @@ Tile::Tile(uint8_t screenID,
|
|||
|
||||
// Time
|
||||
label_time = lv_label_create(lv_scr_act(), nullptr);
|
||||
lv_label_set_text_fmt(label_time, "%02i:%02i", dateTimeController.Hours(), dateTimeController.Minutes());
|
||||
lv_label_set_text(label_time, dateTimeController.FormattedTime().c_str());
|
||||
lv_label_set_align(label_time, LV_LABEL_ALIGN_CENTER);
|
||||
lv_obj_align(label_time, nullptr, LV_ALIGN_IN_TOP_LEFT, 0, 0);
|
||||
|
||||
|
@ -119,7 +119,7 @@ Tile::~Tile() {
|
|||
}
|
||||
|
||||
void Tile::UpdateScreen() {
|
||||
lv_label_set_text_fmt(label_time, "%02i:%02i", dateTimeController.Hours(), dateTimeController.Minutes());
|
||||
lv_label_set_text(label_time, dateTimeController.FormattedTime().c_str());
|
||||
lv_label_set_text(batteryIcon, BatteryIcon::GetBatteryIcon(batteryController.PercentRemaining()));
|
||||
}
|
||||
|
||||
|
|
|
@ -35,7 +35,7 @@ QuickSettings::QuickSettings(Pinetime::Applications::DisplayApp* app,
|
|||
|
||||
// Time
|
||||
label_time = lv_label_create(lv_scr_act(), nullptr);
|
||||
lv_label_set_text_fmt(label_time, "%02i:%02i", dateTimeController.Hours(), dateTimeController.Minutes());
|
||||
lv_label_set_text(label_time, dateTimeController.FormattedTime().c_str());
|
||||
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);
|
||||
|
||||
|
@ -123,7 +123,7 @@ QuickSettings::~QuickSettings() {
|
|||
}
|
||||
|
||||
void QuickSettings::UpdateScreen() {
|
||||
lv_label_set_text_fmt(label_time, "%02i:%02i", dateTimeController.Hours(), dateTimeController.Minutes());
|
||||
lv_label_set_text(label_time, dateTimeController.FormattedTime().c_str());
|
||||
lv_label_set_text(batteryIcon, BatteryIcon::GetBatteryIcon(batteryController.PercentRemaining()));
|
||||
}
|
||||
|
||||
|
|
10
src/main.cpp
10
src/main.cpp
|
@ -101,7 +101,11 @@ Pinetime::Controllers::Ble bleController;
|
|||
Pinetime::Controllers::HeartRateController heartRateController;
|
||||
Pinetime::Applications::HeartRateTask heartRateApp(heartRateSensor, heartRateController);
|
||||
|
||||
Pinetime::Controllers::DateTime dateTimeController;
|
||||
Pinetime::Controllers::FS fs {spiNorFlash};
|
||||
Pinetime::Controllers::Settings settingsController {fs};
|
||||
Pinetime::Controllers::MotorController motorController {};
|
||||
|
||||
Pinetime::Controllers::DateTime dateTimeController {settingsController};
|
||||
Pinetime::Drivers::Watchdog watchdog;
|
||||
Pinetime::Drivers::WatchdogView watchdogView(watchdog);
|
||||
Pinetime::Controllers::NotificationManager notificationManager;
|
||||
|
@ -111,10 +115,6 @@ Pinetime::Controllers::AlarmController alarmController {dateTimeController};
|
|||
Pinetime::Controllers::TouchHandler touchHandler(touchPanel, lvgl);
|
||||
Pinetime::Controllers::ButtonHandler buttonHandler;
|
||||
|
||||
Pinetime::Controllers::FS fs {spiNorFlash};
|
||||
Pinetime::Controllers::Settings settingsController {fs};
|
||||
Pinetime::Controllers::MotorController motorController {};
|
||||
|
||||
Pinetime::Applications::DisplayApp displayApp(lcd,
|
||||
lvgl,
|
||||
touchPanel,
|
||||
|
|
Loading…
Reference in a new issue