subghz_scene_receiver_info.c 7.7 KB

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