2021-05-18 13:51:00 +03:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <furi.h>
|
|
|
|
#include <api-hal-irda.h>
|
|
|
|
#include <api-hal.h>
|
2021-05-24 16:44:14 +03:00
|
|
|
#include <notification/notification-messages.h>
|
2021-05-18 13:51:00 +03:00
|
|
|
|
|
|
|
#define IRDA_TIMINGS_SIZE 2000
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
uint32_t timing_cnt;
|
|
|
|
struct {
|
|
|
|
uint8_t level;
|
|
|
|
uint32_t duration;
|
|
|
|
} timing[IRDA_TIMINGS_SIZE];
|
|
|
|
} IrdaDelaysArray;
|
|
|
|
|
|
|
|
static void irda_rx_callback(void* ctx, bool level, uint32_t duration) {
|
|
|
|
IrdaDelaysArray* delays = ctx;
|
|
|
|
|
|
|
|
if(delays->timing_cnt < IRDA_TIMINGS_SIZE) {
|
|
|
|
if(delays->timing_cnt > 1)
|
|
|
|
furi_check(level != delays->timing[delays->timing_cnt - 1].level);
|
|
|
|
delays->timing[delays->timing_cnt].level = level;
|
|
|
|
delays->timing[delays->timing_cnt].duration = duration;
|
|
|
|
delays->timing_cnt++; // Read-Modify-Write in ISR only: no need to add synchronization
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int32_t irda_monitor_app(void* p) {
|
|
|
|
(void)p;
|
|
|
|
static uint32_t counter = 0;
|
|
|
|
|
|
|
|
IrdaDelaysArray* delays = furi_alloc(sizeof(IrdaDelaysArray));
|
2021-05-24 16:44:14 +03:00
|
|
|
NotificationApp* notification = furi_record_open("notification");
|
2021-05-18 13:51:00 +03:00
|
|
|
|
|
|
|
api_hal_irda_rx_irq_init();
|
|
|
|
api_hal_irda_rx_irq_set_callback(irda_rx_callback, delays);
|
|
|
|
|
|
|
|
while(1) {
|
|
|
|
delay(20);
|
|
|
|
|
|
|
|
if(counter != delays->timing_cnt) {
|
2021-05-24 16:44:14 +03:00
|
|
|
notification_message(notification, &sequence_blink_blue_100);
|
|
|
|
|
2021-05-18 13:51:00 +03:00
|
|
|
counter = delays->timing_cnt;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(delays->timing_cnt >= IRDA_TIMINGS_SIZE) {
|
|
|
|
api_hal_irda_rx_irq_deinit();
|
|
|
|
printf("== IRDA MONITOR FOUND (%d) records) ==\r\n", IRDA_TIMINGS_SIZE);
|
|
|
|
printf("{");
|
|
|
|
for(int i = 0; i < IRDA_TIMINGS_SIZE; ++i) {
|
|
|
|
printf(
|
|
|
|
"%s%lu, ",
|
|
|
|
(delays->timing[i].duration > 15000) ? "\r\n" : "",
|
|
|
|
delays->timing[i].duration);
|
|
|
|
}
|
|
|
|
printf("\r\n};\r\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
free(delays);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|