1
0
Fork 0

Merge branch 'develop' of github.com:JF002/Pinetime into develop

This commit is contained in:
Jean-François Milants 2021-02-14 14:42:42 +01:00
commit f81ff98c30
30 changed files with 934 additions and 503 deletions

View file

@ -21,6 +21,7 @@ RUN apt-get update -qq \
&& rm -rf /var/cache/apt/* /var/lib/apt/lists/*; && rm -rf /var/cache/apt/* /var/lib/apt/lists/*;
RUN pip3 install adafruit-nrfutil RUN pip3 install adafruit-nrfutil
RUN pip3 install -Iv cryptography==3.3
# build.sh knows how to compile # build.sh knows how to compile
COPY build.sh /opt/ COPY build.sh /opt/

View file

@ -36,10 +36,12 @@ set(SDK_SOURCE_FILES
# Base SDK # Base SDK
"${NRF5_SDK_PATH}/components/boards/boards.c" "${NRF5_SDK_PATH}/components/boards/boards.c"
"${NRF5_SDK_PATH}/integration/nrfx/legacy/nrf_drv_clock.c" "${NRF5_SDK_PATH}/integration/nrfx/legacy/nrf_drv_clock.c"
"${NRF5_SDK_PATH}/integration/nrfx/legacy/nrf_drv_clock.h"
"${NRF5_SDK_PATH}/modules/nrfx/drivers/src/nrfx_clock.c" "${NRF5_SDK_PATH}/modules/nrfx/drivers/src/nrfx_clock.c"
"${NRF5_SDK_PATH}/modules/nrfx/drivers/src/nrfx_gpiote.c" "${NRF5_SDK_PATH}/modules/nrfx/drivers/src/nrfx_gpiote.c"
"${NRF5_SDK_PATH}/modules/nrfx/soc/nrfx_atomic.c" "${NRF5_SDK_PATH}/modules/nrfx/soc/nrfx_atomic.c"
"${NRF5_SDK_PATH}/modules/nrfx/drivers/src/nrfx_saadc.c" "${NRF5_SDK_PATH}/modules/nrfx/drivers/src/nrfx_saadc.c"
"${NRF5_SDK_PATH}/components/libraries/timer/app_timer.h"
# FreeRTOS # FreeRTOS
${NRF5_SDK_PATH}/external/freertos/source/croutine.c ${NRF5_SDK_PATH}/external/freertos/source/croutine.c
@ -426,7 +428,6 @@ list(APPEND SOURCE_FILES
displayapp/screens/InfiniPaint.cpp displayapp/screens/InfiniPaint.cpp
displayapp/screens/Paddle.cpp displayapp/screens/Paddle.cpp
displayapp/screens/DropDownDemo.cpp displayapp/screens/DropDownDemo.cpp
displayapp/screens/Modal.cpp
displayapp/screens/BatteryIcon.cpp displayapp/screens/BatteryIcon.cpp
displayapp/screens/BleIcon.cpp displayapp/screens/BleIcon.cpp
displayapp/screens/NotificationIcon.cpp displayapp/screens/NotificationIcon.cpp
@ -469,6 +470,7 @@ list(APPEND SOURCE_FILES
components/ble/ServiceDiscovery.cpp components/ble/ServiceDiscovery.cpp
components/ble/HeartRateService.cpp components/ble/HeartRateService.cpp
components/firmwarevalidator/FirmwareValidator.cpp components/firmwarevalidator/FirmwareValidator.cpp
components/motor/MotorController.cpp
drivers/Cst816s.cpp drivers/Cst816s.cpp
FreeRTOS/port.c FreeRTOS/port.c
FreeRTOS/port_cmsis_systick.c FreeRTOS/port_cmsis_systick.c
@ -520,7 +522,6 @@ set(INCLUDE_FILES
displayapp/screens/InfiniPaint.h displayapp/screens/InfiniPaint.h
displayapp/screens/Paddle.h displayapp/screens/Paddle.h
displayapp/screens/DropDownDemo.h displayapp/screens/DropDownDemo.h
displayapp/screens/Modal.h
displayapp/screens/BatteryIcon.h displayapp/screens/BatteryIcon.h
displayapp/screens/BleIcon.h displayapp/screens/BleIcon.h
displayapp/screens/NotificationIcon.h displayapp/screens/NotificationIcon.h
@ -579,6 +580,7 @@ set(INCLUDE_FILES
components/heartrate/Biquad.h components/heartrate/Biquad.h
components/heartrate/Ptagc.h components/heartrate/Ptagc.h
components/heartrate/HeartRateController.h components/heartrate/HeartRateController.h
components/motor/MotorController.h
) )
include_directories( include_directories(

View file

@ -9,6 +9,7 @@ using namespace Pinetime::Controllers;
constexpr ble_uuid16_t AlertNotificationService::ansUuid; constexpr ble_uuid16_t AlertNotificationService::ansUuid;
constexpr ble_uuid16_t AlertNotificationService::ansCharUuid; constexpr ble_uuid16_t AlertNotificationService::ansCharUuid;
constexpr ble_uuid128_t AlertNotificationService::notificationEventUuid;
int AlertNotificationCallback(uint16_t conn_handle, uint16_t attr_handle, struct ble_gatt_access_ctxt *ctxt, void *arg) { int AlertNotificationCallback(uint16_t conn_handle, uint16_t attr_handle, struct ble_gatt_access_ctxt *ctxt, void *arg) {
@ -33,6 +34,13 @@ AlertNotificationService::AlertNotificationService ( System::SystemTask& systemT
.arg = this, .arg = this,
.flags = BLE_GATT_CHR_F_WRITE .flags = BLE_GATT_CHR_F_WRITE
}, },
{
.uuid = (ble_uuid_t *) &notificationEventUuid,
.access_cb = AlertNotificationCallback,
.arg = this,
.flags = BLE_GATT_CHR_F_NOTIFY,
.val_handle = &eventHandle
},
{ {
0 0
} }
@ -61,14 +69,65 @@ int AlertNotificationService::OnAlert(uint16_t conn_handle, uint16_t attr_handle
const auto dbgPacketLen = OS_MBUF_PKTLEN(ctxt->om); const auto dbgPacketLen = OS_MBUF_PKTLEN(ctxt->om);
size_t bufferSize = std::min(dbgPacketLen + stringTerminatorSize, maxBufferSize); size_t bufferSize = std::min(dbgPacketLen + stringTerminatorSize, maxBufferSize);
auto messageSize = std::min(maxMessageSize, (bufferSize-headerSize)); auto messageSize = std::min(maxMessageSize, (bufferSize-headerSize));
Categories category;
NotificationManager::Notification notif; NotificationManager::Notification notif;
os_mbuf_copydata(ctxt->om, headerSize, messageSize-1, notif.message.data()); os_mbuf_copydata(ctxt->om, headerSize, messageSize-1, notif.message.data());
os_mbuf_copydata(ctxt->om, 0, 1, &category);
notif.message[messageSize-1] = '\0'; notif.message[messageSize-1] = '\0';
notif.category = Pinetime::Controllers::NotificationManager::Categories::SimpleAlert;
notificationManager.Push(std::move(notif));
systemTask.PushMessage(Pinetime::System::SystemTask::Messages::OnNewNotification); // TODO convert all ANS categories to NotificationController categories
switch(category) {
case Categories::Call:
notif.category = Pinetime::Controllers::NotificationManager::Categories::IncomingCall;
break;
default:
notif.category = Pinetime::Controllers::NotificationManager::Categories::SimpleAlert;
break;
}
auto event = Pinetime::System::SystemTask::Messages::OnNewNotification;
notificationManager.Push(std::move(notif));
systemTask.PushMessage(event);
} }
return 0; return 0;
} }
void AlertNotificationService::AcceptIncomingCall() {
auto response = IncomingCallResponses::Answer;
auto *om = ble_hs_mbuf_from_flat(&response, 1);
uint16_t connectionHandle = systemTask.nimble().connHandle();
if (connectionHandle == 0 || connectionHandle == BLE_HS_CONN_HANDLE_NONE) {
return;
}
ble_gattc_notify_custom(connectionHandle, eventHandle, om);
}
void AlertNotificationService::RejectIncomingCall() {
auto response = IncomingCallResponses::Reject;
auto *om = ble_hs_mbuf_from_flat(&response, 1);
uint16_t connectionHandle = systemTask.nimble().connHandle();
if (connectionHandle == 0 || connectionHandle == BLE_HS_CONN_HANDLE_NONE) {
return;
}
ble_gattc_notify_custom(connectionHandle, eventHandle, om);
}
void AlertNotificationService::MuteIncomingCall() {
auto response = IncomingCallResponses::Mute;
auto *om = ble_hs_mbuf_from_flat(&response, 1);
uint16_t connectionHandle = systemTask.nimble().connHandle();
if (connectionHandle == 0 || connectionHandle == BLE_HS_CONN_HANDLE_NONE) {
return;
}
ble_gattc_notify_custom(connectionHandle, eventHandle, om);
}

View file

@ -7,6 +7,9 @@
#undef max #undef max
#undef min #undef min
//00020001-78fc-48fe-8e23-433b3a1942d0
#define NOTIFICATION_EVENT_SERVICE_UUID_BASE {0xd0, 0x42, 0x19, 0x3a, 0x3b, 0x43, 0x23, 0x8e, 0xfe, 0x48, 0xfc, 0x78, 0x01, 0x00, 0x02, 0x00}
namespace Pinetime { namespace Pinetime {
namespace System { namespace System {
@ -24,8 +27,31 @@ namespace Pinetime {
int OnAlert(uint16_t conn_handle, uint16_t attr_handle, int OnAlert(uint16_t conn_handle, uint16_t attr_handle,
struct ble_gatt_access_ctxt *ctxt); struct ble_gatt_access_ctxt *ctxt);
void AcceptIncomingCall();
void RejectIncomingCall();
void MuteIncomingCall();
enum class IncomingCallResponses : uint8_t {
Reject = 0x00,
Answer = 0x01,
Mute = 0x02
};
private: private:
enum class Categories : uint8_t {
SimpleAlert = 0x00,
Email = 0x01,
News = 0x02,
Call = 0x03,
MissedCall = 0x04,
MmsSms = 0x05,
VoiceMail = 0x06,
Schedule = 0x07,
HighPrioritizedAlert = 0x08,
InstantMessage = 0x09,
All = 0xff
};
static constexpr uint16_t ansId {0x1811}; static constexpr uint16_t ansId {0x1811};
static constexpr uint16_t ansCharId {0x2a46}; static constexpr uint16_t ansCharId {0x2a46};
@ -39,11 +65,18 @@ namespace Pinetime {
.value = ansCharId .value = ansCharId
}; };
struct ble_gatt_chr_def characteristicDefinition[2]; static constexpr ble_uuid128_t notificationEventUuid {
.u { .type = BLE_UUID_TYPE_128 },
.value = NOTIFICATION_EVENT_SERVICE_UUID_BASE
};
struct ble_gatt_chr_def characteristicDefinition[3];
struct ble_gatt_svc_def serviceDefinition[2]; struct ble_gatt_svc_def serviceDefinition[2];
Pinetime::System::SystemTask &systemTask; Pinetime::System::SystemTask &systemTask;
NotificationManager &notificationManager; NotificationManager &notificationManager;
uint16_t eventHandle;
}; };
} }
} }

View file

@ -57,9 +57,7 @@ void HeartRateService::Init() {
int HeartRateService::OnHeartRateRequested(uint16_t connectionHandle, uint16_t attributeHandle, int HeartRateService::OnHeartRateRequested(uint16_t connectionHandle, uint16_t attributeHandle,
ble_gatt_access_ctxt *context) { ble_gatt_access_ctxt *context) {
if(attributeHandle == heartRateMeasurementHandle) { if(attributeHandle == heartRateMeasurementHandle) {
NRF_LOG_INFO("BATTERY : handle = %d", heartRateMeasurementHandle); NRF_LOG_INFO("HEARTRATE : handle = %d", heartRateMeasurementHandle);
static uint8_t batteryValue = heartRateController.HeartRate();
uint8_t buffer[2] = {0, heartRateController.HeartRate()}; // [0] = flags, [1] = hr value uint8_t buffer[2] = {0, heartRateController.HeartRate()}; // [0] = flags, [1] = hr value
int res = os_mbuf_append(context->om, buffer, 2); int res = os_mbuf_append(context->om, buffer, 2);

View file

@ -38,8 +38,8 @@ NimbleController::NimbleController(Pinetime::System::SystemTask& systemTask,
navService{systemTask}, navService{systemTask},
batteryInformationService{batteryController}, batteryInformationService{batteryController},
immediateAlertService{systemTask, notificationManager}, immediateAlertService{systemTask, notificationManager},
serviceDiscovery({&currentTimeClient, &alertNotificationClient}), heartRateService{systemTask, heartRateController},
heartRateService{systemTask, heartRateController} { serviceDiscovery({&currentTimeClient, &alertNotificationClient}) {
} }
int GAPEventCallback(struct ble_gap_event *event, void *arg) { int GAPEventCallback(struct ble_gap_event *event, void *arg) {

View file

@ -58,6 +58,7 @@ namespace Pinetime {
Pinetime::Controllers::MusicService& music() {return musicService;}; Pinetime::Controllers::MusicService& music() {return musicService;};
Pinetime::Controllers::NavigationService& navigation() {return navService;}; Pinetime::Controllers::NavigationService& navigation() {return navService;};
Pinetime::Controllers::AlertNotificationService& alertService() {return anService;};
uint16_t connHandle(); uint16_t connHandle();

View file

@ -71,6 +71,14 @@ bool NotificationManager::AreNewNotificationsAvailable() {
return newNotification; return newNotification;
} }
bool NotificationManager::IsVibrationEnabled() {
return vibrationEnabled;
}
void NotificationManager::ToggleVibrations() {
vibrationEnabled = !vibrationEnabled;
}
bool NotificationManager::ClearNewNotificationFlag() { bool NotificationManager::ClearNewNotificationFlag() {
return newNotification.exchange(false); return newNotification.exchange(false);
} }

View file

@ -28,6 +28,8 @@ namespace Pinetime {
Notification GetPrevious(Notification::Id id); Notification GetPrevious(Notification::Id id);
bool ClearNewNotificationFlag(); bool ClearNewNotificationFlag();
bool AreNewNotificationsAvailable(); bool AreNewNotificationsAvailable();
bool IsVibrationEnabled();
void ToggleVibrations();
static constexpr size_t MaximumMessageSize() { return MessageSize; }; static constexpr size_t MaximumMessageSize() { return MessageSize; };
size_t NbNotifications() const; size_t NbNotifications() const;
@ -40,6 +42,7 @@ namespace Pinetime {
uint8_t writeIndex = 0; uint8_t writeIndex = 0;
bool empty = true; bool empty = true;
std::atomic<bool> newNotification{false}; std::atomic<bool> newNotification{false};
bool vibrationEnabled = true;
}; };
} }
} }

View file

@ -13,7 +13,7 @@ using namespace Pinetime::Controllers;
namespace { namespace {
int Compare(int* d1, int* d2, size_t count) { int Compare(int* d1, int* d2, size_t count) {
int e = 0; int e = 0;
for(int i = 0; i < count; i++) { for(size_t i = 0; i < count; i++) {
auto d = d1[i] - d2[i]; auto d = d1[i] - d2[i];
e += d * d; e += d * d;
} }

View file

@ -0,0 +1,25 @@
#include "MotorController.h"
#include <hal/nrf_gpio.h>
#include "systemtask/SystemTask.h"
#include "app_timer.h"
APP_TIMER_DEF(vibTimer);
using namespace Pinetime::Controllers;
void MotorController::Init() {
nrf_gpio_cfg_output(pinMotor);
nrf_gpio_pin_set(pinMotor);
app_timer_init();
app_timer_create(&vibTimer, APP_TIMER_MODE_SINGLE_SHOT, vibrate);
}
void MotorController::SetDuration(uint8_t motorDuration) {
nrf_gpio_pin_clear(pinMotor);
/* Start timer for motorDuration miliseconds and timer triggers vibrate() when it finishes*/
app_timer_start(vibTimer, APP_TIMER_TICKS(motorDuration), NULL);
}
void MotorController::vibrate(void * p_context) {
nrf_gpio_pin_set(pinMotor);
}

