xremote_scene_ir_remote.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #include "../xremote.h"
  2. typedef enum {
  3. ButtonIndexPlus = -2,
  4. ButtonIndexEdit = -1,
  5. ButtonIndexNA = 0,
  6. } ButtonIndex;
  7. static void
  8. xremote_scene_ir_remote_button_menu_callback(void* context, int32_t index, InputType type) {
  9. XRemote* app = context;
  10. uint16_t custom_type;
  11. if(type == InputTypePress) {
  12. custom_type = XRemoteCustomEventMenuVoid;
  13. } else if(type == InputTypeRelease) {
  14. custom_type = XRemoteCustomEventMenuAddIrSelected;
  15. } else if(type == InputTypeShort) {
  16. custom_type = XRemoteCustomEventMenuVoid;
  17. } else {
  18. furi_crash("Unexpected IR input type");
  19. }
  20. view_dispatcher_send_custom_event(
  21. app->view_dispatcher, xremote_custom_menu_event_pack(custom_type, index));
  22. }
  23. void xremote_scene_ir_remote_on_enter(void* context) {
  24. XRemote* app = context;
  25. ButtonMenu* button_menu = app->button_menu_ir;
  26. size_t button_count = xremote_ir_remote_get_button_count(app->ir_remote_buffer);
  27. for(size_t i = 0; i < button_count; i++) {
  28. InfraredRemoteButton* button = xremote_ir_remote_get_button(app->ir_remote_buffer, i);
  29. button_menu_add_item(
  30. button_menu,
  31. xremote_ir_remote_button_get_name(button),
  32. i,
  33. xremote_scene_ir_remote_button_menu_callback,
  34. ButtonMenuItemTypeCommon,
  35. context);
  36. }
  37. button_menu_set_header(button_menu, "Select Cmd");
  38. const int16_t button_index =
  39. (signed)scene_manager_get_scene_state(app->scene_manager, XRemoteViewIdIrRemote);
  40. button_menu_set_selected_item(button_menu, button_index);
  41. view_dispatcher_switch_to_view(app->view_dispatcher, XRemoteViewIdIrRemote);
  42. }
  43. bool xremote_scene_ir_remote_on_event(void* context, SceneManagerEvent event) {
  44. XRemote* app = context;
  45. bool consumed = false;
  46. if(event.type == SceneManagerEventTypeCustom) {
  47. const uint16_t custom_type = xremote_custom_menu_event_get_type(event.event);
  48. const int16_t button_index = xremote_custom_menu_event_get_value(event.event);
  49. if(custom_type == XRemoteCustomEventMenuAddIrSelected) {
  50. scene_manager_set_scene_state(
  51. app->scene_manager, XRemoteSceneIrRemote, (unsigned)button_index);
  52. InfraredRemoteButton* ir_button =
  53. xremote_ir_remote_get_button(app->ir_remote_buffer, button_index);
  54. const char* button_name = xremote_ir_remote_button_get_name(ir_button);
  55. InfraredSignal* signal = xremote_ir_remote_button_get_signal(ir_button);
  56. xremote_cross_remote_add_ir_item(
  57. app->cross_remote, button_name, signal, app->ir_timing);
  58. scene_manager_next_scene(app->scene_manager, XRemoteSceneCreate);
  59. consumed = true;
  60. }
  61. }
  62. return consumed;
  63. }
  64. void xremote_scene_ir_remote_on_exit(void* context) {
  65. XRemote* app = context;
  66. button_menu_reset(app->button_menu_ir);
  67. }