summaryrefslogtreecommitdiff
path: root/src/Components
diff options
context:
space:
mode:
Diffstat (limited to 'src/Components')
-rw-r--r--src/Components/Ble/BleController.cpp28
-rw-r--r--src/Components/Ble/BleController.h14
2 files changed, 42 insertions, 0 deletions
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