Working IR send / Receive class

This commit is contained in:
Siwat Sirichai 2024-01-10 19:26:00 +07:00
parent 23a2f243c9
commit 618f0b51e8
3 changed files with 33 additions and 31 deletions

View file

@ -20,17 +20,13 @@ ir_data_t IRReceiver::end_long_receive() {
// The data in the array is the time between each transition, so we need to convert it to the time of each transition
ir_data_t data;
const size_t size = irBufferPtr-1;
Serial.println("Allocating memory");
data.data = (unsigned int*)calloc(size, sizeof(unsigned int));
if (data.data == nullptr) {
Serial.println("Failed to allocate memory");
data.size = 0;
return data;
}
Serial.println("Copying data");
// The data in the array is the time between each transition, so we need to convert it to the time of each transition
for (size_t i = 1; i <= size; i++) {
Serial.printf("Copying data at index %d\n", i);
data.data[i-1] = irBuffer[i] - irBuffer[i-1];
}
//memcpy(data.data, (const unsigned int*)irBuffer, (size)*sizeof(unsigned int));