From 34a5851e706e7797993b8102069cc56f96a7baae Mon Sep 17 00:00:00 2001 From: David Lee Date: Mon, 5 Feb 2024 16:25:15 +0100 Subject: [PATCH] Settings & Storage for SubGhz Timing --- helpers/subghz/subghz.c | 2 +- helpers/xremote_storage.c | 2 ++ helpers/xremote_storage.h | 1 + scenes/xremote_scene_settings.c | 19 ++++++++++++++++++- xremote.c | 2 ++ xremote.h | 2 ++ 6 files changed, 26 insertions(+), 2 deletions(-) diff --git a/helpers/subghz/subghz.c b/helpers/subghz/subghz.c index 8ac2de29959..61dcddac293 100644 --- a/helpers/subghz/subghz.c +++ b/helpers/subghz/subghz.c @@ -61,7 +61,7 @@ void subghz_send(void* context, const char* path) { } else { subghz_tx_start(app->subghz, subghz_txrx_get_fff_data(app->subghz->txrx)); app->state_notifications = SubGhzNotificationStateTx; - furi_thread_flags_wait(0, FuriFlagWaitAny, 500); + furi_thread_flags_wait(0, FuriFlagWaitAny, app->sg_timing); app->state_notifications = SubGhzNotificationStateIDLE; subghz_txrx_stop(app->subghz->txrx); diff --git a/helpers/xremote_storage.c b/helpers/xremote_storage.c index 76de7d4a45c..7077b01a100 100644 --- a/helpers/xremote_storage.c +++ b/helpers/xremote_storage.c @@ -58,6 +58,7 @@ void xremote_save_settings(void* context) { flipper_format_write_uint32( fff_file, XREMOTE_SETTINGS_KEY_SAVE_SETTINGS, &app->save_settings, 1); flipper_format_write_uint32(fff_file, XREMOTE_SETTINGS_KEY_IR_TIMING, &app->ir_timing, 1); + flipper_format_write_uint32(fff_file, XREMOTE_SETTINGS_KEY_SG_TIMING, &app->sg_timing, 1); if(!flipper_format_rewind(fff_file)) { xremote_close_config_file(fff_file); @@ -110,6 +111,7 @@ void xremote_read_settings(void* context) { flipper_format_read_uint32( fff_file, XREMOTE_SETTINGS_KEY_SAVE_SETTINGS, &app->save_settings, 1); flipper_format_read_uint32(fff_file, XREMOTE_SETTINGS_KEY_IR_TIMING, &app->ir_timing, 1); + flipper_format_read_uint32(fff_file, XREMOTE_SETTINGS_KEY_SG_TIMING, &app->sg_timing, 1); flipper_format_rewind(fff_file); diff --git a/helpers/xremote_storage.h b/helpers/xremote_storage.h index b2f55da788b..650fac2c8ba 100644 --- a/helpers/xremote_storage.h +++ b/helpers/xremote_storage.h @@ -12,6 +12,7 @@ #define XREMOTE_SETTINGS_KEY_SPEAKER "Speaker" #define XREMOTE_SETTINGS_KEY_SAVE_SETTINGS "SaveSettings" #define XREMOTE_SETTINGS_KEY_IR_TIMING "IRTiming" +#define XREMOTE_SETTINGS_KEY_SG_TIMING "SGTiming" void xremote_save_settings(void* context); void xremote_read_settings(void* context); \ No newline at end of file diff --git a/scenes/xremote_scene_settings.c b/scenes/xremote_scene_settings.c index 377e0549bda..7e66d255123 100644 --- a/scenes/xremote_scene_settings.c +++ b/scenes/xremote_scene_settings.c @@ -81,6 +81,15 @@ static void xremote_scene_settings_set_ir_timing(VariableItem* item) { app->ir_timing = (index * 100); } +static void xremote_scene_settings_set_sg_timing(VariableItem* item) { + XRemote* app = variable_item_get_context(item); + uint32_t index = variable_item_get_current_value_index(item); + + snprintf(app->sg_timing_char, 20, "%lu", (index * 100)); + variable_item_set_current_value_text(item, app->sg_timing_char); + app->sg_timing = (index * 100); +} + void xremote_scene_settings_submenu_callback(void* context, uint32_t index) { XRemote* app = context; view_dispatcher_send_custom_event(app->view_dispatcher, index); @@ -121,12 +130,20 @@ void xremote_scene_settings_on_enter(void* context) { // Set Infrared Timer item = variable_item_list_add( - app->variable_item_list, "IR Timing in ms:", 30, xremote_scene_settings_set_ir_timing, app); + app->variable_item_list, "IR Time ms", 30, xremote_scene_settings_set_ir_timing, app); variable_item_set_current_value_index(item, (uint8_t)(app->ir_timing / 100)); snprintf(app->ir_timing_char, 20, "%lu", app->ir_timing); variable_item_set_current_value_text(item, app->ir_timing_char); + // Set SubGhz Timer + item = variable_item_list_add( + app->variable_item_list, "SubG. Time ms", 30, xremote_scene_settings_set_sg_timing, app); + + variable_item_set_current_value_index(item, (uint8_t)(app->sg_timing / 100)); + snprintf(app->sg_timing_char, 20, "%lu", app->sg_timing); + variable_item_set_current_value_text(item, app->sg_timing_char); + view_dispatcher_switch_to_view(app->view_dispatcher, XRemoteViewIdSettings); } diff --git a/xremote.c b/xremote.c index 5a016cb4d15..e87e410c5e9 100644 --- a/xremote.c +++ b/xremote.c @@ -49,6 +49,8 @@ XRemote* xremote_app_alloc() { app->transmitting = 0; app->ir_timing = 1000; app->ir_timing_char = "1000"; + app->sg_timing = 500; + app->sg_timing_char = "500"; app->stop_transmit = false; // Load configs diff --git a/xremote.h b/xremote.h index 4776e4d8cca..1ba4c62d3cf 100644 --- a/xremote.h +++ b/xremote.h @@ -46,6 +46,8 @@ typedef struct { uint32_t edit_item; uint32_t ir_timing; char* ir_timing_char; + uint32_t sg_timing; + char* sg_timing_char; bool transmitting; bool stop_transmit; char text_store[XREMOTE_TEXT_STORE_NUM][XREMOTE_TEXT_STORE_SIZE + 1];