[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:
@@ -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_rc6_i.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <core/check.h>
|
||||
|
||||
typedef struct {
|
||||
InfraredCommonDecoder* common_decoder;
|
||||
@@ -93,7 +90,7 @@ InfraredStatus infrared_decoder_rc6_decode_manchester(
|
||||
void* infrared_decoder_rc6_alloc(void) {
|
||||
InfraredRc6Decoder* decoder = malloc(sizeof(InfraredRc6Decoder));
|
||||
decoder->toggle = false;
|
||||
decoder->common_decoder = infrared_common_decoder_alloc(&protocol_rc6);
|
||||
decoder->common_decoder = infrared_common_decoder_alloc(&infrared_protocol_rc6);
|
||||
decoder->common_decoder->context = decoder;
|
||||
return decoder;
|
||||
}
|
||||
|
@@ -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_rc6_i.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <core/check.h>
|
||||
|
||||
typedef struct InfraredEncoderRC6 {
|
||||
InfraredCommonEncoder* common_encoder;
|
||||
@@ -35,7 +33,7 @@ InfraredStatus infrared_encoder_rc6_encode(void* encoder_ptr, uint32_t* duration
|
||||
|
||||
void* infrared_encoder_rc6_alloc(void) {
|
||||
InfraredEncoderRC6* encoder = malloc(sizeof(InfraredEncoderRC6));
|
||||
encoder->common_encoder = infrared_common_encoder_alloc(&protocol_rc6);
|
||||
encoder->common_encoder = infrared_common_encoder_alloc(&infrared_protocol_rc6);
|
||||
encoder->toggle_bit = false;
|
||||
return encoder;
|
||||
}
|
||||
|
39
lib/infrared/encoder_decoder/rc6/infrared_protocol_rc6.c
Normal file
39
lib/infrared/encoder_decoder/rc6/infrared_protocol_rc6.c
Normal file
@@ -0,0 +1,39 @@
|
||||
#include "infrared_protocol_rc6_i.h"
|
||||
|
||||
const InfraredCommonProtocolSpec infrared_protocol_rc6 = {
|
||||
.timings =
|
||||
{
|
||||
.preamble_mark = INFRARED_RC6_PREAMBLE_MARK,
|
||||
.preamble_space = INFRARED_RC6_PREAMBLE_SPACE,
|
||||
.bit1_mark = INFRARED_RC6_BIT,
|
||||
.preamble_tolerance = INFRARED_RC6_PREAMBLE_TOLERANCE,
|
||||
.bit_tolerance = INFRARED_RC6_BIT_TOLERANCE,
|
||||
.silence_time = INFRARED_RC6_SILENCE,
|
||||
.min_split_time = INFRARED_RC6_MIN_SPLIT_TIME,
|
||||
},
|
||||
.databit_len[0] =
|
||||
1 + 3 + 1 + 8 +
|
||||
8, // start_bit + 3 mode bits, + 1 toggle bit (x2 timing) + 8 address + 8 command
|
||||
.manchester_start_from_space = false,
|
||||
.decode = infrared_decoder_rc6_decode_manchester,
|
||||
.encode = infrared_encoder_rc6_encode_manchester,
|
||||
.interpret = infrared_decoder_rc6_interpret,
|
||||
.decode_repeat = NULL,
|
||||
.encode_repeat = NULL,
|
||||
};
|
||||
|
||||
static const InfraredProtocolVariant infrared_protocol_variant_rc6 = {
|
||||
.name = "RC6",
|
||||
.address_length = 8,
|
||||
.command_length = 8,
|
||||
.frequency = INFRARED_RC6_CARRIER_FREQUENCY,
|
||||
.duty_cycle = INFRARED_RC6_DUTY_CYCLE,
|
||||
.repeat_count = INFRARED_RC6_REPEAT_COUNT_MIN,
|
||||
};
|
||||
|
||||
const InfraredProtocolVariant* infrared_protocol_rc6_get_variant(InfraredProtocol protocol) {
|
||||
if(protocol == InfraredProtocolRC6)
|
||||
return &infrared_protocol_variant_rc6;
|
||||
else
|
||||
return NULL;
|
||||
}
|
37
lib/infrared/encoder_decoder/rc6/infrared_protocol_rc6.h
Normal file
37
lib/infrared/encoder_decoder/rc6/infrared_protocol_rc6.h
Normal file
@@ -0,0 +1,37 @@
|
||||
#pragma once
|
||||
|
||||
#include "../infrared_i.h"
|
||||
|
||||
/***************************************************************************************************
|
||||
* RC6 protocol description
|
||||
* https://www.mikrocontroller.net/articles/IRMP_-_english#RC6_.2B_RC6A
|
||||
****************************************************************************************************
|
||||
* Preamble Manchester/biphase Silence
|
||||
* mark/space Modulation
|
||||
*
|
||||
* 2666 889 444/888 - bit (x2 for toggle bit) 2666
|
||||
*
|
||||
* ________ __ __ __ __ ____ __ __ __ __ __ __ __ __
|
||||
* _ _________ ____ __ __ ____ __ __ __ __ __ __ __ __ _______________
|
||||
* | 1 | 0 | 0 | 0 | 0 | ... | ... | |
|
||||
* s m2 m1 m0 T address (MSB) command (MSB)
|
||||
*
|
||||
* s - start bit (always 1)
|
||||
* m0-2 - mode (000 for RC6)
|
||||
* T - toggle bit, twice longer
|
||||
* address - 8 bit
|
||||
* command - 8 bit
|
||||
***************************************************************************************************/
|
||||
|
||||
void* infrared_decoder_rc6_alloc(void);
|
||||
void infrared_decoder_rc6_reset(void* decoder);
|
||||
void infrared_decoder_rc6_free(void* decoder);
|
||||
InfraredMessage* infrared_decoder_rc6_check_ready(void* ctx);
|
||||
InfraredMessage* infrared_decoder_rc6_decode(void* decoder, bool level, uint32_t duration);
|
||||
|
||||
void* infrared_encoder_rc6_alloc(void);
|
||||
void infrared_encoder_rc6_reset(void* encoder_ptr, const InfraredMessage* message);
|
||||
void infrared_encoder_rc6_free(void* decoder);
|
||||
InfraredStatus infrared_encoder_rc6_encode(void* encoder_ptr, uint32_t* duration, bool* polarity);
|
||||
|
||||
const InfraredProtocolVariant* infrared_protocol_rc6_get_variant(InfraredProtocol protocol);
|
28
lib/infrared/encoder_decoder/rc6/infrared_protocol_rc6_i.h
Normal file
28
lib/infrared/encoder_decoder/rc6/infrared_protocol_rc6_i.h
Normal file
@@ -0,0 +1,28 @@
|
||||
#pragma once
|
||||
|
||||
#include "../common/infrared_common_i.h"
|
||||
|
||||
#define INFRARED_RC6_CARRIER_FREQUENCY 36000
|
||||
#define INFRARED_RC6_DUTY_CYCLE 0.33
|
||||
|
||||
#define INFRARED_RC6_PREAMBLE_MARK 2666
|
||||
#define INFRARED_RC6_PREAMBLE_SPACE 889
|
||||
#define INFRARED_RC6_BIT 444 // half of time-quant for 1 bit
|
||||
#define INFRARED_RC6_PREAMBLE_TOLERANCE 200 // us
|
||||
#define INFRARED_RC6_BIT_TOLERANCE 120 // us
|
||||
/* protocol allows 2700 silence, but it is hard to send 1 message without repeat */
|
||||
#define INFRARED_RC6_SILENCE (2700 * 10)
|
||||
#define INFRARED_RC6_MIN_SPLIT_TIME 2700
|
||||
#define INFRARED_RC6_REPEAT_COUNT_MIN 1
|
||||
|
||||
extern const InfraredCommonProtocolSpec infrared_protocol_rc6;
|
||||
|
||||
bool infrared_decoder_rc6_interpret(InfraredCommonDecoder* decoder);
|
||||
InfraredStatus infrared_decoder_rc6_decode_manchester(
|
||||
InfraredCommonDecoder* decoder,
|
||||
bool level,
|
||||
uint32_t timing);
|
||||
InfraredStatus infrared_encoder_rc6_encode_manchester(
|
||||
InfraredCommonEncoder* encoder_ptr,
|
||||
uint32_t* duration,
|
||||
bool* polarity);
|
@@ -1,17 +0,0 @@
|
||||
#include "../infrared_i.h"
|
||||
#include "infrared_protocol_defs_i.h"
|
||||
|
||||
static const InfraredProtocolSpecification infrared_rc6_protocol_specification = {
|
||||
.name = "RC6",
|
||||
.address_length = 8,
|
||||
.command_length = 8,
|
||||
.frequency = INFRARED_RC6_CARRIER_FREQUENCY,
|
||||
.duty_cycle = INFRARED_RC6_DUTY_CYCLE,
|
||||
};
|
||||
|
||||
const InfraredProtocolSpecification* infrared_rc6_get_spec(InfraredProtocol protocol) {
|
||||
if(protocol == InfraredProtocolRC6)
|
||||
return &infrared_rc6_protocol_specification;
|
||||
else
|
||||
return NULL;
|
||||
}
|
Reference in New Issue
Block a user