Add support for Pioneer SR IR remotes (#3308)

* add support for Pioneer SR IR remotes
* fix minor issues
* fix repeat
* Fix protocol enumeration order
* Add unit tests for Pioneer IR protocol
* Clean up raw test data
* Add encoder/decoder tests, modify parser
* Remove dead code
* Use loops where appropriate

Co-authored-by: Georgii Surkov <37121527+gsurkov@users.noreply.github.com>
Co-authored-by: Georgii Surkov <georgii.surkov@outlook.com>
This commit is contained in:
Egor Koleda
2024-03-22 15:25:52 +03:00
committed by GitHub
parent 4039ccbcca
commit 2aa2dcc71b
15 changed files with 480 additions and 43 deletions

View File

@@ -0,0 +1,57 @@
#include "infrared_protocol_pioneer_i.h"
#include <core/check.h>
InfraredMessage* infrared_decoder_pioneer_check_ready(void* ctx) {
return infrared_common_decoder_check_ready(ctx);
}
bool infrared_decoder_pioneer_interpret(InfraredCommonDecoder* decoder) {
furi_assert(decoder);
uint32_t* data = (void*)&decoder->data[0];
uint8_t address = 0;
uint8_t command = 0;
InfraredProtocol protocol = InfraredProtocolUnknown;
if(decoder->databit_cnt == decoder->protocol->databit_len[0] ||
decoder->databit_cnt == decoder->protocol->databit_len[1]) {
address = *data & 0xFF;
uint8_t real_address_checksum = ~address;
uint8_t address_checksum = (*data >> 8) & 0xFF;
command = (*data >> 16) & 0xFF;
uint8_t real_command_checksum = ~command;
uint8_t command_checksum = (*data >> 24) & 0xFF;
if(address_checksum != real_address_checksum) {
return false;
}
if(command_checksum != real_command_checksum) {
return false;
}
protocol = InfraredProtocolPioneer;
} else {
return false;
}
decoder->message.protocol = protocol;
decoder->message.address = address;
decoder->message.command = command;
decoder->message.repeat = false;
return true;
}
void* infrared_decoder_pioneer_alloc(void) {
return infrared_common_decoder_alloc(&infrared_protocol_pioneer);
}
InfraredMessage* infrared_decoder_pioneer_decode(void* decoder, bool level, uint32_t duration) {
return infrared_common_decode(decoder, level, duration);
}
void infrared_decoder_pioneer_free(void* decoder) {
infrared_common_decoder_free(decoder);
}
void infrared_decoder_pioneer_reset(void* decoder) {
infrared_common_decoder_reset(decoder);
}

View File

@@ -0,0 +1,61 @@
#include "infrared_protocol_pioneer_i.h"
#include <core/check.h>
void infrared_encoder_pioneer_reset(void* encoder_ptr, const InfraredMessage* message) {
furi_assert(encoder_ptr);
furi_assert(message);
InfraredCommonEncoder* encoder = encoder_ptr;
infrared_common_encoder_reset(encoder);
uint8_t* data = encoder->data;
if(message->protocol == InfraredProtocolPioneer) {
data[0] = message->address & 0xFF;
data[1] = ~(message->address & 0xFF);
data[2] = message->command & 0xFF;
data[3] = ~(message->command & 0xFF);
data[4] = 0;
encoder->bits_to_encode = encoder->protocol->databit_len[0];
} else {
furi_crash();
}
}
void* infrared_encoder_pioneer_alloc(void) {
return infrared_common_encoder_alloc(&infrared_protocol_pioneer);
}
void infrared_encoder_pioneer_free(void* encoder_ptr) {
infrared_common_encoder_free(encoder_ptr);
}
InfraredStatus infrared_encoder_pioneer_encode_repeat(
InfraredCommonEncoder* encoder,
uint32_t* duration,
bool* level) {
furi_assert(encoder);
*duration = INFRARED_PIONEER_SILENCE;
*level = false;
encoder->timings_sum = 0;
encoder->timings_encoded = 1;
encoder->bits_encoded = 0;
encoder->state = InfraredCommonEncoderStatePreamble;
return InfraredStatusOk;
}
InfraredStatus
infrared_encoder_pioneer_encode(void* encoder_ptr, uint32_t* duration, bool* level) {
InfraredCommonEncoder* encoder = encoder_ptr;
InfraredStatus status = infrared_common_encode(encoder, duration, level);
if((status == InfraredStatusOk) && (encoder->bits_encoded == encoder->bits_to_encode)) {
furi_assert(!*level);
status = InfraredStatusDone;
encoder->state = InfraredCommonEncoderStateEncodeRepeat;
}
return status;
}

View File

@@ -0,0 +1,40 @@
#include "infrared_protocol_pioneer_i.h"
const InfraredCommonProtocolSpec infrared_protocol_pioneer = {
.timings =
{
.preamble_mark = INFRARED_PIONEER_PREAMBLE_MARK,
.preamble_space = INFRARED_PIONEER_PREAMBLE_SPACE,
.bit1_mark = INFRARED_PIONEER_BIT1_MARK,
.bit1_space = INFRARED_PIONEER_BIT1_SPACE,
.bit0_mark = INFRARED_PIONEER_BIT0_MARK,
.bit0_space = INFRARED_PIONEER_BIT0_SPACE,
.preamble_tolerance = INFRARED_PIONEER_PREAMBLE_TOLERANCE,
.bit_tolerance = INFRARED_PIONEER_BIT_TOLERANCE,
.silence_time = INFRARED_PIONEER_SILENCE,
.min_split_time = INFRARED_PIONEER_MIN_SPLIT_TIME,
},
.databit_len[0] = 33,
.databit_len[1] = 32,
.decode = infrared_common_decode_pdwm,
.encode = infrared_common_encode_pdwm,
.interpret = infrared_decoder_pioneer_interpret,
.decode_repeat = NULL,
.encode_repeat = infrared_encoder_pioneer_encode_repeat,
};
static const InfraredProtocolVariant infrared_protocol_variant_pioneer = {
.name = "Pioneer",
.address_length = 8,
.command_length = 8,
.frequency = INFRARED_PIONEER_CARRIER_FREQUENCY,
.duty_cycle = INFRARED_PIONEER_DUTY_CYCLE,
.repeat_count = INFRARED_PIONEER_REPEAT_COUNT_MIN,
};
const InfraredProtocolVariant* infrared_protocol_pioneer_get_variant(InfraredProtocol protocol) {
if(protocol == InfraredProtocolPioneer)
return &infrared_protocol_variant_pioneer;
else
return NULL;
}

View File

@@ -0,0 +1,36 @@
#pragma once
#include "../infrared_i.h"
/***************************************************************************************************
* Pioneer SR protocol description
* http://www.adrian-kingston.com/IRFormatPioneer.htm
****************************************************************************************************
* Preamble Preamble Pulse Width Modulation Pause Entirely repeat
* mark space up to period message..
*
* 8500 4250 33 bits (500, 1500) ...26000 8500 4250
* __________ _ _ _ _ _ _ _ _ _ _ _ _ _ __________ _ _
* ____ __________ _ _ _ __ __ __ _ _ __ __ _ _ ____________________ __________ _
*
* In 33 bits of data there is:
* - 8 bits address
* - 8 bits address inverse
* - 8 bits command
* - 8 bits command inverse
* - 1 stop bit
***************************************************************************************************/
void* infrared_decoder_pioneer_alloc(void);
void infrared_decoder_pioneer_reset(void* decoder);
InfraredMessage* infrared_decoder_pioneer_check_ready(void* decoder);
void infrared_decoder_pioneer_free(void* decoder);
InfraredMessage* infrared_decoder_pioneer_decode(void* decoder, bool level, uint32_t duration);
void* infrared_encoder_pioneer_alloc(void);
void infrared_encoder_pioneer_reset(void* encoder_ptr, const InfraredMessage* message);
void infrared_encoder_pioneer_free(void* decoder);
InfraredStatus
infrared_encoder_pioneer_encode(void* encoder_ptr, uint32_t* duration, bool* polarity);
const InfraredProtocolVariant* infrared_protocol_pioneer_get_variant(InfraredProtocol protocol);

View File

@@ -0,0 +1,25 @@
#pragma once
#include "../common/infrared_common_i.h"
#define INFRARED_PIONEER_CARRIER_FREQUENCY 40000
#define INFRARED_PIONEER_DUTY_CYCLE 0.33
#define INFRARED_PIONEER_PREAMBLE_MARK 8500
#define INFRARED_PIONEER_PREAMBLE_SPACE 4225
#define INFRARED_PIONEER_BIT1_MARK 500
#define INFRARED_PIONEER_BIT1_SPACE 1500
#define INFRARED_PIONEER_BIT0_MARK 500
#define INFRARED_PIONEER_BIT0_SPACE 500
#define INFRARED_PIONEER_PREAMBLE_TOLERANCE 200 // us
#define INFRARED_PIONEER_BIT_TOLERANCE 120 // us
#define INFRARED_PIONEER_SILENCE 26000
#define INFRARED_PIONEER_MIN_SPLIT_TIME (INFRARED_PIONEER_SILENCE)
#define INFRARED_PIONEER_REPEAT_COUNT_MIN 2
extern const InfraredCommonProtocolSpec infrared_protocol_pioneer;
bool infrared_decoder_pioneer_interpret(InfraredCommonDecoder* decoder);
InfraredStatus infrared_encoder_pioneer_encode_repeat(
InfraredCommonEncoder* encoder,
uint32_t* duration,
bool* level);