[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,5 @@
#include "common/infrared_common_i.h"
#include "infrared.h"
#include "infrared_protocol_defs_i.h"
#include <stdbool.h>
#include <stdint.h>
#include <furi.h>
#include "../infrared_i.h"
#include "infrared_protocol_sirc_i.h"
#include <core/check.h>
InfraredMessage* infrared_decoder_sirc_check_ready(void* ctx) {
return infrared_common_decoder_check_ready(ctx);
@@ -44,7 +39,7 @@ bool infrared_decoder_sirc_interpret(InfraredCommonDecoder* decoder) {
}
void* infrared_decoder_sirc_alloc(void) {
return infrared_common_decoder_alloc(&protocol_sirc);
return infrared_common_decoder_alloc(&infrared_protocol_sirc);
}
InfraredMessage* infrared_decoder_sirc_decode(void* decoder, bool level, uint32_t duration) {

View File

@@ -1,10 +1,5 @@
#include "infrared_protocol_sirc_i.h"
#include <core/check.h>
#include "infrared.h"
#include "common/infrared_common_i.h"
#include <stdint.h>
#include "../infrared_i.h"
#include "infrared_protocol_defs_i.h"
#include <furi.h>
void infrared_encoder_sirc_reset(void* encoder_ptr, const InfraredMessage* message) {
furi_assert(encoder_ptr);
@@ -53,7 +48,7 @@ InfraredStatus infrared_encoder_sirc_encode_repeat(
}
void* infrared_encoder_sirc_alloc(void) {
return infrared_common_encoder_alloc(&protocol_sirc);
return infrared_common_encoder_alloc(&infrared_protocol_sirc);
}
void infrared_encoder_sirc_free(void* encoder_ptr) {

View File

@@ -0,0 +1,64 @@
#include "infrared_protocol_sirc_i.h"
const InfraredCommonProtocolSpec infrared_protocol_sirc = {
.timings =
{
.preamble_mark = INFRARED_SIRC_PREAMBLE_MARK,
.preamble_space = INFRARED_SIRC_PREAMBLE_SPACE,
.bit1_mark = INFRARED_SIRC_BIT1_MARK,
.bit1_space = INFRARED_SIRC_BIT1_SPACE,
.bit0_mark = INFRARED_SIRC_BIT0_MARK,
.bit0_space = INFRARED_SIRC_BIT0_SPACE,
.preamble_tolerance = INFRARED_SIRC_PREAMBLE_TOLERANCE,
.bit_tolerance = INFRARED_SIRC_BIT_TOLERANCE,
.silence_time = INFRARED_SIRC_SILENCE,
.min_split_time = INFRARED_SIRC_MIN_SPLIT_TIME,
},
.databit_len[0] = 20,
.databit_len[1] = 15,
.databit_len[2] = 12,
.no_stop_bit = true,
.decode = infrared_common_decode_pdwm,
.encode = infrared_common_encode_pdwm,
.interpret = infrared_decoder_sirc_interpret,
.decode_repeat = NULL,
.encode_repeat = infrared_encoder_sirc_encode_repeat,
};
static const InfraredProtocolVariant infrared_protocol_variant_sirc = {
.name = "SIRC",
.address_length = 5,
.command_length = 7,
.frequency = INFRARED_SIRC_CARRIER_FREQUENCY,
.duty_cycle = INFRARED_SIRC_DUTY_CYCLE,
.repeat_count = INFRARED_SIRC_REPEAT_COUNT_MIN,
};
static const InfraredProtocolVariant infrared_protocol_variant_sirc15 = {
.name = "SIRC15",
.address_length = 8,
.command_length = 7,
.frequency = INFRARED_SIRC_CARRIER_FREQUENCY,
.duty_cycle = INFRARED_SIRC_DUTY_CYCLE,
.repeat_count = INFRARED_SIRC_REPEAT_COUNT_MIN,
};
static const InfraredProtocolVariant infrared_protocol_variant_sirc20 = {
.name = "SIRC20",
.address_length = 13,
.command_length = 7,
.frequency = INFRARED_SIRC_CARRIER_FREQUENCY,
.duty_cycle = INFRARED_SIRC_DUTY_CYCLE,
.repeat_count = INFRARED_SIRC_REPEAT_COUNT_MIN,
};
const InfraredProtocolVariant* infrared_protocol_sirc_get_variant(InfraredProtocol protocol) {
if(protocol == InfraredProtocolSIRC)
return &infrared_protocol_variant_sirc;
else if(protocol == InfraredProtocolSIRC15)
return &infrared_protocol_variant_sirc15;
else if(protocol == InfraredProtocolSIRC20)
return &infrared_protocol_variant_sirc20;
else
return NULL;
}

View File

@@ -0,0 +1,37 @@
#pragma once
#include "../infrared_i.h"
/***************************************************************************************************
* Sony SIRC protocol description
* https://www.sbprojects.net/knowledge/ir/sirc.php
* http://picprojects.org.uk/
****************************************************************************************************
* Preamble Preamble Pulse Width Modulation Pause Entirely repeat
* mark space up to period message..
*
* 2400 600 12/15/20 bits (600,1200) ...45000 2400 600
* __________ _ _ _ _ _ _ _ _ _ _ _ _ _ __________ _ _
* ____ __________ _ _ _ __ __ __ _ _ __ __ _ _ ____________________ __________ _
* | command | address |
* SIRC | 7b LSB | 5b LSB |
* SIRC15 | 7b LSB | 8b LSB |
* SIRC20 | 7b LSB | 13b LSB |
*
* No way to determine either next message is repeat or not,
* so recognize only fact message received. Sony remotes always send at least 3 messages.
* Assume 8 last extended bits for SIRC20 are address bits.
***************************************************************************************************/
void* infrared_decoder_sirc_alloc(void);
void infrared_decoder_sirc_reset(void* decoder);
InfraredMessage* infrared_decoder_sirc_check_ready(void* decoder);
void infrared_decoder_sirc_free(void* decoder);
InfraredMessage* infrared_decoder_sirc_decode(void* decoder, bool level, uint32_t duration);
void* infrared_encoder_sirc_alloc(void);
void infrared_encoder_sirc_reset(void* encoder_ptr, const InfraredMessage* message);
void infrared_encoder_sirc_free(void* decoder);
InfraredStatus infrared_encoder_sirc_encode(void* encoder_ptr, uint32_t* duration, bool* polarity);
const InfraredProtocolVariant* infrared_protocol_sirc_get_variant(InfraredProtocol protocol);

View File

@@ -0,0 +1,26 @@
#pragma once
#include "../common/infrared_common_i.h"
#define INFRARED_SIRC_CARRIER_FREQUENCY 40000
#define INFRARED_SIRC_DUTY_CYCLE 0.33
#define INFRARED_SIRC_PREAMBLE_MARK 2400
#define INFRARED_SIRC_PREAMBLE_SPACE 600
#define INFRARED_SIRC_BIT1_MARK 1200
#define INFRARED_SIRC_BIT1_SPACE 600
#define INFRARED_SIRC_BIT0_MARK 600
#define INFRARED_SIRC_BIT0_SPACE 600
#define INFRARED_SIRC_PREAMBLE_TOLERANCE 200 // us
#define INFRARED_SIRC_BIT_TOLERANCE 120 // us
#define INFRARED_SIRC_SILENCE 10000
#define INFRARED_SIRC_MIN_SPLIT_TIME (INFRARED_SIRC_SILENCE - 1000)
#define INFRARED_SIRC_REPEAT_PERIOD 45000
#define INFRARED_SIRC_REPEAT_COUNT_MIN 3
extern const InfraredCommonProtocolSpec infrared_protocol_sirc;
bool infrared_decoder_sirc_interpret(InfraredCommonDecoder* decoder);
InfraredStatus infrared_encoder_sirc_encode_repeat(
InfraredCommonEncoder* encoder,
uint32_t* duration,
bool* level);

View File

@@ -1,37 +0,0 @@
#include "../infrared_i.h"
#include "infrared_protocol_defs_i.h"
static const InfraredProtocolSpecification infrared_sirc_protocol_specification = {
.name = "SIRC",
.address_length = 5,
.command_length = 7,
.frequency = INFRARED_SIRC_CARRIER_FREQUENCY,
.duty_cycle = INFRARED_SIRC_DUTY_CYCLE,
};
static const InfraredProtocolSpecification infrared_sirc15_protocol_specification = {
.name = "SIRC15",
.address_length = 8,
.command_length = 7,
.frequency = INFRARED_SIRC_CARRIER_FREQUENCY,
.duty_cycle = INFRARED_SIRC_DUTY_CYCLE,
};
static const InfraredProtocolSpecification infrared_sirc20_protocol_specification = {
.name = "SIRC20",
.address_length = 13,
.command_length = 7,
.frequency = INFRARED_SIRC_CARRIER_FREQUENCY,
.duty_cycle = INFRARED_SIRC_DUTY_CYCLE,
};
const InfraredProtocolSpecification* infrared_sirc_get_spec(InfraredProtocol protocol) {
if(protocol == InfraredProtocolSIRC)
return &infrared_sirc_protocol_specification;
else if(protocol == InfraredProtocolSIRC15)
return &infrared_sirc15_protocol_specification;
else if(protocol == InfraredProtocolSIRC20)
return &infrared_sirc20_protocol_specification;
else
return NULL;
}