subghz_scene_receiver_info.c 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. #include "../subghz_i.h"
  2. typedef enum {
  3. SubGhzSceneReceiverInfoCustomEventTxStart,
  4. SubGhzSceneReceiverInfoCustomEventTxStop,
  5. SubGhzSceneReceiverInfoCustomEventSave,
  6. } SubGhzSceneReceiverInfoCustomEvent;
  7. void subghz_scene_receiver_info_callback(GuiButtonType result, InputType type, void* context) {
  8. furi_assert(context);
  9. SubGhz* subghz = context;
  10. if((result == GuiButtonTypeCenter) && (type == InputTypePress)) {
  11. view_dispatcher_send_custom_event(
  12. subghz->view_dispatcher, SubGhzSceneReceiverInfoCustomEventTxStart);
  13. } else if((result == GuiButtonTypeCenter) && (type == InputTypeRelease)) {
  14. view_dispatcher_send_custom_event(
  15. subghz->view_dispatcher, SubGhzSceneReceiverInfoCustomEventTxStop);
  16. } else if((result == GuiButtonTypeRight) && (type == InputTypeShort)) {
  17. view_dispatcher_send_custom_event(
  18. subghz->view_dispatcher, SubGhzSceneReceiverInfoCustomEventSave);
  19. }
  20. }
  21. static bool subghz_scene_receiver_info_update_parser(void* context) {
  22. SubGhz* subghz = context;
  23. subghz->txrx->protocol_result = subghz_parser_get_by_name(
  24. subghz->txrx->parser,
  25. subghz_history_get_name(subghz->txrx->history, subghz->txrx->idx_menu_chosen));
  26. if(subghz->txrx->protocol_result->to_load_protocol != NULL) {
  27. subghz->txrx->protocol_result->to_load_protocol(
  28. subghz->txrx->protocol_result,
  29. subghz_history_get_raw_data(subghz->txrx->history, subghz->txrx->idx_menu_chosen));
  30. subghz->txrx->frequency =
  31. subghz_history_get_frequency(subghz->txrx->history, subghz->txrx->idx_menu_chosen);
  32. subghz->txrx->preset =
  33. subghz_history_get_preset(subghz->txrx->history, subghz->txrx->idx_menu_chosen);
  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. char buffer_str[16];
  42. snprintf(
  43. buffer_str,
  44. sizeof(buffer_str),
  45. "%03ld.%02ld",
  46. subghz->txrx->frequency / 1000000 % 1000,
  47. subghz->txrx->frequency / 10000 % 100);
  48. widget_add_string_element(
  49. subghz->widget, 78, 0, AlignLeft, AlignTop, FontSecondary, buffer_str);
  50. if(subghz->txrx->preset == FuriHalSubGhzPresetOok650Async ||
  51. subghz->txrx->preset == FuriHalSubGhzPresetOok270Async) {
  52. snprintf(buffer_str, sizeof(buffer_str), "AM");
  53. } else if(subghz->txrx->preset == FuriHalSubGhzPreset2FSKAsync) {
  54. snprintf(buffer_str, sizeof(buffer_str), "FM");
  55. } else {
  56. furi_crash(NULL);
  57. }
  58. widget_add_string_element(
  59. subghz->widget, 113, 0, AlignLeft, AlignTop, FontSecondary, buffer_str);
  60. string_t text;
  61. string_init(text);
  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(text);
  66. if(subghz->txrx->protocol_result && subghz->txrx->protocol_result->to_save_string &&
  67. strcmp(subghz->txrx->protocol_result->name, "KeeLoq")) {
  68. widget_add_button_element(
  69. subghz->widget,
  70. GuiButtonTypeRight,
  71. "Save",
  72. subghz_scene_receiver_info_callback,
  73. subghz);
  74. widget_add_button_element(
  75. subghz->widget,
  76. GuiButtonTypeCenter,
  77. "Send",
  78. subghz_scene_receiver_info_callback,
  79. subghz);
  80. }
  81. } else {
  82. widget_add_icon_element(subghz->widget, 32, 12, &I_DolphinFirstStart7_61x51);
  83. widget_add_string_element(
  84. subghz->widget, 13, 8, AlignLeft, AlignBottom, FontSecondary, "Error history parse.");
  85. }
  86. view_dispatcher_switch_to_view(subghz->view_dispatcher, SubGhzViewWidget);
  87. }
  88. bool subghz_scene_receiver_info_on_event(void* context, SceneManagerEvent event) {
  89. SubGhz* subghz = context;
  90. if(event.type == SceneManagerEventTypeCustom) {
  91. if(event.event == SubGhzSceneReceiverInfoCustomEventTxStart) {
  92. //CC1101 Stop RX -> Start TX
  93. if(subghz->txrx->hopper_state != SubGhzHopperStateOFF) {
  94. subghz->txrx->hopper_state = SubGhzHopperStatePause;
  95. }
  96. if(subghz->txrx->txrx_state == SubGhzTxRxStateRx) {
  97. subghz_rx_end(subghz);
  98. }
  99. if(!subghz_scene_receiver_info_update_parser(subghz)) {
  100. return false;
  101. }
  102. if(subghz->txrx->txrx_state == SubGhzTxRxStateIdle) {
  103. if(!subghz_tx_start(subghz)) {
  104. scene_manager_next_scene(subghz->scene_manager, SubGhzSceneShowOnlyRx);
  105. } else {
  106. subghz->state_notifications = NOTIFICATION_TX_STATE;
  107. }
  108. }
  109. return true;
  110. } else if(event.event == SubGhzSceneReceiverInfoCustomEventTxStop) {
  111. //CC1101 Stop Tx -> Start RX
  112. subghz->state_notifications = NOTIFICATION_IDLE_STATE;
  113. if(subghz->txrx->txrx_state == SubGhzTxRxStateTx) {
  114. subghz_tx_stop(subghz);
  115. }
  116. if(subghz->txrx->txrx_state == SubGhzTxRxStateIdle) {
  117. subghz_begin(subghz, subghz->txrx->preset);
  118. subghz_rx(subghz, subghz->txrx->frequency);
  119. }
  120. if(subghz->txrx->hopper_state == SubGhzHopperStatePause) {
  121. subghz->txrx->hopper_state = SubGhzHopperStateRunnig;
  122. }
  123. subghz->state_notifications = NOTIFICATION_RX_STATE;
  124. return true;
  125. } else if(event.event == SubGhzSceneReceiverInfoCustomEventSave) {
  126. //CC1101 Stop RX -> Save
  127. subghz->state_notifications = NOTIFICATION_IDLE_STATE;
  128. if(subghz->txrx->hopper_state != SubGhzHopperStateOFF) {
  129. subghz->txrx->hopper_state = SubGhzHopperStateOFF;
  130. }
  131. if(subghz->txrx->txrx_state == SubGhzTxRxStateRx) {
  132. subghz_rx_end(subghz);
  133. subghz_sleep(subghz);
  134. }
  135. if(!subghz_scene_receiver_info_update_parser(subghz)) {
  136. return false;
  137. }
  138. if(subghz->txrx->protocol_result && subghz->txrx->protocol_result->to_save_string &&
  139. strcmp(subghz->txrx->protocol_result->name, "KeeLoq")) {
  140. subghz_file_name_clear(subghz);
  141. scene_manager_next_scene(subghz->scene_manager, SubGhzSceneSaveName);
  142. }
  143. return true;
  144. }
  145. } else if(event.type == SceneManagerEventTypeTick) {
  146. if(subghz->txrx->hopper_state != SubGhzHopperStateOFF) {
  147. subghz_hopper_update(subghz);
  148. }
  149. switch(subghz->state_notifications) {
  150. case NOTIFICATION_TX_STATE:
  151. notification_message(subghz->notifications, &sequence_blink_red_10);
  152. break;
  153. case NOTIFICATION_RX_STATE:
  154. notification_message(subghz->notifications, &sequence_blink_blue_10);
  155. break;
  156. default:
  157. break;
  158. }
  159. }
  160. return false;
  161. }
  162. void subghz_scene_receiver_info_on_exit(void* context) {
  163. SubGhz* subghz = context;
  164. widget_clear(subghz->widget);
  165. }