irda-app-scene-learn-success.cpp 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. #include "../irda-app.hpp"
  2. #include "irda.h"
  3. static void dialog_result_callback(DialogExResult result, void* context) {
  4. auto app = static_cast<IrdaApp*>(context);
  5. IrdaAppEvent event;
  6. event.type = IrdaAppEvent::Type::DialogExSelected;
  7. event.payload.dialog_ex_result = result;
  8. app->get_view_manager()->send_event(&event);
  9. }
  10. void IrdaAppSceneLearnSuccess::on_enter(IrdaApp* app) {
  11. IrdaAppViewManager* view_manager = app->get_view_manager();
  12. DialogEx* dialog_ex = view_manager->get_dialog_ex();
  13. app->notify_green_on();
  14. auto transceiver = app->get_transceiver();
  15. auto message = transceiver->get_last_message();
  16. app->set_text_store(0, "%s", irda_get_protocol_name(message->protocol));
  17. app->set_text_store(
  18. 1,
  19. "A: 0x%0*lX\nC: 0x%0*lX\n",
  20. irda_get_protocol_address_length(message->protocol),
  21. message->address,
  22. irda_get_protocol_command_length(message->protocol),
  23. message->command);
  24. dialog_ex_set_header(dialog_ex, app->get_text_store(0), 95, 10, AlignCenter, AlignCenter);
  25. dialog_ex_set_text(dialog_ex, app->get_text_store(1), 75, 23, AlignLeft, AlignTop);
  26. dialog_ex_set_left_button_text(dialog_ex, "Retry");
  27. dialog_ex_set_right_button_text(dialog_ex, "Save");
  28. dialog_ex_set_center_button_text(dialog_ex, "Send");
  29. dialog_ex_set_icon(dialog_ex, 0, 1, &I_DolphinExcited_64x63);
  30. dialog_ex_set_result_callback(dialog_ex, dialog_result_callback);
  31. dialog_ex_set_context(dialog_ex, app);
  32. view_manager->switch_to(IrdaAppViewManager::ViewType::DialogEx);
  33. }
  34. bool IrdaAppSceneLearnSuccess::on_event(IrdaApp* app, IrdaAppEvent* event) {
  35. bool consumed = false;
  36. if(event->type == IrdaAppEvent::Type::DialogExSelected) {
  37. switch(event->payload.dialog_ex_result) {
  38. case DialogExResultLeft:
  39. app->switch_to_next_scene_without_saving(IrdaApp::Scene::Learn);
  40. break;
  41. case DialogExResultCenter: {
  42. app->notify_space_blink();
  43. auto transceiver = app->get_transceiver();
  44. auto message = transceiver->get_last_message();
  45. irda_send(message, 1);
  46. break;
  47. }
  48. case DialogExResultRight:
  49. auto remote_manager = app->get_remote_manager();
  50. if(remote_manager->check_fs()) {
  51. app->switch_to_next_scene(IrdaApp::Scene::LearnEnterName);
  52. } else {
  53. app->switch_to_previous_scene();
  54. }
  55. break;
  56. }
  57. }
  58. return consumed;
  59. }
  60. void IrdaAppSceneLearnSuccess::on_exit(IrdaApp* app) {
  61. IrdaAppViewManager* view_manager = app->get_view_manager();
  62. DialogEx* dialog_ex = view_manager->get_dialog_ex();
  63. dialog_ex_set_center_button_text(dialog_ex, nullptr);
  64. app->notify_green_off();
  65. }