makes GPIO_PIN_RST optional for the sx1276
[ExpressLRS.git] / src / lib / StubbornReceiver / stubborn_receiver.cpp
blob016f4af474528383b855ea9150330016a55b3d58
1 #include <cstdint>
2 #include "stubborn_receiver.h"
4 StubbornReceiver::StubbornReceiver(uint8_t maxPackageIndex)
6 this->maxPackageIndex = maxPackageIndex;
7 this->ResetState();
10 void StubbornReceiver::ResetState()
12 data = 0;
13 bytesPerCall = 1;
14 currentOffset = 0;
15 currentPackage = 0;
16 length = 0;
17 telemetryConfirm = false;
20 bool StubbornReceiver::GetCurrentConfirm()
22 return telemetryConfirm;
25 void StubbornReceiver::SetDataToReceive(uint8_t maxLength, uint8_t* dataToReceive, uint8_t bytesPerCall)
27 length = maxLength;
28 data = dataToReceive;
29 currentPackage = 1;
30 currentOffset = 0;
31 finishedData = false;
32 this->bytesPerCall = bytesPerCall;
35 void StubbornReceiver::ReceiveData(uint8_t packageIndex, volatile uint8_t* receiveData)
37 if (packageIndex == 0 && currentPackage > 1)
39 finishedData = true;
40 telemetryConfirm = !telemetryConfirm;
41 return;
44 if (packageIndex == maxPackageIndex)
46 telemetryConfirm = !telemetryConfirm;
47 currentPackage = 1;
48 currentOffset = 0;
49 finishedData = false;
50 return;
53 if (finishedData)
55 return;
58 if (packageIndex == currentPackage)
60 for (uint8_t i = 0; i < bytesPerCall; i++)
62 data[currentOffset++] = *(receiveData + i);
65 currentPackage++;
66 telemetryConfirm = !telemetryConfirm;
67 return;
70 return;
73 bool StubbornReceiver::HasFinishedData()
75 return finishedData;
78 void StubbornReceiver::Unlock()
80 if (finishedData)
82 currentPackage = 1;
83 currentOffset = 0;
84 finishedData = false;