hex_viewer_scene_startscreen.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #include "../hex_viewer.h"
  2. #include "../helpers/hex_viewer_custom_event.h"
  3. #include "../views/hex_viewer_startscreen.h"
  4. void hex_viewer_scene_startscreen_callback(HexViewerCustomEvent event, void* context) {
  5. furi_assert(context);
  6. HexViewer* app = context;
  7. view_dispatcher_send_custom_event(app->view_dispatcher, event);
  8. }
  9. void hex_viewer_scene_startscreen_on_enter(void* context) {
  10. furi_assert(context);
  11. HexViewer* app = context;
  12. hex_viewer_startscreen_set_callback(
  13. app->hex_viewer_startscreen, hex_viewer_scene_startscreen_callback, app);
  14. view_dispatcher_switch_to_view(app->view_dispatcher, HexViewerViewIdStartscreen);
  15. }
  16. bool hex_viewer_scene_startscreen_on_event(void* context, SceneManagerEvent event) {
  17. HexViewer* app = context;
  18. bool consumed = false;
  19. uint32_t last_byte_on_screen;
  20. if(event.type == SceneManagerEventTypeCustom) {
  21. switch(event.event) {
  22. case HexViewerCustomEventStartscreenLeft:
  23. //app->model->mode = !app->model->mode;
  24. consumed = true;
  25. break;
  26. case HexViewerCustomEventStartscreenRight:
  27. // TODO Dialog
  28. consumed = true;
  29. break;
  30. case HexViewerCustomEventStartscreenUp:
  31. //furi_check(furi_mutex_acquire(hex_viewer->mutex, FuriWaitForever) == FuriStatusOk);
  32. if(app->model->file_offset > 0) {
  33. app->model->file_offset -= HEX_VIEWER_BYTES_PER_LINE;
  34. if(!hex_viewer_read_file(app)) break; // TODO Do smth
  35. }
  36. consumed = true;
  37. //furi_mutex_release(hex_viewer->mutex);
  38. break;
  39. case HexViewerCustomEventStartscreenDown:
  40. //furi_check(furi_mutex_acquire(hex_viewer->mutex, FuriWaitForever) == FuriStatusOk);
  41. last_byte_on_screen = app->model->file_offset + app->model->file_read_bytes;
  42. if(app->model->file_size > last_byte_on_screen) {
  43. app->model->file_offset += HEX_VIEWER_BYTES_PER_LINE;
  44. if(!hex_viewer_read_file(app)) break; // TODO Do smth
  45. }
  46. consumed = true;
  47. //furi_mutex_release(hex_viewer->mutex);
  48. break;
  49. case HexViewerCustomEventStartscreenOk:
  50. if(!app->model->file_size) // TODO
  51. scene_manager_next_scene(app->scene_manager, HexViewerSceneScene_4);
  52. else
  53. scene_manager_next_scene(app->scene_manager, HexViewerSceneMenu);
  54. consumed = true;
  55. break;
  56. case HexViewerCustomEventStartscreenBack: // TODO Delete
  57. notification_message(app->notification, &sequence_reset_red);
  58. notification_message(app->notification, &sequence_reset_green);
  59. notification_message(app->notification, &sequence_reset_blue);
  60. if(!scene_manager_search_and_switch_to_previous_scene(
  61. app->scene_manager, HexViewerSceneStartscreen)) {
  62. scene_manager_stop(app->scene_manager);
  63. view_dispatcher_stop(app->view_dispatcher);
  64. }
  65. consumed = true;
  66. break;
  67. }
  68. }
  69. return consumed;
  70. }
  71. void hex_viewer_scene_startscreen_on_exit(void* context) {
  72. HexViewer* app = context;
  73. UNUSED(app);
  74. }