subghz_scene_receiver_info.c 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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->protocol_result = subghz_parser_get_by_name(
  21. subghz->txrx->parser,
  22. subghz_history_get_name(subghz->txrx->history, subghz->txrx->idx_menu_chosen));
  23. if(subghz->txrx->protocol_result->to_load_protocol != NULL) {
  24. subghz->txrx->protocol_result->to_load_protocol(
  25. subghz->txrx->protocol_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->txrx->protocol_result->to_string(subghz->txrx->protocol_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->protocol_result && subghz->txrx->protocol_result->to_save_file &&
  69. strcmp(subghz->txrx->protocol_result->name, "KeeLoq")) {
  70. widget_add_button_element(
  71. subghz->widget,
  72. GuiButtonTypeRight,
  73. "Save",
  74. subghz_scene_receiver_info_callback,
  75. subghz);
  76. widget_add_button_element(
  77. subghz->widget,
  78. GuiButtonTypeCenter,
  79. "Send",
  80. subghz_scene_receiver_info_callback,
  81. subghz);
  82. }
  83. } else {
  84. widget_add_icon_element(subghz->widget, 32, 12, &I_DolphinFirstStart7_61x51);
  85. widget_add_string_element(
  86. subghz->widget, 13, 8, AlignLeft, AlignBottom, FontSecondary, "Error history parse.");
  87. }
  88. view_dispatcher_switch_to_view(subghz->view_dispatcher, SubGhzViewWidget);
  89. }
  90. bool subghz_scene_receiver_info_on_event(void* context, SceneManagerEvent event) {
  91. SubGhz* subghz = context;
  92. if(event.type == SceneManagerEventTypeCustom) {
  93. if(event.event == SubghzCustomEventSceneReceiverInfoTxStart) {
  94. //CC1101 Stop RX -> Start TX
  95. if(subghz->txrx->hopper_state != SubGhzHopperStateOFF) {
  96. subghz->txrx->hopper_state = SubGhzHopperStatePause;
  97. }
  98. if(subghz->txrx->txrx_state == SubGhzTxRxStateRx) {
  99. subghz_rx_end(subghz);
  100. }
  101. if(!subghz_scene_receiver_info_update_parser(subghz)) {
  102. return false;
  103. }
  104. if(subghz->txrx->txrx_state == SubGhzTxRxStateIDLE ||
  105. subghz->txrx->txrx_state == SubGhzTxRxStateSleep) {
  106. if(!subghz_tx_start(subghz)) {
  107. scene_manager_next_scene(subghz->scene_manager, SubGhzSceneShowOnlyRx);
  108. } else {
  109. subghz->state_notifications = SubGhzNotificationStateTX;
  110. }
  111. }
  112. return true;
  113. } else if(event.event == SubghzCustomEventSceneReceiverInfoTxStop) {
  114. //CC1101 Stop Tx -> Start RX
  115. subghz->state_notifications = SubGhzNotificationStateIDLE;
  116. if(subghz->txrx->txrx_state == SubGhzTxRxStateTx) {
  117. subghz_tx_stop(subghz);
  118. }
  119. if(subghz->txrx->txrx_state == SubGhzTxRxStateIDLE) {
  120. subghz_begin(subghz, subghz->txrx->preset);
  121. subghz_rx(subghz, subghz->txrx->frequency);
  122. }
  123. if(subghz->txrx->hopper_state == SubGhzHopperStatePause) {
  124. subghz->txrx->hopper_state = SubGhzHopperStateRunnig;
  125. }
  126. subghz->state_notifications = SubGhzNotificationStateRX;
  127. return true;
  128. } else if(event.event == SubghzCustomEventSceneReceiverInfoSave) {
  129. //CC1101 Stop RX -> Save
  130. subghz->state_notifications = SubGhzNotificationStateIDLE;
  131. if(subghz->txrx->hopper_state != SubGhzHopperStateOFF) {
  132. subghz->txrx->hopper_state = SubGhzHopperStateOFF;
  133. }
  134. if(subghz->txrx->txrx_state == SubGhzTxRxStateRx) {
  135. subghz_rx_end(subghz);
  136. subghz_sleep(subghz);
  137. }
  138. if(!subghz_scene_receiver_info_update_parser(subghz)) {
  139. return false;
  140. }
  141. if(subghz->txrx->protocol_result && subghz->txrx->protocol_result->to_save_file &&
  142. strcmp(subghz->txrx->protocol_result->name, "KeeLoq")) {
  143. subghz_file_name_clear(subghz);
  144. scene_manager_next_scene(subghz->scene_manager, SubGhzSceneSaveName);
  145. }
  146. return true;
  147. }
  148. } else if(event.type == SceneManagerEventTypeTick) {
  149. if(subghz->txrx->hopper_state != SubGhzHopperStateOFF) {
  150. subghz_hopper_update(subghz);
  151. }
  152. switch(subghz->state_notifications) {
  153. case SubGhzNotificationStateTX:
  154. notification_message(subghz->notifications, &sequence_blink_red_10);
  155. break;
  156. case SubGhzNotificationStateRX:
  157. notification_message(subghz->notifications, &sequence_blink_blue_10);
  158. break;
  159. default:
  160. break;
  161. }
  162. }
  163. return false;
  164. }
  165. void subghz_scene_receiver_info_on_exit(void* context) {
  166. SubGhz* subghz = context;
  167. widget_reset(subghz->widget);
  168. }