Add support for BLE notification (ANS client).

Work In Progress!!!
This commit is contained in:
JF
2020-03-25 21:23:40 +01:00
parent 7e9a7e4d5f
commit 68240704c7
13 changed files with 346 additions and 12 deletions

View File

@@ -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;
}

View File

@@ -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;
};
}
}