subghz_scene_receiver_info.c 7.9 KB

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