hex_viewer_scene_startscreen.c 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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 = !hex_viewer->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. //furi_check(furi_mutex_acquire(hex_viewer->mutex, FuriWaitForever) == FuriStatusOk);
  39. uint32_t last_byte_on_screen =
  40. app->model->file_offset + app->model->file_read_bytes;
  41. if(app->model->file_size > last_byte_on_screen) {
  42. app->model->file_offset += HEX_VIEWER_BYTES_PER_LINE;
  43. if(!hex_viewer_read_file(app)) break; // TODO Do smth
  44. }
  45. consumed = true;
  46. //furi_mutex_release(hex_viewer->mutex);
  47. break;
  48. case HexViewerCustomEventStartscreenOk:
  49. if (!app->model->file_size) // TODO
  50. scene_manager_next_scene(app->scene_manager, HexViewerSceneScene_4);
  51. else scene_manager_next_scene(app->scene_manager, HexViewerSceneMenu);
  52. consumed = true;
  53. break;
  54. case HexViewerCustomEventStartscreenBack: // TODO DElete
  55. notification_message(app->notification, &sequence_reset_red);
  56. notification_message(app->notification, &sequence_reset_green);
  57. notification_message(app->notification, &sequence_reset_blue);
  58. if(!scene_manager_search_and_switch_to_previous_scene(
  59. app->scene_manager, HexViewerSceneStartscreen)) {
  60. scene_manager_stop(app->scene_manager);
  61. view_dispatcher_stop(app->view_dispatcher);
  62. }
  63. consumed = true;
  64. break;
  65. }
  66. }
  67. return consumed;
  68. }
  69. void hex_viewer_scene_startscreen_on_exit(void* context) {
  70. HexViewer* app = context;
  71. UNUSED(app);
  72. }