2021-06-02 15:16:05 +00:00
|
|
|
#include "irda-app.hpp"
|
|
|
|
#include "irda.h"
|
|
|
|
#include <api-hal-irda.h>
|
|
|
|
|
2021-06-25 13:52:27 +00:00
|
|
|
void IrdaAppSignalTransceiver::irda_rx_callback(void* ctx, bool level, uint32_t duration) {
|
2021-06-02 15:16:05 +00:00
|
|
|
IrdaAppEvent event;
|
|
|
|
const IrdaMessage* irda_message;
|
2021-06-25 13:52:27 +00:00
|
|
|
IrdaAppSignalTransceiver* this_ = static_cast<IrdaAppSignalTransceiver*>(ctx);
|
2021-06-02 15:16:05 +00:00
|
|
|
|
|
|
|
irda_message = irda_decode(this_->decoder, level, duration);
|
|
|
|
if(irda_message) {
|
|
|
|
this_->capture_stop();
|
|
|
|
this_->message = *irda_message;
|
|
|
|
event.type = IrdaAppEvent::Type::IrdaMessageReceived;
|
|
|
|
osStatus_t result = osMessageQueuePut(this_->event_queue, &event, 0, 0);
|
|
|
|
furi_check(result == osOK);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-25 13:52:27 +00:00
|
|
|
IrdaAppSignalTransceiver::IrdaAppSignalTransceiver(void)
|
2021-06-02 15:16:05 +00:00
|
|
|
: decoder(irda_alloc_decoder()) {
|
|
|
|
}
|
|
|
|
|
2021-06-25 13:52:27 +00:00
|
|
|
IrdaAppSignalTransceiver::~IrdaAppSignalTransceiver() {
|
2021-06-02 15:16:05 +00:00
|
|
|
api_hal_irda_rx_irq_deinit();
|
|
|
|
irda_free_decoder(decoder);
|
|
|
|
}
|
|
|
|
|
2021-06-25 13:52:27 +00:00
|
|
|
void IrdaAppSignalTransceiver::capture_once_start(osMessageQueueId_t queue) {
|
2021-06-02 15:16:05 +00:00
|
|
|
event_queue = queue;
|
|
|
|
irda_reset_decoder(decoder);
|
|
|
|
api_hal_irda_rx_irq_init();
|
2021-06-25 13:52:27 +00:00
|
|
|
api_hal_irda_rx_irq_set_callback(IrdaAppSignalTransceiver::irda_rx_callback, this);
|
2021-06-02 15:16:05 +00:00
|
|
|
}
|
|
|
|
|
2021-06-25 13:52:27 +00:00
|
|
|
void IrdaAppSignalTransceiver::capture_stop(void) {
|
2021-06-02 15:16:05 +00:00
|
|
|
api_hal_irda_rx_irq_deinit();
|
|
|
|
}
|
|
|
|
|
2021-06-25 13:52:27 +00:00
|
|
|
IrdaMessage* IrdaAppSignalTransceiver::get_last_message(void) {
|
2021-06-02 15:16:05 +00:00
|
|
|
return &message;
|
|
|
|
}
|
|
|
|
|
2021-06-25 13:52:27 +00:00
|
|
|
void IrdaAppSignalTransceiver::send_message(const IrdaMessage* message) const {
|
2021-06-02 15:16:05 +00:00
|
|
|
irda_send(message, 1);
|
|
|
|
}
|