bad_usb_scene_work.c 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #include "../bad_usb_script.h"
  2. #include "../bad_usb_app_i.h"
  3. #include "../views/bad_usb_view.h"
  4. #include "furi_hal.h"
  5. void bad_usb_scene_work_ok_callback(InputType type, void* context) {
  6. furi_assert(context);
  7. BadUsbApp* app = context;
  8. view_dispatcher_send_custom_event(app->view_dispatcher, type);
  9. }
  10. bool bad_usb_scene_work_on_event(void* context, SceneManagerEvent event) {
  11. BadUsbApp* app = context;
  12. bool consumed = false;
  13. if(event.type == SceneManagerEventTypeCustom) {
  14. bad_usb_script_toggle(app->bad_usb_script);
  15. consumed = true;
  16. } else if(event.type == SceneManagerEventTypeTick) {
  17. bad_usb_set_state(app->bad_usb_view, bad_usb_script_get_state(app->bad_usb_script));
  18. }
  19. return consumed;
  20. }
  21. void bad_usb_scene_work_on_enter(void* context) {
  22. BadUsbApp* app = context;
  23. string_t file_name;
  24. string_init(file_name);
  25. bad_usb_set_file_name(app->bad_usb_view, app->file_name);
  26. string_printf(
  27. file_name, "%s/%s%s", BAD_USB_APP_PATH_FOLDER, app->file_name, BAD_USB_APP_EXTENSION);
  28. app->bad_usb_script = bad_usb_script_open(file_name);
  29. string_clear(file_name);
  30. bad_usb_set_state(app->bad_usb_view, bad_usb_script_get_state(app->bad_usb_script));
  31. bad_usb_set_ok_callback(app->bad_usb_view, bad_usb_scene_work_ok_callback, app);
  32. view_dispatcher_switch_to_view(app->view_dispatcher, BadUsbAppViewWork);
  33. }
  34. void bad_usb_scene_work_on_exit(void* context) {
  35. BadUsbApp* app = context;
  36. bad_usb_script_close(app->bad_usb_script);
  37. }