mirror of
https://github.com/DarkFlippers/unleashed-firmware.git
synced 2025-12-13 05:06:30 +04:00
[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,13 +1,16 @@
|
||||
#include "infrared.h"
|
||||
#include <core/check.h>
|
||||
#include "common/infrared_common_i.h"
|
||||
#include "infrared_protocol_defs_i.h"
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <furi.h>
|
||||
#include "infrared_i.h"
|
||||
#include <furi_hal_infrared.h>
|
||||
#include <string.h>
|
||||
#include <core/check.h>
|
||||
#include <core/common_defines.h>
|
||||
|
||||
#include "nec/infrared_protocol_nec.h"
|
||||
#include "samsung/infrared_protocol_samsung.h"
|
||||
#include "rc5/infrared_protocol_rc5.h"
|
||||
#include "rc6/infrared_protocol_rc6.h"
|
||||
#include "sirc/infrared_protocol_sirc.h"
|
||||
#include "kaseikyo/infrared_protocol_kaseikyo.h"
|
||||
|
||||
typedef struct {
|
||||
InfraredAlloc alloc;
|
||||
@@ -36,7 +39,7 @@ struct InfraredEncoderHandler {
|
||||
typedef struct {
|
||||
InfraredEncoders encoder;
|
||||
InfraredDecoders decoder;
|
||||
InfraredGetProtocolSpec get_protocol_spec;
|
||||
InfraredGetProtocolVariant get_protocol_variant;
|
||||
} InfraredEncoderDecoder;
|
||||
|
||||
static const InfraredEncoderDecoder infrared_encoder_decoder[] = {
|
||||
@@ -52,7 +55,7 @@ static const InfraredEncoderDecoder infrared_encoder_decoder[] = {
|
||||
.encode = infrared_encoder_nec_encode,
|
||||
.reset = infrared_encoder_nec_reset,
|
||||
.free = infrared_encoder_nec_free},
|
||||
.get_protocol_spec = infrared_nec_get_spec,
|
||||
.get_protocol_variant = infrared_protocol_nec_get_variant,
|
||||
},
|
||||
{
|
||||
.decoder =
|
||||
@@ -66,7 +69,7 @@ static const InfraredEncoderDecoder infrared_encoder_decoder[] = {
|
||||
.encode = infrared_encoder_samsung32_encode,
|
||||
.reset = infrared_encoder_samsung32_reset,
|
||||
.free = infrared_encoder_samsung32_free},
|
||||
.get_protocol_spec = infrared_samsung32_get_spec,
|
||||
.get_protocol_variant = infrared_protocol_samsung32_get_variant,
|
||||
},
|
||||
{
|
||||
.decoder =
|
||||
@@ -80,7 +83,7 @@ static const InfraredEncoderDecoder infrared_encoder_decoder[] = {
|
||||
.encode = infrared_encoder_rc5_encode,
|
||||
.reset = infrared_encoder_rc5_reset,
|
||||
.free = infrared_encoder_rc5_free},
|
||||
.get_protocol_spec = infrared_rc5_get_spec,
|
||||
.get_protocol_variant = infrared_protocol_rc5_get_variant,
|
||||
},
|
||||
{
|
||||
.decoder =
|
||||
@@ -94,7 +97,7 @@ static const InfraredEncoderDecoder infrared_encoder_decoder[] = {
|
||||
.encode = infrared_encoder_rc6_encode,
|
||||
.reset = infrared_encoder_rc6_reset,
|
||||
.free = infrared_encoder_rc6_free},
|
||||
.get_protocol_spec = infrared_rc6_get_spec,
|
||||
.get_protocol_variant = infrared_protocol_rc6_get_variant,
|
||||
},
|
||||
{
|
||||
.decoder =
|
||||
@@ -108,7 +111,7 @@ static const InfraredEncoderDecoder infrared_encoder_decoder[] = {
|
||||
.encode = infrared_encoder_sirc_encode,
|
||||
.reset = infrared_encoder_sirc_reset,
|
||||
.free = infrared_encoder_sirc_free},
|
||||
.get_protocol_spec = infrared_sirc_get_spec,
|
||||
.get_protocol_variant = infrared_protocol_sirc_get_variant,
|
||||
},
|
||||
{
|
||||
.decoder =
|
||||
@@ -122,13 +125,12 @@ static const InfraredEncoderDecoder infrared_encoder_decoder[] = {
|
||||
.encode = infrared_encoder_kaseikyo_encode,
|
||||
.reset = infrared_encoder_kaseikyo_reset,
|
||||
.free = infrared_encoder_kaseikyo_free},
|
||||
.get_protocol_spec = infrared_kaseikyo_get_spec,
|
||||
.get_protocol_variant = infrared_protocol_kaseikyo_get_variant,
|
||||
},
|
||||
};
|
||||
|
||||
static int infrared_find_index_by_protocol(InfraredProtocol protocol);
|
||||
static const InfraredProtocolSpecification*
|
||||
infrared_get_spec_by_protocol(InfraredProtocol protocol);
|
||||
static const InfraredProtocolVariant* infrared_get_variant_by_protocol(InfraredProtocol protocol);
|
||||
|
||||
const InfraredMessage*
|
||||
infrared_decode(InfraredDecoderHandler* handler, bool level, uint32_t duration) {
|
||||
@@ -224,7 +226,7 @@ void infrared_free_encoder(InfraredEncoderHandler* handler) {
|
||||
|
||||
static int infrared_find_index_by_protocol(InfraredProtocol protocol) {
|
||||
for(size_t i = 0; i < COUNT_OF(infrared_encoder_decoder); ++i) {
|
||||
if(infrared_encoder_decoder[i].get_protocol_spec(protocol)) {
|
||||
if(infrared_encoder_decoder[i].get_protocol_variant(protocol)) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
@@ -282,34 +284,37 @@ InfraredProtocol infrared_get_protocol_by_name(const char* protocol_name) {
|
||||
return InfraredProtocolUnknown;
|
||||
}
|
||||
|
||||
static const InfraredProtocolSpecification*
|
||||
infrared_get_spec_by_protocol(InfraredProtocol protocol) {
|
||||
static const InfraredProtocolVariant* infrared_get_variant_by_protocol(InfraredProtocol protocol) {
|
||||
int index = infrared_find_index_by_protocol(protocol);
|
||||
const InfraredProtocolSpecification* spec = NULL;
|
||||
const InfraredProtocolVariant* variant = NULL;
|
||||
if(index >= 0) {
|
||||
spec = infrared_encoder_decoder[index].get_protocol_spec(protocol);
|
||||
variant = infrared_encoder_decoder[index].get_protocol_variant(protocol);
|
||||
}
|
||||
|
||||
furi_assert(spec);
|
||||
return spec;
|
||||
furi_assert(variant);
|
||||
return variant;
|
||||
}
|
||||
|
||||
const char* infrared_get_protocol_name(InfraredProtocol protocol) {
|
||||
return infrared_get_spec_by_protocol(protocol)->name;
|
||||
return infrared_get_variant_by_protocol(protocol)->name;
|
||||
}
|
||||
|
||||
uint8_t infrared_get_protocol_address_length(InfraredProtocol protocol) {
|
||||
return infrared_get_spec_by_protocol(protocol)->address_length;
|
||||
return infrared_get_variant_by_protocol(protocol)->address_length;
|
||||
}
|
||||
|
||||
uint8_t infrared_get_protocol_command_length(InfraredProtocol protocol) {
|
||||
return infrared_get_spec_by_protocol(protocol)->command_length;
|
||||
return infrared_get_variant_by_protocol(protocol)->command_length;
|
||||
}
|
||||
|
||||
uint32_t infrared_get_protocol_frequency(InfraredProtocol protocol) {
|
||||
return infrared_get_spec_by_protocol(protocol)->frequency;
|
||||
return infrared_get_variant_by_protocol(protocol)->frequency;
|
||||
}
|
||||
|
||||
float infrared_get_protocol_duty_cycle(InfraredProtocol protocol) {
|
||||
return infrared_get_spec_by_protocol(protocol)->duty_cycle;
|
||||
return infrared_get_variant_by_protocol(protocol)->duty_cycle;
|
||||
}
|
||||
|
||||
size_t infrared_get_protocol_min_repeat_count(InfraredProtocol protocol) {
|
||||
return infrared_get_variant_by_protocol(protocol)->repeat_count;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user