|
|
@@ -6,16 +6,14 @@
|
|
|
|
|
|
#include "mp_flipper_context.h"
|
|
|
|
|
|
-typedef struct {
|
|
|
- uint32_t* buffer;
|
|
|
- uint16_t pointer;
|
|
|
- bool running;
|
|
|
-} mp_flipper_infrared_rx_session_t;
|
|
|
-
|
|
|
static void infrared_receive_callback(void* ctx, bool level, uint32_t duration) {
|
|
|
- mp_flipper_infrared_rx_session_t* session = ctx;
|
|
|
+ mp_flipper_infrared_rx_t* session = ctx;
|
|
|
+
|
|
|
+ if(session->pointer == 0 && !level) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
|
|
|
- if(session->pointer < MP_FLIPPER_INFRARED_RX_BUFFER_SIZE) {
|
|
|
+ if(session->pointer < session->size) {
|
|
|
session->buffer[session->pointer] = duration;
|
|
|
|
|
|
session->pointer++;
|
|
|
@@ -25,7 +23,7 @@ static void infrared_receive_callback(void* ctx, bool level, uint32_t duration)
|
|
|
}
|
|
|
|
|
|
static void infrared_timeout_callback(void* ctx) {
|
|
|
- mp_flipper_infrared_rx_session_t* session = ctx;
|
|
|
+ mp_flipper_infrared_rx_t* session = ctx;
|
|
|
|
|
|
session->running = false;
|
|
|
|
|
|
@@ -33,9 +31,10 @@ static void infrared_timeout_callback(void* ctx) {
|
|
|
}
|
|
|
|
|
|
inline uint32_t* mp_flipper_infrared_receive(uint32_t timeout, size_t* length) {
|
|
|
- mp_flipper_infrared_rx_session_t* session = malloc(sizeof(mp_flipper_infrared_rx_session_t));
|
|
|
+ const mp_flipper_context_t* ctx = mp_flipper_context;
|
|
|
+
|
|
|
+ mp_flipper_infrared_rx_t* session = ctx->infrared_rx;
|
|
|
|
|
|
- session->buffer = calloc(MP_FLIPPER_INFRARED_RX_BUFFER_SIZE, sizeof(uint32_t));
|
|
|
session->pointer = 0;
|
|
|
session->running = true;
|
|
|
|
|
|
@@ -47,14 +46,10 @@ inline uint32_t* mp_flipper_infrared_receive(uint32_t timeout, size_t* length) {
|
|
|
furi_hal_infrared_async_rx_set_timeout(timeout);
|
|
|
|
|
|
while(session->running) {
|
|
|
- furi_delay_us(10);
|
|
|
+ furi_delay_tick(10);
|
|
|
}
|
|
|
|
|
|
*length = session->pointer;
|
|
|
|
|
|
- void* pointer = session->buffer;
|
|
|
-
|
|
|
- free(session);
|
|
|
-
|
|
|
- return pointer;
|
|
|
+ return session->buffer;
|
|
|
}
|