flipperzero-firmware/lib/irda/encoder_decoder/samsung/irda_decoder_samsung.c
Albert Kharisov 13c5a8cb20
[FL-1505] Add RAW format (#576)
* Add RAW format
* F5 stubs for build to pass
* Fix saving decoded signal error
* Irda: set ISR before starting timer, remove explicit NVIC configuration

Co-authored-by: あく <alleteam@gmail.com>
2021-07-16 19:43:54 +03:00

71 lines
2.3 KiB
C

#include "irda_protocol_defs_i.h"
#include <stdbool.h>
#include <stdint.h>
#include <furi.h>
#include "../irda_i.h"
bool irda_decoder_samsung32_interpret(IrdaCommonDecoder* decoder) {
furi_assert(decoder);
bool result = false;
uint8_t address1 = decoder->data[0];
uint8_t address2 = decoder->data[1];
uint8_t command = decoder->data[2];
uint8_t command_inverse = decoder->data[3];
if ((address1 == address2) && (command == (uint8_t) ~command_inverse)) {
decoder->message.command = command;
decoder->message.address = address1;
decoder->message.repeat = false;
result = true;
}
return result;
}
// timings start from Space (delay between message and repeat)
IrdaStatus irda_decoder_samsung32_decode_repeat(IrdaCommonDecoder* decoder) {
furi_assert(decoder);
float preamble_tolerance = decoder->protocol->timings.preamble_tolerance;
uint32_t bit_tolerance = decoder->protocol->timings.bit_tolerance;
IrdaStatus status = IrdaStatusError;
if (decoder->timings_cnt < 6)
return IrdaStatusOk;
if ((decoder->timings[0] > IRDA_SAMSUNG_REPEAT_PAUSE_MIN)
&& (decoder->timings[0] < IRDA_SAMSUNG_REPEAT_PAUSE_MAX)
&& MATCH_PREAMBLE_TIMING(decoder->timings[1], IRDA_SAMSUNG_REPEAT_MARK, preamble_tolerance)
&& MATCH_PREAMBLE_TIMING(decoder->timings[2], IRDA_SAMSUNG_REPEAT_SPACE, preamble_tolerance)
&& MATCH_BIT_TIMING(decoder->timings[3], decoder->protocol->timings.bit1_mark, bit_tolerance)
&& MATCH_BIT_TIMING(decoder->timings[4], decoder->protocol->timings.bit1_space, bit_tolerance)
&& MATCH_BIT_TIMING(decoder->timings[5], decoder->protocol->timings.bit1_mark, bit_tolerance)
) {
status = IrdaStatusReady;
decoder->timings_cnt = 0;
} else {
status = IrdaStatusError;
}
return status;
}
void* irda_decoder_samsung32_alloc(void) {
return irda_common_decoder_alloc(&protocol_samsung32);
}
IrdaMessage* irda_decoder_samsung32_decode(void* decoder, bool level, uint32_t duration) {
return irda_common_decode(decoder, level, duration);
}
void irda_decoder_samsung32_free(void* decoder) {
irda_common_decoder_free(decoder);
}
void irda_decoder_samsung32_reset(void* decoder) {
irda_common_decoder_reset(decoder);
}