irda-app-scene-learn-enter-name.cpp 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #include "../irda-app.hpp"
  2. #include "gui/modules/text_input.h"
  3. void IrdaAppSceneLearnEnterName::on_enter(IrdaApp* app) {
  4. IrdaAppViewManager* view_manager = app->get_view_manager();
  5. TextInput* text_input = view_manager->get_text_input();
  6. auto signal = app->get_received_signal();
  7. if(!signal.is_raw()) {
  8. auto message = &signal.get_message();
  9. app->set_text_store(
  10. 0,
  11. "%.4s_%0*lX",
  12. irda_get_protocol_name(message->protocol),
  13. irda_get_protocol_command_length(message->protocol),
  14. message->command);
  15. } else {
  16. auto raw_signal = signal.get_raw_signal();
  17. app->set_text_store(0, "RAW_%d", raw_signal.timings_cnt);
  18. }
  19. text_input_set_header_text(text_input, "Name the key");
  20. text_input_set_result_callback(
  21. text_input,
  22. IrdaApp::text_input_callback,
  23. app,
  24. app->get_text_store(0),
  25. app->get_text_store_size());
  26. view_manager->switch_to(IrdaAppViewManager::ViewType::TextInput);
  27. }
  28. bool IrdaAppSceneLearnEnterName::on_event(IrdaApp* app, IrdaAppEvent* event) {
  29. bool consumed = false;
  30. if(event->type == IrdaAppEvent::Type::TextEditDone) {
  31. auto remote_manager = app->get_remote_manager();
  32. bool result = false;
  33. if(app->get_learn_new_remote()) {
  34. result = remote_manager->add_remote_with_button(
  35. app->get_text_store(0), app->get_received_signal());
  36. } else {
  37. result =
  38. remote_manager->add_button(app->get_text_store(0), app->get_received_signal());
  39. }
  40. if(!result) {
  41. app->search_and_switch_to_previous_scene(
  42. {IrdaApp::Scene::Start, IrdaApp::Scene::RemoteList});
  43. } else {
  44. app->switch_to_next_scene_without_saving(IrdaApp::Scene::LearnDone);
  45. }
  46. }
  47. return consumed;
  48. }
  49. void IrdaAppSceneLearnEnterName::on_exit(IrdaApp* app) {
  50. }