e3c7201a20
* Furi: rename and move core * Furi: drop CMSIS_OS header and unused api, partially refactor and cleanup the rest * Furi: CMSIS_OS drop and refactoring. * Furi: refactoring, remove cmsis legacy * Furi: fix incorrect assert on queue deallocation, cleanup timer * Furi: improve delay api, get rid of floats * hal: dropped furi_hal_crc * Furi: move DWT based delay to cortex HAL * Furi: update core documentation Co-authored-by: hedger <hedger@nanode.su>
67 lines
1.9 KiB
C
67 lines
1.9 KiB
C
#include <stdlib.h>
|
|
#include "pulse_decoder.h"
|
|
#include <string.h>
|
|
#include <core/check.h>
|
|
|
|
#define MAX_PROTOCOL 5
|
|
|
|
struct PulseDecoder {
|
|
PulseProtocol* protocols[MAX_PROTOCOL];
|
|
};
|
|
|
|
PulseDecoder* pulse_decoder_alloc() {
|
|
PulseDecoder* decoder = malloc(sizeof(PulseDecoder));
|
|
memset(decoder, 0, sizeof(PulseDecoder));
|
|
return decoder;
|
|
}
|
|
|
|
void pulse_decoder_free(PulseDecoder* reader) {
|
|
furi_assert(reader);
|
|
free(reader);
|
|
}
|
|
|
|
void pulse_decoder_add_protocol(PulseDecoder* reader, PulseProtocol* protocol, int32_t index) {
|
|
furi_check(index < MAX_PROTOCOL);
|
|
furi_check(reader->protocols[index] == NULL);
|
|
reader->protocols[index] = protocol;
|
|
}
|
|
|
|
void pulse_decoder_process_pulse(PulseDecoder* reader, bool polarity, uint32_t length) {
|
|
furi_assert(reader);
|
|
for(size_t index = 0; index < MAX_PROTOCOL; index++) {
|
|
if(reader->protocols[index] != NULL) {
|
|
pulse_protocol_process_pulse(reader->protocols[index], polarity, length);
|
|
}
|
|
}
|
|
}
|
|
|
|
int32_t pulse_decoder_get_decoded_index(PulseDecoder* reader) {
|
|
furi_assert(reader);
|
|
int32_t decoded = -1;
|
|
for(size_t index = 0; index < MAX_PROTOCOL; index++) {
|
|
if(reader->protocols[index] != NULL) {
|
|
if(pulse_protocol_decoded(reader->protocols[index])) {
|
|
decoded = index;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
return decoded;
|
|
}
|
|
|
|
void pulse_decoder_reset(PulseDecoder* reader) {
|
|
furi_assert(reader);
|
|
for(size_t index = 0; index < MAX_PROTOCOL; index++) {
|
|
if(reader->protocols[index] != NULL) {
|
|
pulse_protocol_reset(reader->protocols[index]);
|
|
}
|
|
}
|
|
}
|
|
|
|
void pulse_decoder_get_data(PulseDecoder* reader, int32_t index, uint8_t* data, size_t length) {
|
|
furi_assert(reader);
|
|
furi_check(reader->protocols[index] != NULL);
|
|
pulse_protocol_get_data(reader->protocols[index], data, length);
|
|
}
|