diff --git a/applications/bad_usb/bad_usb_app.c b/applications/bad_usb/bad_usb_app.c index 9891c49b9..107371e4e 100644 --- a/applications/bad_usb/bad_usb_app.c +++ b/applications/bad_usb/bad_usb_app.c @@ -102,7 +102,7 @@ BadUsbApp* bad_usb_app_alloc(char* arg) { scene_manager_next_scene(app->scene_manager, BadUsbSceneError); } else { if(!string_empty_p(app->file_path)) { - scene_manager_next_scene(app->scene_manager, BadUsbSceneWork); + scene_manager_next_scene(app->scene_manager, BadUsbScenePWork); } else { string_set_str(app->file_path, BAD_USB_APP_BASE_FOLDER); scene_manager_next_scene(app->scene_manager, BadUsbSceneFileSelect); diff --git a/applications/bad_usb/bad_usb_script.c b/applications/bad_usb/bad_usb_script.c index c0504bf8e..f50c86284 100644 --- a/applications/bad_usb/bad_usb_script.c +++ b/applications/bad_usb/bad_usb_script.c @@ -661,4 +661,8 @@ void bad_usb_script_toggle(BadUsbScript* bad_usb) { BadUsbState* bad_usb_script_get_state(BadUsbScript* bad_usb) { furi_assert(bad_usb); return &(bad_usb->st); +} + +void bad_usb_script_set_run_state(BadUsbState* st, bool run) { + st->run_from_p = run; } \ No newline at end of file diff --git a/applications/bad_usb/bad_usb_script.h b/applications/bad_usb/bad_usb_script.h index 71066cb13..4cf661ddd 100644 --- a/applications/bad_usb/bad_usb_script.h +++ b/applications/bad_usb/bad_usb_script.h @@ -22,6 +22,7 @@ typedef enum { typedef struct { BadUsbWorkerState state; + bool run_from_p; uint16_t line_cur; uint16_t line_nb; uint32_t delay_remain; @@ -42,6 +43,8 @@ void bad_usb_script_toggle(BadUsbScript* bad_usb); BadUsbState* bad_usb_script_get_state(BadUsbScript* bad_usb); +void bad_usb_script_set_run_state(BadUsbState* st, bool run); + #ifdef __cplusplus } #endif \ No newline at end of file diff --git a/applications/bad_usb/scenes/bad_usb_scene_config.h b/applications/bad_usb/scenes/bad_usb_scene_config.h index 423aedc51..e19b185ee 100644 --- a/applications/bad_usb/scenes/bad_usb_scene_config.h +++ b/applications/bad_usb/scenes/bad_usb_scene_config.h @@ -1,5 +1,6 @@ ADD_SCENE(bad_usb, file_select, FileSelect) ADD_SCENE(bad_usb, work, Work) +ADD_SCENE(bad_usb, pwork, PWork) ADD_SCENE(bad_usb, error, Error) ADD_SCENE(bad_usb, config, Config) ADD_SCENE(bad_usb, config_layout, ConfigLayout) diff --git a/applications/bad_usb/scenes/bad_usb_scene_pwork.c b/applications/bad_usb/scenes/bad_usb_scene_pwork.c new file mode 100644 index 000000000..8ac1a6ee8 --- /dev/null +++ b/applications/bad_usb/scenes/bad_usb_scene_pwork.c @@ -0,0 +1,56 @@ +#include "../bad_usb_script.h" +#include "../bad_usb_app_i.h" +#include "../views/bad_usb_view.h" +#include "furi_hal.h" +#include "m-string.h" +#include "toolbox/path.h" + +void bad_usb_scene_pwork_button_callback(InputKey key, void* context) { + furi_assert(context); + BadUsbApp* app = context; + view_dispatcher_send_custom_event(app->view_dispatcher, key); +} + +bool bad_usb_scene_pwork_on_event(void* context, SceneManagerEvent event) { + BadUsbApp* app = context; + bool consumed = false; + + if(event.type == SceneManagerEventTypeCustom) { + if(event.event == InputKeyOk) { + bad_usb_script_toggle(app->bad_usb_script); + consumed = true; + } + } else if(event.type == SceneManagerEventTypeTick) { + bad_usb_set_state(app->bad_usb_view, bad_usb_script_get_state(app->bad_usb_script)); + } + return consumed; +} + +void bad_usb_scene_pwork_on_enter(void* context) { + BadUsbApp* app = context; + + string_t file_name; + string_init(file_name); + + path_extract_filename(app->file_path, file_name, true); + bad_usb_set_file_name(app->bad_usb_view, string_get_cstr(file_name)); + app->bad_usb_script = bad_usb_script_open(app->file_path); + + bad_usb_script_set_keyboard_layout(app->bad_usb_script, app->keyboard_layout); + + string_clear(file_name); + + bad_usb_set_state(app->bad_usb_view, bad_usb_script_get_state(app->bad_usb_script)); + + // set app state - is executed from archive app + bad_usb_script_set_run_state(bad_usb_script_get_state(app->bad_usb_script), true); + + bad_usb_set_button_callback(app->bad_usb_view, bad_usb_scene_pwork_button_callback, app); + view_dispatcher_switch_to_view(app->view_dispatcher, BadUsbAppViewWork); +} + +void bad_usb_scene_pwork_on_exit(void* context) { + UNUSED(context); + //BadUsbApp* app = context; + //bad_usb_script_close(app->bad_usb_script); +} \ No newline at end of file diff --git a/applications/bad_usb/scenes/bad_usb_scene_work.c b/applications/bad_usb/scenes/bad_usb_scene_work.c index ee081e237..7f4cb88a9 100644 --- a/applications/bad_usb/scenes/bad_usb_scene_work.c +++ b/applications/bad_usb/scenes/bad_usb_scene_work.c @@ -40,6 +40,9 @@ void bad_usb_scene_work_on_enter(void* context) { bad_usb_set_state(app->bad_usb_view, bad_usb_script_get_state(app->bad_usb_script)); + // set app state - is executed from archive app + bad_usb_script_set_run_state(bad_usb_script_get_state(app->bad_usb_script), false); + bad_usb_set_button_callback(app->bad_usb_view, bad_usb_scene_work_button_callback, app); view_dispatcher_switch_to_view(app->view_dispatcher, BadUsbAppViewWork); } diff --git a/applications/bad_usb/views/bad_usb_view.c b/applications/bad_usb/views/bad_usb_view.c index 238f14262..b7baf8b0e 100644 --- a/applications/bad_usb/views/bad_usb_view.c +++ b/applications/bad_usb/views/bad_usb_view.c @@ -34,8 +34,9 @@ static void bad_usb_draw_callback(Canvas* canvas, void* _model) { elements_button_center(canvas, "Stop"); } - if((model->state.state == BadUsbStateNotConnected) || - (model->state.state == BadUsbStateIdle) || (model->state.state == BadUsbStateDone)) { + if(((model->state.state == BadUsbStateNotConnected) || + (model->state.state == BadUsbStateIdle) || (model->state.state == BadUsbStateDone)) && + !model->state.run_from_p) { elements_button_left(canvas, "Config"); }