unleashed-firmware/applications/irda/irda-app-receiver.cpp
Albert Kharisov 31c31db479
[FL-1250, FL-1252, FL-1323, FL-1324] New IRDA Application (part 1) (#497)
* Add new IrdaApp (half ready), add ButtonMenu

* Fix NEC's extension

* clang-format

* Fix leak

* Add submenu optional header

* IRDA: add Edit button

* clang-format

* IrdaApp: Fix scene flow

* Add IRDA NEC extended protocol

* IRDA: Add address/command length

Co-authored-by: SG <who.just.the.doctor@gmail.com>
2021-06-02 18:16:05 +03:00

46 lines
1.3 KiB
C++

#include "irda-app.hpp"
#include "irda.h"
#include <api-hal-irda.h>
void IrdaAppSignalReceiver::irda_rx_callback(void* ctx, bool level, uint32_t duration) {
IrdaAppEvent event;
const IrdaMessage* irda_message;
IrdaAppSignalReceiver* this_ = static_cast<IrdaAppSignalReceiver*>(ctx);
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);
}
}
IrdaAppSignalReceiver::IrdaAppSignalReceiver(void)
: decoder(irda_alloc_decoder()) {
}
IrdaAppSignalReceiver::~IrdaAppSignalReceiver() {
api_hal_irda_rx_irq_deinit();
irda_free_decoder(decoder);
}
void IrdaAppSignalReceiver::capture_once_start(osMessageQueueId_t queue) {
event_queue = queue;
irda_reset_decoder(decoder);
api_hal_irda_rx_irq_init();
api_hal_irda_rx_irq_set_callback(IrdaAppSignalReceiver::irda_rx_callback, this);
}
void IrdaAppSignalReceiver::capture_stop(void) {
api_hal_irda_rx_irq_deinit();
}
IrdaMessage* IrdaAppSignalReceiver::get_last_message(void) {
return &message;
}
void IrdaAppSignalReceiver::send_message(const IrdaMessage* message) {
irda_send(message, 1);
}