app.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #include "views/countdown_view.h"
  2. #include "app.h"
  3. static void register_view(ViewDispatcher* dispatcher, View* view, uint32_t viewid);
  4. int32_t app_main(void* p) {
  5. UNUSED(p);
  6. CountDownTimerApp* app = countdown_app_new();
  7. countdown_app_run(app);
  8. countdown_app_delete(app);
  9. return 0;
  10. }
  11. static uint32_t view_exit(void* ctx) {
  12. furi_assert(ctx);
  13. return VIEW_NONE;
  14. }
  15. CountDownTimerApp* countdown_app_new(void) {
  16. CountDownTimerApp* app = (CountDownTimerApp*)(malloc(sizeof(CountDownTimerApp)));
  17. // 1.1 open gui
  18. app->gui = furi_record_open(RECORD_GUI);
  19. // 2.1 setup view dispatcher
  20. app->view_dispatcher = view_dispatcher_alloc();
  21. view_dispatcher_enable_queue(app->view_dispatcher);
  22. // 2.2 attach view dispatcher to gui
  23. view_dispatcher_attach_to_gui(app->view_dispatcher, app->gui, ViewDispatcherTypeFullscreen);
  24. // 2.3 attach views to the dispatcher
  25. // helloworld view
  26. app->helloworld_view = countdown_timer_view_new();
  27. register_view(app->view_dispatcher, countdown_timer_view_get_view(app->helloworld_view), 0xff);
  28. // 2.5 switch to default view
  29. view_dispatcher_switch_to_view(app->view_dispatcher, 0xff);
  30. return app;
  31. }
  32. void countdown_app_delete(CountDownTimerApp* app) {
  33. furi_assert(app);
  34. // delete views
  35. view_dispatcher_remove_view(app->view_dispatcher, 0xff);
  36. countdown_timer_view_delete(app->helloworld_view); // hello world view
  37. // delete view dispatcher
  38. view_dispatcher_free(app->view_dispatcher);
  39. furi_record_close(RECORD_GUI);
  40. // self
  41. free(app);
  42. }
  43. void countdown_app_run(CountDownTimerApp* app) {
  44. view_dispatcher_run(app->view_dispatcher);
  45. }
  46. static void register_view(ViewDispatcher* dispatcher, View* view, uint32_t viewid) {
  47. view_dispatcher_add_view(dispatcher, viewid, view);
  48. view_set_previous_callback(view, view_exit);
  49. }