subghz_scene_receiver_info.c 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. #include "../subghz_i.h"
  2. #include "../helpers/subghz_custom_event.h"
  3. void subghz_scene_receiver_info_callback(GuiButtonType result, InputType type, void* context) {
  4. furi_assert(context);
  5. SubGhz* subghz = context;
  6. if((result == GuiButtonTypeCenter) && (type == InputTypePress)) {
  7. view_dispatcher_send_custom_event(
  8. subghz->view_dispatcher, SubghzCustomEventSceneReceiverInfoTxStart);
  9. } else if((result == GuiButtonTypeCenter) && (type == InputTypeRelease)) {
  10. view_dispatcher_send_custom_event(
  11. subghz->view_dispatcher, SubghzCustomEventSceneReceiverInfoTxStop);
  12. } else if((result == GuiButtonTypeRight) && (type == InputTypeShort)) {
  13. view_dispatcher_send_custom_event(
  14. subghz->view_dispatcher, SubghzCustomEventSceneReceiverInfoSave);
  15. }
  16. }
  17. static bool subghz_scene_receiver_info_update_parser(void* context) {
  18. SubGhz* subghz = context;
  19. subghz->txrx->protocol_result = subghz_parser_get_by_name(
  20. subghz->txrx->parser,
  21. subghz_history_get_name(subghz->txrx->history, subghz->txrx->idx_menu_chosen));
  22. if(subghz->txrx->protocol_result->to_load_protocol != NULL) {
  23. subghz->txrx->protocol_result->to_load_protocol(
  24. subghz->txrx->protocol_result,
  25. subghz_history_get_raw_data(subghz->txrx->history, subghz->txrx->idx_menu_chosen));
  26. subghz->txrx->frequency =
  27. subghz_history_get_frequency(subghz->txrx->history, subghz->txrx->idx_menu_chosen);
  28. subghz->txrx->preset =
  29. subghz_history_get_preset(subghz->txrx->history, subghz->txrx->idx_menu_chosen);
  30. return true;
  31. }
  32. return false;
  33. }
  34. void subghz_scene_receiver_info_on_enter(void* context) {
  35. SubGhz* subghz = context;
  36. if(subghz_scene_receiver_info_update_parser(subghz)) {
  37. string_t frequency_str;
  38. string_t modulation_str;
  39. string_t text;
  40. string_init(frequency_str);
  41. string_init(modulation_str);
  42. string_init(text);
  43. subghz_get_frequency_modulation(subghz, frequency_str, modulation_str);
  44. widget_add_string_element(
  45. subghz->widget,
  46. 78,
  47. 0,
  48. AlignLeft,
  49. AlignTop,
  50. FontSecondary,
  51. string_get_cstr(frequency_str));
  52. widget_add_string_element(
  53. subghz->widget,
  54. 113,
  55. 0,
  56. AlignLeft,
  57. AlignTop,
  58. FontSecondary,
  59. string_get_cstr(modulation_str));
  60. subghz->txrx->protocol_result->to_string(subghz->txrx->protocol_result, text);
  61. widget_add_string_multiline_element(
  62. subghz->widget, 0, 0, AlignLeft, AlignTop, FontSecondary, string_get_cstr(text));
  63. string_clear(frequency_str);
  64. string_clear(modulation_str);
  65. string_clear(text);
  66. if(subghz->txrx->protocol_result && subghz->txrx->protocol_result->to_save_file &&
  67. strcmp(subghz->txrx->protocol_result->name, "KeeLoq")) {
  68. widget_add_button_element(
  69. subghz->widget,
  70. GuiButtonTypeRight,
  71. "Save",
  72. subghz_scene_receiver_info_callback,
  73. subghz);
  74. widget_add_button_element(
  75. subghz->widget,
  76. GuiButtonTypeCenter,
  77. "Send",
  78. subghz_scene_receiver_info_callback,
  79. subghz);
  80. }
  81. } else {
  82. widget_add_icon_element(subghz->widget, 32, 12, &I_DolphinFirstStart7_61x51);
  83. widget_add_string_element(
  84. subghz->widget, 13, 8, AlignLeft, AlignBottom, FontSecondary, "Error history parse.");
  85. }
  86. view_dispatcher_switch_to_view(subghz->view_dispatcher, SubGhzViewWidget);
  87. }
  88. bool subghz_scene_receiver_info_on_event(void* context, SceneManagerEvent event) {
  89. SubGhz* subghz = context;
  90. if(event.type == SceneManagerEventTypeCustom) {
  91. if(event.event == SubghzCustomEventSceneReceiverInfoTxStart) {
  92. //CC1101 Stop RX -> Start TX
  93. if(subghz->txrx->hopper_state != SubGhzHopperStateOFF) {
  94. subghz->txrx->hopper_state = SubGhzHopperStatePause;
  95. }
  96. if(subghz->txrx->txrx_state == SubGhzTxRxStateRx) {
  97. subghz_rx_end(subghz);
  98. }
  99. if(!subghz_scene_receiver_info_update_parser(subghz)) {
  100. return false;
  101. }
  102. if(subghz->txrx->txrx_state == SubGhzTxRxStateIDLE ||
  103. subghz->txrx->txrx_state == SubGhzTxRxStateSleep) {
  104. if(!subghz_tx_start(subghz)) {
  105. scene_manager_next_scene(subghz->scene_manager, SubGhzSceneShowOnlyRx);
  106. } else {
  107. subghz->state_notifications = SubGhzNotificationStateTX;
  108. }
  109. }
  110. return true;
  111. } else if(event.event == SubghzCustomEventSceneReceiverInfoTxStop) {
  112. //CC1101 Stop Tx -> Start RX
  113. subghz->state_notifications = SubGhzNotificationStateIDLE;
  114. if(subghz->txrx->txrx_state == SubGhzTxRxStateTx) {
  115. subghz_tx_stop(subghz);
  116. }
  117. if(subghz->txrx->txrx_state == SubGhzTxRxStateIDLE) {
  118. subghz_begin(subghz, subghz->txrx->preset);
  119. subghz_rx(subghz, subghz->txrx->frequency);
  120. }
  121. if(subghz->txrx->hopper_state == SubGhzHopperStatePause) {
  122. subghz->txrx->hopper_state = SubGhzHopperStateRunnig;
  123. }
  124. subghz->state_notifications = SubGhzNotificationStateRX;
  125. return true;
  126. } else if(event.event == SubghzCustomEventSceneReceiverInfoSave) {
  127. //CC1101 Stop RX -> Save
  128. subghz->state_notifications = SubGhzNotificationStateIDLE;
  129. if(subghz->txrx->hopper_state != SubGhzHopperStateOFF) {
  130. subghz->txrx->hopper_state = SubGhzHopperStateOFF;
  131. }
  132. if(subghz->txrx->txrx_state == SubGhzTxRxStateRx) {
  133. subghz_rx_end(subghz);
  134. subghz_sleep(subghz);
  135. }
  136. if(!subghz_scene_receiver_info_update_parser(subghz)) {
  137. return false;
  138. }
  139. if(subghz->txrx->protocol_result && subghz->txrx->protocol_result->to_save_file &&
  140. strcmp(subghz->txrx->protocol_result->name, "KeeLoq")) {
  141. subghz_file_name_clear(subghz);
  142. scene_manager_next_scene(subghz->scene_manager, SubGhzSceneSaveName);
  143. }
  144. return true;
  145. }
  146. } else if(event.type == SceneManagerEventTypeTick) {
  147. if(subghz->txrx->hopper_state != SubGhzHopperStateOFF) {
  148. subghz_hopper_update(subghz);
  149. }
  150. switch(subghz->state_notifications) {
  151. case SubGhzNotificationStateTX:
  152. notification_message(subghz->notifications, &sequence_blink_red_10);
  153. break;
  154. case SubGhzNotificationStateRX:
  155. notification_message(subghz->notifications, &sequence_blink_blue_10);
  156. break;
  157. default:
  158. break;
  159. }
  160. }
  161. return false;
  162. }
  163. void subghz_scene_receiver_info_on_exit(void* context) {
  164. SubGhz* subghz = context;
  165. widget_clear(subghz->widget);
  166. }