diff --git a/applications/main/subghz/scenes/subghz_scene_receiver_info.c b/applications/main/subghz/scenes/subghz_scene_receiver_info.c index 807cc3ba2..5cf79eabc 100644 --- a/applications/main/subghz/scenes/subghz_scene_receiver_info.c +++ b/applications/main/subghz/scenes/subghz_scene_receiver_info.c @@ -165,6 +165,9 @@ bool subghz_scene_receiver_info_on_event(void* context, SceneManagerEvent event) if(subghz_txrx_protocol_is_serializable(subghz->txrx)) { subghz_file_name_clear(subghz); + subghz->save_datetime = + subghz_history_get_datetime(subghz->history, subghz->idx_menu_chosen); + subghz->save_datetime_set = true; scene_manager_next_scene(subghz->scene_manager, SubGhzSceneSaveName); } return true; diff --git a/applications/main/subghz/scenes/subghz_scene_save_name.c b/applications/main/subghz/scenes/subghz_scene_save_name.c index e1bb6c33b..c0768de4b 100644 --- a/applications/main/subghz/scenes/subghz_scene_save_name.c +++ b/applications/main/subghz/scenes/subghz_scene_save_name.c @@ -6,44 +6,12 @@ #include #include -#define MAX_TEXT_INPUT_LEN 23 - void subghz_scene_save_name_text_input_callback(void* context) { furi_assert(context); SubGhz* subghz = context; view_dispatcher_send_custom_event(subghz->view_dispatcher, SubGhzCustomEventSceneSaveName); } -void subghz_scene_save_name_get_timefilename( - FuriString* name, - const char* proto_name, - bool fulldate) { - FuriHalRtcDateTime datetime = {0}; - furi_hal_rtc_get_datetime(&datetime); - if(fulldate) { - furi_string_printf( - name, - "%s_%.4d%.2d%.2d-%.2d%.2d%.2d", - proto_name, - datetime.year, - datetime.month, - datetime.day, - datetime.hour, - datetime.minute, - datetime.second); - } else { - furi_string_printf( - name, - "%s_%.2d%.2d-%.2d%.2d%.2d", - proto_name, - datetime.month, - datetime.day, - datetime.hour, - datetime.minute, - datetime.second); - } -} - void subghz_scene_save_name_on_enter(void* context) { SubGhz* subghz = context; @@ -54,35 +22,33 @@ void subghz_scene_save_name_on_enter(void* context) { FuriString* file_name = furi_string_alloc(); FuriString* dir_name = furi_string_alloc(); + char file_name_buf[SUBGHZ_MAX_LEN_NAME] = {0}; + FuriHalRtcDateTime* datetime = subghz->save_datetime_set ? &subghz->save_datetime : NULL; + subghz->save_datetime_set = false; if(!subghz_path_is_file(subghz->file_path)) { - char file_name_buf[SUBGHZ_MAX_LEN_NAME] = {0}; - if(subghz->last_settings->timestamp_file_names) { - SubGhzProtocolDecoderBase* decoder_result = subghz_txrx_get_decoder(subghz->txrx); - if(decoder_result != 0x0) { - if(decoder_result != NULL) { - if(strlen(decoder_result->protocol->name) != 0) { - if(scene_manager_has_previous_scene( - subghz->scene_manager, SubGhzSceneSetType)) { - subghz_scene_save_name_get_timefilename(file_name, "S", true); - } else { - subghz_scene_save_name_get_timefilename( - file_name, decoder_result->protocol->name, false); - } + SubGhzProtocolDecoderBase* decoder_result = subghz_txrx_get_decoder(subghz->txrx); - } else { - subghz_scene_save_name_get_timefilename(file_name, "S", true); + bool skip_dec_is_present = false; + if(decoder_result != 0x0) { + if(decoder_result != NULL) { + if(strlen(decoder_result->protocol->name) != 0 && + subghz->last_settings->timestamp_file_names) { + if(!scene_manager_has_previous_scene( + subghz->scene_manager, SubGhzSceneSetType)) { + name_generator_make_auto_datetime( + file_name_buf, + SUBGHZ_MAX_LEN_NAME, + decoder_result->protocol->name, + datetime); + skip_dec_is_present = true; } - } else { - subghz_scene_save_name_get_timefilename(file_name, "S", true); } - } else { - subghz_scene_save_name_get_timefilename(file_name, "S", true); } - } else { - name_generator_make_auto( - file_name_buf, SUBGHZ_MAX_LEN_NAME, SUBGHZ_APP_FILENAME_PREFIX); - furi_string_set(file_name, file_name_buf); } + if(!skip_dec_is_present) { + name_generator_make_auto_datetime(file_name_buf, SUBGHZ_MAX_LEN_NAME, NULL, datetime); + } + furi_string_set(file_name, file_name_buf); furi_string_set(subghz->file_path, SUBGHZ_APP_FOLDER); //highlighting the entire filename by default dev_name_empty = true; @@ -96,7 +62,9 @@ void subghz_scene_save_name_on_enter(void* context) { if(scene_manager_get_scene_state(subghz->scene_manager, SubGhzSceneReadRAW) == SubGhzCustomEventManagerSetRAW) { dev_name_empty = true; - subghz_scene_save_name_get_timefilename(file_name, "RAW", true); + name_generator_make_auto_datetime( + file_name_buf, SUBGHZ_MAX_LEN_NAME, "RAW", datetime); + furi_string_set(file_name, file_name_buf); } } furi_string_set(subghz->file_path, dir_name); @@ -109,7 +77,7 @@ void subghz_scene_save_name_on_enter(void* context) { subghz_scene_save_name_text_input_callback, subghz, subghz->file_name_tmp, - MAX_TEXT_INPUT_LEN, + SUBGHZ_MAX_LEN_NAME, dev_name_empty); ValidatorIsFile* validator_is_file = validator_is_file_alloc_init( diff --git a/applications/main/subghz/subghz_history.c b/applications/main/subghz/subghz_history.c index 048104f35..2f0371985 100644 --- a/applications/main/subghz/subghz_history.c +++ b/applications/main/subghz/subghz_history.c @@ -131,6 +131,16 @@ const char* subghz_history_get_protocol_name(SubGhzHistory* instance, uint16_t i return furi_string_get_cstr(instance->tmp_string); } +FuriHalRtcDateTime subghz_history_get_datetime(SubGhzHistory* instance, uint16_t idx) { + furi_assert(instance); + SubGhzHistoryItem* item = SubGhzHistoryItemArray_get(instance->history->data, idx); + if(item) { + return item->datetime; + } else { + return (FuriHalRtcDateTime){}; + } +} + FlipperFormat* subghz_history_get_raw_data(SubGhzHistory* instance, uint16_t idx) { furi_assert(instance); SubGhzHistoryItem* item = SubGhzHistoryItemArray_get(instance->history->data, idx); diff --git a/applications/main/subghz/subghz_history.h b/applications/main/subghz/subghz_history.h index cc63c0259..2e940a8d8 100644 --- a/applications/main/subghz/subghz_history.h +++ b/applications/main/subghz/subghz_history.h @@ -70,6 +70,14 @@ uint8_t subghz_history_get_type_protocol(SubGhzHistory* instance, uint16_t idx); */ const char* subghz_history_get_protocol_name(SubGhzHistory* instance, uint16_t idx); +/** Get datetime from history[idx] + * + * @param instance - SubGhzHistory instance + * @param idx - record index + * @return datetime - FuriHalRtcDateTime received timestamp + */ +FuriHalRtcDateTime subghz_history_get_datetime(SubGhzHistory* instance, uint16_t idx); + /** Get string item menu to history[idx] * * @param instance - SubGhzHistory instance diff --git a/applications/main/subghz/subghz_i.h b/applications/main/subghz/subghz_i.h index 4297699db..09caed7a9 100644 --- a/applications/main/subghz/subghz_i.h +++ b/applications/main/subghz/subghz_i.h @@ -79,6 +79,9 @@ struct SubGhz { SubGhzReadRAW* subghz_read_raw; bool raw_send_only; + bool save_datetime_set; + FuriHalRtcDateTime save_datetime; + SubGhzLastSettings* last_settings; SubGhzProtocolFlag filter; diff --git a/lib/subghz/protocols/keeloq.c b/lib/subghz/protocols/keeloq.c index 281373527..3a6ee5796 100644 --- a/lib/subghz/protocols/keeloq.c +++ b/lib/subghz/protocols/keeloq.c @@ -714,13 +714,13 @@ static inline bool subghz_protocol_keeloq_check_decrypt( if((decrypt >> 28 == btn) && (((((uint16_t)(decrypt >> 16)) & 0xFF) == end_serial) || ((((uint16_t)(decrypt >> 16)) & 0xFF) == 0))) { instance->cnt = decrypt & 0x0000FFFF; - FURI_LOG_I( + /*FURI_LOG_I( "KL", "decrypt: 0x%08lX, btn: %d, end_serial: 0x%03lX, cnt: %ld", decrypt, btn, end_serial, - instance->cnt); + instance->cnt);*/ return true; } return false; diff --git a/lib/toolbox/name_generator.c b/lib/toolbox/name_generator.c index 732fdfedf..541622b88 100644 --- a/lib/toolbox/name_generator.c +++ b/lib/toolbox/name_generator.c @@ -44,15 +44,23 @@ const char* const name_generator_right[] = { "stuff", }; -void name_generator_make_auto(char* name, size_t max_name_size, const char* prefix) { +void name_generator_make_auto_datetime( + char* name, + size_t max_name_size, + const char* prefix, + FuriHalRtcDateTime* custom_time) { if(furi_hal_rtc_is_flag_set(FuriHalRtcFlagDetailedFilename)) { - name_generator_make_detailed(name, max_name_size, prefix); + name_generator_make_detailed_datetime(name, max_name_size, prefix, custom_time); } else { - name_generator_make_random(name, max_name_size); + name_generator_make_random_prefixed(name, max_name_size, prefix); } } -void name_generator_make_random(char* name, size_t max_name_size) { +void name_generator_make_auto(char* name, size_t max_name_size, const char* prefix) { + name_generator_make_auto_datetime(name, max_name_size, prefix, NULL); +} + +void name_generator_make_random_prefixed(char* name, size_t max_name_size, const char* prefix) { furi_assert(name); furi_assert(max_name_size); @@ -62,30 +70,52 @@ void name_generator_make_random(char* name, size_t max_name_size) { snprintf( name, max_name_size, - "%s_%s", + "%s%s%s_%s", + prefix ? prefix : "", + prefix ? "_" : "", name_generator_left[name_generator_left_i], name_generator_right[name_generator_right_i]); // Set first symbol to upper case - name[0] = name[0] - 0x20; + if(islower((int)name[0])) name[0] = name[0] - 0x20; } -void name_generator_make_detailed(char* name, size_t max_name_size, const char* prefix) { +void name_generator_make_random(char* name, size_t max_name_size) { + name_generator_make_random_prefixed(name, max_name_size, NULL); +} + +void name_generator_make_detailed_datetime( + char* name, + size_t max_name_size, + const char* prefix, + FuriHalRtcDateTime* custom_time) { furi_assert(name); furi_assert(max_name_size); furi_assert(prefix); FuriHalRtcDateTime dateTime; - furi_hal_rtc_get_datetime(&dateTime); + if(custom_time) { + dateTime = *custom_time; + } else { + furi_hal_rtc_get_datetime(&dateTime); + } snprintf( name, max_name_size, - "%s-%.4d_%.2d_%.2d-%.2d_%.2d", - prefix, + "%s-%.4d_%.2d_%.2d-%.2d_%.2d_%.2d", + prefix ? prefix : "S", dateTime.year, dateTime.month, dateTime.day, dateTime.hour, - dateTime.minute); + dateTime.minute, + dateTime.second); + + // Set first symbol to upper case + if(islower((int)name[0])) name[0] = name[0] - 0x20; +} + +void name_generator_make_detailed(char* name, size_t max_name_size, const char* prefix) { + name_generator_make_detailed_datetime(name, max_name_size, prefix, NULL); } diff --git a/lib/toolbox/name_generator.h b/lib/toolbox/name_generator.h index bc17d54cd..ac9cdf6f5 100644 --- a/lib/toolbox/name_generator.h +++ b/lib/toolbox/name_generator.h @@ -2,6 +2,7 @@ #include #include +#include #ifdef __cplusplus extern "C" { @@ -14,13 +15,20 @@ extern "C" { * @param[in] prefix The prefix of the name */ void name_generator_make_auto(char* name, size_t max_name_size, const char* prefix); +void name_generator_make_auto_datetime( + char* name, + size_t max_name_size, + const char* prefix, + FuriHalRtcDateTime* custom_time); /** Generates random name * * @param name buffer to write random name * @param max_name_size length of given buffer + * @param[in] prefix The prefix of the name */ void name_generator_make_random(char* name, size_t max_name_size); +void name_generator_make_random_prefixed(char* name, size_t max_name_size, const char* prefix); /** Generates detailed name * @@ -29,6 +37,11 @@ void name_generator_make_random(char* name, size_t max_name_size); * @param[in] prefix The prefix of the name */ void name_generator_make_detailed(char* name, size_t max_name_size, const char* prefix); +void name_generator_make_detailed_datetime( + char* name, + size_t max_name_size, + const char* prefix, + FuriHalRtcDateTime* custom_time); #ifdef __cplusplus } diff --git a/targets/f7/api_symbols.csv b/targets/f7/api_symbols.csv index 11d4918cc..5b317bc16 100644 --- a/targets/f7/api_symbols.csv +++ b/targets/f7/api_symbols.csv @@ -2478,8 +2478,11 @@ Function,-,music_worker_set_volume,void,"MusicWorker*, float" Function,-,music_worker_start,void,MusicWorker* Function,-,music_worker_stop,void,MusicWorker* Function,+,name_generator_make_auto,void,"char*, size_t, const char*" +Function,+,name_generator_make_auto_datetime,void,"char*, size_t, const char*, FuriHalRtcDateTime*" Function,+,name_generator_make_detailed,void,"char*, size_t, const char*" +Function,+,name_generator_make_detailed_datetime,void,"char*, size_t, const char*, FuriHalRtcDateTime*" Function,+,name_generator_make_random,void,"char*, size_t" +Function,+,name_generator_make_random_prefixed,void,"char*, size_t, const char*" Function,-,nan,double,const char* Function,-,nanf,float,const char* Function,-,nanl,long double,const char*