Compare commits
6 Commits
develop
...
rei/develo
Author | SHA1 | Date |
---|---|---|
Olivier 'reivilibre' | e54d78a04b | |
Olivier 'reivilibre' | 8f32478141 | |
Olivier 'reivilibre' | b002fddc29 | |
Olivier 'reivilibre' | ea62510eb6 | |
Olivier 'reivilibre' | a4598ed63e | |
Olivier 'reivilibre' | 72a020127f |
|
@ -403,6 +403,7 @@ list(APPEND SOURCE_FILES
|
|||
displayapp/screens/Error.cpp
|
||||
displayapp/screens/Alarm.cpp
|
||||
displayapp/screens/Styles.cpp
|
||||
displayapp/screens/Agenda.cpp
|
||||
displayapp/Colors.cpp
|
||||
displayapp/widgets/Counter.cpp
|
||||
|
||||
|
@ -457,6 +458,7 @@ list(APPEND SOURCE_FILES
|
|||
components/ble/MusicService.cpp
|
||||
components/ble/weather/WeatherService.cpp
|
||||
components/ble/NavigationService.cpp
|
||||
components/ble/AgendaService.cpp
|
||||
components/ble/BatteryInformationService.cpp
|
||||
components/ble/FSService.cpp
|
||||
components/ble/ImmediateAlertService.cpp
|
||||
|
@ -528,6 +530,7 @@ list(APPEND RECOVERY_SOURCE_FILES
|
|||
components/ble/ImmediateAlertService.cpp
|
||||
components/ble/ServiceDiscovery.cpp
|
||||
components/ble/NavigationService.cpp
|
||||
components/ble/AgendaService.cpp
|
||||
components/ble/HeartRateService.cpp
|
||||
components/ble/MotionService.cpp
|
||||
components/firmwarevalidator/FirmwareValidator.cpp
|
||||
|
|
|
@ -0,0 +1,109 @@
|
|||
/* Copyright (C) 2021 Adam Pigg
|
||||
|
||||
This file is part of InfiniTime.
|
||||
|
||||
InfiniTime is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published
|
||||
by the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
InfiniTime is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "components/ble/AgendaService.h"
|
||||
|
||||
#include "systemtask/SystemTask.h"
|
||||
|
||||
namespace {
|
||||
// 3fdaYYXX-e246-472e-b7e0-d2b0f3d9c17a
|
||||
constexpr ble_uuid128_t CharUuid(uint8_t x, uint8_t y) {
|
||||
return ble_uuid128_t {.u = {.type = BLE_UUID_TYPE_128},
|
||||
.value = {0x7a, 0xc1, 0xd9, 0xf3, 0xb0, 0xd2, 0xe0, 0xb7, 0x2e, 0x47, 0x46, 0xe2, x, y, 0xda, 0x3f}};
|
||||
}
|
||||
|
||||
// 00010000-78fc-48fe-8e23-433b3a1942d0
|
||||
constexpr ble_uuid128_t BaseUuid() {
|
||||
return CharUuid(0x00, 0x00);
|
||||
}
|
||||
|
||||
constexpr ble_uuid128_t agendaUuid {BaseUuid()};
|
||||
|
||||
constexpr ble_uuid128_t agendaItemCharUuid {CharUuid(0x01, 0x00)};
|
||||
/*constexpr ble_uuid128_t navNarrativeCharUuid {CharUuid(0x02, 0x00)};
|
||||
constexpr ble_uuid128_t navManDistCharUuid {CharUuid(0x03, 0x00)};
|
||||
constexpr ble_uuid128_t navProgressCharUuid {CharUuid(0x04, 0x00)};*/
|
||||
|
||||
int AgendaCallback(uint16_t conn_handle, uint16_t attr_handle, struct ble_gatt_access_ctxt* ctxt, void* arg) {
|
||||
auto agendaService = static_cast<Pinetime::Controllers::AgendaService*>(arg);
|
||||
return agendaService->OnCommand(conn_handle, attr_handle, ctxt);
|
||||
}
|
||||
} // namespace
|
||||
|
||||
Pinetime::Controllers::AgendaService::AgendaService(Pinetime::System::SystemTask& system) : m_system(system) {
|
||||
characteristicDefinition[0] = {.uuid = &agendaItemCharUuid.u,
|
||||
.access_cb = AgendaCallback,
|
||||
.arg = this,
|
||||
.flags = BLE_GATT_CHR_F_WRITE | BLE_GATT_CHR_F_READ};
|
||||
|
||||
characteristicDefinition[1] = {0};
|
||||
|
||||
serviceDefinition[0] = {.type = BLE_GATT_SVC_TYPE_PRIMARY, .uuid = &agendaUuid.u, .characteristics = characteristicDefinition};
|
||||
serviceDefinition[1] = {0};
|
||||
}
|
||||
|
||||
void Pinetime::Controllers::AgendaService::Init() {
|
||||
int res = 0;
|
||||
res = ble_gatts_count_cfg(serviceDefinition);
|
||||
ASSERT(res == 0);
|
||||
|
||||
res = ble_gatts_add_svcs(serviceDefinition);
|
||||
ASSERT(res == 0);
|
||||
|
||||
m_agenda_times[0] = 1655327841;
|
||||
m_agenda_pieces[0] = "C++ Fumbling";
|
||||
}
|
||||
|
||||
int Pinetime::Controllers::AgendaService::OnCommand(uint16_t conn_handle, uint16_t attr_handle, struct ble_gatt_access_ctxt* ctxt) {
|
||||
|
||||
if (ctxt->op == BLE_GATT_ACCESS_OP_WRITE_CHR) {
|
||||
size_t notifSize = OS_MBUF_PKTLEN(ctxt->om);
|
||||
uint8_t data[notifSize + 1];
|
||||
data[notifSize] = '\0';
|
||||
os_mbuf_copydata(ctxt->om, 0, notifSize, data);
|
||||
if (ble_uuid_cmp(ctxt->chr->uuid, &agendaItemCharUuid.u) == 0) {
|
||||
if (notifSize >= 5) {
|
||||
uint8_t itemIndex = (uint8_t) data[0];
|
||||
uint32_t itemTime = ((uint32_t) data[1]) << 24 | ((uint32_t) data[2]) << 16 | ((uint32_t) data[3]) << 8 | ((uint32_t) data[4]);
|
||||
char* sAgendaItem = (char*) &data[5];
|
||||
if (itemIndex < AGENDA_CAPACITY) { // don't allow a buffer overflow
|
||||
m_agenda_times[itemIndex] = itemTime;
|
||||
// implicit std::string copy/conversion here:
|
||||
m_agenda_pieces[itemIndex] = sAgendaItem;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint32_t Pinetime::Controllers::AgendaService::getAgendaTime(uint8_t index) {
|
||||
if (index < AGENDA_CAPACITY) {
|
||||
return m_agenda_times[index];
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
std::string Pinetime::Controllers::AgendaService::getAgendaPiece(uint8_t index) {
|
||||
if (index < AGENDA_CAPACITY) {
|
||||
return m_agenda_pieces[index];
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,59 @@
|
|||
/* Copyright (C) 2021 Adam Pigg
|
||||
|
||||
This file is part of InfiniTime.
|
||||
|
||||
InfiniTime is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published
|
||||
by the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
InfiniTime is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
#define min // workaround: nimble's min/max macros conflict with libstdc++
|
||||
#define max
|
||||
#include <host/ble_gap.h>
|
||||
#include <host/ble_uuid.h>
|
||||
#undef max
|
||||
#undef min
|
||||
|
||||
namespace Pinetime {
|
||||
namespace System {
|
||||
class SystemTask;
|
||||
}
|
||||
namespace Controllers {
|
||||
|
||||
class AgendaService {
|
||||
public:
|
||||
static const uint8_t AGENDA_CAPACITY = 35;
|
||||
|
||||
explicit AgendaService(Pinetime::System::SystemTask& system);
|
||||
|
||||
void Init();
|
||||
|
||||
int OnCommand(uint16_t conn_handle, uint16_t attr_handle, struct ble_gatt_access_ctxt* ctxt);
|
||||
|
||||
uint32_t getAgendaTime(uint8_t index);
|
||||
|
||||
std::string getAgendaPiece(uint8_t index);
|
||||
|
||||
private:
|
||||
struct ble_gatt_chr_def characteristicDefinition[2];
|
||||
struct ble_gatt_svc_def serviceDefinition[2];
|
||||
|
||||
uint32_t m_agenda_times[AGENDA_CAPACITY];
|
||||
std::string m_agenda_pieces[AGENDA_CAPACITY];
|
||||
|
||||
Pinetime::System::SystemTask& m_system;
|
||||
};
|
||||
}
|
||||
}
|
|
@ -51,6 +51,7 @@ NimbleController::NimbleController(Pinetime::System::SystemTask& systemTask,
|
|||
heartRateService {systemTask, heartRateController},
|
||||
motionService {systemTask, motionController},
|
||||
fsService {systemTask, fs},
|
||||
agendaService {systemTask},
|
||||
serviceDiscovery({¤tTimeClient, &alertNotificationClient}) {
|
||||
}
|
||||
|
||||
|
@ -93,6 +94,7 @@ void NimbleController::Init() {
|
|||
musicService.Init();
|
||||
weatherService.Init();
|
||||
navService.Init();
|
||||
agendaService.Init();
|
||||
anService.Init();
|
||||
dfuService.Init();
|
||||
batteryInformationService.Init();
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
#include "components/ble/NavigationService.h"
|
||||
#include "components/ble/ServiceDiscovery.h"
|
||||
#include "components/ble/MotionService.h"
|
||||
#include "components/ble/AgendaService.h"
|
||||
#include "components/ble/weather/WeatherService.h"
|
||||
#include "components/fs/FS.h"
|
||||
|
||||
|
@ -61,6 +62,9 @@ namespace Pinetime {
|
|||
Pinetime::Controllers::NavigationService& navigation() {
|
||||
return navService;
|
||||
};
|
||||
Pinetime::Controllers::AgendaService& agenda() {
|
||||
return agendaService;
|
||||
};
|
||||
Pinetime::Controllers::AlertNotificationService& alertService() {
|
||||
return anService;
|
||||
};
|
||||
|
@ -103,6 +107,7 @@ namespace Pinetime {
|
|||
HeartRateService heartRateService;
|
||||
MotionService motionService;
|
||||
FSService fsService;
|
||||
AgendaService agendaService;
|
||||
ServiceDiscovery serviceDiscovery;
|
||||
|
||||
uint8_t addrType;
|
||||
|
|
|
@ -39,7 +39,9 @@ namespace Pinetime {
|
|||
SettingChimes,
|
||||
SettingShakeThreshold,
|
||||
SettingBluetooth,
|
||||
Error
|
||||
Error,
|
||||
// oli: custom
|
||||
Agenda
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,6 +30,8 @@
|
|||
#include "displayapp/screens/PassKey.h"
|
||||
#include "displayapp/screens/Error.h"
|
||||
|
||||
#include "displayapp/screens/Agenda.h"
|
||||
|
||||
#include "drivers/Cst816s.h"
|
||||
#include "drivers/St7789.h"
|
||||
#include "drivers/Watchdog.h"
|
||||
|
@ -323,7 +325,8 @@ void DisplayApp::LoadApp(Apps app, DisplayApp::FullRefreshDirections direction)
|
|||
notificationManager,
|
||||
settingsController,
|
||||
heartRateController,
|
||||
motionController);
|
||||
motionController,
|
||||
systemTask->nimble().agenda());
|
||||
break;
|
||||
|
||||
case Apps::Error:
|
||||
|
@ -474,6 +477,10 @@ void DisplayApp::LoadApp(Apps app, DisplayApp::FullRefreshDirections direction)
|
|||
case Apps::Steps:
|
||||
currentScreen = std::make_unique<Screens::Steps>(this, motionController, settingsController);
|
||||
break;
|
||||
|
||||
case Apps::Agenda:
|
||||
currentScreen = std::make_unique<Screens::Agenda>(this, systemTask->nimble().agenda(), dateTimeController);
|
||||
break;
|
||||
}
|
||||
currentApp = app;
|
||||
}
|
||||
|
@ -511,6 +518,9 @@ void DisplayApp::SetFullRefresh(DisplayApp::FullRefreshDirections direction) {
|
|||
case DisplayApp::FullRefreshDirections::RightAnim:
|
||||
lvgl.SetFullRefresh(Components::LittleVgl::FullRefreshDirections::RightAnim);
|
||||
break;
|
||||
// case DisplayApp::FullRefreshDirections::None:
|
||||
// lvgl.SetFullRefresh(Components::LittleVgl::FullRefreshDirections::None);
|
||||
// break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,147 @@
|
|||
#include "displayapp/screens/Agenda.h"
|
||||
#include <date/date.h>
|
||||
#include <nrf_log.h>
|
||||
|
||||
using Pinetime::Applications::TouchEvents;
|
||||
using namespace Pinetime::Applications::Screens;
|
||||
|
||||
using namespace Pinetime::Controllers;
|
||||
|
||||
Agenda::Agenda(DisplayApp* app, AgendaService& agenda, Controllers::DateTime& dateTimeController) : Screen(app), agendaSvc(agenda), dateTimeController(dateTimeController) {
|
||||
lv_obj_t* alignNextTo = lv_scr_act();
|
||||
|
||||
for (uint8_t i = 0; i < AGENDA_ONSCREEN; ++i) {
|
||||
lv_obj_t* agendaItem = lv_label_create(lv_scr_act(), nullptr);
|
||||
lv_label_set_text_static(agendaItem, ".\n.");
|
||||
//lv_label_set_align(agendaItem, LV_LABEL_ALIGN_CENTER);
|
||||
if (i != 0) {
|
||||
lv_obj_align(agendaItem, alignNextTo, LV_ALIGN_OUT_BOTTOM_MID, 0, 0);
|
||||
}
|
||||
|
||||
agendaItems[i] = agendaItem;
|
||||
alignNextTo = agendaItem;
|
||||
}
|
||||
|
||||
pagingOffset = 0;
|
||||
|
||||
using namespace date;
|
||||
using namespace std::chrono;
|
||||
|
||||
std::chrono::system_clock::time_point nowTp = dateTimeController.CurrentDateTime();
|
||||
//sys_seconds now = nowTp;
|
||||
|
||||
// Find first entry that is just after the current time (- 5 min)!
|
||||
for (uint8_t i = 0; i < AgendaService::AGENDA_CAPACITY; ++i) {
|
||||
uint32_t time = agendaSvc.getAgendaTime(i);
|
||||
sys_seconds timestamp = sys_days{1970_y/1/1} + seconds{time};
|
||||
|
||||
if (timestamp > nowTp - minutes{5}) {
|
||||
uint8_t positionInPage = i % AGENDA_ONSCREEN;
|
||||
pagingOffset = i - positionInPage;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
taskRefresh = lv_task_create(RefreshTaskCallback, LV_DISP_DEF_REFR_PERIOD, LV_TASK_PRIO_MID, this);
|
||||
Relabel();
|
||||
//Refresh();
|
||||
}
|
||||
|
||||
bool Agenda::OnTouchEvent(TouchEvents event) {
|
||||
// NRF_LOG_INFO("touch");
|
||||
switch (event) {
|
||||
case TouchEvents::SwipeDown:
|
||||
if (pagingOffset >= AGENDA_ONSCREEN) {
|
||||
// NRF_LOG_INFO("swdn");
|
||||
pagingOffset -= AGENDA_ONSCREEN;
|
||||
app->SetFullRefresh(DisplayApp::FullRefreshDirections::Down);
|
||||
Relabel();
|
||||
}
|
||||
break;
|
||||
|
||||
case TouchEvents::SwipeUp:
|
||||
if (pagingOffset + 2*AGENDA_ONSCREEN <= AgendaService::AGENDA_CAPACITY) {
|
||||
// NRF_LOG_INFO("swup");
|
||||
pagingOffset += AGENDA_ONSCREEN;
|
||||
app->SetFullRefresh(DisplayApp::FullRefreshDirections::Up);
|
||||
Relabel();
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Agenda::~Agenda() {
|
||||
lv_task_del(taskRefresh);
|
||||
lv_obj_clean(lv_scr_act());
|
||||
}
|
||||
|
||||
void Agenda::Relabel() {
|
||||
using namespace date;
|
||||
using namespace std::chrono;
|
||||
std::chrono::system_clock::time_point now = dateTimeController.CurrentDateTime();
|
||||
auto todayDate = floor<date::days>(now);
|
||||
//auto nowTimePart = make_time(now - todayDate);
|
||||
|
||||
//auto todayYmd = year_month_day(todayDate);
|
||||
// NRF_LOG_INFO("date CURRENT %d-%u-%u %ldh%ldh%ld", (int) todayYmd.year(), (unsigned) todayYmd.month(), (unsigned) todayYmd.day(), nowTimePart.hours().count(), nowTimePart.minutes().count(), nowTimePart.seconds().count());
|
||||
|
||||
//std::cout << todayDate << ' ' << nowTimePart << '\n';
|
||||
|
||||
for (uint8_t i = 0; i < AGENDA_ONSCREEN; ++i) {
|
||||
uint8_t itemIdx = i + pagingOffset;
|
||||
uint32_t time = agendaSvc.getAgendaTime(itemIdx);
|
||||
|
||||
lv_obj_t* agendaItem = agendaItems[i];
|
||||
|
||||
if (time == 0) {
|
||||
lv_label_set_text_static(agendaItem, "--h--\n .....");
|
||||
lv_obj_set_style_local_text_color(agendaItem, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x332222));
|
||||
} else {
|
||||
sys_seconds timestamp = sys_days{1970_y/1/1} + seconds{time};
|
||||
//auto timestamp = std::chrono::system_clock::time_point{time * 1s};
|
||||
sys_days agendaDate = floor<days>(timestamp);
|
||||
time_of_day<seconds> agendaTimePart = make_time(timestamp - agendaDate);
|
||||
year_month_day ymd = year_month_day(agendaDate);
|
||||
//std::cout << agendaDate << ' ' << agendaTimePart << '\n';
|
||||
|
||||
/*std::time_t result = std::time(nullptr);
|
||||
std::time_t result = std::time(nullptr);
|
||||
std::chrono::time_point = */;
|
||||
|
||||
// NRF_LOG_INFO("IDX %u", itemIdx);
|
||||
// NRF_LOG_INFO("unix %u", time);
|
||||
// NRF_LOG_INFO("date %d-%u-%u ", (int) ymd.year(), (unsigned) ymd.month(), (unsigned) ymd.day());
|
||||
// NRF_LOG_INFO("time %ldh%ldm%ld", agendaTimePart.hours().count(), agendaTimePart.minutes().count(), agendaTimePart.seconds().count());
|
||||
// NRF_LOG_INFO("item %s", agendaSvc.getAgendaPiece(itemIdx).data());
|
||||
|
||||
if (agendaDate == todayDate) {
|
||||
lv_label_set_text_fmt(agendaItem, "%02lldh%02lld\n %s", agendaTimePart.hours().count(), agendaTimePart.minutes().count(), agendaSvc.getAgendaPiece(itemIdx).data());
|
||||
} else {
|
||||
lv_label_set_text_fmt(agendaItem, "%04d-%02u-%02u %02lldh%02lld\n %s", (int) ymd.year(), (unsigned) ymd.month(), (unsigned) ymd.day(), agendaTimePart.hours().count(), agendaTimePart.minutes().count(), agendaSvc.getAgendaPiece(itemIdx).data());
|
||||
}
|
||||
|
||||
if (timestamp + 30min < now) {
|
||||
lv_obj_set_style_local_text_color(agendaItem, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x334433));
|
||||
} else if (timestamp + 5min < now) {
|
||||
lv_obj_set_style_local_text_color(agendaItem, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x00FFE7));
|
||||
} else if (timestamp - 5min < now && now < timestamp + 5min) {
|
||||
lv_obj_set_style_local_text_color(agendaItem, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0xFFA500));
|
||||
} else if (now + 5min < timestamp) {
|
||||
lv_obj_set_style_local_text_color(agendaItem, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0xFFFF00));
|
||||
} else if (now + 30min < timestamp) {
|
||||
lv_obj_set_style_local_text_color(agendaItem, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0xFFFFFF));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Refresh seems to refer to re-render, but changing any LVGL widgets triggers a refresh again! */
|
||||
void Agenda::Refresh() {
|
||||
//NRF_LOG_INFO("refr");
|
||||
}
|
|
@ -0,0 +1,40 @@
|
|||
#pragma once
|
||||
|
||||
#include "displayapp/screens/Screen.h"
|
||||
#include "components/ble/AgendaService.h"
|
||||
#include "displayapp/DisplayApp.h"
|
||||
#include "components/datetime/DateTimeController.h"
|
||||
#include <lvgl/lvgl.h>
|
||||
|
||||
namespace Pinetime {
|
||||
namespace Controllers {
|
||||
class DateTime;
|
||||
}
|
||||
namespace Applications {
|
||||
namespace Screens {
|
||||
class Agenda : public Screen {
|
||||
public:
|
||||
static const uint8_t AGENDA_ONSCREEN = 5;
|
||||
|
||||
Agenda(DisplayApp* app, Pinetime::Controllers::AgendaService& agendaSvc, Pinetime::Controllers::DateTime &dateTimeController);
|
||||
~Agenda() override;
|
||||
|
||||
bool OnTouchEvent(TouchEvents event) override;
|
||||
|
||||
void Refresh() override;
|
||||
|
||||
void Relabel();
|
||||
|
||||
private:
|
||||
Pinetime::Controllers::AgendaService& agendaSvc;
|
||||
|
||||
Controllers::DateTime& dateTimeController;
|
||||
|
||||
lv_obj_t* agendaItems[AGENDA_ONSCREEN];
|
||||
uint8_t pagingOffset;
|
||||
|
||||
lv_task_t* taskRefresh;
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
|
@ -25,6 +25,9 @@ ApplicationList::ApplicationList(Pinetime::Applications::DisplayApp* app,
|
|||
[this]() -> std::unique_ptr<Screen> {
|
||||
return CreateScreen2();
|
||||
},
|
||||
[this]() -> std::unique_ptr<Screen> {
|
||||
return CreateScreen3();
|
||||
},
|
||||
//[this]() -> std::unique_ptr<Screen> { return CreateScreen3(); }
|
||||
},
|
||||
Screens::ScreenListModes::UpDown} {
|
||||
|
@ -48,7 +51,7 @@ std::unique_ptr<Screen> ApplicationList::CreateScreen1() {
|
|||
{Symbols::music, Apps::Music},
|
||||
}};
|
||||
|
||||
return std::make_unique<Screens::Tile>(0, 2, app, settingsController, batteryController, dateTimeController, applications);
|
||||
return std::make_unique<Screens::Tile>(0, 3, app, settingsController, batteryController, dateTimeController, applications);
|
||||
}
|
||||
|
||||
std::unique_ptr<Screen> ApplicationList::CreateScreen2() {
|
||||
|
@ -61,7 +64,20 @@ std::unique_ptr<Screen> ApplicationList::CreateScreen2() {
|
|||
{Symbols::map, Apps::Navigation},
|
||||
}};
|
||||
|
||||
return std::make_unique<Screens::Tile>(1, 2, app, settingsController, batteryController, dateTimeController, applications);
|
||||
return std::make_unique<Screens::Tile>(1, 3, app, settingsController, batteryController, dateTimeController, applications);
|
||||
}
|
||||
|
||||
std::unique_ptr<Screen> ApplicationList::CreateScreen3() {
|
||||
std::array<Screens::Tile::Applications, 6> applications {{
|
||||
{"A", Apps::Agenda},
|
||||
{".", Apps::Paddle},
|
||||
{".", Apps::Twos},
|
||||
{".", Apps::Motion},
|
||||
{".", Apps::Metronome},
|
||||
{".", Apps::Navigation},
|
||||
}};
|
||||
|
||||
return std::make_unique<Screens::Tile>(2, 3, app, settingsController, batteryController, dateTimeController, applications);
|
||||
}
|
||||
|
||||
/*std::unique_ptr<Screen> ApplicationList::CreateScreen3() {
|
||||
|
|
|
@ -25,10 +25,10 @@ namespace Pinetime {
|
|||
Pinetime::Controllers::Battery& batteryController;
|
||||
Controllers::DateTime& dateTimeController;
|
||||
|
||||
ScreenList<2> screens;
|
||||
ScreenList<3> screens;
|
||||
std::unique_ptr<Screen> CreateScreen1();
|
||||
std::unique_ptr<Screen> CreateScreen2();
|
||||
// std::unique_ptr<Screen> CreateScreen3();
|
||||
std::unique_ptr<Screen> CreateScreen3();
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,7 +22,8 @@ Clock::Clock(DisplayApp* app,
|
|||
Controllers::NotificationManager& notificatioManager,
|
||||
Controllers::Settings& settingsController,
|
||||
Controllers::HeartRateController& heartRateController,
|
||||
Controllers::MotionController& motionController)
|
||||
Controllers::MotionController& motionController,
|
||||
Controllers::AgendaService& agendaService)
|
||||
: Screen(app),
|
||||
dateTimeController {dateTimeController},
|
||||
batteryController {batteryController},
|
||||
|
@ -31,6 +32,7 @@ Clock::Clock(DisplayApp* app,
|
|||
settingsController {settingsController},
|
||||
heartRateController {heartRateController},
|
||||
motionController {motionController},
|
||||
agendaService {agendaService},
|
||||
screen {[this, &settingsController]() {
|
||||
switch (settingsController.GetClockFace()) {
|
||||
case 0:
|
||||
|
@ -71,7 +73,8 @@ std::unique_ptr<Screen> Clock::WatchFaceDigitalScreen() {
|
|||
notificatioManager,
|
||||
settingsController,
|
||||
heartRateController,
|
||||
motionController);
|
||||
motionController,
|
||||
agendaService);
|
||||
}
|
||||
|
||||
std::unique_ptr<Screen> Clock::WatchFaceAnalogScreen() {
|
||||
|
|
|
@ -15,6 +15,7 @@ namespace Pinetime {
|
|||
class Ble;
|
||||
class NotificationManager;
|
||||
class MotionController;
|
||||
class AgendaService;
|
||||
}
|
||||
|
||||
namespace Applications {
|
||||
|
@ -28,7 +29,8 @@ namespace Pinetime {
|
|||
Controllers::NotificationManager& notificatioManager,
|
||||
Controllers::Settings& settingsController,
|
||||
Controllers::HeartRateController& heartRateController,
|
||||
Controllers::MotionController& motionController);
|
||||
Controllers::MotionController& motionController,
|
||||
Controllers::AgendaService& agendaService);
|
||||
~Clock() override;
|
||||
|
||||
bool OnTouchEvent(TouchEvents event) override;
|
||||
|
@ -42,6 +44,7 @@ namespace Pinetime {
|
|||
Controllers::Settings& settingsController;
|
||||
Controllers::HeartRateController& heartRateController;
|
||||
Controllers::MotionController& motionController;
|
||||
Controllers::AgendaService& agendaService;
|
||||
|
||||
std::unique_ptr<Screen> screen;
|
||||
std::unique_ptr<Screen> WatchFaceDigitalScreen();
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#include "displayapp/screens/WatchFaceDigital.h"
|
||||
|
||||
#include <nrf_log.h>
|
||||
#include <date/date.h>
|
||||
#include <lvgl/lvgl.h>
|
||||
#include <cstdio>
|
||||
|
@ -22,7 +23,8 @@ WatchFaceDigital::WatchFaceDigital(DisplayApp* app,
|
|||
Controllers::NotificationManager& notificatioManager,
|
||||
Controllers::Settings& settingsController,
|
||||
Controllers::HeartRateController& heartRateController,
|
||||
Controllers::MotionController& motionController)
|
||||
Controllers::MotionController& motionController,
|
||||
Controllers::AgendaService& agendaService)
|
||||
: Screen(app),
|
||||
currentDateTime {{}},
|
||||
dateTimeController {dateTimeController},
|
||||
|
@ -31,7 +33,8 @@ WatchFaceDigital::WatchFaceDigital(DisplayApp* app,
|
|||
notificatioManager {notificatioManager},
|
||||
settingsController {settingsController},
|
||||
heartRateController {heartRateController},
|
||||
motionController {motionController} {
|
||||
motionController {motionController},
|
||||
agendaService {agendaService} {
|
||||
|
||||
batteryIcon.Create(lv_scr_act());
|
||||
lv_obj_align(batteryIcon.GetObject(), lv_scr_act(), LV_ALIGN_IN_TOP_RIGHT, 0, 0);
|
||||
|
@ -84,6 +87,19 @@ WatchFaceDigital::WatchFaceDigital(DisplayApp* app,
|
|||
lv_label_set_text_static(stepIcon, Symbols::shoe);
|
||||
lv_obj_align(stepIcon, stepValue, LV_ALIGN_OUT_LEFT_MID, -5, 0);
|
||||
|
||||
|
||||
agendaEntries[0] = lv_label_create(lv_scr_act(), nullptr);
|
||||
lv_obj_align(agendaEntries[0], lv_scr_act(), LV_ALIGN_IN_TOP_LEFT, 0, 0);
|
||||
lv_obj_set_style_local_text_color(agendaEntries[0], LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x332222));
|
||||
lv_label_set_text_static(agendaEntries[0], ".\n.");
|
||||
|
||||
|
||||
agendaEntries[1] = lv_label_create(lv_scr_act(), nullptr);
|
||||
lv_obj_align(agendaEntries[1], agendaEntries[0], LV_ALIGN_OUT_BOTTOM_LEFT, 0, 0);
|
||||
lv_obj_set_style_local_text_color(agendaEntries[1], LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x332222));
|
||||
lv_label_set_text_static(agendaEntries[1], ".\n.");
|
||||
|
||||
|
||||
taskRefresh = lv_task_create(RefreshTaskCallback, LV_DISP_DEF_REFR_PERIOD, LV_TASK_PRIO_MID, this);
|
||||
Refresh();
|
||||
}
|
||||
|
@ -93,6 +109,89 @@ WatchFaceDigital::~WatchFaceDigital() {
|
|||
lv_obj_clean(lv_scr_act());
|
||||
}
|
||||
|
||||
void WatchFaceDigital::RefreshMiniAgenda() {
|
||||
using namespace date;
|
||||
using namespace std::chrono;
|
||||
|
||||
// Set our offset to just before the newest event
|
||||
// We only show events destined for today.
|
||||
|
||||
bool found = false;
|
||||
uint8_t firstFutureEvent = 0;
|
||||
|
||||
std::chrono::system_clock::time_point now = dateTimeController.CurrentDateTime();
|
||||
auto today = floor<days>(now);
|
||||
|
||||
// Find first entry that is just after the current time (- 5 min)!
|
||||
for (uint8_t i = 0; i < Pinetime::Controllers::AgendaService::AGENDA_CAPACITY; ++i) {
|
||||
uint32_t time = agendaService.getAgendaTime(i);
|
||||
firstFutureEvent = i;
|
||||
if (time == 0) break;
|
||||
sys_seconds timestamp = sys_days{1970_y/1/1} + seconds{time};
|
||||
sys_days dayOfEvent = floor<days>(timestamp);
|
||||
|
||||
if (dayOfEvent > today) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (timestamp > now) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
bool suitable[2] = {false, found};
|
||||
|
||||
if (firstFutureEvent != 0) {
|
||||
uint32_t time = agendaService.getAgendaTime(firstFutureEvent - 1);
|
||||
if (time != 0) {
|
||||
sys_seconds timestamp = sys_days{1970_y/1/1} + seconds{time};
|
||||
|
||||
sys_days dayOfEvent = floor<days>(timestamp);
|
||||
|
||||
if (dayOfEvent == today) {
|
||||
suitable[0] = true;
|
||||
}
|
||||
|
||||
}
|
||||
// No earlier events in the day.
|
||||
lv_label_set_text_static(agendaEntries[0], "--h--\n .....");
|
||||
lv_obj_set_style_local_text_color(agendaEntries[0], LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x332222));
|
||||
}
|
||||
|
||||
for (uint8_t i = 0; i < 2; ++i) {
|
||||
if (! suitable[i]) {
|
||||
lv_label_set_text_static(agendaEntries[i], "--h--\n .....");
|
||||
lv_obj_set_style_local_text_color(agendaEntries[i], LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x332222));
|
||||
continue;
|
||||
}
|
||||
|
||||
uint8_t itemIdx = firstFutureEvent - (1 - i);
|
||||
|
||||
uint32_t time = agendaService.getAgendaTime(itemIdx);
|
||||
|
||||
sys_seconds timestamp = sys_days{1970_y/1/1} + seconds{time};
|
||||
//auto timestamp = std::chrono::system_clock::time_point{time * 1s};
|
||||
sys_days agendaDate = floor<days>(timestamp);
|
||||
time_of_day<seconds> agendaTimePart = make_time(timestamp - agendaDate);
|
||||
|
||||
lv_label_set_text_fmt(agendaEntries[i], "%02lldh%02lld\n %s", agendaTimePart.hours().count(), agendaTimePart.minutes().count(), agendaService.getAgendaPiece(itemIdx).data());
|
||||
|
||||
if (timestamp + 30min < now) {
|
||||
lv_obj_set_style_local_text_color(agendaEntries[i], LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x334433));
|
||||
} else if (timestamp + 5min < now) {
|
||||
lv_obj_set_style_local_text_color(agendaEntries[i], LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x00FFE7));
|
||||
} else if (timestamp - 5min < now && now < timestamp + 5min) {
|
||||
lv_obj_set_style_local_text_color(agendaEntries[i], LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0xFFA500));
|
||||
} else if (now + 5min < timestamp) {
|
||||
lv_obj_set_style_local_text_color(agendaEntries[i], LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0xFFFF00));
|
||||
} else if (now + 30min < timestamp) {
|
||||
lv_obj_set_style_local_text_color(agendaEntries[i], LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0xFFFFFF));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void WatchFaceDigital::Refresh() {
|
||||
powerPresent = batteryController.IsPowerPresent();
|
||||
if (powerPresent.IsUpdated()) {
|
||||
|
@ -136,6 +235,8 @@ void WatchFaceDigital::Refresh() {
|
|||
uint8_t minute = time.minutes().count();
|
||||
|
||||
if (displayedHour != hour || displayedMinute != minute) {
|
||||
RefreshMiniAgenda();
|
||||
|
||||
displayedHour = hour;
|
||||
displayedMinute = minute;
|
||||
|
||||
|
|
|
@ -17,6 +17,7 @@ namespace Pinetime {
|
|||
class NotificationManager;
|
||||
class HeartRateController;
|
||||
class MotionController;
|
||||
class AgendaService;
|
||||
}
|
||||
|
||||
namespace Applications {
|
||||
|
@ -31,11 +32,14 @@ namespace Pinetime {
|
|||
Controllers::NotificationManager& notificatioManager,
|
||||
Controllers::Settings& settingsController,
|
||||
Controllers::HeartRateController& heartRateController,
|
||||
Controllers::MotionController& motionController);
|
||||
Controllers::MotionController& motionController,
|
||||
Controllers::AgendaService& agendaService);
|
||||
~WatchFaceDigital() override;
|
||||
|
||||
void Refresh() override;
|
||||
|
||||
void RefreshMiniAgenda();
|
||||
|
||||
private:
|
||||
uint8_t displayedHour = -1;
|
||||
uint8_t displayedMinute = -1;
|
||||
|
@ -67,6 +71,8 @@ namespace Pinetime {
|
|||
lv_obj_t* stepValue;
|
||||
lv_obj_t* notificationIcon;
|
||||
|
||||
lv_obj_t* agendaEntries[2];
|
||||
|
||||
BatteryIcon batteryIcon;
|
||||
|
||||
Controllers::DateTime& dateTimeController;
|
||||
|
@ -76,6 +82,7 @@ namespace Pinetime {
|
|||
Controllers::Settings& settingsController;
|
||||
Controllers::HeartRateController& heartRateController;
|
||||
Controllers::MotionController& motionController;
|
||||
Controllers::AgendaService& agendaService;
|
||||
|
||||
lv_task_t* taskRefresh;
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue