irda-app-scene-universal-common.cpp 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. #include "../irda-app.hpp"
  2. #include "assets_icons.h"
  3. #include "gui/modules/button_menu.h"
  4. #include "gui/modules/button_panel.h"
  5. #include "../view/irda-app-brut-view.h"
  6. #include "gui/view.h"
  7. #include "irda/irda-app-view-manager.hpp"
  8. #include "irda/scene/irda-app-scene.hpp"
  9. void IrdaAppSceneUniversalCommon::irda_app_item_callback(void* context, uint32_t index) {
  10. IrdaApp* app = static_cast<IrdaApp*>(context);
  11. IrdaAppEvent event;
  12. event.type = IrdaAppEvent::Type::ButtonPanelPressed;
  13. event.payload.menu_index = index;
  14. app->get_view_manager()->send_event(&event);
  15. }
  16. static bool irda_popup_brut_input_callback(InputEvent* event, void* context) {
  17. furi_assert(context);
  18. furi_assert(event);
  19. auto app = static_cast<IrdaApp*>(context);
  20. bool consumed = false;
  21. if((event->type == InputTypeShort) && (event->key == InputKeyBack)) {
  22. consumed = true;
  23. IrdaAppEvent irda_event;
  24. irda_event.type = IrdaAppEvent::Type::ButtonPanelPopupBackPressed;
  25. app->get_view_manager()->send_event(&irda_event);
  26. }
  27. return consumed;
  28. }
  29. void IrdaAppSceneUniversalCommon::remove_popup(IrdaApp* app) {
  30. auto button_panel = app->get_view_manager()->get_button_panel();
  31. button_panel_set_popup_draw_callback(button_panel, NULL, NULL);
  32. button_panel_set_popup_input_callback(button_panel, NULL, NULL);
  33. }
  34. void IrdaAppSceneUniversalCommon::show_popup(IrdaApp* app, int record_amount) {
  35. auto button_panel = app->get_view_manager()->get_button_panel();
  36. auto popup_brut = app->get_view_manager()->get_popup_brut();
  37. popup_brut_set_progress_max(popup_brut, record_amount);
  38. button_panel_set_popup_draw_callback(button_panel, popup_brut_draw_callback, popup_brut);
  39. button_panel_set_popup_input_callback(button_panel, irda_popup_brut_input_callback, app);
  40. }
  41. void IrdaAppSceneUniversalCommon::progress_popup(IrdaApp* app) {
  42. popup_brut_increase_progress(app->get_view_manager()->get_popup_brut());
  43. auto button_panel = app->get_view_manager()->get_button_panel();
  44. with_view_model_cpp(button_panel_get_view(button_panel), void*, model, { return true; });
  45. }
  46. bool IrdaAppSceneUniversalCommon::on_event(IrdaApp* app, IrdaAppEvent* event) {
  47. bool consumed = false;
  48. if(event->type == IrdaAppEvent::Type::Tick) {
  49. if(brute_force_started) {
  50. if(brute_force.send_next_bruteforce(*app->get_transceiver())) {
  51. progress_popup(app);
  52. } else {
  53. brute_force.stop_bruteforce();
  54. brute_force_started = false;
  55. remove_popup(app);
  56. }
  57. }
  58. consumed = true;
  59. }
  60. if(event->type == IrdaAppEvent::Type::ButtonPanelPopupBackPressed) {
  61. consumed = true;
  62. brute_force_started = false;
  63. brute_force.stop_bruteforce();
  64. remove_popup(app);
  65. } else if(event->type == IrdaAppEvent::Type::ButtonPanelPressed) {
  66. int record_amount = 0;
  67. if(brute_force.start_bruteforce(event->payload.menu_index, record_amount)) {
  68. if(record_amount > 0) {
  69. brute_force_started = true;
  70. show_popup(app, record_amount);
  71. }
  72. } else {
  73. app->switch_to_previous_scene();
  74. }
  75. consumed = true;
  76. }
  77. return consumed;
  78. }
  79. void IrdaAppSceneUniversalCommon::on_exit(IrdaApp* app) {
  80. IrdaAppViewManager* view_manager = app->get_view_manager();
  81. ButtonPanel* button_panel = view_manager->get_button_panel();
  82. button_panel_clean(button_panel);
  83. }