bad_usb_scene_work.c 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. #include "m-string.h"
  6. #include "toolbox/path.h"
  7. void bad_usb_scene_work_ok_callback(InputType type, void* context) {
  8. furi_assert(context);
  9. BadUsbApp* app = context;
  10. view_dispatcher_send_custom_event(app->view_dispatcher, type);
  11. }
  12. bool bad_usb_scene_work_on_event(void* context, SceneManagerEvent event) {
  13. BadUsbApp* app = context;
  14. bool consumed = false;
  15. if(event.type == SceneManagerEventTypeCustom) {
  16. bad_usb_script_toggle(app->bad_usb_script);
  17. consumed = true;
  18. } else if(event.type == SceneManagerEventTypeTick) {
  19. bad_usb_set_state(app->bad_usb_view, bad_usb_script_get_state(app->bad_usb_script));
  20. }
  21. return consumed;
  22. }
  23. void bad_usb_scene_work_on_enter(void* context) {
  24. BadUsbApp* app = context;
  25. string_t file_name;
  26. string_init(file_name);
  27. path_extract_filename(app->file_path, file_name, true);
  28. bad_usb_set_file_name(app->bad_usb_view, string_get_cstr(file_name));
  29. app->bad_usb_script = bad_usb_script_open(app->file_path);
  30. string_clear(file_name);
  31. bad_usb_set_state(app->bad_usb_view, bad_usb_script_get_state(app->bad_usb_script));
  32. bad_usb_set_ok_callback(app->bad_usb_view, bad_usb_scene_work_ok_callback, app);
  33. view_dispatcher_switch_to_view(app->view_dispatcher, BadUsbAppViewWork);
  34. }
  35. void bad_usb_scene_work_on_exit(void* context) {
  36. BadUsbApp* app = context;
  37. bad_usb_script_close(app->bad_usb_script);
  38. }