subghz.c 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /* Reduced variant of the Flipper Zero SubGhz Class */
  2. #include "subghz_i.h"
  3. #include "../../helpers/xremote_custom_event.h"
  4. #include "../../helpers/xremote_led.h"
  5. SubGhz* subghz_alloc() {
  6. SubGhz* subghz = malloc(sizeof(SubGhz));
  7. subghz->file_path = furi_string_alloc();
  8. subghz->txrx = subghz_txrx_alloc();
  9. subghz->dialogs = furi_record_open(RECORD_DIALOGS);
  10. return subghz;
  11. }
  12. void subghz_free(SubGhz* subghz) {
  13. subghz_txrx_free(subghz->txrx);
  14. furi_string_free(subghz->file_path);
  15. furi_record_close(RECORD_DIALOGS);
  16. // The rest
  17. free(subghz);
  18. }
  19. void subghz_scene_transmit_callback_end_tx(void* context) {
  20. furi_assert(context);
  21. FURI_LOG_D(TAG, "callback end");
  22. XRemote* app = context;
  23. view_dispatcher_send_custom_event(
  24. app->view_dispatcher, XRemoteCustomEventViewTransmitterSendStop);
  25. //app->state_notifications = SubGhzNotificationStateIDLE;
  26. //subghz_txrx_stop(app->subghz->txrx);
  27. //app->transmitting = false;
  28. //xremote_scene_ir_notification_message(app, SubGhzNotificationMessageBlinkStop);
  29. xremote_cross_remote_set_transmitting(app->cross_remote, XRemoteTransmittingStopSubghz);
  30. }
  31. void subghz_send(void* context, const char* path) {
  32. XRemote* app = context;
  33. if(!subghz_load_protocol_from_file(app->subghz, path)) {
  34. xremote_cross_remote_set_transmitting(app->cross_remote, XRemoteTransmittingStop);
  35. app->transmitting = false;
  36. return;
  37. }
  38. if(subghz_get_load_type_file(app->subghz) == SubGhzLoadTypeFileRaw) {
  39. FURI_LOG_D(TAG, "Starting Transmission");
  40. subghz_txrx_tx_start(
  41. app->subghz->txrx,
  42. subghz_txrx_get_fff_data(app->subghz->txrx)); //Seems like it must be done this way
  43. FURI_LOG_D(TAG, "setting sugbhz raw file encoder worker callback");
  44. subghz_txrx_set_raw_file_encoder_worker_callback_end(
  45. app->subghz->txrx, subghz_scene_transmit_callback_end_tx, app);
  46. app->state_notifications = SubGhzNotificationStateTx;
  47. FURI_LOG_D(TAG, "Finished Transmitting");
  48. } else {
  49. subghz_tx_start(app->subghz, subghz_txrx_get_fff_data(app->subghz->txrx));
  50. app->state_notifications = SubGhzNotificationStateTx;
  51. furi_thread_flags_wait(0, FuriFlagWaitAny, app->sg_timing);
  52. app->state_notifications = SubGhzNotificationStateIDLE;
  53. subghz_txrx_stop(app->subghz->txrx);
  54. xremote_cross_remote_set_transmitting(app->cross_remote, XRemoteTransmittingStop);
  55. app->transmitting = false;
  56. }
  57. }