bad_usb_scene_error.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #include "../bad_usb_app_i.h"
  2. typedef enum {
  3. BadUsbCustomEventErrorBack,
  4. } BadUsbCustomEvent;
  5. static void
  6. bad_usb_scene_error_event_callback(GuiButtonType result, InputType type, void* context) {
  7. furi_assert(context);
  8. BadUsbApp* app = context;
  9. if((result == GuiButtonTypeLeft) && (type == InputTypeShort)) {
  10. view_dispatcher_send_custom_event(app->view_dispatcher, BadUsbCustomEventErrorBack);
  11. }
  12. }
  13. void bad_usb_scene_error_on_enter(void* context) {
  14. BadUsbApp* app = context;
  15. if(app->error == BadUsbAppErrorNoFiles) {
  16. widget_add_icon_element(app->widget, 0, 0, &I_SDQuestion_35x43);
  17. widget_add_string_multiline_element(
  18. app->widget,
  19. 81,
  20. 4,
  21. AlignCenter,
  22. AlignTop,
  23. FontSecondary,
  24. "No SD card or\napp data found.\nThis app will not\nwork without\nrequired files.");
  25. } else if(app->error == BadUsbAppErrorCloseRpc) {
  26. widget_add_string_multiline_element(
  27. app->widget,
  28. 63,
  29. 10,
  30. AlignCenter,
  31. AlignTop,
  32. FontSecondary,
  33. "Disconnect from\ncompanion app\nto use this function");
  34. }
  35. widget_add_button_element(
  36. app->widget, GuiButtonTypeLeft, "Back", bad_usb_scene_error_event_callback, app);
  37. view_dispatcher_switch_to_view(app->view_dispatcher, BadUsbAppViewError);
  38. }
  39. bool bad_usb_scene_error_on_event(void* context, SceneManagerEvent event) {
  40. BadUsbApp* app = context;
  41. bool consumed = false;
  42. if(event.type == SceneManagerEventTypeCustom) {
  43. if(event.event == BadUsbCustomEventErrorBack) {
  44. view_dispatcher_stop(app->view_dispatcher);
  45. consumed = true;
  46. }
  47. }
  48. return consumed;
  49. }
  50. void bad_usb_scene_error_on_exit(void* context) {
  51. BadUsbApp* app = context;
  52. widget_reset(app->widget);
  53. }