subghz.c 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. xremote_cross_remote_set_transmitting(app->cross_remote, XRemoteTransmittingStopSubghz);
  25. }
  26. void subghz_send(void* context, const char* path) {
  27. XRemote* app = context;
  28. if(!subghz_load_protocol_from_file(app->subghz, path)) {
  29. xremote_cross_remote_set_transmitting(app->cross_remote, XRemoteTransmittingStop);
  30. app->transmitting = false;
  31. return;
  32. }
  33. if(subghz_get_load_type_file(app->subghz) == SubGhzLoadTypeFileRaw) {
  34. FURI_LOG_D(TAG, "Starting Transmission");
  35. subghz_txrx_tx_start(
  36. app->subghz->txrx,
  37. subghz_txrx_get_fff_data(app->subghz->txrx)); //Seems like it must be done this way
  38. FURI_LOG_D(TAG, "setting sugbhz raw file encoder worker callback");
  39. subghz_txrx_set_raw_file_encoder_worker_callback_end(
  40. app->subghz->txrx, subghz_scene_transmit_callback_end_tx, app);
  41. app->state_notifications = SubGhzNotificationStateTx;
  42. FURI_LOG_D(TAG, "Finished Transmitting");
  43. } else {
  44. subghz_tx_start(app->subghz, subghz_txrx_get_fff_data(app->subghz->txrx));
  45. app->state_notifications = SubGhzNotificationStateTx;
  46. furi_thread_flags_wait(0, FuriFlagWaitAny, app->sg_timing);
  47. app->state_notifications = SubGhzNotificationStateIDLE;
  48. subghz_txrx_stop(app->subghz->txrx);
  49. xremote_cross_remote_set_transmitting(app->cross_remote, XRemoteTransmittingStop);
  50. app->transmitting = false;
  51. }
  52. }