[FL-1369, FL-1397, FL-1420] IRDA + SDcard (#513)
* Add saving to SD-Card (not ready yet) * Add saving to SD-card (done) * Select previous menu item * Fix central button * Fix current_button * Refactoring * Add notifications * [FL-1417] Add IRDA CLI CLI commands: 1) ir_rx Receives all IR-trafic, decodes and prints result to stdout 2) ir_tx <protocol> <address> <command> Transmits IR-signal. Address and command are hex-formatted * Fix BUG with random memory corruption at random time in random place in random universe in random unknown space and time forever amen * Fix submenu set_selected_item * Bring protocol order back * Add TODO sdcard check
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
#include "irda.h"
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
@@ -58,7 +59,7 @@ static const IrdaProtocolImplementation irda_protocols[] = {
|
||||
.address_length = 2,
|
||||
.command_length = 2,
|
||||
},
|
||||
// #2
|
||||
// #2 - have to be after NEC
|
||||
{ .protocol = IrdaProtocolNECext,
|
||||
.name = "NECext",
|
||||
.decoder = {
|
||||
@@ -81,10 +82,12 @@ const IrdaMessage* irda_decode(IrdaHandler* handler, bool level, uint32_t durati
|
||||
IrdaMessage* result = NULL;
|
||||
|
||||
for (int i = 0; i < COUNT_OF(irda_protocols); ++i) {
|
||||
message = irda_protocols[i].decoder.decode(handler->ctx[i], level, duration);
|
||||
if (!result && message) {
|
||||
message->protocol = irda_protocols[i].protocol;
|
||||
result = message;
|
||||
if (irda_protocols[i].decoder.decode) {
|
||||
message = irda_protocols[i].decoder.decode(handler->ctx[i], level, duration);
|
||||
if (!result && message) {
|
||||
message->protocol = irda_protocols[i].protocol;
|
||||
result = message;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -96,8 +99,9 @@ IrdaHandler* irda_alloc_decoder(void) {
|
||||
handler->ctx = furi_alloc(sizeof(void*) * COUNT_OF(irda_protocols));
|
||||
|
||||
for (int i = 0; i < COUNT_OF(irda_protocols); ++i) {
|
||||
handler->ctx[i] = irda_protocols[i].decoder.alloc();
|
||||
furi_check(handler->ctx[i]);
|
||||
handler->ctx[i] = 0;
|
||||
if (irda_protocols[i].decoder.alloc)
|
||||
handler->ctx[i] = irda_protocols[i].decoder.alloc();
|
||||
}
|
||||
|
||||
return handler;
|
||||
@@ -108,7 +112,8 @@ void irda_free_decoder(IrdaHandler* handler) {
|
||||
furi_assert(handler->ctx);
|
||||
|
||||
for (int i = 0; i < COUNT_OF(irda_protocols); ++i) {
|
||||
irda_protocols[i].decoder.free(handler->ctx[i]);
|
||||
if (irda_protocols[i].decoder.free)
|
||||
irda_protocols[i].decoder.free(handler->ctx[i]);
|
||||
}
|
||||
|
||||
free(handler->ctx);
|
||||
@@ -117,31 +122,54 @@ void irda_free_decoder(IrdaHandler* handler) {
|
||||
|
||||
void irda_reset_decoder(IrdaHandler* handler) {
|
||||
for (int i = 0; i < COUNT_OF(irda_protocols); ++i) {
|
||||
irda_protocols[i].decoder.reset(handler->ctx[i]);
|
||||
if (irda_protocols[i].decoder.reset)
|
||||
irda_protocols[i].decoder.reset(handler->ctx[i]);
|
||||
}
|
||||
}
|
||||
|
||||
void irda_send(const IrdaMessage* message, int times) {
|
||||
furi_assert(message);
|
||||
furi_assert(irda_is_protocol_valid(message->protocol));
|
||||
|
||||
for (int i = 0; i < times; ++i) {
|
||||
osKernelLock();
|
||||
__disable_irq();
|
||||
irda_protocols[message->protocol].encoder.encode(message->address, message->command, !!i);
|
||||
__enable_irq();
|
||||
osKernelUnlock();
|
||||
if(irda_protocols[message->protocol].encoder.encode) {
|
||||
__disable_irq();
|
||||
irda_protocols[message->protocol].encoder.encode(message->address, message->command, !!i);
|
||||
__enable_irq();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool irda_is_protocol_valid(IrdaProtocol protocol) {
|
||||
return (protocol >= 0) && (protocol < COUNT_OF(irda_protocols));
|
||||
}
|
||||
|
||||
IrdaProtocol irda_get_protocol_by_name(const char* protocol_name) {
|
||||
for (int i = 0; i < COUNT_OF(irda_protocols); ++i) {
|
||||
if (!strcmp(irda_protocols[i].name, protocol_name))
|
||||
return i;
|
||||
}
|
||||
return IrdaProtocolUnknown;
|
||||
}
|
||||
|
||||
const char* irda_get_protocol_name(IrdaProtocol protocol) {
|
||||
return irda_protocols[protocol].name;
|
||||
if (irda_is_protocol_valid(protocol))
|
||||
return irda_protocols[protocol].name;
|
||||
else
|
||||
return "Invalid";
|
||||
}
|
||||
|
||||
uint8_t irda_get_protocol_address_length(IrdaProtocol protocol) {
|
||||
return irda_protocols[protocol].address_length;
|
||||
if (irda_is_protocol_valid(protocol))
|
||||
return irda_protocols[protocol].address_length;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint8_t irda_get_protocol_command_length(IrdaProtocol protocol) {
|
||||
return irda_protocols[protocol].command_length;
|
||||
if (irda_is_protocol_valid(protocol))
|
||||
return irda_protocols[protocol].command_length;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@@ -11,6 +11,7 @@ typedef struct IrdaHandler IrdaHandler;
|
||||
|
||||
// Do not change protocol order, as it can be saved into memory and fw update can be performed!
|
||||
typedef enum {
|
||||
IrdaProtocolUnknown = -1,
|
||||
IrdaProtocolSamsung32 = 0,
|
||||
IrdaProtocolNEC = 1,
|
||||
IrdaProtocolNECext = 2,
|
||||
@@ -74,6 +75,14 @@ void irda_send(const IrdaMessage* message, int times);
|
||||
*/
|
||||
const char* irda_get_protocol_name(IrdaProtocol protocol);
|
||||
|
||||
/**
|
||||
* Get protocol enum by protocol name.
|
||||
*
|
||||
* \param[in] protocol_name - string to protocol name.
|
||||
* \return protocol identifier.
|
||||
*/
|
||||
IrdaProtocol irda_get_protocol_by_name(const char* protocol_name);
|
||||
|
||||
/**
|
||||
* Get address length by protocol enum.
|
||||
*
|
||||
@@ -90,6 +99,14 @@ uint8_t irda_get_protocol_address_length(IrdaProtocol protocol);
|
||||
*/
|
||||
uint8_t irda_get_protocol_command_length(IrdaProtocol protocol);
|
||||
|
||||
/**
|
||||
* Checks whether protocol valid.
|
||||
*
|
||||
* \param[in] protocol - protocol identifier.
|
||||
* \return true if protocol is valid, false otherwise.
|
||||
*/
|
||||
bool irda_is_protocol_valid(IrdaProtocol protocol);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user