Merge branch 'statusBarTimeFormat' of https://github.com/mruss77/InfiniTime into mruss77-statusBarTimeFormat
# Conflicts: # src/components/datetime/DateTimeController.cpp
This commit is contained in:
commit
87d882b151
|
@ -11,6 +11,9 @@ namespace {
|
||||||
char const* MonthsStringLow[] = {"--", "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
|
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) {
|
void DateTime::SetCurrentTime(std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds> t) {
|
||||||
this->currentDateTime = t;
|
this->currentDateTime = t;
|
||||||
UpdateTime(previousSystickCounter); // Update internal state without updating the time
|
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) {
|
void DateTime::Register(Pinetime::System::SystemTask* systemTask) {
|
||||||
this->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 <cstdint>
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
|
#include <string>
|
||||||
|
#include "components/settings/Settings.h"
|
||||||
|
|
||||||
namespace Pinetime {
|
namespace Pinetime {
|
||||||
namespace System {
|
namespace System {
|
||||||
|
@ -10,6 +12,7 @@ namespace Pinetime {
|
||||||
namespace Controllers {
|
namespace Controllers {
|
||||||
class DateTime {
|
class DateTime {
|
||||||
public:
|
public:
|
||||||
|
DateTime(Controllers::Settings& settingsController);
|
||||||
enum class Days : uint8_t { Unknown, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday };
|
enum class Days : uint8_t { Unknown, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday };
|
||||||
enum class Months : uint8_t {
|
enum class Months : uint8_t {
|
||||||
Unknown,
|
Unknown,
|
||||||
|
@ -71,6 +74,7 @@ namespace Pinetime {
|
||||||
|
|
||||||
void Register(System::SystemTask* systemTask);
|
void Register(System::SystemTask* systemTask);
|
||||||
void SetCurrentTime(std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds> t);
|
void SetCurrentTime(std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds> t);
|
||||||
|
std::string FormattedTime();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
uint16_t year = 0;
|
uint16_t year = 0;
|
||||||
|
@ -89,6 +93,7 @@ namespace Pinetime {
|
||||||
bool isHourAlreadyNotified = true;
|
bool isHourAlreadyNotified = true;
|
||||||
bool isHalfHourAlreadyNotified = true;
|
bool isHalfHourAlreadyNotified = true;
|
||||||
System::SystemTask* systemTask = nullptr;
|
System::SystemTask* systemTask = nullptr;
|
||||||
|
Controllers::Settings& settingsController;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <bitset>
|
#include <bitset>
|
||||||
#include "components/datetime/DateTimeController.h"
|
|
||||||
#include "components/brightness/BrightnessController.h"
|
#include "components/brightness/BrightnessController.h"
|
||||||
#include "components/fs/FS.h"
|
#include "components/fs/FS.h"
|
||||||
|
|
||||||
|
|
|
@ -33,7 +33,7 @@ Tile::Tile(uint8_t screenID,
|
||||||
|
|
||||||
// Time
|
// Time
|
||||||
label_time = lv_label_create(lv_scr_act(), nullptr);
|
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_label_set_align(label_time, LV_LABEL_ALIGN_CENTER);
|
||||||
lv_obj_align(label_time, nullptr, LV_ALIGN_IN_TOP_LEFT, 0, 0);
|
lv_obj_align(label_time, nullptr, LV_ALIGN_IN_TOP_LEFT, 0, 0);
|
||||||
|
|
||||||
|
@ -119,7 +119,7 @@ Tile::~Tile() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Tile::UpdateScreen() {
|
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()));
|
lv_label_set_text(batteryIcon, BatteryIcon::GetBatteryIcon(batteryController.PercentRemaining()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -35,7 +35,7 @@ QuickSettings::QuickSettings(Pinetime::Applications::DisplayApp* app,
|
||||||
|
|
||||||
// Time
|
// Time
|
||||||
label_time = lv_label_create(lv_scr_act(), nullptr);
|
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_label_set_align(label_time, LV_LABEL_ALIGN_CENTER);
|
||||||
lv_obj_align(label_time, lv_scr_act(), LV_ALIGN_IN_TOP_LEFT, 0, 0);
|
lv_obj_align(label_time, lv_scr_act(), LV_ALIGN_IN_TOP_LEFT, 0, 0);
|
||||||
|
|
||||||
|
@ -123,7 +123,7 @@ QuickSettings::~QuickSettings() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void QuickSettings::UpdateScreen() {
|
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()));
|
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::Controllers::HeartRateController heartRateController;
|
||||||
Pinetime::Applications::HeartRateTask heartRateApp(heartRateSensor, 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::Watchdog watchdog;
|
||||||
Pinetime::Drivers::WatchdogView watchdogView(watchdog);
|
Pinetime::Drivers::WatchdogView watchdogView(watchdog);
|
||||||
Pinetime::Controllers::NotificationManager notificationManager;
|
Pinetime::Controllers::NotificationManager notificationManager;
|
||||||
|
@ -111,10 +115,6 @@ Pinetime::Controllers::AlarmController alarmController {dateTimeController};
|
||||||
Pinetime::Controllers::TouchHandler touchHandler(touchPanel, lvgl);
|
Pinetime::Controllers::TouchHandler touchHandler(touchPanel, lvgl);
|
||||||
Pinetime::Controllers::ButtonHandler buttonHandler;
|
Pinetime::Controllers::ButtonHandler buttonHandler;
|
||||||
|
|
||||||
Pinetime::Controllers::FS fs {spiNorFlash};
|
|
||||||
Pinetime::Controllers::Settings settingsController {fs};
|
|
||||||
Pinetime::Controllers::MotorController motorController {};
|
|
||||||
|
|
||||||
Pinetime::Applications::DisplayApp displayApp(lcd,
|
Pinetime::Applications::DisplayApp displayApp(lcd,
|
||||||
lvgl,
|
lvgl,
|
||||||
touchPanel,
|
touchPanel,
|
||||||
|
|
Loading…
Reference in a new issue