1
mirror of https://github.com/DarkFlippers/unleashed-firmware.git synced 2025-12-12 20:49:49 +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 <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) {
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) {
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_ptr = NULL;
switch(subghz->gen_info->type) {
case GenFaacSLH:
byte_ptr = (uint8_t*)&subghz->gen_info->faac_slh.cnt;
byte_count = sizeof(subghz->gen_info->faac_slh.cnt);
break;
case GenKeeloq:
byte_ptr = (uint8_t*)&subghz->gen_info->keeloq.cnt;
byte_count = sizeof(subghz->gen_info->keeloq.cnt);
break;
case GenCameAtomo:
byte_ptr = (uint8_t*)&subghz->gen_info->came_atomo.cnt;
byte_count = sizeof(subghz->gen_info->came_atomo.cnt);
break;
case GenKeeloqBFT:
byte_ptr = (uint8_t*)&subghz->gen_info->keeloq_bft.cnt;
byte_count = sizeof(subghz->gen_info->keeloq_bft.cnt);
break;
case GenAlutechAt4n:
byte_ptr = (uint8_t*)&subghz->gen_info->alutech_at_4n.cnt;
byte_count = sizeof(subghz->gen_info->alutech_at_4n.cnt);
break;
case GenSomfyTelis:
byte_ptr = (uint8_t*)&subghz->gen_info->somfy_telis.cnt;
byte_count = sizeof(subghz->gen_info->somfy_telis.cnt);
break;
case GenNiceFlorS:
byte_ptr = (uint8_t*)&subghz->gen_info->nice_flor_s.cnt;
byte_count = sizeof(subghz->gen_info->nice_flor_s.cnt);
break;
case GenSecPlus2:
byte_ptr = (uint8_t*)&subghz->gen_info->sec_plus_2.cnt;
byte_count = sizeof(subghz->gen_info->sec_plus_2.cnt);
break;
case GenPhoenixV2:
byte_ptr = (uint8_t*)&subghz->gen_info->phoenix_v2.cnt;
byte_count = sizeof(subghz->gen_info->phoenix_v2.cnt);
break;
// Not needed for these types
case GenData:
case GenSecPlus1:
default:
furi_crash("fuck!");
break;
subghz_protocol_decoder_base_get_string(subghz_txrx_get_decoder(subghz->txrx), text);
FURI_LOG_D(TAG, furi_string_get_cstr(text));
// In protocols output we allways have HEX format for "Cnt:" output (text formating like ...Cnt:%05lX\r\n")
// Both "Cnt:0x1111" and "Cnt:1111" always mean 0x1111 hex value, so we just use part after "0x"
// we take 8 simbols starting from "Cnt:0x........" or "Cnt:........"
// default value for textcnt "0000"
furi_string_set_str(textCnt, "0000");
int8_t cnt_place = furi_string_search_str(text, "Cnt:0x", 0);
if(cnt_place > 0) {
furi_string_set_n(textCnt, text, cnt_place + 6, 8);
} else {
cnt_place = furi_string_search_str(text, "Cnt:", 0);
if(cnt_place > 0) {
furi_string_set_n(textCnt, text, cnt_place + 4, 8);
}
}
///// Добавить проверку Cnt:????\r\n"
furi_string_trim(textCnt);
FURI_LOG_D(TAG,"Counter from file %s", furi_string_get_cstr(textCnt));
//convert 8 simbols string to uint based on base 16 (hex);
strint_to_uint32(furi_string_get_cstr(textCnt), NULL, &counter32, 16);
// Check will be counter 2(less than 65535) or 4 (more than 65535) hex bytes long and use corresponding variable for ByteInput
// To correct display hex value we must revert bytes for ByteInput view and display 2 or 4 hex bytes to edit
if (counter32 > 0xFFFF) {
byte_count = 4;
counter32 = __bswap32(counter32);
byte_ptr = (uint8_t*)&counter32;
} else {
counter16 = counter32;
byte_count = 2;
counter16 = __bswap16(counter16);
byte_ptr = (uint8_t*)&counter16;
}
FURI_LOG_D(TAG,"Byte count %i",byte_count);
FURI_LOG_D(TAG, "Counter Int %li", counter32);
furi_assert(byte_ptr);
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
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,
@@ -82,7 +81,12 @@ void subghz_scene_signal_settings_counter_on_enter(void* context) {
subghz,
byte_ptr,
byte_count);
furi_string_free(text);
furi_string_free(textCnt);
view_dispatcher_switch_to_view(subghz->view_dispatcher, SubGhzViewIdByteInput);
}
bool subghz_scene_signal_settings_counter_on_event(void* context, SceneManagerEvent event) {