hex_viewer_scene_startscreen.c 3.4 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(app->hex_viewer_startscreen, hex_viewer_scene_startscreen_callback, app);
  13. view_dispatcher_switch_to_view(app->view_dispatcher, HexViewerViewIdStartscreen);
  14. }
  15. bool hex_viewer_scene_startscreen_on_event(void* context, SceneManagerEvent event) {
  16. HexViewer* app = context;
  17. bool consumed = false;
  18. if(event.type == SceneManagerEventTypeCustom) {
  19. switch(event.event) {
  20. case HexViewerCustomEventStartscreenLeft:
  21. app->model->mode = !app->model->mode;
  22. consumed = true;
  23. break;
  24. case HexViewerCustomEventStartscreenRight:
  25. // TODO Dialog
  26. consumed = true;
  27. break;
  28. case HexViewerCustomEventStartscreenUp:
  29. //furi_check(furi_mutex_acquire(hex_viewer->mutex, FuriWaitForever) == FuriStatusOk);
  30. if(app->model->file_offset > 0) {
  31. app->model->file_offset -= HEX_VIEWER_BYTES_PER_LINE;
  32. if(!hex_viewer_read_file(app)) break;
  33. }
  34. consumed = true;
  35. //furi_mutex_release(hex_viewer->mutex);
  36. break;
  37. case HexViewerCustomEventStartscreenDown:
  38. {
  39. //furi_check(furi_mutex_acquire(hex_viewer->mutex, FuriWaitForever) == FuriStatusOk);
  40. uint32_t last_byte_on_screen =
  41. 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. }
  50. case HexViewerCustomEventStartscreenOk:
  51. if (!app->model->file_size) // TODO
  52. scene_manager_next_scene(app->scene_manager, HexViewerSceneScene_4);
  53. else 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. }