subghz_scene_transmitter.c 3.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. #include "../subghz_i.h"
  2. #include "../views/transmitter.h"
  3. #include <dolphin/dolphin.h>
  4. void subghz_scene_transmitter_callback(SubGhzCustomEvent event, void* context) {
  5. furi_assert(context);
  6. SubGhz* subghz = context;
  7. view_dispatcher_send_custom_event(subghz->view_dispatcher, event);
  8. }
  9. bool subghz_scene_transmitter_update_data_show(void* context) {
  10. SubGhz* subghz = context;
  11. bool ret = false;
  12. SubGhzProtocolDecoderBase* decoder = subghz_txrx_get_decoder(subghz->txrx);
  13. if(decoder) {
  14. FuriString* key_str = furi_string_alloc();
  15. FuriString* frequency_str = furi_string_alloc();
  16. FuriString* modulation_str = furi_string_alloc();
  17. if(subghz_protocol_decoder_base_deserialize(
  18. decoder, subghz_txrx_get_fff_data(subghz->txrx)) == SubGhzProtocolStatusOk) {
  19. subghz_protocol_decoder_base_get_string(decoder, key_str);
  20. subghz_txrx_get_frequency_and_modulation(subghz->txrx, frequency_str, modulation_str);
  21. subghz_view_transmitter_add_data_to_show(
  22. subghz->subghz_transmitter,
  23. furi_string_get_cstr(key_str),
  24. furi_string_get_cstr(frequency_str),
  25. furi_string_get_cstr(modulation_str),
  26. subghz_txrx_protocol_is_transmittable(subghz->txrx, false));
  27. ret = true;
  28. }
  29. furi_string_free(frequency_str);
  30. furi_string_free(modulation_str);
  31. furi_string_free(key_str);
  32. }
  33. return ret;
  34. }
  35. void subghz_scene_transmitter_on_enter(void* context) {
  36. SubGhz* subghz = context;
  37. if(!subghz_scene_transmitter_update_data_show(subghz)) {
  38. view_dispatcher_send_custom_event(
  39. subghz->view_dispatcher, SubGhzCustomEventViewTransmitterError);
  40. }
  41. subghz_view_transmitter_set_callback(
  42. subghz->subghz_transmitter, subghz_scene_transmitter_callback, subghz);
  43. subghz->state_notifications = SubGhzNotificationStateIDLE;
  44. view_dispatcher_switch_to_view(subghz->view_dispatcher, SubGhzViewIdTransmitter);
  45. }
  46. bool subghz_scene_transmitter_on_event(void* context, SceneManagerEvent event) {
  47. SubGhz* subghz = context;
  48. if(event.type == SceneManagerEventTypeCustom) {
  49. if(event.event == SubGhzCustomEventViewTransmitterSendStart) {
  50. subghz->state_notifications = SubGhzNotificationStateIDLE;
  51. if(subghz_tx_start(subghz, subghz_txrx_get_fff_data(subghz->txrx))) {
  52. subghz->state_notifications = SubGhzNotificationStateTx;
  53. subghz_scene_transmitter_update_data_show(subghz);
  54. DOLPHIN_DEED(DolphinDeedSubGhzSend);
  55. }
  56. return true;
  57. } else if(event.event == SubGhzCustomEventViewTransmitterSendStop) {
  58. subghz->state_notifications = SubGhzNotificationStateIDLE;
  59. subghz_txrx_stop(subghz->txrx);
  60. return true;
  61. } else if(event.event == SubGhzCustomEventViewTransmitterBack) {
  62. subghz->state_notifications = SubGhzNotificationStateIDLE;
  63. scene_manager_search_and_switch_to_previous_scene(
  64. subghz->scene_manager, SubGhzSceneStart);
  65. return true;
  66. } else if(event.event == SubGhzCustomEventViewTransmitterError) {
  67. furi_string_set(subghz->error_str, "Protocol not\nfound!");
  68. scene_manager_next_scene(subghz->scene_manager, SubGhzSceneShowErrorSub);
  69. }
  70. } else if(event.type == SceneManagerEventTypeTick) {
  71. if(subghz->state_notifications == SubGhzNotificationStateTx) {
  72. notification_message(subghz->notifications, &sequence_blink_magenta_10);
  73. }
  74. return true;
  75. }
  76. return false;
  77. }
  78. void subghz_scene_transmitter_on_exit(void* context) {
  79. SubGhz* subghz = context;
  80. subghz->state_notifications = SubGhzNotificationStateIDLE;
  81. }