View file

@ -0,0 +1,19 @@
#pragma once
#include <cstdint>
#include "app_timer.h"
namespace Pinetime {
namespace Controllers {
static constexpr uint8_t pinMotor = 16;
class MotorController {
public:
void Init();
void SetDuration(uint8_t motorDuration);
private:
static void vibrate(void * p_context);
};
}
}

View file

@ -46,7 +46,6 @@ DisplayApp::DisplayApp(Drivers::St7789 &lcd, Components::LittleVgl &lvgl, Driver
heartRateController{heartRateController} { heartRateController{heartRateController} {
msgQueue = xQueueCreate(queueSize, itemSize); msgQueue = xQueueCreate(queueSize, itemSize);
onClockApp = true; onClockApp = true;
modal.reset(new Screens::Modal(this));
} }
void DisplayApp::Start() { void DisplayApp::Start() {
@ -110,9 +109,6 @@ void DisplayApp::Refresh() {
brightnessController.Restore(); brightnessController.Restore();
state = States::Running; state = States::Running;
break; break;
case Messages::UpdateDateTime:
// modal->Show();
break;
case Messages::UpdateBleConnection: case Messages::UpdateBleConnection:
// clockScreen.SetBleConnectionState(bleController.IsConnected() ? Screens::Clock::BleConnectionStates::Connected : Screens::Clock::BleConnectionStates::NotConnected); // clockScreen.SetBleConnectionState(bleController.IsConnected() ? Screens::Clock::BleConnectionStates::Connected : Screens::Clock::BleConnectionStates::NotConnected);
break; break;
@ -124,7 +120,7 @@ void DisplayApp::Refresh() {
currentScreen.reset(nullptr); currentScreen.reset(nullptr);
lvgl.SetFullRefresh(Components::LittleVgl::FullRefreshDirections::Up); lvgl.SetFullRefresh(Components::LittleVgl::FullRefreshDirections::Up);
onClockApp = false; onClockApp = false;
currentScreen.reset(new Screens::Notifications(this, notificationManager, Screens::Notifications::Modes::Preview)); currentScreen.reset(new Screens::Notifications(this, notificationManager, systemTask.nimble().alertService(), Screens::Notifications::Modes::Preview));
} }
} }
break; break;
@ -215,7 +211,7 @@ void DisplayApp::RunningState() {
case Apps::Music : currentScreen.reset(new Screens::Music(this, systemTask.nimble().music())); break; case Apps::Music : currentScreen.reset(new Screens::Music(this, systemTask.nimble().music())); break;
case Apps::Navigation : currentScreen.reset(new Screens::Navigation(this, systemTask.nimble().navigation())); break; case Apps::Navigation : currentScreen.reset(new Screens::Navigation(this, systemTask.nimble().navigation())); break;
case Apps::FirmwareValidation: currentScreen.reset(new Screens::FirmwareValidation(this, validator)); break; case Apps::FirmwareValidation: currentScreen.reset(new Screens::FirmwareValidation(this, validator)); break;
case Apps::Notifications: currentScreen.reset(new Screens::Notifications(this, notificationManager, Screens::Notifications::Modes::Normal)); break; case Apps::Notifications: currentScreen.reset(new Screens::Notifications(this, notificationManager, systemTask.nimble().alertService(), Screens::Notifications::Modes::Normal)); break;
case Apps::HeartRate: currentScreen.reset(new Screens::HeartRate(this, heartRateController)); break; case Apps::HeartRate: currentScreen.reset(new Screens::HeartRate(this, heartRateController)); break;
} }
nextApp = Apps::None; nextApp = Apps::None;

