-
Notifications
You must be signed in to change notification settings - Fork 183
/
BleOutputReceiver.cpp
38 lines (32 loc) · 974 Bytes
/
BleOutputReceiver.cpp
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
#include "BleOutputReceiver.h"
BleOutputReceiver::BleOutputReceiver(uint16_t outputReportLength)
{
this->outputReportLength = outputReportLength;
outputBuffer = new uint8_t[outputReportLength];
}
BleOutputReceiver::~BleOutputReceiver()
{
// Release memory
if (outputBuffer)
{
delete[] outputBuffer;
}
}
void BleOutputReceiver::onWrite(NimBLECharacteristic *pCharacteristic, NimBLEConnInfo& connInfo)
{
// Retrieve data sent from the host
std::string value = pCharacteristic->getValue();
// Store the received data in the buffer
for (int i = 0; i < std::min(value.length(), (size_t)outputReportLength); i++)
{
outputBuffer[i] = (uint8_t)value[i];
}
// Testing
// Serial.println("Received data from host:");
// for (size_t i = 0; i < value.length(); i++) {
// Serial.print((uint8_t)value[i], HEX);
// Serial.print(" ");
// }
// Serial.println();
outputFlag = true;
}