[FL-3078] Per protocol signal repeat count (#2293)

* Better Infrared protocol file structure
* Rename InfraredProtocolSpec to InfraredProtocolVariant
* Slightly better names
* Add repeat count field to protocol variant description
* Repeat the signal the appropriate number of times when brute-forcing
* Repeat the signal the appropriate number of times when sending via worker
* Better signal count logic in infrared_transmit
* Better variable names
* Convert some raw signals to messages in tv.ir

Co-authored-by: あく <alleteam@gmail.com>
This commit is contained in:
Georgii Surkov
2023-01-13 16:50:19 +03:00
committed by GitHub
parent ad9d746a27
commit 75e9de12b0
47 changed files with 1220 additions and 1180 deletions

View File

@@ -1,10 +1,7 @@
#include "infrared.h"
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <furi.h>
#include "../infrared_i.h"
#include "../infrared_protocol_defs_i.h"
#include "infrared_protocol_rc5_i.h"
#include <stdlib.h>
#include <core/check.h>
typedef struct {
InfraredCommonDecoder* common_decoder;
@@ -60,7 +57,7 @@ bool infrared_decoder_rc5_interpret(InfraredCommonDecoder* decoder) {
void* infrared_decoder_rc5_alloc(void) {
InfraredRc5Decoder* decoder = malloc(sizeof(InfraredRc5Decoder));
decoder->toggle = false;
decoder->common_decoder = infrared_common_decoder_alloc(&protocol_rc5);
decoder->common_decoder = infrared_common_decoder_alloc(&infrared_protocol_rc5);
decoder->common_decoder->context = decoder;
return decoder;
}

View File

@@ -1,9 +1,7 @@
#include <core/memmgr.h>
#include "infrared.h"
#include "common/infrared_common_i.h"
#include "infrared_protocol_defs_i.h"
#include <stdint.h>
#include "../infrared_i.h"
#include "infrared_protocol_rc5_i.h"
#include <stdlib.h>
#include <core/check.h>
typedef struct InfraredEncoderRC5 {
InfraredCommonEncoder* common_encoder;
@@ -41,7 +39,7 @@ InfraredStatus infrared_encoder_rc5_encode(void* encoder_ptr, uint32_t* duration
void* infrared_encoder_rc5_alloc(void) {
InfraredEncoderRC5* encoder = malloc(sizeof(InfraredEncoderRC5));
encoder->common_encoder = infrared_common_encoder_alloc(&protocol_rc5);
encoder->common_encoder = infrared_common_encoder_alloc(&infrared_protocol_rc5);
encoder->toggle_bit = false;
return encoder;
}

View File

@@ -0,0 +1,49 @@
#include "infrared_protocol_rc5_i.h"
const InfraredCommonProtocolSpec infrared_protocol_rc5 = {
.timings =
{
.preamble_mark = 0,
.preamble_space = 0,
.bit1_mark = INFRARED_RC5_BIT,
.preamble_tolerance = 0,
.bit_tolerance = INFRARED_RC5_BIT_TOLERANCE,
.silence_time = INFRARED_RC5_SILENCE,
.min_split_time = INFRARED_RC5_MIN_SPLIT_TIME,
},
.databit_len[0] = 1 + 1 + 1 + 5 +
6, // start_bit + start_bit/command_bit + toggle_bit + 5 address + 6 command
.manchester_start_from_space = true,
.decode = infrared_common_decode_manchester,
.encode = infrared_common_encode_manchester,
.interpret = infrared_decoder_rc5_interpret,
.decode_repeat = NULL,
.encode_repeat = NULL,
};
static const InfraredProtocolVariant infrared_protocol_variant_rc5 = {
.name = "RC5",
.address_length = 5,
.command_length = 6,
.frequency = INFRARED_RC5_CARRIER_FREQUENCY,
.duty_cycle = INFRARED_RC5_DUTY_CYCLE,
.repeat_count = INFRARED_RC5_REPEAT_COUNT_MIN,
};
static const InfraredProtocolVariant infrared_protocol_variant_rc5x = {
.name = "RC5X",
.address_length = 5,
.command_length = 7,
.frequency = INFRARED_RC5_CARRIER_FREQUENCY,
.duty_cycle = INFRARED_RC5_DUTY_CYCLE,
.repeat_count = INFRARED_RC5_REPEAT_COUNT_MIN,
};
const InfraredProtocolVariant* infrared_protocol_rc5_get_variant(InfraredProtocol protocol) {
if(protocol == InfraredProtocolRC5)
return &infrared_protocol_variant_rc5;
else if(protocol == InfraredProtocolRC5X)
return &infrared_protocol_variant_rc5x;
else
return NULL;
}

View File

@@ -0,0 +1,38 @@
#pragma once
#include "../infrared_i.h"
/***************************************************************************************************
* RC5 protocol description
* https://www.mikrocontroller.net/articles/IRMP_-_english#RC5_.2B_RC5X
****************************************************************************************************
* Manchester/biphase
* Modulation
*
* 888/1776 - bit (x2 for toggle bit)
*
* __ ____ __ __ __ __ __ __ __ __
* __ __ ____ __ __ __ __ __ __ __ _
* | 1 | 1 | 0 | ... | ... |
* s si T address (MSB) command (MSB)
*
* Note: manchester starts from space timing, so it have to be handled properly
* s - start bit (always 1)
* si - RC5: start bit (always 1), RC5X - 7-th bit of address (in our case always 0)
* T - toggle bit, change it's value every button press
* address - 5 bit
* command - 6/7 bit
***************************************************************************************************/
void* infrared_decoder_rc5_alloc(void);
void infrared_decoder_rc5_reset(void* decoder);
void infrared_decoder_rc5_free(void* decoder);
InfraredMessage* infrared_decoder_rc5_check_ready(void* ctx);
InfraredMessage* infrared_decoder_rc5_decode(void* decoder, bool level, uint32_t duration);
void* infrared_encoder_rc5_alloc(void);
void infrared_encoder_rc5_reset(void* encoder_ptr, const InfraredMessage* message);
void infrared_encoder_rc5_free(void* decoder);
InfraredStatus infrared_encoder_rc5_encode(void* encoder_ptr, uint32_t* duration, bool* polarity);
const InfraredProtocolVariant* infrared_protocol_rc5_get_variant(InfraredProtocol protocol);

View File

@@ -0,0 +1,20 @@
#pragma once
#include "../common/infrared_common_i.h"
#define INFRARED_RC5_CARRIER_FREQUENCY 36000
#define INFRARED_RC5_DUTY_CYCLE 0.33
#define INFRARED_RC5_PREAMBLE_MARK 0
#define INFRARED_RC5_PREAMBLE_SPACE 0
#define INFRARED_RC5_BIT 888 // half of time-quant for 1 bit
#define INFRARED_RC5_PREAMBLE_TOLERANCE 200 // us
#define INFRARED_RC5_BIT_TOLERANCE 120 // us
/* protocol allows 2700 silence, but it is hard to send 1 message without repeat */
#define INFRARED_RC5_SILENCE (2700 * 10)
#define INFRARED_RC5_MIN_SPLIT_TIME 2700
#define INFRARED_RC5_REPEAT_COUNT_MIN 1
extern const InfraredCommonProtocolSpec infrared_protocol_rc5;
bool infrared_decoder_rc5_interpret(InfraredCommonDecoder* decoder);

View File

@@ -1,27 +0,0 @@
#include "../infrared_i.h"
#include "infrared_protocol_defs_i.h"
static const InfraredProtocolSpecification infrared_rc5_protocol_specification = {
.name = "RC5",
.address_length = 5,
.command_length = 6,
.frequency = INFRARED_RC5_CARRIER_FREQUENCY,
.duty_cycle = INFRARED_RC5_DUTY_CYCLE,
};
static const InfraredProtocolSpecification infrared_rc5x_protocol_specification = {
.name = "RC5X",
.address_length = 5,
.command_length = 7,
.frequency = INFRARED_RC5_CARRIER_FREQUENCY,
.duty_cycle = INFRARED_RC5_DUTY_CYCLE,
};
const InfraredProtocolSpecification* infrared_rc5_get_spec(InfraredProtocol protocol) {
if(protocol == InfraredProtocolRC5)
return &infrared_rc5_protocol_specification;
else if(protocol == InfraredProtocolRC5X)
return &infrared_rc5x_protocol_specification;
else
return NULL;
}