subghz_scene_receiver_info.c 8.0 KB

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