subghz.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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_txrx_set_need_save_callback(subghz->txrx, subghz_save_to_file, subghz);
  10. subghz->dialogs = furi_record_open(RECORD_DIALOGS);
  11. return subghz;
  12. }
  13. void subghz_free(SubGhz* subghz) {
  14. subghz_txrx_free(subghz->txrx);
  15. furi_string_free(subghz->file_path);
  16. furi_record_close(RECORD_DIALOGS);
  17. // The rest
  18. free(subghz);
  19. }
  20. void subghz_scene_transmit_callback_end_tx(void* context) {
  21. furi_assert(context);
  22. FURI_LOG_D(TAG, "callback end");
  23. XRemote* app = context;
  24. view_dispatcher_send_custom_event(
  25. app->view_dispatcher, XRemoteCustomEventViewTransmitterSendStop);
  26. //app->state_notifications = SubGhzNotificationStateIDLE;
  27. //subghz_txrx_stop(app->subghz->txrx);
  28. //app->transmitting = false;
  29. //xremote_scene_ir_notification_message(app, SubGhzNotificationMessageBlinkStop);
  30. xremote_cross_remote_set_transmitting(app->cross_remote, XRemoteTransmittingStopSubghz);
  31. }
  32. void subghz_send(void* context, const char* path) {
  33. XRemote* app = context;
  34. if(!subghz_load_protocol_from_file(app->subghz, path)) {
  35. xremote_cross_remote_set_transmitting(app->cross_remote, XRemoteTransmittingStop);
  36. app->transmitting = false;
  37. return;
  38. }
  39. if(subghz_get_load_type_file(app->subghz) == SubGhzLoadTypeFileRaw) {
  40. FURI_LOG_D(TAG, "Starting Transmission");
  41. subghz_txrx_tx_start(
  42. app->subghz->txrx,
  43. subghz_txrx_get_fff_data(app->subghz->txrx)); //Seems like it must be done this way
  44. FURI_LOG_D(TAG, "setting sugbhz raw file encoder worker callback");
  45. subghz_txrx_set_raw_file_encoder_worker_callback_end(
  46. app->subghz->txrx, subghz_scene_transmit_callback_end_tx, app);
  47. app->state_notifications = SubGhzNotificationStateTx;
  48. FURI_LOG_D(TAG, "Finished Transmitting");
  49. } else {
  50. subghz_tx_start(app->subghz, subghz_txrx_get_fff_data(app->subghz->txrx));
  51. app->state_notifications = SubGhzNotificationStateTx;
  52. furi_thread_flags_wait(0, FuriFlagWaitAny, app->sg_timing);
  53. app->state_notifications = SubGhzNotificationStateIDLE;
  54. subghz_txrx_stop(app->subghz->txrx);
  55. xremote_cross_remote_set_transmitting(app->cross_remote, XRemoteTransmittingStop);
  56. app->transmitting = false;
  57. }
  58. }