summaryrefslogtreecommitdiff
path: root/src/Components/Ble/BleController.cpp
blob: fd405896de3cb8cc071205ede7c855f28c1c1442 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include <cstring>
#include <cstdlib>
#include "BleController.h"

using namespace Pinetime::Controllers;

Ble::Ble() {
  notificationQueue = xQueueCreate(10, sizeof(NotificationMessage));
}

void Ble::Connect() {
  isConnected = true;
}

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