2022-01-05 16:10:18 +00:00
|
|
|
#include "irda_app_signal.h"
|
2021-07-16 16:43:54 +00:00
|
|
|
#include <irda_transmit.h>
|
|
|
|
|
2022-01-10 17:13:41 +00:00
|
|
|
void IrdaAppSignal::copy_raw_signal(
|
|
|
|
const uint32_t* timings,
|
|
|
|
size_t size,
|
|
|
|
uint32_t frequency,
|
|
|
|
float duty_cycle) {
|
2021-07-16 16:43:54 +00:00
|
|
|
furi_assert(size);
|
|
|
|
furi_assert(timings);
|
|
|
|
|
2022-01-10 17:13:41 +00:00
|
|
|
payload.raw.frequency = frequency;
|
|
|
|
payload.raw.duty_cycle = duty_cycle;
|
2021-08-19 00:18:42 +00:00
|
|
|
payload.raw.timings_cnt = size;
|
2021-07-16 16:43:54 +00:00
|
|
|
if(size) {
|
|
|
|
payload.raw.timings = new uint32_t[size];
|
|
|
|
memcpy(payload.raw.timings, timings, size * sizeof(uint32_t));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void IrdaAppSignal::clear_timings() {
|
2022-01-10 17:13:41 +00:00
|
|
|
if(raw_signal) {
|
2021-07-16 16:43:54 +00:00
|
|
|
delete[] payload.raw.timings;
|
|
|
|
payload.raw.timings_cnt = 0;
|
|
|
|
payload.raw.timings = nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-10 17:13:41 +00:00
|
|
|
IrdaAppSignal::IrdaAppSignal(
|
|
|
|
const uint32_t* timings,
|
|
|
|
size_t timings_cnt,
|
|
|
|
uint32_t frequency,
|
|
|
|
float duty_cycle) {
|
|
|
|
raw_signal = true;
|
|
|
|
copy_raw_signal(timings, timings_cnt, frequency, duty_cycle);
|
2021-07-16 16:43:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
IrdaAppSignal::IrdaAppSignal(const IrdaMessage* irda_message) {
|
2022-01-10 17:13:41 +00:00
|
|
|
raw_signal = false;
|
2021-07-16 16:43:54 +00:00
|
|
|
payload.message = *irda_message;
|
|
|
|
}
|
|
|
|
|
|
|
|
IrdaAppSignal& IrdaAppSignal::operator=(const IrdaAppSignal& other) {
|
|
|
|
clear_timings();
|
2022-01-10 17:13:41 +00:00
|
|
|
raw_signal = other.raw_signal;
|
|
|
|
if(!raw_signal) {
|
2021-07-16 16:43:54 +00:00
|
|
|
payload.message = other.payload.message;
|
|
|
|
} else {
|
2022-01-10 17:13:41 +00:00
|
|
|
copy_raw_signal(
|
|
|
|
other.payload.raw.timings,
|
|
|
|
other.payload.raw.timings_cnt,
|
|
|
|
other.payload.raw.frequency,
|
|
|
|
other.payload.raw.duty_cycle);
|
2021-07-16 16:43:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
IrdaAppSignal::IrdaAppSignal(const IrdaAppSignal& other) {
|
2022-01-10 17:13:41 +00:00
|
|
|
raw_signal = other.raw_signal;
|
|
|
|
if(!raw_signal) {
|
2021-07-16 16:43:54 +00:00
|
|
|
payload.message = other.payload.message;
|
|
|
|
} else {
|
2022-01-10 17:13:41 +00:00
|
|
|
copy_raw_signal(
|
|
|
|
other.payload.raw.timings,
|
|
|
|
other.payload.raw.timings_cnt,
|
|
|
|
other.payload.raw.frequency,
|
|
|
|
other.payload.raw.duty_cycle);
|
2021-07-16 16:43:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
IrdaAppSignal::IrdaAppSignal(IrdaAppSignal&& other) {
|
2022-01-10 17:13:41 +00:00
|
|
|
raw_signal = other.raw_signal;
|
|
|
|
if(!raw_signal) {
|
2021-07-16 16:43:54 +00:00
|
|
|
payload.message = other.payload.message;
|
|
|
|
} else {
|
|
|
|
furi_assert(other.payload.raw.timings_cnt > 0);
|
|
|
|
|
|
|
|
payload.raw.timings = other.payload.raw.timings;
|
|
|
|
payload.raw.timings_cnt = other.payload.raw.timings_cnt;
|
2022-01-10 17:13:41 +00:00
|
|
|
payload.raw.frequency = other.payload.raw.frequency;
|
|
|
|
payload.raw.duty_cycle = other.payload.raw.duty_cycle;
|
2021-07-16 16:43:54 +00:00
|
|
|
other.payload.raw.timings = nullptr;
|
|
|
|
other.payload.raw.timings_cnt = 0;
|
2022-01-10 17:13:41 +00:00
|
|
|
other.raw_signal = false;
|
2021-07-16 16:43:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void IrdaAppSignal::set_message(const IrdaMessage* irda_message) {
|
|
|
|
clear_timings();
|
2022-01-10 17:13:41 +00:00
|
|
|
raw_signal = false;
|
2021-07-16 16:43:54 +00:00
|
|
|
payload.message = *irda_message;
|
|
|
|
}
|
|
|
|
|
2022-01-10 17:13:41 +00:00
|
|
|
void IrdaAppSignal::set_raw_signal(
|
|
|
|
uint32_t* timings,
|
|
|
|
size_t timings_cnt,
|
|
|
|
uint32_t frequency,
|
|
|
|
float duty_cycle) {
|
2021-07-16 16:43:54 +00:00
|
|
|
clear_timings();
|
2022-01-10 17:13:41 +00:00
|
|
|
raw_signal = true;
|
|
|
|
copy_raw_signal(timings, timings_cnt, frequency, duty_cycle);
|
2021-07-16 16:43:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void IrdaAppSignal::transmit() const {
|
2022-01-10 17:13:41 +00:00
|
|
|
if(!raw_signal) {
|
2021-07-16 16:43:54 +00:00
|
|
|
irda_send(&payload.message, 1);
|
|
|
|
} else {
|
2022-01-10 17:13:41 +00:00
|
|
|
irda_send_raw_ext(
|
|
|
|
payload.raw.timings,
|
|
|
|
payload.raw.timings_cnt,
|
|
|
|
true,
|
|
|
|
payload.raw.frequency,
|
|
|
|
payload.raw.duty_cycle);
|
2021-07-16 16:43:54 +00:00
|
|
|
}
|
|
|
|
}
|