infrared_app_scene_universal_tv.cpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. #include <stdint.h>
  2. #include <gui/modules/loading.h>
  3. #include <gui/view_stack.h>
  4. #include "infrared/scene/infrared_app_scene.h"
  5. #include "infrared/infrared_app.h"
  6. void InfraredAppSceneUniversalTV::on_enter(InfraredApp* app) {
  7. InfraredAppViewManager* view_manager = app->get_view_manager();
  8. ButtonPanel* button_panel = view_manager->get_button_panel();
  9. button_panel_reserve(button_panel, 2, 3);
  10. int i = 0;
  11. button_panel_add_item(
  12. button_panel,
  13. i,
  14. 0,
  15. 0,
  16. 3,
  17. 19,
  18. &I_Power_25x27,
  19. &I_Power_hvr_25x27,
  20. infrared_app_item_callback,
  21. app);
  22. brute_force.add_record(i, "POWER");
  23. ++i;
  24. button_panel_add_item(
  25. button_panel,
  26. i,
  27. 1,
  28. 0,
  29. 36,
  30. 19,
  31. &I_Mute_25x27,
  32. &I_Mute_hvr_25x27,
  33. infrared_app_item_callback,
  34. app);
  35. brute_force.add_record(i, "MUTE");
  36. ++i;
  37. button_panel_add_item(
  38. button_panel,
  39. i,
  40. 0,
  41. 1,
  42. 3,
  43. 66,
  44. &I_Vol_up_25x27,
  45. &I_Vol_up_hvr_25x27,
  46. infrared_app_item_callback,
  47. app);
  48. brute_force.add_record(i, "VOL+");
  49. ++i;
  50. button_panel_add_item(
  51. button_panel,
  52. i,
  53. 1,
  54. 1,
  55. 36,
  56. 66,
  57. &I_Up_25x27,
  58. &I_Up_hvr_25x27,
  59. infrared_app_item_callback,
  60. app);
  61. brute_force.add_record(i, "CH+");
  62. ++i;
  63. button_panel_add_item(
  64. button_panel,
  65. i,
  66. 0,
  67. 2,
  68. 3,
  69. 98,
  70. &I_Vol_down_25x27,
  71. &I_Vol_down_hvr_25x27,
  72. infrared_app_item_callback,
  73. app);
  74. brute_force.add_record(i, "VOL-");
  75. ++i;
  76. button_panel_add_item(
  77. button_panel,
  78. i,
  79. 1,
  80. 2,
  81. 36,
  82. 98,
  83. &I_Down_25x27,
  84. &I_Down_hvr_25x27,
  85. infrared_app_item_callback,
  86. app);
  87. brute_force.add_record(i, "CH-");
  88. button_panel_add_label(button_panel, 6, 11, FontPrimary, "TV remote");
  89. button_panel_add_label(button_panel, 9, 64, FontSecondary, "Vol");
  90. button_panel_add_label(button_panel, 43, 64, FontSecondary, "Ch");
  91. view_manager->switch_to(InfraredAppViewManager::ViewId::UniversalRemote);
  92. auto stack_view = app->get_view_manager()->get_universal_view_stack();
  93. auto loading_view = app->get_view_manager()->get_loading();
  94. view_stack_add_view(stack_view, loading_get_view(loading_view));
  95. /**
  96. * Problem: Update events are not handled in Loading View, because:
  97. * 1) Timer task has least prio
  98. * 2) Storage service uses drivers that capture whole CPU time
  99. * to handle SD communication
  100. *
  101. * Ugly workaround, but it works for current situation:
  102. * raise timer task prio for DB scanning period.
  103. */
  104. TaskHandle_t timer_task = xTaskGetHandle(configTIMER_SERVICE_TASK_NAME);
  105. TaskHandle_t storage_task = xTaskGetHandle("StorageSrv");
  106. uint32_t timer_prio = uxTaskPriorityGet(timer_task);
  107. uint32_t storage_prio = uxTaskPriorityGet(storage_task);
  108. vTaskPrioritySet(timer_task, storage_prio + 1);
  109. bool result = brute_force.calculate_messages();
  110. vTaskPrioritySet(timer_task, timer_prio);
  111. view_stack_remove_view(stack_view, loading_get_view(loading_view));
  112. if(!result) {
  113. app->switch_to_previous_scene();
  114. }
  115. }