[FL-3116, FL-3136] BadUSB UI fixes (#2439)

This commit is contained in:
Nikolay Minaylov 2023-02-27 17:04:14 +03:00 committed by GitHub
parent e6d1bcc421
commit 9ae58f5462
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 27 additions and 10 deletions

View File

@ -142,10 +142,6 @@ void bad_usb_app_free(BadUsbApp* app) {
app->bad_usb_script = NULL; app->bad_usb_script = NULL;
} }
if(app->usb_if_prev) {
furi_check(furi_hal_usb_set_config(app->usb_if_prev, NULL));
}
// Views // Views
view_dispatcher_remove_view(app->view_dispatcher, BadUsbAppViewWork); view_dispatcher_remove_view(app->view_dispatcher, BadUsbAppViewWork);
bad_usb_free(app->bad_usb_view); bad_usb_free(app->bad_usb_view);
@ -172,6 +168,10 @@ void bad_usb_app_free(BadUsbApp* app) {
furi_string_free(app->file_path); furi_string_free(app->file_path);
furi_string_free(app->keyboard_layout); furi_string_free(app->keyboard_layout);
if(app->usb_if_prev) {
furi_check(furi_hal_usb_set_config(app->usb_if_prev, NULL));
}
free(app); free(app);
} }

View File

@ -16,7 +16,9 @@ bool bad_usb_scene_work_on_event(void* context, SceneManagerEvent event) {
if(event.type == SceneManagerEventTypeCustom) { if(event.type == SceneManagerEventTypeCustom) {
if(event.event == InputKeyLeft) { if(event.event == InputKeyLeft) {
if(bad_usb_is_idle_state(app->bad_usb_view)) {
scene_manager_next_scene(app->scene_manager, BadUsbSceneConfig); scene_manager_next_scene(app->scene_manager, BadUsbSceneConfig);
}
consumed = true; consumed = true;
} else if(event.event == InputKeyOk) { } else if(event.event == InputKeyOk) {
bad_usb_script_toggle(app->bad_usb_script); bad_usb_script_toggle(app->bad_usb_script);

View File

@ -48,17 +48,13 @@ static void bad_usb_draw_callback(Canvas* canvas, void* _model) {
if((model->state.state == BadUsbStateIdle) || (model->state.state == BadUsbStateDone) || if((model->state.state == BadUsbStateIdle) || (model->state.state == BadUsbStateDone) ||
(model->state.state == BadUsbStateNotConnected)) { (model->state.state == BadUsbStateNotConnected)) {
elements_button_center(canvas, "Run"); elements_button_center(canvas, "Run");
elements_button_left(canvas, "Config");
} else if((model->state.state == BadUsbStateRunning) || (model->state.state == BadUsbStateDelay)) { } else if((model->state.state == BadUsbStateRunning) || (model->state.state == BadUsbStateDelay)) {
elements_button_center(canvas, "Stop"); elements_button_center(canvas, "Stop");
} else if(model->state.state == BadUsbStateWillRun) { } else if(model->state.state == BadUsbStateWillRun) {
elements_button_center(canvas, "Cancel"); elements_button_center(canvas, "Cancel");
} }
if((model->state.state == BadUsbStateNotConnected) ||
(model->state.state == BadUsbStateIdle) || (model->state.state == BadUsbStateDone)) {
elements_button_left(canvas, "Config");
}
if(model->state.state == BadUsbStateNotConnected) { if(model->state.state == BadUsbStateNotConnected) {
canvas_draw_icon(canvas, 4, 26, &I_Clock_18x18); canvas_draw_icon(canvas, 4, 26, &I_Clock_18x18);
canvas_set_font(canvas, FontPrimary); canvas_set_font(canvas, FontPrimary);
@ -203,6 +199,7 @@ void bad_usb_set_layout(BadUsb* bad_usb, const char* layout) {
{ strlcpy(model->layout, layout, MAX_NAME_LEN); }, { strlcpy(model->layout, layout, MAX_NAME_LEN); },
true); true);
} }
void bad_usb_set_state(BadUsb* bad_usb, BadUsbState* st) { void bad_usb_set_state(BadUsb* bad_usb, BadUsbState* st) {
furi_assert(st); furi_assert(st);
with_view_model( with_view_model(
@ -214,3 +211,19 @@ void bad_usb_set_state(BadUsb* bad_usb, BadUsbState* st) {
}, },
true); true);
} }
bool bad_usb_is_idle_state(BadUsb* bad_usb) {
bool is_idle = false;
with_view_model(
bad_usb->view,
BadUsbModel * model,
{
if((model->state.state == BadUsbStateIdle) ||
(model->state.state == BadUsbStateDone) ||
(model->state.state == BadUsbStateNotConnected)) {
is_idle = true;
}
},
false);
return is_idle;
}

View File

@ -19,3 +19,5 @@ void bad_usb_set_file_name(BadUsb* bad_usb, const char* name);
void bad_usb_set_layout(BadUsb* bad_usb, const char* layout); void bad_usb_set_layout(BadUsb* bad_usb, const char* layout);
void bad_usb_set_state(BadUsb* bad_usb, BadUsbState* st); void bad_usb_set_state(BadUsb* bad_usb, BadUsbState* st);
bool bad_usb_is_idle_state(BadUsb* bad_usb);