Merge branch 'fz-dev' into dev

This commit is contained in:
MX 2022-11-03 16:56:15 +03:00
commit d92212f0ea
No known key found for this signature in database
GPG Key ID: 6C4C311DFD4B4AB5
3 changed files with 40 additions and 2 deletions

View File

@ -533,12 +533,16 @@ static int32_t bad_usb_worker(void* context) {
} else if(worker_state == BadUsbStateNotConnected) { // State: USB not connected } else if(worker_state == BadUsbStateNotConnected) { // State: USB not connected
uint32_t flags = furi_thread_flags_wait( uint32_t flags = furi_thread_flags_wait(
WorkerEvtEnd | WorkerEvtConnect, FuriFlagWaitAny, FuriWaitForever); WorkerEvtEnd | WorkerEvtConnect | WorkerEvtToggle,
FuriFlagWaitAny,
FuriWaitForever);
furi_check((flags & FuriFlagError) == 0); furi_check((flags & FuriFlagError) == 0);
if(flags & WorkerEvtEnd) { if(flags & WorkerEvtEnd) {
break; break;
} else if(flags & WorkerEvtConnect) { } else if(flags & WorkerEvtConnect) {
worker_state = BadUsbStateIdle; // Ready to run worker_state = BadUsbStateIdle; // Ready to run
} else if(flags & WorkerEvtToggle) {
worker_state = BadUsbStateWillRun; // Will run when USB is connected
} }
bad_usb->st.state = worker_state; bad_usb->st.state = worker_state;
@ -565,6 +569,31 @@ static int32_t bad_usb_worker(void* context) {
} }
bad_usb->st.state = worker_state; bad_usb->st.state = worker_state;
} else if(worker_state == BadUsbStateWillRun) { // State: start on connection
uint32_t flags = furi_thread_flags_wait(
WorkerEvtEnd | WorkerEvtConnect | WorkerEvtToggle,
FuriFlagWaitAny,
FuriWaitForever);
furi_check((flags & FuriFlagError) == 0);
if(flags & WorkerEvtEnd) {
break;
} else if(flags & WorkerEvtConnect) { // Start executing script
DOLPHIN_DEED(DolphinDeedBadUsbPlayScript);
delay_val = 0;
bad_usb->buf_len = 0;
bad_usb->st.line_cur = 0;
bad_usb->defdelay = 0;
bad_usb->repeat_cnt = 0;
bad_usb->file_end = false;
storage_file_seek(script_file, 0, true);
// extra time for PC to recognize Flipper as keyboard
furi_thread_flags_wait(0, FuriFlagWaitAny, 1500);
worker_state = BadUsbStateRunning;
} else if(flags & WorkerEvtToggle) { // Cancel scheduled execution
worker_state = BadUsbStateNotConnected;
}
bad_usb->st.state = worker_state;
} else if(worker_state == BadUsbStateRunning) { // State: running } else if(worker_state == BadUsbStateRunning) { // State: running
uint16_t delay_cur = (delay_val > 1000) ? (1000) : (delay_val); uint16_t delay_cur = (delay_val > 1000) ? (1000) : (delay_val);
uint32_t flags = furi_thread_flags_wait( uint32_t flags = furi_thread_flags_wait(

View File

@ -12,6 +12,7 @@ typedef enum {
BadUsbStateInit, BadUsbStateInit,
BadUsbStateNotConnected, BadUsbStateNotConnected,
BadUsbStateIdle, BadUsbStateIdle,
BadUsbStateWillRun,
BadUsbStateRunning, BadUsbStateRunning,
BadUsbStateDelay, BadUsbStateDelay,
BadUsbStateDone, BadUsbStateDone,

View File

@ -45,10 +45,13 @@ static void bad_usb_draw_callback(Canvas* canvas, void* _model) {
canvas_draw_icon(canvas, 22, 24, &I_UsbTree_48x22); canvas_draw_icon(canvas, 22, 24, &I_UsbTree_48x22);
if((model->state.state == BadUsbStateIdle) || (model->state.state == BadUsbStateDone)) { if((model->state.state == BadUsbStateIdle) || (model->state.state == BadUsbStateDone) ||
(model->state.state == BadUsbStateNotConnected)) {
elements_button_center(canvas, "Run"); elements_button_center(canvas, "Run");
} 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) {
elements_button_center(canvas, "Cancel");
} }
if((model->state.state == BadUsbStateNotConnected) || if((model->state.state == BadUsbStateNotConnected) ||
@ -61,6 +64,11 @@ static void bad_usb_draw_callback(Canvas* canvas, void* _model) {
canvas_set_font(canvas, FontPrimary); canvas_set_font(canvas, FontPrimary);
canvas_draw_str_aligned(canvas, 127, 31, AlignRight, AlignBottom, "Connect"); canvas_draw_str_aligned(canvas, 127, 31, AlignRight, AlignBottom, "Connect");
canvas_draw_str_aligned(canvas, 127, 43, AlignRight, AlignBottom, "to USB"); canvas_draw_str_aligned(canvas, 127, 43, AlignRight, AlignBottom, "to USB");
} else if(model->state.state == BadUsbStateWillRun) {
canvas_draw_icon(canvas, 4, 22, &I_Clock_18x18);
canvas_set_font(canvas, FontPrimary);
canvas_draw_str_aligned(canvas, 127, 27, AlignRight, AlignBottom, "Will run");
canvas_draw_str_aligned(canvas, 127, 39, AlignRight, AlignBottom, "on connect");
} else if(model->state.state == BadUsbStateFileError) { } else if(model->state.state == BadUsbStateFileError) {
canvas_draw_icon(canvas, 4, 26, &I_Error_18x18); canvas_draw_icon(canvas, 4, 26, &I_Error_18x18);
canvas_set_font(canvas, FontPrimary); canvas_set_font(canvas, FontPrimary);