2021-07-08 21:20:13 +03:00
|
|
|
#include "irda_protocol_defs_i.h"
|
2021-05-18 13:51:00 +03:00
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <furi.h>
|
|
|
|
#include "../irda_i.h"
|
|
|
|
|
2021-06-02 18:16:05 +03:00
|
|
|
|
2021-07-08 21:20:13 +03:00
|
|
|
bool irda_decoder_nec_interpret(IrdaCommonDecoder* decoder) {
|
2021-05-18 13:51:00 +03:00
|
|
|
furi_assert(decoder);
|
|
|
|
|
|
|
|
bool result = false;
|
2021-06-02 18:16:05 +03:00
|
|
|
uint8_t address = decoder->data[0];
|
|
|
|
uint8_t address_inverse = decoder->data[1];
|
2021-05-18 13:51:00 +03:00
|
|
|
uint8_t command = decoder->data[2];
|
|
|
|
uint8_t command_inverse = decoder->data[3];
|
|
|
|
|
2021-06-02 18:16:05 +03:00
|
|
|
if ((command == (uint8_t) ~command_inverse) && (address == (uint8_t) ~address_inverse)) {
|
2021-05-18 13:51:00 +03:00
|
|
|
decoder->message.command = command;
|
|
|
|
decoder->message.address = address;
|
|
|
|
decoder->message.repeat = false;
|
|
|
|
result = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2021-06-02 18:16:05 +03:00
|
|
|
// Some NEC's extensions allow 16 bit address
|
2021-07-08 21:20:13 +03:00
|
|
|
bool irda_decoder_necext_interpret(IrdaCommonDecoder* decoder) {
|
2021-06-02 18:16:05 +03:00
|
|
|
furi_assert(decoder);
|
|
|
|
|
|
|
|
bool result = false;
|
|
|
|
uint8_t command = decoder->data[2];
|
|
|
|
uint8_t command_inverse = decoder->data[3];
|
|
|
|
|
|
|
|
if(command == (uint8_t)~command_inverse) {
|
|
|
|
decoder->message.command = command;
|
|
|
|
decoder->message.address = decoder->data[0] | (decoder->data[1] << 8);
|
|
|
|
decoder->message.repeat = false;
|
|
|
|
result = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2021-05-18 13:51:00 +03:00
|
|
|
// timings start from Space (delay between message and repeat)
|
2021-07-08 21:20:13 +03:00
|
|
|
IrdaStatus irda_decoder_nec_decode_repeat(IrdaCommonDecoder* decoder) {
|
2021-05-18 13:51:00 +03:00
|
|
|
furi_assert(decoder);
|
|
|
|
|
|
|
|
float preamble_tolerance = decoder->protocol->timings.preamble_tolerance;
|
|
|
|
uint32_t bit_tolerance = decoder->protocol->timings.bit_tolerance;
|
2021-07-08 21:20:13 +03:00
|
|
|
IrdaStatus status = IrdaStatusError;
|
2021-05-18 13:51:00 +03:00
|
|
|
|
2021-07-08 21:20:13 +03:00
|
|
|
if(decoder->timings_cnt < 4) return IrdaStatusOk;
|
2021-05-18 13:51:00 +03:00
|
|
|
|
2021-05-24 16:44:14 +03:00
|
|
|
if((decoder->timings[0] > IRDA_NEC_REPEAT_PAUSE_MIN) &&
|
|
|
|
(decoder->timings[0] < IRDA_NEC_REPEAT_PAUSE_MAX) &&
|
|
|
|
MATCH_PREAMBLE_TIMING(decoder->timings[1], IRDA_NEC_REPEAT_MARK, preamble_tolerance) &&
|
|
|
|
MATCH_PREAMBLE_TIMING(decoder->timings[2], IRDA_NEC_REPEAT_SPACE, preamble_tolerance) &&
|
|
|
|
MATCH_BIT_TIMING(decoder->timings[3], decoder->protocol->timings.bit1_mark, bit_tolerance)) {
|
2021-07-08 21:20:13 +03:00
|
|
|
status = IrdaStatusReady;
|
2021-05-18 13:51:00 +03:00
|
|
|
decoder->timings_cnt = 0;
|
|
|
|
} else {
|
2021-07-08 21:20:13 +03:00
|
|
|
status = IrdaStatusError;
|
2021-05-18 13:51:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
void* irda_decoder_nec_alloc(void) {
|
|
|
|
return irda_common_decoder_alloc(&protocol_nec);
|
|
|
|
}
|
|
|
|
|
2021-06-02 18:16:05 +03:00
|
|
|
void* irda_decoder_necext_alloc(void) {
|
|
|
|
return irda_common_decoder_alloc(&protocol_necext);
|
|
|
|
}
|
|
|
|
|
2021-05-18 13:51:00 +03:00
|
|
|
IrdaMessage* irda_decoder_nec_decode(void* decoder, bool level, uint32_t duration) {
|
|
|
|
return irda_common_decode(decoder, level, duration);
|
|
|
|
}
|
|
|
|
|
|
|
|
void irda_decoder_nec_free(void* decoder) {
|
|
|
|
irda_common_decoder_free(decoder);
|
|
|
|
}
|
2021-06-02 18:16:05 +03:00
|
|
|
|
|
|
|
void irda_decoder_nec_reset(void* decoder) {
|
|
|
|
irda_common_decoder_reset(decoder);
|
|
|
|
}
|
|
|
|
|