app.c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. // 2.2 attach view dispatcher to gui
  22. view_dispatcher_attach_to_gui(app->view_dispatcher, app->gui, ViewDispatcherTypeFullscreen);
  23. // 2.3 attach views to the dispatcher
  24. // helloworld view
  25. app->helloworld_view = countdown_timer_view_new();
  26. register_view(app->view_dispatcher, countdown_timer_view_get_view(app->helloworld_view), 0xff);
  27. // 2.5 switch to default view
  28. view_dispatcher_switch_to_view(app->view_dispatcher, 0xff);
  29. return app;
  30. }
  31. void countdown_app_delete(CountDownTimerApp* app) {
  32. furi_assert(app);
  33. // delete views
  34. view_dispatcher_remove_view(app->view_dispatcher, 0xff);
  35. countdown_timer_view_delete(app->helloworld_view); // hello world view
  36. // delete view dispatcher
  37. view_dispatcher_free(app->view_dispatcher);
  38. furi_record_close(RECORD_GUI);
  39. // self
  40. free(app);
  41. }
  42. void countdown_app_run(CountDownTimerApp* app) {
  43. view_dispatcher_run(app->view_dispatcher);
  44. }
  45. static void register_view(ViewDispatcher* dispatcher, View* view, uint32_t viewid) {
  46. view_dispatcher_add_view(dispatcher, viewid, view);
  47. view_set_previous_callback(view, view_exit);
  48. }