From 2b03066109b1cba60c39c8e51dbb456741b180bd Mon Sep 17 00:00:00 2001 From: Jimi Sanchez Date: Wed, 18 May 2022 19:47:41 -0400 Subject: [PATCH] Fixes bug with double sending on input press --- applications/universal_rf/universal_rf.c | 54 ++++--------------- .../resources/subghz/assets/universal_rf_map | 7 +++ 2 files changed, 16 insertions(+), 45 deletions(-) create mode 100644 assets/resources/subghz/assets/universal_rf_map diff --git a/applications/universal_rf/universal_rf.c b/applications/universal_rf/universal_rf.c index d37c3835..61a11c42 100644 --- a/applications/universal_rf/universal_rf.c +++ b/applications/universal_rf/universal_rf.c @@ -31,16 +31,15 @@ static char* subString(char* someString, int n) { char* new = malloc(sizeof(char) * n + 1); strncpy(new, someString, n); new[n] = '\0'; - return new; + return(new); } static char* file_stub(const char* file_name) { string_t filename; string_init(filename); - // string_init(file_name); path_extract_filename_no_ext(file_name, filename); - return subString((char*)string_get_cstr(filename), 8); + return(subString((char*)string_get_cstr(filename), 8)); } static void remote_send_signal(uint32_t frequency, string_t signal, string_t protocol) { @@ -115,7 +114,6 @@ static void remote_render_callback(Canvas* canvas, void* ctx) { canvas_draw_str(canvas, 0, 36, strings[3]); canvas_draw_str(canvas, 85, 36, strings[4]); canvas_draw_str(canvas, 0, 48, strings[0]); - // canvas_draw_circle(canvas, 100, 26, 25); if(state->press[0]) { string_cat_printf(signal, "%s", string_get_cstr(right_file)); @@ -159,13 +157,15 @@ static void remote_render_callback(Canvas* canvas, void* ctx) { } canvas_draw_str(canvas, 10, 63, "[back] - skip, hold to exit"); - + remote_reset_state(state); release_mutex((ValueMutex*)ctx, state); } static void remote_input_callback(InputEvent* input_event, void* ctx) { - osMessageQueueId_t event_queue = ctx; - osMessageQueuePut(event_queue, input_event, 0, osWaitForever); + if (input_event->type == InputTypeRelease) { + osMessageQueueId_t event_queue = ctx; + osMessageQueuePut(event_queue, input_event, 0, osWaitForever); + } } int32_t universal_rf_remote_app(void* p) { @@ -218,7 +218,7 @@ int32_t universal_rf_remote_app(void* p) { ValueMutex state_mutex; if(!init_mutex(&state_mutex, &_state, sizeof(RemoteAppState))) { FURI_LOG_D(TAG, "cannot create mutex"); - return 0; + return(0); } ViewPort* view_port = view_port_alloc(); @@ -226,7 +226,6 @@ int32_t universal_rf_remote_app(void* p) { view_port_draw_callback_set(view_port, remote_render_callback, &state_mutex); view_port_input_callback_set(view_port, remote_input_callback, event_queue); - // Open GUI and register view_port Gui* gui = furi_record_open("gui"); gui_add_view_port(gui, view_port, GuiLayerFullscreen); @@ -240,58 +239,23 @@ int32_t universal_rf_remote_app(void* p) { input_get_type_name(event.type)); if(event.key == InputKeyRight) { - if(event.type == InputTypePress) { state->press[0] = true; - } else if(event.type == InputTypeRelease) { - state->press[0] = false; - } else if(event.type == InputTypeShort) { - state->press[0] = false; - } } else if(event.key == InputKeyLeft) { - if(event.type == InputTypePress) { state->press[1] = true; - } else if(event.type == InputTypeRelease) { - state->press[1] = false; - } else if(event.type == InputTypeShort) { - state->press[1] = false; - } } else if(event.key == InputKeyUp) { - if(event.type == InputTypePress) { state->press[2] = true; - } else if(event.type == InputTypeRelease) { - state->press[2] = false; - } else if(event.type == InputTypeShort) { - state->press[2] = false; - } } else if(event.key == InputKeyDown) { - if(event.type == InputTypePress) { state->press[3] = true; - } else if(event.type == InputTypeRelease) { - state->press[3] = false; - } else if(event.type == InputTypeShort) { - state->press[3] = false; - } } else if(event.key == InputKeyOk) { - if(event.type == InputTypePress) { state->press[4] = true; - } else if(event.type == InputTypeRelease) { - state->press[4] = false; - } else if(event.type == InputTypeShort) { - state->press[4] = false; - } } else if(event.key == InputKeyBack) { - if(event.type == InputTypeLong) { release_mutex(&state_mutex, state); break; - } else if(event.type == InputTypeShort) { - remote_reset_state(state); - } } release_mutex(&state_mutex, state); view_port_update(view_port); } - // remove & free all stuff created by app gui_remove_view_port(gui, view_port); view_port_free(view_port); osMessageQueueDelete(event_queue); @@ -299,5 +263,5 @@ int32_t universal_rf_remote_app(void* p) { furi_record_close("gui"); - return 0; + return(0); } diff --git a/assets/resources/subghz/assets/universal_rf_map b/assets/resources/subghz/assets/universal_rf_map new file mode 100644 index 00000000..acd53e37 --- /dev/null +++ b/assets/resources/subghz/assets/universal_rf_map @@ -0,0 +1,7 @@ +Filetype: Flipper SubGhz RAW File +Version: 1 +UP: /any/subghz/Tesla.sub +DOWN: /any/subghz/P1.sub +LEFT: /any/subghz/tesla-2.sub +RIGHT: /any/subghz/Dad1.sub +OK: /any/subghz/test.sub \ No newline at end of file