action_ir.c 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. // Methods for IR transmission
  2. #include "quac.h"
  3. #include "action_i.h"
  4. #include "action_ir_utils.h"
  5. void action_ir_tx(void* context, const FuriString* action_path, FuriString* error) {
  6. UNUSED(error);
  7. App* app = context;
  8. const char* file_name = furi_string_get_cstr(action_path);
  9. InfraredSignal* signal = infrared_utils_signal_alloc();
  10. FlipperFormat* fff_data_file = flipper_format_file_alloc(app->storage);
  11. FuriString* temp_str;
  12. temp_str = furi_string_alloc();
  13. // uint32_t temp_data32;
  14. // https://developer.flipper.net/flipperzero/doxygen/infrared_file_format.html
  15. // TODO: Right now we only read the first signal found in the file. Add support
  16. // for reading any signal by 'name'?
  17. do {
  18. if(!flipper_format_file_open_existing(fff_data_file, file_name)) {
  19. ACTION_SET_ERROR("IR: Error opening %s", file_name);
  20. break;
  21. }
  22. uint32_t index = 0;
  23. if(!infrared_utils_read_signal_at_index(fff_data_file, index, signal, temp_str)) {
  24. ACTION_SET_ERROR("IR: Failed to read from file");
  25. break;
  26. }
  27. if(signal->is_raw) {
  28. // raw
  29. FURI_LOG_I(
  30. TAG,
  31. "IR: Sending (%s) type=raw => %d timings, %lu Hz, %f",
  32. file_name,
  33. signal->payload.raw.timings_size,
  34. signal->payload.raw.frequency,
  35. (double)signal->payload.raw.duty_cycle);
  36. infrared_send_raw_ext(
  37. signal->payload.raw.timings,
  38. signal->payload.raw.timings_size,
  39. true,
  40. signal->payload.raw.frequency,
  41. signal->payload.raw.duty_cycle);
  42. FURI_LOG_I(TAG, "IR: Send complete");
  43. } else {
  44. //parsed
  45. FURI_LOG_I(
  46. TAG,
  47. "IR: Sending (%s) type=parsed => %s %lu %lu",
  48. file_name,
  49. infrared_get_protocol_name(signal->payload.message.protocol),
  50. signal->payload.message.address,
  51. signal->payload.message.command);
  52. infrared_send(&signal->payload.message, 1);
  53. FURI_LOG_I(TAG, "IR: Send complete");
  54. }
  55. } while(false);
  56. furi_string_free(temp_str);
  57. flipper_format_free(fff_data_file);
  58. infrared_utils_signal_free(signal);
  59. }