mirror of
https://github.com/DarkFlippers/unleashed-firmware.git
synced 2025-12-12 04:34:43 +04:00
SubGhz custom btn improved code readability some "if" optimization
This commit is contained in:
@@ -76,8 +76,8 @@ bool subghz_scene_transmitter_on_event(void* context, SceneManagerEvent event) {
|
||||
} else if(event.event == SubGhzCustomEventViewTransmitterSendStop) {
|
||||
subghz->state_notifications = SubGhzNotificationStateIDLE;
|
||||
subghz_txrx_stop(subghz->txrx);
|
||||
if(subghz_custom_btn_get() != 0) {
|
||||
subghz_custom_btn_set(0);
|
||||
if(subghz_custom_btn_get() != SUBGHZ_CUSTOM_BTN_OK) {
|
||||
subghz_custom_btn_set(SUBGHZ_CUSTOM_BTN_OK);
|
||||
uint8_t tmp_counter = furi_hal_subghz_get_rolling_counter_mult();
|
||||
furi_hal_subghz_set_rolling_counter_mult(0);
|
||||
// Calling restore!
|
||||
|
||||
@@ -137,7 +137,7 @@ bool subghz_view_transmitter_input(InputEvent* event, void* context) {
|
||||
true);
|
||||
|
||||
if(can_be_sent && event->key == InputKeyOk && event->type == InputTypePress) {
|
||||
subghz_custom_btn_set(0);
|
||||
subghz_custom_btn_set(SUBGHZ_CUSTOM_BTN_OK);
|
||||
with_view_model(
|
||||
subghz_transmitter->view,
|
||||
SubGhzViewTransmitterModel * model,
|
||||
@@ -157,14 +157,14 @@ bool subghz_view_transmitter_input(InputEvent* event, void* context) {
|
||||
|
||||
// Temp Buttons (UP)
|
||||
if(can_be_sent && event->key == InputKeyUp && event->type == InputTypePress) {
|
||||
subghz_custom_btn_set(1);
|
||||
subghz_custom_btn_set(SUBGHZ_CUSTOM_BTN_UP);
|
||||
with_view_model(
|
||||
subghz_transmitter->view,
|
||||
SubGhzViewTransmitterModel * model,
|
||||
{
|
||||
furi_string_reset(model->temp_button_id);
|
||||
if(subghz_custom_btn_get_original() != 0) {
|
||||
if(subghz_custom_btn_get() == 1) {
|
||||
if(subghz_custom_btn_get() == SUBGHZ_CUSTOM_BTN_UP) {
|
||||
furi_string_printf(
|
||||
model->temp_button_id, "%01X", subghz_custom_btn_get_original());
|
||||
model->draw_temp_button = true;
|
||||
@@ -182,14 +182,14 @@ bool subghz_view_transmitter_input(InputEvent* event, void* context) {
|
||||
}
|
||||
// Down
|
||||
if(can_be_sent && event->key == InputKeyDown && event->type == InputTypePress) {
|
||||
subghz_custom_btn_set(2);
|
||||
subghz_custom_btn_set(SUBGHZ_CUSTOM_BTN_DOWN);
|
||||
with_view_model(
|
||||
subghz_transmitter->view,
|
||||
SubGhzViewTransmitterModel * model,
|
||||
{
|
||||
furi_string_reset(model->temp_button_id);
|
||||
if(subghz_custom_btn_get_original() != 0) {
|
||||
if(subghz_custom_btn_get() == 2) {
|
||||
if(subghz_custom_btn_get() == SUBGHZ_CUSTOM_BTN_DOWN) {
|
||||
furi_string_printf(
|
||||
model->temp_button_id, "%01X", subghz_custom_btn_get_original());
|
||||
model->draw_temp_button = true;
|
||||
@@ -207,14 +207,14 @@ bool subghz_view_transmitter_input(InputEvent* event, void* context) {
|
||||
}
|
||||
// Left
|
||||
if(can_be_sent && event->key == InputKeyLeft && event->type == InputTypePress) {
|
||||
subghz_custom_btn_set(3);
|
||||
subghz_custom_btn_set(SUBGHZ_CUSTOM_BTN_LEFT);
|
||||
with_view_model(
|
||||
subghz_transmitter->view,
|
||||
SubGhzViewTransmitterModel * model,
|
||||
{
|
||||
furi_string_reset(model->temp_button_id);
|
||||
if(subghz_custom_btn_get_original() != 0) {
|
||||
if(subghz_custom_btn_get() == 3) {
|
||||
if(subghz_custom_btn_get() == SUBGHZ_CUSTOM_BTN_LEFT) {
|
||||
furi_string_printf(
|
||||
model->temp_button_id, "%01X", subghz_custom_btn_get_original());
|
||||
model->draw_temp_button = true;
|
||||
@@ -232,14 +232,14 @@ bool subghz_view_transmitter_input(InputEvent* event, void* context) {
|
||||
}
|
||||
// Right
|
||||
if(can_be_sent && event->key == InputKeyRight && event->type == InputTypePress) {
|
||||
subghz_custom_btn_set(4);
|
||||
subghz_custom_btn_set(SUBGHZ_CUSTOM_BTN_RIGHT);
|
||||
with_view_model(
|
||||
subghz_transmitter->view,
|
||||
SubGhzViewTransmitterModel * model,
|
||||
{
|
||||
furi_string_reset(model->temp_button_id);
|
||||
if(subghz_custom_btn_get_original() != 0) {
|
||||
if(subghz_custom_btn_get() == 4) {
|
||||
if(subghz_custom_btn_get() == SUBGHZ_CUSTOM_BTN_RIGHT) {
|
||||
furi_string_printf(
|
||||
model->temp_button_id, "%01X", subghz_custom_btn_get_original());
|
||||
model->draw_temp_button = true;
|
||||
|
||||
@@ -354,7 +354,7 @@ bool subghz_remote_key_load(
|
||||
|
||||
bool res = false;
|
||||
|
||||
subghz_custom_btn_set(0);
|
||||
subghz_custom_btn_set(SUBGHZ_CUSTOM_BTN_OK);
|
||||
keeloq_reset_original_btn();
|
||||
subghz_custom_btns_reset();
|
||||
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
#include "custom_btn.h"
|
||||
|
||||
static uint8_t custom_btn_id = 0;
|
||||
static uint8_t custom_btn_id = SUBGHZ_CUSTOM_BTN_OK;
|
||||
static uint8_t custom_btn_original = 0;
|
||||
static uint8_t custom_btn_max_btns = 0;
|
||||
|
||||
void subghz_custom_btn_set(uint8_t b) {
|
||||
if(b > custom_btn_max_btns) {
|
||||
custom_btn_id = 0;
|
||||
void subghz_custom_btn_set(uint8_t btn_id) {
|
||||
if(btn_id > custom_btn_max_btns) {
|
||||
custom_btn_id = SUBGHZ_CUSTOM_BTN_OK;
|
||||
} else {
|
||||
custom_btn_id = b;
|
||||
custom_btn_id = btn_id;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,8 +16,8 @@ uint8_t subghz_custom_btn_get() {
|
||||
return custom_btn_id;
|
||||
}
|
||||
|
||||
void subghz_custom_btn_set_original(uint8_t b) {
|
||||
custom_btn_original = b;
|
||||
void subghz_custom_btn_set_original(uint8_t btn_code) {
|
||||
custom_btn_original = btn_code;
|
||||
}
|
||||
|
||||
uint8_t subghz_custom_btn_get_original() {
|
||||
|
||||
@@ -4,11 +4,18 @@
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
|
||||
void subghz_custom_btn_set(uint8_t b);
|
||||
// Default btn ID
|
||||
#define SUBGHZ_CUSTOM_BTN_OK (0U)
|
||||
#define SUBGHZ_CUSTOM_BTN_UP (1U)
|
||||
#define SUBGHZ_CUSTOM_BTN_DOWN (2U)
|
||||
#define SUBGHZ_CUSTOM_BTN_LEFT (3U)
|
||||
#define SUBGHZ_CUSTOM_BTN_RIGHT (4U)
|
||||
|
||||
void subghz_custom_btn_set(uint8_t btn_id);
|
||||
|
||||
uint8_t subghz_custom_btn_get();
|
||||
|
||||
void subghz_custom_btn_set_original(uint8_t b);
|
||||
void subghz_custom_btn_set_original(uint8_t btn_code);
|
||||
|
||||
uint8_t subghz_custom_btn_get_original();
|
||||
|
||||
|
||||
@@ -334,11 +334,15 @@ static bool subghz_protocol_encoder_alutech_at_4n_get_upload(
|
||||
}
|
||||
|
||||
uint8_t custom_btn_id = subghz_custom_btn_get();
|
||||
uint8_t original_btn_num = subghz_custom_btn_get_original();
|
||||
uint8_t original_btn_code = subghz_custom_btn_get_original();
|
||||
|
||||
// Set custom button
|
||||
if(custom_btn_id == 1) {
|
||||
switch(original_btn_num) {
|
||||
// Basic set | 0x11 | 0x22 | 0xFF | 0x44 | 0x33 |
|
||||
if((custom_btn_id == SUBGHZ_CUSTOM_BTN_OK) && (original_btn_code != 0)) {
|
||||
// Restore original button code
|
||||
btn = original_btn_code;
|
||||
} else if(custom_btn_id == SUBGHZ_CUSTOM_BTN_UP) {
|
||||
switch(original_btn_code) {
|
||||
case 0x11:
|
||||
btn = 0x22;
|
||||
break;
|
||||
@@ -358,9 +362,8 @@ static bool subghz_protocol_encoder_alutech_at_4n_get_upload(
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(custom_btn_id == 2) {
|
||||
switch(original_btn_num) {
|
||||
} else if(custom_btn_id == SUBGHZ_CUSTOM_BTN_DOWN) {
|
||||
switch(original_btn_code) {
|
||||
case 0x11:
|
||||
btn = 0x44;
|
||||
break;
|
||||
@@ -380,9 +383,8 @@ static bool subghz_protocol_encoder_alutech_at_4n_get_upload(
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(custom_btn_id == 3) {
|
||||
switch(original_btn_num) {
|
||||
} else if(custom_btn_id == SUBGHZ_CUSTOM_BTN_LEFT) {
|
||||
switch(original_btn_code) {
|
||||
case 0x11:
|
||||
btn = 0x33;
|
||||
break;
|
||||
@@ -402,9 +404,8 @@ static bool subghz_protocol_encoder_alutech_at_4n_get_upload(
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(custom_btn_id == 4) {
|
||||
switch(original_btn_num) {
|
||||
} else if(custom_btn_id == SUBGHZ_CUSTOM_BTN_RIGHT) {
|
||||
switch(original_btn_code) {
|
||||
case 0x11:
|
||||
btn = 0xFF;
|
||||
break;
|
||||
@@ -426,9 +427,6 @@ static bool subghz_protocol_encoder_alutech_at_4n_get_upload(
|
||||
}
|
||||
}
|
||||
|
||||
if((custom_btn_id == 0) && (original_btn_num != 0)) {
|
||||
btn = original_btn_num;
|
||||
}
|
||||
// Gen new key
|
||||
if(!subghz_protocol_alutech_at_4n_gen_data(instance, btn)) {
|
||||
return false;
|
||||
|
||||
@@ -397,10 +397,15 @@ static bool
|
||||
}
|
||||
|
||||
uint8_t custom_btn_id = subghz_custom_btn_get();
|
||||
uint8_t original_btn_num = subghz_custom_btn_get_original();
|
||||
uint8_t original_btn_code = subghz_custom_btn_get_original();
|
||||
|
||||
// Set custom button
|
||||
if(custom_btn_id == 1) {
|
||||
switch(original_btn_num) {
|
||||
// Basic set | 0x1 | 0x2 | 0x4 | 0x8 | 0xA or Special Learning Code |
|
||||
if((custom_btn_id == SUBGHZ_CUSTOM_BTN_OK) && (original_btn_code != 0)) {
|
||||
// Restore original button code
|
||||
btn = original_btn_code;
|
||||
} else if(custom_btn_id == SUBGHZ_CUSTOM_BTN_UP) {
|
||||
switch(original_btn_code) {
|
||||
case 0x1:
|
||||
btn = 0x2;
|
||||
break;
|
||||
@@ -424,9 +429,8 @@ static bool
|
||||
btn = 0x1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(custom_btn_id == 2) {
|
||||
switch(original_btn_num) {
|
||||
} else if(custom_btn_id == SUBGHZ_CUSTOM_BTN_DOWN) {
|
||||
switch(original_btn_code) {
|
||||
case 0x1:
|
||||
btn = 0x4;
|
||||
break;
|
||||
@@ -450,9 +454,8 @@ static bool
|
||||
btn = 0x4;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(custom_btn_id == 3) {
|
||||
switch(original_btn_num) {
|
||||
} else if(custom_btn_id == SUBGHZ_CUSTOM_BTN_LEFT) {
|
||||
switch(original_btn_code) {
|
||||
case 0x1:
|
||||
btn = 0x8;
|
||||
break;
|
||||
@@ -476,9 +479,8 @@ static bool
|
||||
btn = 0x8;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(custom_btn_id == 4) {
|
||||
switch(original_btn_num) {
|
||||
} else if(custom_btn_id == SUBGHZ_CUSTOM_BTN_RIGHT) {
|
||||
switch(original_btn_code) {
|
||||
case 0x1:
|
||||
btn = klq_last_custom_btn;
|
||||
break;
|
||||
@@ -503,11 +505,8 @@ static bool
|
||||
break;
|
||||
}
|
||||
}
|
||||
if((custom_btn_id == 0) && (original_btn_num != 0)) {
|
||||
btn = original_btn_num;
|
||||
}
|
||||
|
||||
// Generate new key
|
||||
|
||||
if(subghz_protocol_keeloq_gen_data(instance, btn, true)) {
|
||||
// OK
|
||||
} else {
|
||||
|
||||
@@ -136,11 +136,15 @@ static void subghz_protocol_encoder_nice_flor_s_get_upload(
|
||||
}
|
||||
|
||||
uint8_t custom_btn_id = subghz_custom_btn_get();
|
||||
uint8_t original_btn_num = subghz_custom_btn_get_original();
|
||||
uint8_t original_btn_code = subghz_custom_btn_get_original();
|
||||
|
||||
// Set custom button
|
||||
if(custom_btn_id == 1) {
|
||||
switch(original_btn_num) {
|
||||
// Basic set | 0x1 | 0x2 | 0x4 | 0x8 |
|
||||
if((custom_btn_id == SUBGHZ_CUSTOM_BTN_OK) && (original_btn_code != 0)) {
|
||||
// Restore original button code
|
||||
btn = original_btn_code;
|
||||
} else if(custom_btn_id == SUBGHZ_CUSTOM_BTN_UP) {
|
||||
switch(original_btn_code) {
|
||||
case 0x1:
|
||||
btn = 0x2;
|
||||
break;
|
||||
@@ -157,9 +161,8 @@ static void subghz_protocol_encoder_nice_flor_s_get_upload(
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(custom_btn_id == 2) {
|
||||
switch(original_btn_num) {
|
||||
} else if(custom_btn_id == SUBGHZ_CUSTOM_BTN_DOWN) {
|
||||
switch(original_btn_code) {
|
||||
case 0x1:
|
||||
btn = 0x4;
|
||||
break;
|
||||
@@ -176,9 +179,8 @@ static void subghz_protocol_encoder_nice_flor_s_get_upload(
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(custom_btn_id == 3) {
|
||||
switch(original_btn_num) {
|
||||
} else if(custom_btn_id == SUBGHZ_CUSTOM_BTN_LEFT) {
|
||||
switch(original_btn_code) {
|
||||
case 0x1:
|
||||
btn = 0x8;
|
||||
break;
|
||||
@@ -197,10 +199,6 @@ static void subghz_protocol_encoder_nice_flor_s_get_upload(
|
||||
}
|
||||
}
|
||||
|
||||
if((custom_btn_id == 0) && (original_btn_num != 0)) {
|
||||
btn = original_btn_num;
|
||||
}
|
||||
|
||||
size_t size_upload = ((instance->generic.data_count_bit * 2) + ((37 + 2 + 2) * 2) * 16);
|
||||
if(size_upload > instance->encoder.size_upload) {
|
||||
FURI_LOG_E(TAG, "Size upload exceeds allocated encoder buffer.");
|
||||
|
||||
@@ -387,11 +387,15 @@ static void subghz_protocol_secplus_v2_encode(SubGhzProtocolEncoderSecPlus_v2* i
|
||||
}
|
||||
|
||||
uint8_t custom_btn_id = subghz_custom_btn_get();
|
||||
uint8_t original_btn_num = subghz_custom_btn_get_original();
|
||||
uint8_t original_btn_code = subghz_custom_btn_get_original();
|
||||
|
||||
// Set custom button
|
||||
if(custom_btn_id == 1) {
|
||||
switch(original_btn_num) {
|
||||
// Basic set | 0x68 | 0x80 | 0x81 | 0xE2 |
|
||||
if((custom_btn_id == SUBGHZ_CUSTOM_BTN_OK) && (original_btn_code != 0)) {
|
||||
// Restore original button code
|
||||
instance->generic.btn = original_btn_code;
|
||||
} else if(custom_btn_id == SUBGHZ_CUSTOM_BTN_UP) {
|
||||
switch(original_btn_code) {
|
||||
case 0x68:
|
||||
instance->generic.btn = 0x80;
|
||||
break;
|
||||
@@ -408,9 +412,8 @@ static void subghz_protocol_secplus_v2_encode(SubGhzProtocolEncoderSecPlus_v2* i
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(custom_btn_id == 2) {
|
||||
switch(original_btn_num) {
|
||||
} else if(custom_btn_id == SUBGHZ_CUSTOM_BTN_DOWN) {
|
||||
switch(original_btn_code) {
|
||||
case 0x68:
|
||||
instance->generic.btn = 0x81;
|
||||
break;
|
||||
@@ -427,9 +430,8 @@ static void subghz_protocol_secplus_v2_encode(SubGhzProtocolEncoderSecPlus_v2* i
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(custom_btn_id == 3) {
|
||||
switch(original_btn_num) {
|
||||
} else if(custom_btn_id == SUBGHZ_CUSTOM_BTN_LEFT) {
|
||||
switch(original_btn_code) {
|
||||
case 0x68:
|
||||
instance->generic.btn = 0xE2;
|
||||
break;
|
||||
@@ -447,9 +449,7 @@ static void subghz_protocol_secplus_v2_encode(SubGhzProtocolEncoderSecPlus_v2* i
|
||||
break;
|
||||
}
|
||||
}
|
||||
if((custom_btn_id == 0) && (original_btn_num != 0)) {
|
||||
instance->generic.btn = original_btn_num;
|
||||
}
|
||||
|
||||
uint32_t fixed_1[1] = {instance->generic.btn << 12 | instance->generic.serial >> 20};
|
||||
uint32_t fixed_2[1] = {instance->generic.serial & 0xFFFFF};
|
||||
uint8_t rolling_digits[18] = {0};
|
||||
|
||||
@@ -116,11 +116,15 @@ static bool subghz_protocol_somfy_telis_gen_data(
|
||||
}
|
||||
|
||||
uint8_t custom_btn_id = subghz_custom_btn_get();
|
||||
uint8_t original_btn_num = subghz_custom_btn_get_original();
|
||||
uint8_t original_btn_code = subghz_custom_btn_get_original();
|
||||
|
||||
// Set custom button
|
||||
if(custom_btn_id == 1) {
|
||||
switch(original_btn_num) {
|
||||
// Basic set | 0x1 | 0x2 | 0x4 | 0x8 |
|
||||
if((custom_btn_id == SUBGHZ_CUSTOM_BTN_OK) && (original_btn_code != 0)) {
|
||||
// Restore original button code
|
||||
btn = original_btn_code;
|
||||
} else if(custom_btn_id == SUBGHZ_CUSTOM_BTN_UP) {
|
||||
switch(original_btn_code) {
|
||||
case 0x1:
|
||||
btn = 0x2;
|
||||
break;
|
||||
@@ -137,9 +141,8 @@ static bool subghz_protocol_somfy_telis_gen_data(
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(custom_btn_id == 2) {
|
||||
switch(original_btn_num) {
|
||||
} else if(custom_btn_id == SUBGHZ_CUSTOM_BTN_DOWN) {
|
||||
switch(original_btn_code) {
|
||||
case 0x1:
|
||||
btn = 0x4;
|
||||
break;
|
||||
@@ -156,9 +159,8 @@ static bool subghz_protocol_somfy_telis_gen_data(
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(custom_btn_id == 3) {
|
||||
switch(original_btn_num) {
|
||||
} else if(custom_btn_id == SUBGHZ_CUSTOM_BTN_LEFT) {
|
||||
switch(original_btn_code) {
|
||||
case 0x1:
|
||||
btn = 0x8;
|
||||
break;
|
||||
@@ -177,10 +179,6 @@ static bool subghz_protocol_somfy_telis_gen_data(
|
||||
}
|
||||
}
|
||||
|
||||
if((custom_btn_id == 0) && (original_btn_num != 0)) {
|
||||
btn = original_btn_num;
|
||||
}
|
||||
|
||||
if(instance->generic.cnt < 0xFFFF) {
|
||||
if((instance->generic.cnt + furi_hal_subghz_get_rolling_counter_mult()) >= 0xFFFF) {
|
||||
instance->generic.cnt = 0;
|
||||
|
||||
Reference in New Issue
Block a user