summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJF <jf@codingfield.com>2020-03-25 21:23:40 +0100
committerJF <jf@codingfield.com>2020-03-25 21:23:40 +0100
commit68240704c7a60534342cfc0157564f11cf82d9d8 (patch)
tree8472af61a5fa8a99ce5549f2de73b47f73cf41b6
parent7e9a7e4d5fa0f55b43180600d499f1d0ce6aded1 (diff)
Add support for BLE notification (ANS client).
Work In Progress!!!
-rwxr-xr-xcmake-nRF5x/CMake_nRF5x.cmake3
-rw-r--r--src/BLE/BleManager.c220
-rw-r--r--src/BLE/BleManager.h4
-rw-r--r--src/Components/Ble/BleController.cpp28
-rw-r--r--src/Components/Ble/BleController.h14
-rw-r--r--src/DisplayApp/DisplayApp.cpp11
-rw-r--r--src/DisplayApp/DisplayApp.h7
-rw-r--r--src/DisplayApp/Screens/Modal.cpp37
-rw-r--r--src/DisplayApp/Screens/Modal.h3
-rw-r--r--src/SystemTask/SystemTask.cpp8
-rw-r--r--src/SystemTask/SystemTask.h3
-rw-r--r--src/main.cpp8
-rw-r--r--src/sdk_config.h12
13 files changed, 346 insertions, 12 deletions
diff --git a/cmake-nRF5x/CMake_nRF5x.cmake b/cmake-nRF5x/CMake_nRF5x.cmake
index 8a43cf12..3e8e96aa 100755
--- a/cmake-nRF5x/CMake_nRF5x.cmake
+++ b/cmake-nRF5x/CMake_nRF5x.cmake
@@ -260,7 +260,8 @@ macro(nRF5x_setup)
list(APPEND SDK_SOURCE_FILES
"${NRF5_SDK_PATH}/components/ble/ble_db_discovery/ble_db_discovery.c"
"${NRF5_SDK_PATH}/components/ble/ble_services/ble_cts_c/ble_cts_c.c"
- "${NRF5_SDK_PATH}/external/thedotfactory_fonts/orkney24pts.c"
+ "${NRF5_SDK_PATH}/components/ble/ble_services/ble_ans_c/ble_ans_c.c"
+# "${NRF5_SDK_PATH}/external/thedotfactory_fonts/orkney24pts.c"
)
#BLE S132
diff --git a/src/BLE/BleManager.c b/src/BLE/BleManager.c
index 48653982..b7d6074a 100644
--- a/src/BLE/BleManager.c
+++ b/src/BLE/BleManager.c
@@ -12,6 +12,7 @@
#include <ble/ble_services/ble_hrs/ble_hrs.h>
#include <ble/ble_services/ble_bas/ble_bas.h>
#include <ble/ble_services/ble_dis/ble_dis.h>
+#include <ble/ble_services/ble_ans_c/ble_ans_c.h>
#include <ble/common/ble_conn_params.h>
#include <libraries/fds/fds.h>
#include "nrf_sdh_soc.h"
@@ -42,14 +43,31 @@ void ble_manager_cts_print_time(ble_cts_c_evt_t *p_evt);
void ble_manager_conn_params_event_handler(ble_conn_params_evt_t *p_evt);
void ble_manager_conn_params_error_handler(uint32_t nrf_error);
+typedef enum
+{
+ ALERT_NOTIFICATION_DISABLED, /**< Alert Notifications has been disabled. */
+ ALERT_NOTIFICATION_ENABLED, /**< Alert Notifications has been enabled. */
+ ALERT_NOTIFICATION_ON, /**< Alert State is on. */
+} ble_ans_c_alert_state_t;
+
+void on_ans_c_evt(ble_ans_c_evt_t * p_evt);
+void alert_notification_error_handler(uint32_t nrf_error);
+void handle_alert_notification(ble_ans_c_evt_t * p_evt);
+void supported_alert_notification_read(void);
+void alert_notification_setup(void);
+void control_point_setup(ble_ans_c_evt_t * p_evt);
+
uint16_t ble_manager_connection_handle = BLE_CONN_HANDLE_INVALID; // Handle of the current connection.
NRF_BLE_QWR_DEF(ble_manager_queue_write); // Context for the Queued Write module.
BLE_CTS_C_DEF(ble_manager_cts_client); // Current Time service instance.
NRF_BLE_GATT_DEF(ble_manager_gatt); // GATT module instance.
BLE_ADVERTISING_DEF(ble_manager_advertising); // Advertising module instance.
BLE_DB_DISCOVERY_DEF(ble_manager_db_discovery);
+BLE_ANS_C_DEF(m_ans_c);
-
+static uint8_t m_alert_message_buffer[MESSAGE_BUFFER_SIZE]; /**< Message buffer for optional notify messages. */
+static ble_ans_c_alert_state_t m_new_alert_state = ALERT_NOTIFICATION_DISABLED; /**< State that holds the current state of New Alert Notifications, i.e. Enabled, Alert On, Disabled. */
+static ble_ans_c_alert_state_t m_unread_alert_state = ALERT_NOTIFICATION_DISABLED; /**< State that holds the current state of Unread Alert Notifications, i.e. Enabled, Alert On, Disabled. */
static ble_uuid_t ble_manager_advertising_uuids[] = /* Universally unique service identifiers.*/
{
@@ -88,6 +106,21 @@ static char const *month_of_year[] =
"December"
};
+static char const * lit_catid[BLE_ANS_NB_OF_CATEGORY_ID] =
+ {
+ "Simple alert",
+ "Email",
+ "News",
+ "Incoming call",
+ "Missed call",
+ "SMS/MMS",
+ "Voice mail",
+ "Schedule",
+ "High prioritized alert",
+ "Instant message"
+ };
+
+
void ble_manager_init() {
ble_manager_init_stack();
ble_manager_init_gap_params();
@@ -133,6 +166,11 @@ void ble_manager_set_ble_disconnection_callback(void (*OnBleDisconnection)()) {
OnBleDisconnectionCallback = OnBleDisconnection;
}
+void (*OnNewNotificationCallback)(const char* message, uint8_t size);
+void ble_manager_set_new_notification_callback(void (*OnNewNotification)(const char*, uint8_t size)) {
+ OnNewNotificationCallback = OnNewNotification;
+}
+
void ble_manager_event_handler(ble_evt_t const *p_ble_evt, void *p_context) {
uint32_t err_code;
@@ -227,6 +265,8 @@ void ble_manager_init_db_discovery() {
void ble_manager_discover_handler(ble_db_discovery_evt_t *p_evt) {
ble_cts_c_on_db_disc_evt(&ble_manager_cts_client, p_evt);
+ NRF_LOG_INFO("ble_ans_c_on_db_disc_evt");
+ ble_ans_c_on_db_disc_evt(&m_ans_c, p_evt);
}
void ble_manager_init_advertising() {
@@ -382,12 +422,165 @@ void ble_manager_start_advertising(void *p_erase_bonds) {
}
}
+void handle_alert_notification(ble_ans_c_evt_t * p_evt)
+{
+ ret_code_t err_code;
+
+ if (p_evt->uuid.uuid == BLE_UUID_UNREAD_ALERT_CHAR)
+ {
+ if (m_unread_alert_state == ALERT_NOTIFICATION_ENABLED)
+ {
+// err_code = bsp_indication_set(BSP_INDICATE_ALERT_1);
+ APP_ERROR_CHECK(err_code);
+ m_unread_alert_state = ALERT_NOTIFICATION_ON;
+ NRF_LOG_INFO("Unread Alert state: On.");
+ NRF_LOG_INFO(" Category: %s",
+ (uint32_t)lit_catid[p_evt->data.alert.alert_category]);
+ NRF_LOG_INFO(" Number of unread alerts: %d",
+ p_evt->data.alert.alert_category_count);
+ }
+ }
+ else if (p_evt->uuid.uuid == BLE_UUID_NEW_ALERT_CHAR)
+ {
+// if (m_new_alert_state == ALERT_NOTIFICATION_ENABLED)
+ if(true)
+ {
+// err_code = bsp_indication_set(BSP_INDICATE_ALERT_0);
+// APP_ERROR_CHECK(err_code);
+ m_new_alert_state = ALERT_NOTIFICATION_ON;
+ NRF_LOG_INFO("New Alert state: On.");
+ NRF_LOG_INFO(" Category: %s",
+ (uint32_t)lit_catid[p_evt->data.alert.alert_category]);
+ NRF_LOG_INFO(" Number of new alerts: %d",
+ p_evt->data.alert.alert_category_count);
+ NRF_LOG_INFO(" Text String Information: (%d) %s",
+ p_evt->data.alert.alert_msg_length, (uint32_t)p_evt->data.alert.p_alert_msg_buf);
+
+ OnNewNotificationCallback(p_evt->data.alert.p_alert_msg_buf, p_evt->data.alert.alert_msg_length);
+ }
+ }
+ else
+ {
+ // Only Unread and New Alerts exists, thus do nothing.
+ }
+}
+
+void supported_alert_notification_read(void)
+{
+ NRF_LOG_INFO("Read supported Alert Notification characteristics on the connected peer.");
+
+ ret_code_t err_code;
+
+ err_code = ble_ans_c_new_alert_read(&m_ans_c);
+ APP_ERROR_CHECK(err_code);
+
+ err_code = ble_ans_c_unread_alert_read(&m_ans_c);
+ APP_ERROR_CHECK(err_code);
+
+}
+
+void alert_notification_setup(void)
+{
+ ret_code_t err_code;
+
+ err_code = ble_ans_c_enable_notif_new_alert(&m_ans_c);
+ APP_ERROR_CHECK(err_code);
+
+ m_new_alert_state = ALERT_NOTIFICATION_ENABLED;
+ NRF_LOG_INFO("New Alert State: Enabled.");
+
+ err_code = ble_ans_c_enable_notif_unread_alert(&m_ans_c);
+ APP_ERROR_CHECK(err_code);
+
+ m_unread_alert_state = ALERT_NOTIFICATION_ENABLED;
+ NRF_LOG_INFO("Unread Alert State: Enabled.");
+
+ NRF_LOG_INFO("Notifications enabled.");
+}
+
+void control_point_setup(ble_ans_c_evt_t * p_evt)
+{
+ uint32_t err_code;
+ ble_ans_control_point_t setting;
+
+ if (p_evt->uuid.uuid == BLE_UUID_SUPPORTED_UNREAD_ALERT_CATEGORY_CHAR)
+ {
+ setting.command = ANS_ENABLE_UNREAD_CATEGORY_STATUS_NOTIFICATION;
+ setting.category = (ble_ans_category_id_t)p_evt->data.alert.alert_category;
+ NRF_LOG_INFO("Unread status notification enabled for received categories.");
+ }
+ else if (p_evt->uuid.uuid == BLE_UUID_SUPPORTED_NEW_ALERT_CATEGORY_CHAR)
+ {
+ setting.command = ANS_ENABLE_NEW_INCOMING_ALERT_NOTIFICATION;
+ setting.category = (ble_ans_category_id_t)p_evt->data.alert.alert_category;
+ NRF_LOG_INFO("New incoming notification enabled for received categories.");
+ }
+ else
+ {
+ return;
+ }
+
+ err_code = ble_ans_c_control_point_write(&m_ans_c, &setting);
+ APP_ERROR_CHECK(err_code);
+}
+
+void on_ans_c_evt(ble_ans_c_evt_t * p_evt)
+{
+ ret_code_t err_code;
+ NRF_LOG_INFO("ANS %d", p_evt->evt_type);
+
+
+ switch (p_evt->evt_type)
+ {
+ case BLE_ANS_C_EVT_DISCOVERY_FAILED:
+ NRF_LOG_INFO("ANS discovery failed");
+ break;
+ case BLE_ANS_C_EVT_NOTIFICATION:
+ handle_alert_notification(p_evt);
+ NRF_LOG_INFO("Alert Notification received from server, UUID: %X.", p_evt->uuid.uuid);
+ break; // BLE_ANS_C_EVT_NOTIFICATION
+
+ case BLE_ANS_C_EVT_DISCOVERY_COMPLETE:
+ NRF_LOG_INFO("Alert Notification Service discovered on the server.");
+ err_code = ble_ans_c_handles_assign(&m_ans_c,
+ p_evt->conn_handle,
+ &p_evt->data.service);
+ APP_ERROR_CHECK(err_code);
+ supported_alert_notification_read();
+ alert_notification_setup();
+ break; // BLE_ANS_C_EVT_DISCOVERY_COMPLETE
+
+ case BLE_ANS_C_EVT_READ_RESP:
+ NRF_LOG_INFO("Alert Setup received from server, UUID: %X.", p_evt->uuid.uuid);
+ control_point_setup(p_evt);
+ break; // BLE_ANS_C_EVT_READ_RESP
+
+ case BLE_ANS_C_EVT_DISCONN_COMPLETE:
+ m_new_alert_state = ALERT_NOTIFICATION_DISABLED;
+ m_unread_alert_state = ALERT_NOTIFICATION_DISABLED;
+
+// err_code = bsp_indication_set(BSP_INDICATE_ALERT_OFF);
+ APP_ERROR_CHECK(err_code);
+ break; // BLE_ANS_C_EVT_DISCONN_COMPLETE
+
+ default:
+ // No implementation needed.
+ break;
+ }
+}
+
+void alert_notification_error_handler(uint32_t nrf_error)
+{
+ APP_ERROR_HANDLER(nrf_error);
+}
+
void ble_manager_init_services() {
ret_code_t err_code;
ble_hrs_init_t hrs_init;
ble_bas_init_t bas_init;
ble_dis_init_t dis_init;
ble_cts_c_init_t cts_init;
+ ble_ans_c_init_t ans_init_obj;
nrf_ble_qwr_init_t qwr_init = {0};
uint8_t body_sensor_location;
@@ -441,6 +634,21 @@ void ble_manager_init_services() {
cts_init.error_handler = ble_manager_cts_error_handler;
err_code = ble_cts_c_init(&ble_manager_cts_client, &cts_init);
APP_ERROR_CHECK(err_code);
+
+ // Alert Notification service
+ memset(&ans_init_obj, 0, sizeof(ans_init_obj));
+ memset(m_alert_message_buffer, 0, MESSAGE_BUFFER_SIZE);
+
+ ans_init_obj.evt_handler = on_ans_c_evt;
+ ans_init_obj.message_buffer_size = MESSAGE_BUFFER_SIZE;
+ ans_init_obj.p_message_buffer = m_alert_message_buffer;
+ ans_init_obj.error_handler = alert_notification_error_handler;
+
+ NRF_LOG_INFO("ble_ans_c_init");
+ err_code = ble_ans_c_init(&m_ans_c, &ans_init_obj);
+ NRF_SDH_BLE_OBSERVER(ans_observer, BLE_ANS_C_BLE_OBSERVER_PRIO,*ble_ans_c_on_ble_evt, &m_ans_c);
+
+ APP_ERROR_CHECK(err_code);
}
void ble_manager_queue_write_error_handler(uint32_t nrf_error) {
@@ -467,11 +675,11 @@ void ble_manager_cts_event_handler(ble_cts_c_t *p_cts, ble_cts_c_evt_t *p_evt) {
NRF_LOG_INFO("Current Time Service not found on server. ");
// CTS not found in this case we just disconnect. There is no reason to stay
// in the connection for this simple app since it all wants is to interact with CT
- if (p_evt->conn_handle != BLE_CONN_HANDLE_INVALID) {
- err_code = sd_ble_gap_disconnect(p_evt->conn_handle,
- BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION);
- APP_ERROR_CHECK(err_code);
- }
+// if (p_evt->conn_handle != BLE_CONN_HANDLE_INVALID) {
+// err_code = sd_ble_gap_disconnect(p_evt->conn_handle,
+// BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION);
+// APP_ERROR_CHECK(err_code);
+// }
break;
case BLE_CTS_C_EVT_DISCONN_COMPLETE:
diff --git a/src/BLE/BleManager.h b/src/BLE/BleManager.h
index 4424d665..e3b9faf3 100644
--- a/src/BLE/BleManager.h
+++ b/src/BLE/BleManager.h
@@ -31,6 +31,8 @@ extern "C" {
#define NEXT_CONN_PARAMS_UPDATE_DELAY 30000 /* Time between each call to sd_ble_gap_conn_param_update after the first call (30 seconds). */
#define MAX_CONN_PARAMS_UPDATE_COUNT 3 /* Number of attempts before giving up the connection parameter negotiation. */
+#define MESSAGE_BUFFER_SIZE 18 /**< Size of buffer holding optional messages in notifications. */
+#define BLE_ANS_NB_OF_CATEGORY_ID 10 /**< Number of categories. */
void ble_manager_init();
void ble_manager_start_advertising(void *p_erase_bonds);
@@ -41,6 +43,8 @@ void ble_manager_set_new_time_callback(void (*OnNewTime)(current_time_char_t* cu
void ble_manager_set_ble_disconnection_callback(void (*OnBleDisconnection)());
void ble_manager_set_ble_connection_callback(void (*OnBleConnection)());
+void ble_manager_set_new_notification_callback(void (*OnNewNotification)(const char* message, uint8_t size));
+
#ifdef __cplusplus
}
diff --git a/src/Components/Ble/BleController.cpp b/src/Components/Ble/BleController.cpp
index c2458087..fd405896 100644
--- a/src/Components/Ble/BleController.cpp
+++ b/src/Components/Ble/BleController.cpp
@@ -1,7 +1,13 @@
+#include <cstring>
+#include <cstdlib>
#include "BleController.h"
using namespace Pinetime::Controllers;
+Ble::Ble() {
+ notificationQueue = xQueueCreate(10, sizeof(NotificationMessage));
+}
+
void Ble::Connect() {
isConnected = true;
}
@@ -9,3 +15,25 @@ void Ble::Connect() {
void Ble::Disconnect() {
isConnected = false;
}
+
+void Ble::PushNotification(const char *message, uint8_t size) {
+ char* messageCopy = static_cast<char *>(malloc(sizeof(char) * size));
+ std::memcpy(messageCopy, message, size);
+ NotificationMessage msg;
+ msg.size = size;
+ msg.message = messageCopy;
+
+ BaseType_t xHigherPriorityTaskWoken;
+ xHigherPriorityTaskWoken = pdFALSE;
+ xQueueSendFromISR(notificationQueue, &msg, &xHigherPriorityTaskWoken);
+ if (xHigherPriorityTaskWoken) {
+ /* Actual macro used here is port specific. */
+ // TODO : should I do something here?
+ }
+}
+
+bool Ble::PopNotification(Ble::NotificationMessage& msg) {
+ return xQueueReceive(notificationQueue, &msg, 0) != 0;
+}
+
+
diff --git a/src/Components/Ble/BleController.h b/src/Components/Ble/BleController.h
index be491ee9..4f037fc1 100644
--- a/src/Components/Ble/BleController.h
+++ b/src/Components/Ble/BleController.h
@@ -1,15 +1,29 @@
#pragma once
+#include <FreeRTOS.h>>
+#include <queue.h>
+
namespace Pinetime {
namespace Controllers {
class Ble {
public:
+ struct NotificationMessage {
+ uint8_t size = 0;
+ const char* message = nullptr;
+ };
+
+ Ble();
bool IsConnected() const {return isConnected;}
void Connect();
void Disconnect();
+ void PushNotification(const char* message, uint8_t size);
+ bool PopNotification(NotificationMessage& msg);
+
private:
bool isConnected = false;
+ QueueHandle_t notificationQueue;
+
};
}
} \ No newline at end of file
diff --git a/src/DisplayApp/DisplayApp.cpp b/src/DisplayApp/DisplayApp.cpp
index e7187f1d..2e07cbc5 100644
--- a/src/DisplayApp/DisplayApp.cpp
+++ b/src/DisplayApp/DisplayApp.cpp
@@ -38,6 +38,7 @@ DisplayApp::DisplayApp(Pinetime::Drivers::St7789& lcd,
systemTask{systemTask} {
msgQueue = xQueueCreate(queueSize, itemSize);
onClockApp = true;
+ modal.reset(new Screens::Modal(this));
}
void DisplayApp::Start() {
@@ -103,6 +104,7 @@ void DisplayApp::Refresh() {
state = States::Running;
break;
case Messages::UpdateDateTime:
+// modal->Show();
break;
case Messages::UpdateBleConnection:
// clockScreen.SetBleConnectionState(bleController.IsConnected() ? Screens::Clock::BleConnectionStates::Connected : Screens::Clock::BleConnectionStates::NotConnected);
@@ -110,6 +112,15 @@ void DisplayApp::Refresh() {
case Messages::UpdateBatteryLevel:
// clockScreen.SetBatteryPercentRemaining(batteryController.PercentRemaining());
break;
+ case Messages::NewNotification: {
+ Pinetime::Controllers::Ble::NotificationMessage notificationMessage;
+ if (bleController.PopNotification(notificationMessage)) {
+ std::string m {notificationMessage.message, notificationMessage.size};
+ modal->Show(m);
+ // TODO delete message
+ }
+ }
+ break;
case Messages::TouchEvent: {
if (state != States::Running) break;
auto gesture = OnTouchEvent();
diff --git a/src/DisplayApp/DisplayApp.h b/src/DisplayApp/DisplayApp.h
index 04c82fee..ad817331 100644
--- a/src/DisplayApp/DisplayApp.h
+++ b/src/DisplayApp/DisplayApp.h
@@ -16,6 +16,7 @@
#include <date/date.h>
#include <DisplayApp/Screens/Clock.h>
#include <drivers/Watchdog.h>
+#include <DisplayApp/Screens/Modal.h>
#include "TouchEvents.h"
@@ -27,7 +28,9 @@ namespace Pinetime {
class DisplayApp {
public:
enum class States {Idle, Running};
- enum class Messages : uint8_t {GoToSleep, GoToRunning, UpdateDateTime, UpdateBleConnection, UpdateBatteryLevel, TouchEvent, SwitchScreen,ButtonPushed};
+ enum class Messages : uint8_t {GoToSleep, GoToRunning, UpdateDateTime, UpdateBleConnection, UpdateBatteryLevel, TouchEvent, SwitchScreen,ButtonPushed,
+ NewNotification
+ };
enum class FullRefreshDirections { None, Up, Down };
@@ -78,6 +81,8 @@ namespace Pinetime {
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.
Controllers::BrightnessController brightnessController;
+ std::unique_ptr<Screens::Modal> modal;
+
};
}
}
diff --git a/src/DisplayApp/Screens/Modal.cpp b/src/DisplayApp/Screens/Modal.cpp
index fc353c49..ec477b6e 100644
--- a/src/DisplayApp/Screens/Modal.cpp
+++ b/src/DisplayApp/Screens/Modal.cpp
@@ -26,6 +26,8 @@ bool Modal::OnButtonPushed() {
}
void Modal::Show() {
+ if(isVisible) return;
+ isVisible = true;
lv_style_copy(&modal_style, &lv_style_plain_color);
modal_style.body.main_color = modal_style.body.grad_color = LV_COLOR_BLACK;
modal_style.body.opa = LV_OPA_50;
@@ -63,6 +65,7 @@ void Modal::Hide() {
/* Delete the parent modal background */
lv_obj_del_async(lv_obj_get_parent(mbox));
mbox = NULL; /* happens before object is actually deleted! */
+ isVisible = false;
}
void Modal::mbox_event_cb(lv_obj_t *obj, lv_event_t evt) {
@@ -79,3 +82,37 @@ void Modal::OnEvent(lv_obj_t *event_obj, lv_event_t evt) {
// Hide();
}
}
+
+void Modal::Show(const std::string& message) {
+ if(isVisible) return;
+ this->message = message;
+ isVisible = true;
+ lv_style_copy(&modal_style, &lv_style_plain_color);
+ modal_style.body.main_color = modal_style.body.grad_color = LV_COLOR_BLACK;
+ modal_style.body.opa = LV_OPA_50;
+
+ obj = lv_obj_create(lv_scr_act(), NULL);
+ lv_obj_set_style(obj, &modal_style);
+ lv_obj_set_pos(obj, 0, 0);
+ 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 */
+
+ static const char * btns2[] = {"Ok", ""};
+
+ /* Create the message box as a child of the modal background */
+ mbox = lv_mbox_create(obj, NULL);
+ lv_mbox_add_btns(mbox, btns2);
+ lv_mbox_set_text(mbox, message.data());
+ lv_obj_align(mbox, NULL, LV_ALIGN_CENTER, 0, 0);
+ lv_obj_set_event_cb(mbox, Modal::mbox_event_cb);
+
+ mbox->user_data = this;
+
+ /* Fade the message box in with an animation */
+ lv_anim_t a;
+ lv_anim_init(&a);
+ lv_anim_set_time(&a, 500, 0);
+ lv_anim_set_values(&a, LV_OPA_TRANSP, LV_OPA_COVER);
+ lv_anim_set_exec_cb(&a, obj, (lv_anim_exec_xcb_t)lv_obj_set_opa_scale);
+ lv_anim_create(&a);
+}
diff --git a/src/DisplayApp/Screens/Modal.h b/src/DisplayApp/Screens/Modal.h
index de287293..b13b5c60 100644
--- a/src/DisplayApp/Screens/Modal.h
+++ b/src/DisplayApp/Screens/Modal.h
@@ -23,6 +23,7 @@ namespace Pinetime {
~Modal() override;
void Show();
+ void Show(const std::string& message);
void Hide();
bool Refresh() override;
@@ -37,6 +38,8 @@ namespace Pinetime {
lv_obj_t *mbox;
lv_obj_t *info;
bool running = true;
+ bool isVisible = false;
+ std::string message;
};
}
diff --git a/src/SystemTask/SystemTask.cpp b/src/SystemTask/SystemTask.cpp
index c4e1386c..0080c6b6 100644
--- a/src/SystemTask/SystemTask.cpp
+++ b/src/SystemTask/SystemTask.cpp
@@ -35,7 +35,7 @@ void SystemTask::Work() {
watchdog.Start();
NRF_LOG_INFO("Last reset reason : %s", Pinetime::Drivers::Watchdog::ResetReasonToString(watchdog.ResetReason()));
APP_GPIOTE_INIT(2);
- bool erase_bonds=false;
+ bool erase_bonds=true;
ble_manager_init_peer_manager();
nrf_sdh_freertos_init(ble_manager_start_advertising, &erase_bonds);
@@ -84,6 +84,12 @@ void SystemTask::Work() {
NRF_LOG_INFO("[SystemTask] Going to sleep");
displayApp->PushMessage(Pinetime::Applications::DisplayApp::Messages::GoToSleep);
isSleeping = true; break;
+ case Messages::OnNewTime:
+ displayApp->PushMessage(Pinetime::Applications::DisplayApp::Messages::UpdateDateTime);
+ break;
+ case Messages::OnNewNotification:
+ displayApp->PushMessage(Pinetime::Applications::DisplayApp::Messages::NewNotification);
+ break;
default: break;
}
}
diff --git a/src/SystemTask/SystemTask.h b/src/SystemTask/SystemTask.h
index a2775d9d..b64fda65 100644
--- a/src/SystemTask/SystemTask.h
+++ b/src/SystemTask/SystemTask.h
@@ -13,7 +13,8 @@ namespace Pinetime {
namespace System {
class SystemTask {
public:
- enum class Messages {GoToSleep, GoToRunning};
+ enum class Messages {GoToSleep, GoToRunning, OnNewTime, OnNewNotification
+ };
SystemTask(Pinetime::Drivers::SpiMaster& spi,
Pinetime::Drivers::St7789& lcd,
diff --git a/src/main.cpp b/src/main.cpp
index 25a8a6c9..a4a759d9 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -85,6 +85,11 @@ void OnBleDisconnection() {
bleController.Disconnect();
}
+void OnNewNotification(const char* message, uint8_t size) {
+ bleController.PushNotification(message, size);
+ systemTask->PushMessage(Pinetime::System::SystemTask::Messages::OnNewNotification);
+}
+
void OnNewTime(current_time_char_t* currentTime) {
auto dayOfWeek = currentTime->exact_time_256.day_date_time.day_of_week;
auto year = currentTime->exact_time_256.day_date_time.date_time.year;
@@ -96,6 +101,8 @@ void OnNewTime(current_time_char_t* currentTime) {
dateTimeController.SetTime(year, month, day,
dayOfWeek, hour, minute, second, nrf_rtc_counter_get(portNRF_RTC_REG));
+
+ systemTask->PushMessage(Pinetime::System::SystemTask::Messages::OnNewTime);
}
void SPIM0_SPIS0_TWIM0_TWIS0_SPI0_TWI0_IRQHandler(void) {
@@ -128,6 +135,7 @@ int main(void) {
ble_manager_set_new_time_callback(OnNewTime);
ble_manager_set_ble_connection_callback(OnBleConnection);
ble_manager_set_ble_disconnection_callback(OnBleDisconnection);
+ ble_manager_set_new_notification_callback(OnNewNotification);
vTaskStartScheduler();
diff --git a/src/sdk_config.h b/src/sdk_config.h
index 0d9b2744..5bff52ee 100644
--- a/src/sdk_config.h
+++ b/src/sdk_config.h
@@ -1322,7 +1322,15 @@
#ifndef BLE_ANS_C_ENABLED
-#define BLE_ANS_C_ENABLED 0
+#define BLE_ANS_C_ENABLED 1
+#endif
+
+#ifndef BLE_ANS_C_LOG_ENABLED
+#define BLE_ANS_C_LOG_ENABLED 1
+#endif
+
+#ifndef BLE_ANS_C_LOG_LEVEL
+#define BLE_ANS_C_LOG_LEVEL 4
#endif
// <q> BLE_BAS_C_ENABLED - ble_bas_c - Battery Service Client
@@ -8532,7 +8540,7 @@
// <4=> Debug
#ifndef NRF_LOG_DEFAULT_LEVEL
-#define NRF_LOG_DEFAULT_LEVEL 3
+#define NRF_LOG_DEFAULT_LEVEL 4
#endif
// <q> NRF_LOG_DEFERRED - Enable deffered logger.