mirror of
https://github.com/DarkFlippers/unleashed-firmware
synced 2024-11-22 20:43:07 +00:00
Subghz save files with receive time [ci skip]
+ merge better scene_save_name code (removing kostily) some modifications to original code was made to keep previous formats original implementation by Willy-JL Source:a1c7dc5eaa
7e7509d481 (diff-1708ba08196de5331f4b4c3d8e13162e78d5edb33e1308c1b4cc09975264151e)
This commit is contained in:
parent
cbc0231461
commit
16b8fa4715
9 changed files with 108 additions and 70 deletions
|
@ -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;
|
||||
|
|
|
@ -6,44 +6,12 @@
|
|||
#include <dolphin/dolphin.h>
|
||||
#include <toolbox/name_generator.h>
|
||||
|
||||
#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(
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
#include <furi_hal_rtc.h>
|
||||
|
||||
#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
|
||||
}
|
||||
|
|
|
@ -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*
|
||||
|
|
|
Loading…
Reference in a new issue