View file

@ -85,7 +85,6 @@ namespace Pinetime {
Apps nextApp = Apps::None; Apps nextApp = Apps::None;
bool onClockApp = false; // TODO find a better way to know that we should handle gestures and button differently for the Clock app. bool onClockApp = false; // TODO find a better way to know that we should handle gestures and button differently for the Clock app.
Controllers::BrightnessController brightnessController; Controllers::BrightnessController brightnessController;
std::unique_ptr<Screens::Modal> modal;
Pinetime::Controllers::NotificationManager& notificationManager; Pinetime::Controllers::NotificationManager& notificationManager;
Pinetime::Controllers::FirmwareValidator validator; Pinetime::Controllers::FirmwareValidator validator;
TouchModes touchMode = TouchModes::Gestures; TouchModes touchMode = TouchModes::Gestures;

View file

@ -9,13 +9,13 @@
* Size : 20 * Size : 20
* Bpp : 1 bit-per-pixel * Bpp : 1 bit-per-pixel
* Do not enable font compression and horizontal subpixel hinting * Do not enable font compression and horizontal subpixel hinting
* Load the file `JetBrainsMono-Bold.woff` and specify the following range : `0x20-0x7f, 0x410-0x44f` * Load the file `JetBrainsMono-Bold.tff` and specify the following range : `0x20-0x7f, 0x410-0x44f`
* Add a 2nd font, load the file `FontAwesome5-Solid+Brands+Regular.woff` and specify the following range : `0xf293, 0xf294, 0xf244, 0xf240, 0xf242, 0xf243, 0xf241, 0xf54b, 0xf21e, 0xf1e6, 0xf54b, 0xf017, 0xf129, 0xf03a, 0xf185, 0xf560, 0xf001, 0xf3fd, 0xf069, 0xf1fc, 0xf45d` * Add a 2nd font, load the file `FontAwesome5-Solid+Brands+Regular.woff` and specify the following range : `0xf293, 0xf294, 0xf244, 0xf240, 0xf242, 0xf243, 0xf241, 0xf54b, 0xf21e, 0xf1e6, 0xf54b, 0xf017, 0xf129, 0xf03a, 0xf185, 0xf560, 0xf001, 0xf3fd, 0xf069, 0xf1fc, 0xf45d, 0xf59f, 0xf5a0, 0xf029, 0xf027, 0xf028, 0xf6a9, 0xf04b, 0xf04c, 0xf048, 0xf051, 0xf095, 0xf3dd`
* Click on Convert, and download the file `jetbrains_mono_bold_20.c` and copy it in `src/DisplayApp/Fonts` * Click on Convert, and download the file `jetbrains_mono_bold_20.c` and copy it in `src/DisplayApp/Fonts`
Add new symbols: Add new symbols:
* Browse the [cheatsheet](https://fontawesome.com/cheatsheet/free/solid) and find your new symbols * Browse the [cheatsheet](https://fontawesome.com/cheatsheet/free/solid) and find your new symbols
* For each symbol, add its hex code (0xf641 for the 'Ad' icon, for example) to the *Range* list * For each symbol, add its hex code (0xf641 for the 'Ad' icon, for example) to the *Range* list (Remember to keep this readme updated with newest range list)
* Convert this hex value into a UTF-8 code using [this site](http://www.ltg.ed.ac.uk/~richard/utf-8.cgi?input=f185&mode=hex) * Convert this hex value into a UTF-8 code using [this site](http://www.ltg.ed.ac.uk/~richard/utf-8.cgi?input=f185&mode=hex)
* Define the new symbols in `src/DisplayApp/Screens/Symbols.h`: * Define the new symbols in `src/DisplayApp/Screens/Symbols.h`:
``` ```

File diff suppressed because it is too large Load diff

View file

@ -21,11 +21,10 @@ namespace Pinetime {
template <class T> template <class T>
class DirtyValue { class DirtyValue {
public: public:
explicit DirtyValue(T v) { value = v; } DirtyValue() = default; // Use NSDMI
explicit DirtyValue(T& v) { value = v; } explicit DirtyValue(T const& v):value{v}{} // Use MIL and const-lvalue-ref
bool IsUpdated() const { return isUpdated; } bool IsUpdated() const { return isUpdated; }
T& Get() { this->isUpdated = false; return value; } T const& Get() { this->isUpdated = false; return value; } // never expose a non-const lvalue-ref
DirtyValue& operator=(const T& other) { DirtyValue& operator=(const T& other) {
if (this->value != other) { if (this->value != other) {
this->value = other; this->value = other;
@ -34,9 +33,10 @@ namespace Pinetime {
return *this; return *this;
} }
private: private:
T value; T value{}; // NSDMI - default initialise type
bool isUpdated = true; bool isUpdated{true}; // NSDMI - use brace initilisation
}; };
class Clock : public Screen { class Clock : public Screen {
public: public:
Clock(DisplayApp* app, Clock(DisplayApp* app,
@ -64,13 +64,13 @@ namespace Pinetime {
Pinetime::Controllers::DateTime::Days currentDayOfWeek = Pinetime::Controllers::DateTime::Days::Unknown; Pinetime::Controllers::DateTime::Days currentDayOfWeek = Pinetime::Controllers::DateTime::Days::Unknown;
uint8_t currentDay = 0; uint8_t currentDay = 0;
DirtyValue<int> batteryPercentRemaining {0}; DirtyValue<int> batteryPercentRemaining {};
DirtyValue<bool> bleState {false}; DirtyValue<bool> bleState {};
DirtyValue<std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds>> currentDateTime; DirtyValue<std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds>> currentDateTime{};
DirtyValue<uint32_t> stepCount {0}; DirtyValue<uint32_t> stepCount {};
DirtyValue<uint8_t> heartbeat {0}; DirtyValue<uint8_t> heartbeat {};
DirtyValue<bool> heartbeatRunning {false}; DirtyValue<bool> heartbeatRunning {};
DirtyValue<bool> notificationState {false}; DirtyValue<bool> notificationState {};
lv_obj_t* label_time; lv_obj_t* label_time;
lv_obj_t* label_date; lv_obj_t* label_date;

View file

@ -6,10 +6,7 @@ using namespace Pinetime::Applications::Screens;
extern lv_font_t jetbrains_mono_extrabold_compressed; extern lv_font_t jetbrains_mono_extrabold_compressed;
extern lv_font_t jetbrains_mono_bold_20; extern lv_font_t jetbrains_mono_bold_20;
Modal::Modal(Pinetime::Applications::DisplayApp *app) : Screen(app) { Modal::Modal(Pinetime::Applications::DisplayApp *app) : Screen(app), alertNotificationService(nullptr) {}
}
Modal::~Modal() { Modal::~Modal() {
lv_obj_clean(lv_scr_act()); lv_obj_clean(lv_scr_act());
@ -41,13 +38,46 @@ void Modal::OnEvent(lv_obj_t *event_obj, lv_event_t evt) {
if(evt == LV_EVENT_DELETE && event_obj == mbox) { if(evt == LV_EVENT_DELETE && event_obj == mbox) {
Hide(); Hide();
} else if(evt == LV_EVENT_VALUE_CHANGED) { } else if(evt == LV_EVENT_VALUE_CHANGED) {
/* A button was clicked */ if(event_obj == mbox) {
lv_mbox_start_auto_close(mbox, 0); if(strcmp(lv_mbox_get_active_btn_text(event_obj), this->positiveButton.c_str()) == 0) {
// Hide(); if(alertNotificationService != nullptr) {
alertNotificationService->event(Pinetime::Controllers::AlertNotificationService::EVENT_ANSWER_CALL);
}
} else {
if(alertNotificationService != nullptr) {
alertNotificationService->event(Pinetime::Controllers::AlertNotificationService::EVENT_HANG_UP_CALL);
}
}
lv_mbox_start_auto_close(mbox, 0);
}
} }
} }
void Modal::Show(const char* msg) { void Modal::NewNotification(Pinetime::Controllers::NotificationManager &notificationManager, Pinetime::Controllers::AlertNotificationService* alertService) {
alertNotificationService = alertService;
auto notification = notificationManager.GetLastNotification();
std::string msg;
if(notification.valid) {
switch(notification.category) {
case Pinetime::Controllers::NotificationManager::Categories::IncomingCall:
this->positiveButton = "Answer";
this->negativeButton = "Hang up";
msg += "Incoming call from:\n";
msg += notification.message.data();
break;
default:
this->positiveButton = "Ok";
this->negativeButton = "Cancel";
msg = notification.message.data();
break;
}
static const char *btns[] = {this->positiveButton.c_str(), this->negativeButton.c_str(), ""};
this->Show(msg.c_str(), btns);
}
}
void Modal::Show(const char* msg, const char *btns[]) {
if(isVisible) return; if(isVisible) return;
isVisible = true; isVisible = true;
lv_style_copy(&modal_style, &lv_style_plain_color); lv_style_copy(&modal_style, &lv_style_plain_color);
@ -60,11 +90,9 @@ void Modal::Show(const char* msg) {
lv_obj_set_size(obj, LV_HOR_RES, LV_VER_RES); lv_obj_set_size(obj, LV_HOR_RES, LV_VER_RES);
lv_obj_set_opa_scale_enable(obj, true); /* Enable opacity scaling for the animation */ lv_obj_set_opa_scale_enable(obj, true); /* Enable opacity scaling for the animation */
static const char * btns2[] = {"Ok", ""};
/* Create the message box as a child of the modal background */ /* Create the message box as a child of the modal background */
mbox = lv_mbox_create(obj, nullptr); mbox = lv_mbox_create(obj, nullptr);
lv_mbox_add_btns(mbox, btns2); lv_mbox_add_btns(mbox, btns);
lv_mbox_set_text(mbox, msg); lv_mbox_set_text(mbox, msg);
lv_obj_align(mbox, nullptr, LV_ALIGN_CENTER, 0, 0); lv_obj_align(mbox, nullptr, LV_ALIGN_CENTER, 0, 0);
lv_obj_set_event_cb(mbox, Modal::mbox_event_cb); lv_obj_set_event_cb(mbox, Modal::mbox_event_cb);

View file

@ -3,6 +3,8 @@
#include "Screen.h" #include "Screen.h"
#include <lvgl/src/lv_core/lv_style.h> #include <lvgl/src/lv_core/lv_style.h>
#include <lvgl/src/lv_core/lv_obj.h> #include <lvgl/src/lv_core/lv_obj.h>
#include <components/ble/NotificationManager.h>
#include <components/ble/AlertNotificationService.h>
namespace Pinetime { namespace Pinetime {
namespace Applications { namespace Applications {
@ -13,7 +15,9 @@ namespace Pinetime {
Modal(DisplayApp* app); Modal(DisplayApp* app);
~Modal() override; ~Modal() override;
void Show(const char* msg);
void NewNotification(Pinetime::Controllers::NotificationManager &notificationManager, Pinetime::Controllers::AlertNotificationService* alertService);
void Show(const char* msg, const char *btns[]);
void Hide(); void Hide();
bool Refresh() override; bool Refresh() override;
@ -23,6 +27,11 @@ namespace Pinetime {
private: private:
void OnEvent(lv_obj_t *event_obj, lv_event_t evt); void OnEvent(lv_obj_t *event_obj, lv_event_t evt);
Pinetime::Controllers::AlertNotificationService* alertNotificationService = nullptr;
std::string positiveButton;
std::string negativeButton;
lv_style_t modal_style; lv_style_t modal_style;
lv_obj_t *obj; lv_obj_t *obj;
lv_obj_t *mbox; lv_obj_t *mbox;

View file

@ -16,6 +16,7 @@
along with this program. If not, see <https://www.gnu.org/licenses/>. along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
#include "Music.h" #include "Music.h"
#include "Symbols.h"
#include <cstdint> #include <cstdint>
#include "../DisplayApp.h" #include "../DisplayApp.h"
#include "components/ble/MusicService.h" #include "components/ble/MusicService.h"
@ -58,7 +59,7 @@ Music::Music(Pinetime::Applications::DisplayApp *app, Pinetime::Controllers::Mus
lv_obj_set_size(btnVolDown, LV_HOR_RES / 3, 80); lv_obj_set_size(btnVolDown, LV_HOR_RES / 3, 80);
lv_obj_align(btnVolDown, nullptr, LV_ALIGN_IN_BOTTOM_LEFT, 0, 0); lv_obj_align(btnVolDown, nullptr, LV_ALIGN_IN_BOTTOM_LEFT, 0, 0);
label = lv_label_create(btnVolDown, nullptr); label = lv_label_create(btnVolDown, nullptr);
lv_label_set_text(label, "V-"); lv_label_set_text(label, Symbols::volumDown);
lv_obj_set_hidden(btnVolDown, !displayVolumeButtons); lv_obj_set_hidden(btnVolDown, !displayVolumeButtons);
btnVolUp = lv_btn_create(lv_scr_act(), nullptr); btnVolUp = lv_btn_create(lv_scr_act(), nullptr);
@ -67,7 +68,7 @@ Music::Music(Pinetime::Applications::DisplayApp *app, Pinetime::Controllers::Mus
lv_obj_set_size(btnVolUp, LV_HOR_RES / 3, 80); lv_obj_set_size(btnVolUp, LV_HOR_RES / 3, 80);
lv_obj_align(btnVolUp, nullptr, LV_ALIGN_IN_BOTTOM_RIGHT, 0, 0); lv_obj_align(btnVolUp, nullptr, LV_ALIGN_IN_BOTTOM_RIGHT, 0, 0);
label = lv_label_create(btnVolUp, nullptr); label = lv_label_create(btnVolUp, nullptr);
lv_label_set_text(label, "V+"); lv_label_set_text(label, Symbols::volumUp);
lv_obj_set_hidden(btnVolDown, !displayVolumeButtons); lv_obj_set_hidden(btnVolDown, !displayVolumeButtons);
btnPrev = lv_btn_create(lv_scr_act(), nullptr); btnPrev = lv_btn_create(lv_scr_act(), nullptr);
@ -76,7 +77,7 @@ Music::Music(Pinetime::Applications::DisplayApp *app, Pinetime::Controllers::Mus
lv_obj_set_size(btnPrev, LV_HOR_RES / 3, 80); lv_obj_set_size(btnPrev, LV_HOR_RES / 3, 80);
lv_obj_align(btnPrev, nullptr, LV_ALIGN_IN_BOTTOM_LEFT, 0, 0); lv_obj_align(btnPrev, nullptr, LV_ALIGN_IN_BOTTOM_LEFT, 0, 0);
label = lv_label_create(btnPrev, nullptr); label = lv_label_create(btnPrev, nullptr);
lv_label_set_text(label, "<<"); lv_label_set_text(label, Symbols::stepBackward);
btnNext = lv_btn_create(lv_scr_act(), nullptr); btnNext = lv_btn_create(lv_scr_act(), nullptr);
btnNext->user_data = this; btnNext->user_data = this;
@ -84,7 +85,7 @@ Music::Music(Pinetime::Applications::DisplayApp *app, Pinetime::Controllers::Mus
lv_obj_set_size(btnNext, LV_HOR_RES / 3, 80); lv_obj_set_size(btnNext, LV_HOR_RES / 3, 80);
lv_obj_align(btnNext, nullptr, LV_ALIGN_IN_BOTTOM_RIGHT, 0, 0); lv_obj_align(btnNext, nullptr, LV_ALIGN_IN_BOTTOM_RIGHT, 0, 0);
label = lv_label_create(btnNext, nullptr); label = lv_label_create(btnNext, nullptr);
lv_label_set_text(label, ">>"); lv_label_set_text(label, Symbols::stepForward);
btnPlayPause = lv_btn_create(lv_scr_act(), nullptr); btnPlayPause = lv_btn_create(lv_scr_act(), nullptr);
btnPlayPause->user_data = this; btnPlayPause->user_data = this;
@ -92,7 +93,7 @@ Music::Music(Pinetime::Applications::DisplayApp *app, Pinetime::Controllers::Mus
lv_obj_set_size(btnPlayPause, LV_HOR_RES / 3, 80); lv_obj_set_size(btnPlayPause, LV_HOR_RES / 3, 80);
lv_obj_align(btnPlayPause, nullptr, LV_ALIGN_IN_BOTTOM_MID, 0, 0); lv_obj_align(btnPlayPause, nullptr, LV_ALIGN_IN_BOTTOM_MID, 0, 0);
txtPlayPause = lv_label_create(btnPlayPause, nullptr); txtPlayPause = lv_label_create(btnPlayPause, nullptr);
lv_label_set_text(txtPlayPause, ">"); lv_label_set_text(txtPlayPause, Symbols::play);
txtTrackDuration = lv_label_create(lv_scr_act(), nullptr); txtTrackDuration = lv_label_create(lv_scr_act(), nullptr);
lv_label_set_long_mode(txtTrackDuration, LV_LABEL_LONG_SROLL); lv_label_set_long_mode(txtTrackDuration, LV_LABEL_LONG_SROLL);
@ -179,7 +180,7 @@ bool Music::Refresh() {
} }
if (playing == Pinetime::Controllers::MusicService::MusicStatus::Playing) { if (playing == Pinetime::Controllers::MusicService::MusicStatus::Playing) {
lv_label_set_text(txtPlayPause, "||"); lv_label_set_text(txtPlayPause, Symbols::pause);
if (xTaskGetTickCount() - 1024 >= lastIncrement) { if (xTaskGetTickCount() - 1024 >= lastIncrement) {
if (frameB) { if (frameB) {
@ -203,7 +204,7 @@ bool Music::Refresh() {
UpdateLength(); UpdateLength();
} }
} else { } else {
lv_label_set_text(txtPlayPause, ">"); lv_label_set_text(txtPlayPause, Symbols::play);
} }
return running; return running;

View file

@ -1,18 +1,37 @@
#include "Notifications.h" #include "Notifications.h"
#include <displayapp/DisplayApp.h> #include <displayapp/DisplayApp.h>
#include "components/ble/MusicService.h"
#include "Symbols.h"
using namespace Pinetime::Applications::Screens; using namespace Pinetime::Applications::Screens;
extern lv_font_t jetbrains_mono_extrabold_compressed;
extern lv_font_t jetbrains_mono_bold_20;
Notifications::Notifications(DisplayApp *app, Pinetime::Controllers::NotificationManager &notificationManager, Modes mode) : Notifications::Notifications(DisplayApp *app,
Screen(app), notificationManager{notificationManager}, mode{mode} { Pinetime::Controllers::NotificationManager &notificationManager,
Pinetime::Controllers::AlertNotificationService& alertNotificationService,
Modes mode) :
Screen(app), notificationManager{notificationManager}, alertNotificationService{alertNotificationService}, mode{mode} {
notificationManager.ClearNewNotificationFlag(); notificationManager.ClearNewNotificationFlag();
auto notification = notificationManager.GetLastNotification(); auto notification = notificationManager.GetLastNotification();
if(notification.valid) { if(notification.valid) {
currentId = notification.id; currentId = notification.id;
currentItem.reset(new NotificationItem("\nNotification", notification.message.data(), notification.index, notificationManager.NbNotifications(), mode)); currentItem.reset(new NotificationItem("\nNotification",
notification.message.data(),
notification.index,
notification.category,
notificationManager.NbNotifications(),
mode,
alertNotificationService));
validDisplay = true; validDisplay = true;
} else { } else {
currentItem.reset(new NotificationItem("\nNotification", "No notification to display", 0, notificationManager.NbNotifications(), Modes::Preview)); currentItem.reset(new NotificationItem("\nNotification",
"No notification to display",
0,
notification.category,
notificationManager.NbNotifications(),
Modes::Preview,
alertNotificationService));
} }
if(mode == Modes::Preview) { if(mode == Modes::Preview) {
@ -22,7 +41,6 @@ Notifications::Notifications(DisplayApp *app, Pinetime::Controllers::Notificatio
style_line.line.width = 3; style_line.line.width = 3;
style_line.line.rounded = 0; style_line.line.rounded = 0;
timeoutLine = lv_line_create(lv_scr_act(), nullptr); timeoutLine = lv_line_create(lv_scr_act(), nullptr);
lv_line_set_style(timeoutLine, LV_LINE_STYLE_MAIN, &style_line); lv_line_set_style(timeoutLine, LV_LINE_STYLE_MAIN, &style_line);
lv_line_set_points(timeoutLine, timeoutLinePoints, 2); lv_line_set_points(timeoutLine, timeoutLinePoints, 2);
@ -69,7 +87,13 @@ bool Notifications::OnTouchEvent(Pinetime::Applications::TouchEvents event) {
currentId = previousNotification.id; currentId = previousNotification.id;
currentItem.reset(nullptr); currentItem.reset(nullptr);
app->SetFullRefresh(DisplayApp::FullRefreshDirections::Up); app->SetFullRefresh(DisplayApp::FullRefreshDirections::Up);
currentItem.reset(new NotificationItem("\nNotification", previousNotification.message.data(), previousNotification.index, notificationManager.NbNotifications(), mode)); currentItem.reset(new NotificationItem("\nNotification",
previousNotification.message.data(),
previousNotification.index,
previousNotification.category,
notificationManager.NbNotifications(),
mode,
alertNotificationService));
} }
return true; return true;
case Pinetime::Applications::TouchEvents::SwipeDown: { case Pinetime::Applications::TouchEvents::SwipeDown: {
@ -85,9 +109,19 @@ bool Notifications::OnTouchEvent(Pinetime::Applications::TouchEvents event) {
currentId = nextNotification.id; currentId = nextNotification.id;
currentItem.reset(nullptr); currentItem.reset(nullptr);
app->SetFullRefresh(DisplayApp::FullRefreshDirections::Down); app->SetFullRefresh(DisplayApp::FullRefreshDirections::Down);
currentItem.reset(new NotificationItem("\nNotification", nextNotification.message.data(), nextNotification.index, notificationManager.NbNotifications(), mode)); currentItem.reset(new NotificationItem("\nNotification",
nextNotification.message.data(),
nextNotification.index,
nextNotification.category,
notificationManager.NbNotifications(),
mode,
alertNotificationService));
} }
return true; return true;
case Pinetime::Applications::TouchEvents::LongTap: {
notificationManager.ToggleVibrations();
return true;
}
default: default:
return false; return false;
} }
@ -99,9 +133,31 @@ bool Notifications::OnButtonPushed() {
return true; return true;
} }
namespace {
static void AcceptIncomingCallEventHandler(lv_obj_t *obj, lv_event_t event) {
auto* item = static_cast<Notifications::NotificationItem *>(obj->user_data);
item->OnAcceptIncomingCall(event);
}
Notifications::NotificationItem::NotificationItem(const char *title, const char *msg, uint8_t notifNr, uint8_t notifNb, Modes mode) static void MuteIncomingCallEventHandler(lv_obj_t *obj, lv_event_t event) {
: notifNr{notifNr}, notifNb{notifNb}, mode{mode} { auto* item = static_cast<Notifications::NotificationItem *>(obj->user_data);
item->OnMuteIncomingCall(event);
}
static void RejectIncomingCallEventHandler(lv_obj_t *obj, lv_event_t event) {
auto* item = static_cast<Notifications::NotificationItem *>(obj->user_data);
item->OnRejectIncomingCall(event);
}
}
Notifications::NotificationItem::NotificationItem(const char *title,
const char *msg,
uint8_t notifNr,
Controllers::NotificationManager::Categories category,
uint8_t notifNb,
Modes mode,
Pinetime::Controllers::AlertNotificationService& alertNotificationService)
: notifNr{notifNr}, notifNb{notifNb}, mode{mode}, alertNotificationService{alertNotificationService} {
container1 = lv_cont_create(lv_scr_act(), nullptr); container1 = lv_cont_create(lv_scr_act(), nullptr);
static lv_style_t contStyle; static lv_style_t contStyle;
lv_style_copy(&contStyle, lv_cont_get_style(container1, LV_CONT_STYLE_MAIN)); lv_style_copy(&contStyle, lv_cont_get_style(container1, LV_CONT_STYLE_MAIN));
@ -142,16 +198,68 @@ Notifications::NotificationItem::NotificationItem(const char *title, const char
auto titleHeight = lv_obj_get_height(t1); auto titleHeight = lv_obj_get_height(t1);
l1 = lv_label_create(container1, nullptr); switch(category) {
lv_label_set_style(l1, LV_LABEL_STYLE_MAIN, &textStyle); default: {
lv_obj_set_pos(l1, textStyle.body.padding.left, l1 = lv_label_create(container1, nullptr);
titleHeight + offscreenOffset + textStyle.body.padding.bottom + lv_label_set_style(l1, LV_LABEL_STYLE_MAIN, &textStyle);
textStyle.body.padding.top); lv_obj_set_pos(l1, textStyle.body.padding.left,
titleHeight + offscreenOffset + textStyle.body.padding.bottom +
textStyle.body.padding.top);
lv_label_set_long_mode(l1, LV_LABEL_LONG_BREAK); lv_label_set_long_mode(l1, LV_LABEL_LONG_BREAK);
lv_label_set_body_draw(l1, true); lv_label_set_body_draw(l1, true);
lv_obj_set_width(l1, LV_HOR_RES - (textStyle.body.padding.left + textStyle.body.padding.right)); lv_obj_set_width(l1, LV_HOR_RES - (textStyle.body.padding.left + textStyle.body.padding.right));
lv_label_set_text(l1, msg); lv_label_set_text(l1, msg);
}
break;
case Controllers::NotificationManager::Categories::IncomingCall: {
l1 = lv_label_create(container1, nullptr);
lv_label_set_style(l1, LV_LABEL_STYLE_MAIN, &textStyle);
lv_obj_set_pos(l1, textStyle.body.padding.left,
titleHeight + offscreenOffset + textStyle.body.padding.bottom +
textStyle.body.padding.top);
lv_label_set_long_mode(l1, LV_LABEL_LONG_BREAK);
lv_label_set_body_draw(l1, true);
lv_obj_set_width(l1, LV_HOR_RES - (textStyle.body.padding.left + textStyle.body.padding.right));
lv_label_set_text(l1, "Incoming call from ");
auto l1Height = lv_obj_get_height(l1);
l2 = lv_label_create(container1, nullptr);
lv_label_set_style(l2, LV_LABEL_STYLE_MAIN, &textStyle);
lv_obj_set_pos(l2, textStyle.body.padding.left,
titleHeight + l1Height + offscreenOffset + (textStyle.body.padding.bottom*2) +
(textStyle.body.padding.top*2));
lv_label_set_long_mode(l2, LV_LABEL_LONG_BREAK);
lv_label_set_body_draw(l2, true);
lv_obj_set_width(l2, LV_HOR_RES - (textStyle.body.padding.left + textStyle.body.padding.right));
lv_label_set_text(l2, msg);
bt_accept = lv_btn_create(container1, nullptr);
bt_accept->user_data = this;
lv_obj_set_event_cb(bt_accept, AcceptIncomingCallEventHandler);
lv_obj_set_size(bt_accept, LV_HOR_RES / 3, 80);
lv_obj_align(bt_accept, lv_scr_act(), LV_ALIGN_IN_BOTTOM_LEFT, 0, -20);
label_accept = lv_label_create(bt_accept, nullptr);
lv_label_set_text(label_accept, Symbols::phone);
bt_reject = lv_btn_create(container1, nullptr);
bt_reject->user_data = this;
lv_obj_set_event_cb(bt_reject, RejectIncomingCallEventHandler);
lv_obj_set_size(bt_reject, LV_HOR_RES / 3, 80);
lv_obj_align(bt_reject, lv_scr_act(), LV_ALIGN_IN_BOTTOM_RIGHT, 0, -20);
label_reject = lv_label_create(bt_reject, nullptr);
lv_label_set_text(label_reject, Symbols::phoneSlash);
bt_mute = lv_btn_create(container1, nullptr);
bt_mute->user_data = this;
lv_obj_set_event_cb(bt_mute, MuteIncomingCallEventHandler);
lv_obj_set_size(bt_mute, LV_HOR_RES / 3, 80);
lv_obj_align(bt_mute, lv_scr_act(), LV_ALIGN_IN_BOTTOM_MID, 0, -20);
label_mute = lv_label_create(bt_mute, nullptr);
lv_label_set_text(label_mute, Symbols::volumMute);
}
}
if(mode == Modes::Normal) { if(mode == Modes::Normal) {
if(notifNr < notifNb) { if(notifNr < notifNb) {
@ -166,6 +274,23 @@ Notifications::NotificationItem::NotificationItem(const char *title, const char
} }
} }
void Notifications::NotificationItem::OnAcceptIncomingCall(lv_event_t event) {
if (event != LV_EVENT_CLICKED) return;
alertNotificationService.AcceptIncomingCall();
}
void Notifications::NotificationItem::OnMuteIncomingCall(lv_event_t event) {
if (event != LV_EVENT_CLICKED) return;
alertNotificationService.MuteIncomingCall();
}
void Notifications::NotificationItem::OnRejectIncomingCall(lv_event_t event) {
if (event != LV_EVENT_CLICKED) return;
alertNotificationService.RejectIncomingCall();
}
Notifications::NotificationItem::~NotificationItem() { Notifications::NotificationItem::~NotificationItem() {
lv_obj_clean(lv_scr_act()); lv_obj_clean(lv_scr_act());

View file

@ -7,44 +7,62 @@
#include "components/ble/NotificationManager.h" #include "components/ble/NotificationManager.h"
namespace Pinetime { namespace Pinetime {
namespace Controllers {
class AlertNotificationService;
}
namespace Applications { namespace Applications {
namespace Screens { namespace Screens {
class Notifications : public Screen { class Notifications : public Screen {
public: public:
enum class Modes {Normal, Preview}; enum class Modes {Normal, Preview};
explicit Notifications(DisplayApp* app, Pinetime::Controllers::NotificationManager& notificationManager, Modes mode); explicit Notifications(DisplayApp* app, Pinetime::Controllers::NotificationManager& notificationManager, Pinetime::Controllers::AlertNotificationService& alertNotificationService, Modes mode);
~Notifications() override; ~Notifications() override;
bool Refresh() override; bool Refresh() override;
bool OnButtonPushed() override; bool OnButtonPushed() override;
bool OnTouchEvent(Pinetime::Applications::TouchEvents event) override; bool OnTouchEvent(Pinetime::Applications::TouchEvents event) override;
class NotificationItem {
public:
NotificationItem(const char* title, const char* msg, uint8_t notifNr, Controllers::NotificationManager::Categories, uint8_t notifNb, Modes mode, Pinetime::Controllers::AlertNotificationService& alertNotificationService);
~NotificationItem();
bool Refresh() {return false;}
void OnAcceptIncomingCall(lv_event_t event);
void OnMuteIncomingCall(lv_event_t event);
void OnRejectIncomingCall(lv_event_t event);
private:
uint8_t notifNr = 0;
uint8_t notifNb = 0;
char pageText[4];
lv_obj_t* container1;
lv_obj_t* t1;
lv_obj_t* l1;
lv_obj_t* l2;
lv_obj_t* bt_accept;
lv_obj_t* bt_mute;
lv_obj_t* bt_reject;
lv_obj_t* label_accept;
lv_obj_t* label_mute;
lv_obj_t* label_reject;
lv_obj_t* bottomPlaceholder;
Modes mode;
Pinetime::Controllers::AlertNotificationService& alertNotificationService;
};
private: private:
bool running = true; bool running = true;
class NotificationItem {
public:
NotificationItem(const char* title, const char* msg, uint8_t notifNr, uint8_t notifNb, Modes mode);
~NotificationItem();
bool Refresh() {return false;}
private:
uint8_t notifNr = 0;
uint8_t notifNb = 0;
char pageText[4];
lv_obj_t* container1;
lv_obj_t* t1;
lv_obj_t* l1;
lv_obj_t* bottomPlaceholder;
Modes mode;
};
struct NotificationData { struct NotificationData {
const char* title; const char* title;
const char* text; const char* text;
}; };
Pinetime::Controllers::NotificationManager& notificationManager; Pinetime::Controllers::NotificationManager& notificationManager;
Pinetime::Controllers::AlertNotificationService& alertNotificationService;
Modes mode = Modes::Normal; Modes mode = Modes::Normal;
std::unique_ptr<NotificationItem> currentItem; std::unique_ptr<NotificationItem> currentItem;
Controllers::NotificationManager::Notification::Id currentId; Controllers::NotificationManager::Notification::Id currentId;

View file

@ -26,6 +26,16 @@ namespace Pinetime {
static constexpr const char* paintbrush = "\xEF\x87\xBC"; static constexpr const char* paintbrush = "\xEF\x87\xBC";
static constexpr const char* paddle = "\xEF\x91\x9D"; static constexpr const char* paddle = "\xEF\x91\x9D";
static constexpr const char* map = "\xEF\x96\xa0"; static constexpr const char* map = "\xEF\x96\xa0";
static constexpr const char* qrcode = "\xEF\x80\xa9";
static constexpr const char* phone = "\xEF\x82\x95";
static constexpr const char* phoneSlash = "\xEF\x8F\x9D";
static constexpr const char* volumMute = "\xEF\x9A\xA9";
static constexpr const char* volumUp = "\xEF\x80\xA8";
static constexpr const char* volumDown = "\xEF\x80\xA7";
static constexpr const char* stepForward = "\xEF\x81\x91";
static constexpr const char* stepBackward = "\xEF\x81\x88";
static constexpr const char* play = "\xEF\x81\x8B";
static constexpr const char* pause = "\xEF\x81\x8C";
} }
} }
} }

View file

@ -22,7 +22,6 @@ Tile::Tile(DisplayApp* app, std::array<Applications, 6>& applications) : Screen(
appIndex++; appIndex++;
} }
} }
modal.reset(new Modal(app));
btnm1 = lv_btnm_create(lv_scr_act(), nullptr); btnm1 = lv_btnm_create(lv_scr_act(), nullptr);
lv_btnm_set_map(btnm1, btnm_map1); lv_btnm_set_map(btnm1, btnm_map1);

View file

@ -29,8 +29,6 @@ namespace Pinetime {
lv_obj_t * btnm1; lv_obj_t * btnm1;
bool running = true; bool running = true;
std::unique_ptr<Modal> modal;
const char* btnm_map1[8]; const char* btnm_map1[8];
Pinetime::Applications::Apps apps[6]; Pinetime::Applications::Apps apps[6];
}; };

View file

@ -70,13 +70,14 @@ uint16_t Hrs3300::ReadAls() {
} }
void Hrs3300::SetGain(uint8_t gain) { void Hrs3300::SetGain(uint8_t gain) {
static constexpr uint8_t maxGain = 64; constexpr uint8_t maxGain = 64U;
gain = std::min(gain, maxGain); gain = std::min(gain, maxGain);
uint8_t hgain = 0; uint8_t hgain = 0;
while((1 << hgain) < gain) while((1 << hgain) < gain){
hgain++; ++hgain;
}
WriteRegister(static_cast<uint8_t>(Registers::Hgain), hgain << 2); WriteRegister(static_cast<uint8_t>(Registers::Hgain), hgain << 2);
} }
void Hrs3300::SetDrive(uint8_t drive) { void Hrs3300::SetDrive(uint8_t drive) {

View file

@ -30,6 +30,7 @@
#include "components/battery/BatteryController.h" #include "components/battery/BatteryController.h"
#include "components/ble/BleController.h" #include "components/ble/BleController.h"
#include "components/ble/NotificationManager.h" #include "components/ble/NotificationManager.h"
#include "components/motor/MotorController.h"
#include "components/datetime/DateTimeController.h" #include "components/datetime/DateTimeController.h"
#include "displayapp/DisplayApp.h" #include "displayapp/DisplayApp.h"
#include "displayapp/LittleVgl.h" #include "displayapp/LittleVgl.h"
@ -98,7 +99,7 @@ void ble_manager_set_ble_disconnection_callback(void (*disconnection)());
static constexpr uint8_t pinTouchIrq = 28; static constexpr uint8_t pinTouchIrq = 28;
std::unique_ptr<Pinetime::System::SystemTask> systemTask; std::unique_ptr<Pinetime::System::SystemTask> systemTask;
Pinetime::Controllers::NotificationManager notificationManager; Pinetime::Controllers::MotorController motorController;
void nrfx_gpiote_evt_handler(nrfx_gpiote_pin_t pin, nrf_gpiote_polarity_t action) { void nrfx_gpiote_evt_handler(nrfx_gpiote_pin_t pin, nrf_gpiote_polarity_t action) {
if(pin == pinTouchIrq) { if(pin == pinTouchIrq) {
@ -232,7 +233,7 @@ void nimble_port_ll_task_func(void *args) {
ble_ll_task(args); ble_ll_task(args);
} }
} }
int countT2 = 0;
int main(void) { int main(void) {
logger.Init(); logger.Init();
@ -241,7 +242,7 @@ int main(void) {
debounceTimer = xTimerCreate ("debounceTimer", 200, pdFALSE, (void *) 0, DebounceTimerCallback); debounceTimer = xTimerCreate ("debounceTimer", 200, pdFALSE, (void *) 0, DebounceTimerCallback);
systemTask.reset(new Pinetime::System::SystemTask(spi, lcd, spiNorFlash, twiMaster, touchPanel, lvgl, batteryController, bleController, systemTask.reset(new Pinetime::System::SystemTask(spi, lcd, spiNorFlash, twiMaster, touchPanel, lvgl, batteryController, bleController,
dateTimeController, notificationManager, heartRateSensor)); dateTimeController, motorController, heartRateSensor));
systemTask->Start(); systemTask->Start();
nimble_port_init(); nimble_port_init();

View file

@ -40,14 +40,14 @@ SystemTask::SystemTask(Drivers::SpiMaster &spi, Drivers::St7789 &lcd,
Components::LittleVgl &lvgl, Components::LittleVgl &lvgl,
Controllers::Battery &batteryController, Controllers::Ble &bleController, Controllers::Battery &batteryController, Controllers::Ble &bleController,
Controllers::DateTime &dateTimeController, Controllers::DateTime &dateTimeController,
Pinetime::Controllers::NotificationManager& notificationManager, Pinetime::Controllers::MotorController& motorController,
Pinetime::Drivers::Hrs3300& heartRateSensor) : Pinetime::Drivers::Hrs3300& heartRateSensor) :
spi{spi}, lcd{lcd}, spiNorFlash{spiNorFlash}, spi{spi}, lcd{lcd}, spiNorFlash{spiNorFlash},
twiMaster{twiMaster}, touchPanel{touchPanel}, lvgl{lvgl}, batteryController{batteryController}, twiMaster{twiMaster}, touchPanel{touchPanel}, lvgl{lvgl}, batteryController{batteryController},
heartRateController{*this}, heartRateController{*this},
bleController{bleController}, dateTimeController{dateTimeController}, bleController{bleController}, dateTimeController{dateTimeController},
watchdog{}, watchdogView{watchdog}, notificationManager{notificationManager}, watchdog{}, watchdogView{watchdog},
heartRateSensor{heartRateSensor}, motorController{motorController}, heartRateSensor{heartRateSensor},
nimbleController(*this, bleController,dateTimeController, notificationManager, batteryController, spiNorFlash, heartRateController) { nimbleController(*this, bleController,dateTimeController, notificationManager, batteryController, spiNorFlash, heartRateController) {
systemTasksMsgQueue = xQueueCreate(10, 1); systemTasksMsgQueue = xQueueCreate(10, 1);
} }
@ -79,15 +79,17 @@ void SystemTask::Work() {
twiMaster.Init(); twiMaster.Init();
touchPanel.Init(); touchPanel.Init();
batteryController.Init(); batteryController.Init();
motorController.Init();
displayApp.reset(new Pinetime::Applications::DisplayApp(lcd, lvgl, touchPanel, batteryController, bleController, displayApp.reset(new Pinetime::Applications::DisplayApp(lcd, lvgl, touchPanel, batteryController, bleController,
dateTimeController, watchdogView, *this, notificationManager, heartRateController)); dateTimeController, watchdogView, *this, notificationManager,
heartRateController));
displayApp->Start(); displayApp->Start();
batteryController.Update(); batteryController.Update();
displayApp->PushMessage(Pinetime::Applications::DisplayApp::Messages::UpdateBatteryLevel); displayApp->PushMessage(Pinetime::Applications::DisplayApp::Messages::UpdateBatteryLevel);
heartRateSensor.Init(); heartRateSensor.Init();
heartRateSensor.Disable(); heartRateSensor.Disable();
heartRateApp.reset(new Pinetime::Applications::HeartRateTask(heartRateSensor, heartRateController)); heartRateApp.reset(new Pinetime::Applications::HeartRateTask(heartRateSensor, heartRateController));
@ -159,6 +161,7 @@ void SystemTask::Work() {
break; break;
case Messages::OnNewNotification: case Messages::OnNewNotification:
if(isSleeping && !isWakingUp) GoToRunning(); if(isSleeping && !isWakingUp) GoToRunning();
if(notificationManager.IsVibrationEnabled()) motorController.SetDuration(35);
displayApp->PushMessage(Pinetime::Applications::DisplayApp::Messages::NewNotification); displayApp->PushMessage(Pinetime::Applications::DisplayApp::Messages::NewNotification);
break; break;
case Messages::BleConnected: case Messages::BleConnected:

View file

@ -12,6 +12,7 @@
#include "components/battery/BatteryController.h" #include "components/battery/BatteryController.h"
#include "components/ble/NimbleController.h" #include "components/ble/NimbleController.h"
#include "components/ble/NotificationManager.h" #include "components/ble/NotificationManager.h"
#include "components/motor/MotorController.h"
#include "displayapp/DisplayApp.h" #include "displayapp/DisplayApp.h"
#include "drivers/Watchdog.h" #include "drivers/Watchdog.h"
@ -27,7 +28,7 @@ namespace Pinetime {
namespace System { namespace System {
class SystemTask { class SystemTask {
public: public:
enum class Messages {GoToSleep, GoToRunning, OnNewTime, OnNewNotification, BleConnected, enum class Messages {GoToSleep, GoToRunning, OnNewTime, OnNewNotification, OnNewCall, BleConnected,
BleFirmwareUpdateStarted, BleFirmwareUpdateFinished, OnTouchEvent, OnButtonEvent, OnDisplayTaskSleeping BleFirmwareUpdateStarted, BleFirmwareUpdateFinished, OnTouchEvent, OnButtonEvent, OnDisplayTaskSleeping
}; };
@ -37,7 +38,7 @@ namespace Pinetime {
Components::LittleVgl &lvgl, Components::LittleVgl &lvgl,
Controllers::Battery &batteryController, Controllers::Ble &bleController, Controllers::Battery &batteryController, Controllers::Ble &bleController,
Controllers::DateTime &dateTimeController, Controllers::DateTime &dateTimeController,
Pinetime::Controllers::NotificationManager& manager, Pinetime::Controllers::MotorController& motorController,
Pinetime::Drivers::Hrs3300& heartRateSensor); Pinetime::Drivers::Hrs3300& heartRateSensor);
@ -73,7 +74,8 @@ namespace Pinetime {
std::atomic<bool> isWakingUp{false}; std::atomic<bool> isWakingUp{false};
Pinetime::Drivers::Watchdog watchdog; Pinetime::Drivers::Watchdog watchdog;
Pinetime::Drivers::WatchdogView watchdogView; Pinetime::Drivers::WatchdogView watchdogView;
Pinetime::Controllers::NotificationManager& notificationManager; Pinetime::Controllers::NotificationManager notificationManager;
Pinetime::Controllers::MotorController& motorController;
Pinetime::Drivers::Hrs3300& heartRateSensor; Pinetime::Drivers::Hrs3300& heartRateSensor;
Pinetime::Controllers::NimbleController nimbleController; Pinetime::Controllers::NimbleController nimbleController;