1
mirror of https://github.com/DarkFlippers/unleashed-firmware.git synced 2025-12-12 04:34:43 +04:00

From work to home

This commit is contained in:
Dmitry422
2025-11-28 20:13:56 +07:00
parent 7fd30911fe
commit a493612444

View File

@@ -2,8 +2,11 @@
#include "../helpers/subghz_txrx_create_protocol_key.h" #include "../helpers/subghz_txrx_create_protocol_key.h"
#include <machine/endian.h> #include <machine/endian.h>
#include <toolbox/strint.h>
#define TAG "SubGhzSceneSignalSettingsCounter"
#define TAG "SubGhzSignalSettingsCounter" uint32_t counter32 = 0x0;
uint16_t counter16 = 0x0;
void subghz_scene_signal_settings_counter_byte_input_callback(void* context) { void subghz_scene_signal_settings_counter_byte_input_callback(void* context) {
SubGhz* subghz = context; SubGhz* subghz = context;
@@ -14,66 +17,62 @@ void subghz_scene_signal_settings_counter_byte_input_callback(void* context) {
void subghz_scene_signal_settings_counter_on_enter(void* context) { void subghz_scene_signal_settings_counter_on_enter(void* context) {
SubGhz* subghz = context; SubGhz* subghz = context;
uint8_t* byte_ptr = NULL; FuriString* text = furi_string_alloc();
FuriString* textCnt = furi_string_alloc();
uint8_t byte_count = 0; uint8_t byte_count = 0;
uint8_t* byte_ptr = NULL;
subghz_protocol_decoder_base_get_string(subghz_txrx_get_decoder(subghz->txrx), text);
FURI_LOG_D(TAG, furi_string_get_cstr(text));
switch(subghz->gen_info->type) { // In protocols output we allways have HEX format for "Cnt:" output (text formating like ...Cnt:%05lX\r\n")
case GenFaacSLH: // Both "Cnt:0x1111" and "Cnt:1111" always mean 0x1111 hex value, so we just use part after "0x"
byte_ptr = (uint8_t*)&subghz->gen_info->faac_slh.cnt; // we take 8 simbols starting from "Cnt:0x........" or "Cnt:........"
byte_count = sizeof(subghz->gen_info->faac_slh.cnt); // default value for textcnt "0000"
break; furi_string_set_str(textCnt, "0000");
case GenKeeloq: int8_t cnt_place = furi_string_search_str(text, "Cnt:0x", 0);
byte_ptr = (uint8_t*)&subghz->gen_info->keeloq.cnt;
byte_count = sizeof(subghz->gen_info->keeloq.cnt); if(cnt_place > 0) {
break; furi_string_set_n(textCnt, text, cnt_place + 6, 8);
case GenCameAtomo: } else {
byte_ptr = (uint8_t*)&subghz->gen_info->came_atomo.cnt; cnt_place = furi_string_search_str(text, "Cnt:", 0);
byte_count = sizeof(subghz->gen_info->came_atomo.cnt); if(cnt_place > 0) {
break; furi_string_set_n(textCnt, text, cnt_place + 4, 8);
case GenKeeloqBFT: }
byte_ptr = (uint8_t*)&subghz->gen_info->keeloq_bft.cnt; }
byte_count = sizeof(subghz->gen_info->keeloq_bft.cnt); ///// Добавить проверку Cnt:????\r\n"
break;
case GenAlutechAt4n:
byte_ptr = (uint8_t*)&subghz->gen_info->alutech_at_4n.cnt;
byte_count = sizeof(subghz->gen_info->alutech_at_4n.cnt); furi_string_trim(textCnt);
break; FURI_LOG_D(TAG,"Counter from file %s", furi_string_get_cstr(textCnt));
case GenSomfyTelis:
byte_ptr = (uint8_t*)&subghz->gen_info->somfy_telis.cnt; //convert 8 simbols string to uint based on base 16 (hex);
byte_count = sizeof(subghz->gen_info->somfy_telis.cnt); strint_to_uint32(furi_string_get_cstr(textCnt), NULL, &counter32, 16);
break;
case GenNiceFlorS: // Check will be counter 2(less than 65535) or 4 (more than 65535) hex bytes long and use corresponding variable for ByteInput
byte_ptr = (uint8_t*)&subghz->gen_info->nice_flor_s.cnt; // To correct display hex value we must revert bytes for ByteInput view and display 2 or 4 hex bytes to edit
byte_count = sizeof(subghz->gen_info->nice_flor_s.cnt); if (counter32 > 0xFFFF) {
break; byte_count = 4;
case GenSecPlus2: counter32 = __bswap32(counter32);
byte_ptr = (uint8_t*)&subghz->gen_info->sec_plus_2.cnt; byte_ptr = (uint8_t*)&counter32;
byte_count = sizeof(subghz->gen_info->sec_plus_2.cnt);
break; } else {
case GenPhoenixV2: counter16 = counter32;
byte_ptr = (uint8_t*)&subghz->gen_info->phoenix_v2.cnt; byte_count = 2;
byte_count = sizeof(subghz->gen_info->phoenix_v2.cnt); counter16 = __bswap16(counter16);
break; byte_ptr = (uint8_t*)&counter16;
// Not needed for these types
case GenData:
case GenSecPlus1:
default:
furi_crash("fuck!");
break;
} }
FURI_LOG_D(TAG,"Byte count %i",byte_count);
FURI_LOG_D(TAG, "Counter Int %li", counter32);
furi_assert(byte_ptr); furi_assert(byte_ptr);
furi_assert(byte_count > 0); furi_assert(byte_count > 0);
if(byte_count == 2) {
*((uint16_t*)byte_ptr) = __bswap16(*((uint16_t*)byte_ptr)); // Convert
} else if(byte_count == 4) {
*((uint32_t*)byte_ptr) = __bswap32(*((uint32_t*)byte_ptr)); // Convert
}
// Setup view // Setup view
ByteInput* byte_input = subghz->byte_input; ByteInput* byte_input = subghz->byte_input;
byte_input_set_header_text(byte_input, "Enter COUNTER in hex"); byte_input_set_header_text(byte_input, "Enter COUNTER in HEX");
byte_input_set_result_callback( byte_input_set_result_callback(
byte_input, byte_input,
@@ -82,7 +81,12 @@ void subghz_scene_signal_settings_counter_on_enter(void* context) {
subghz, subghz,
byte_ptr, byte_ptr,
byte_count); byte_count);
furi_string_free(text);
furi_string_free(textCnt);
view_dispatcher_switch_to_view(subghz->view_dispatcher, SubGhzViewIdByteInput); view_dispatcher_switch_to_view(subghz->view_dispatcher, SubGhzViewIdByteInput);
} }
bool subghz_scene_signal_settings_counter_on_event(void* context, SceneManagerEvent event) { bool subghz_scene_signal_settings_counter_on_event(void* context, SceneManagerEvent event) {