subghz_scene_receiver_info.c 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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. char buffer_str[16];
  38. snprintf(
  39. buffer_str,
  40. sizeof(buffer_str),
  41. "%03ld.%02ld",
  42. subghz->txrx->frequency / 1000000 % 1000,
  43. subghz->txrx->frequency / 10000 % 100);
  44. widget_add_string_element(
  45. subghz->widget, 78, 0, AlignLeft, AlignTop, FontSecondary, buffer_str);
  46. if(subghz->txrx->preset == FuriHalSubGhzPresetOok650Async ||
  47. subghz->txrx->preset == FuriHalSubGhzPresetOok270Async) {
  48. snprintf(buffer_str, sizeof(buffer_str), "AM");
  49. } else if(
  50. subghz->txrx->preset == FuriHalSubGhzPreset2FSKDev238Async ||
  51. subghz->txrx->preset == FuriHalSubGhzPreset2FSKDev476Async) {
  52. snprintf(buffer_str, sizeof(buffer_str), "FM");
  53. } else {
  54. furi_crash(NULL);
  55. }
  56. widget_add_string_element(
  57. subghz->widget, 113, 0, AlignLeft, AlignTop, FontSecondary, buffer_str);
  58. string_t text;
  59. string_init(text);
  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(text);
  64. if(subghz->txrx->protocol_result && subghz->txrx->protocol_result->to_save_string &&
  65. strcmp(subghz->txrx->protocol_result->name, "KeeLoq")) {
  66. widget_add_button_element(
  67. subghz->widget,
  68. GuiButtonTypeRight,
  69. "Save",
  70. subghz_scene_receiver_info_callback,
  71. subghz);
  72. widget_add_button_element(
  73. subghz->widget,
  74. GuiButtonTypeCenter,
  75. "Send",
  76. subghz_scene_receiver_info_callback,
  77. subghz);
  78. }
  79. } else {
  80. widget_add_icon_element(subghz->widget, 32, 12, &I_DolphinFirstStart7_61x51);
  81. widget_add_string_element(
  82. subghz->widget, 13, 8, AlignLeft, AlignBottom, FontSecondary, "Error history parse.");
  83. }
  84. view_dispatcher_switch_to_view(subghz->view_dispatcher, SubGhzViewWidget);
  85. }
  86. bool subghz_scene_receiver_info_on_event(void* context, SceneManagerEvent event) {
  87. SubGhz* subghz = context;
  88. if(event.type == SceneManagerEventTypeCustom) {
  89. if(event.event == SubghzCustomEventSceneReceiverInfoTxStart) {
  90. //CC1101 Stop RX -> Start TX
  91. if(subghz->txrx->hopper_state != SubGhzHopperStateOFF) {
  92. subghz->txrx->hopper_state = SubGhzHopperStatePause;
  93. }
  94. if(subghz->txrx->txrx_state == SubGhzTxRxStateRx) {
  95. subghz_rx_end(subghz);
  96. }
  97. if(!subghz_scene_receiver_info_update_parser(subghz)) {
  98. return false;
  99. }
  100. if(subghz->txrx->txrx_state == SubGhzTxRxStateIDLE ||
  101. subghz->txrx->txrx_state == SubGhzTxRxStateSleep) {
  102. if(!subghz_tx_start(subghz)) {
  103. scene_manager_next_scene(subghz->scene_manager, SubGhzSceneShowOnlyRx);
  104. } else {
  105. subghz->state_notifications = NOTIFICATION_TX_STATE;
  106. }
  107. }
  108. return true;
  109. } else if(event.event == SubghzCustomEventSceneReceiverInfoTxStop) {
  110. //CC1101 Stop Tx -> Start RX
  111. subghz->state_notifications = NOTIFICATION_IDLE_STATE;
  112. if(subghz->txrx->txrx_state == SubGhzTxRxStateTx) {
  113. subghz_tx_stop(subghz);
  114. }
  115. if(subghz->txrx->txrx_state == SubGhzTxRxStateIDLE) {
  116. subghz_begin(subghz, subghz->txrx->preset);
  117. subghz_rx(subghz, subghz->txrx->frequency);
  118. }
  119. if(subghz->txrx->hopper_state == SubGhzHopperStatePause) {
  120. subghz->txrx->hopper_state = SubGhzHopperStateRunnig;
  121. }
  122. subghz->state_notifications = NOTIFICATION_RX_STATE;
  123. return true;
  124. } else if(event.event == SubghzCustomEventSceneReceiverInfoSave) {
  125. //CC1101 Stop RX -> Save
  126. subghz->state_notifications = NOTIFICATION_IDLE_STATE;
  127. if(subghz->txrx->hopper_state != SubGhzHopperStateOFF) {
  128. subghz->txrx->hopper_state = SubGhzHopperStateOFF;
  129. }
  130. if(subghz->txrx->txrx_state == SubGhzTxRxStateRx) {
  131. subghz_rx_end(subghz);
  132. subghz_sleep(subghz);
  133. }
  134. if(!subghz_scene_receiver_info_update_parser(subghz)) {
  135. return false;
  136. }
  137. if(subghz->txrx->protocol_result && subghz->txrx->protocol_result->to_save_string &&
  138. strcmp(subghz->txrx->protocol_result->name, "KeeLoq")) {
  139. subghz_file_name_clear(subghz);
  140. scene_manager_next_scene(subghz->scene_manager, SubGhzSceneSaveName);
  141. }
  142. return true;
  143. }
  144. } else if(event.type == SceneManagerEventTypeTick) {
  145. if(subghz->txrx->hopper_state != SubGhzHopperStateOFF) {
  146. subghz_hopper_update(subghz);
  147. }
  148. switch(subghz->state_notifications) {
  149. case NOTIFICATION_TX_STATE:
  150. notification_message(subghz->notifications, &sequence_blink_red_10);
  151. break;
  152. case NOTIFICATION_RX_STATE:
  153. notification_message(subghz->notifications, &sequence_blink_blue_10);
  154. break;
  155. default:
  156. break;
  157. }
  158. }
  159. return false;
  160. }
  161. void subghz_scene_receiver_info_on_exit(void* context) {
  162. SubGhz* subghz = context;
  163. widget_clear(subghz->widget);
  164. }