diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index c8490d23..2c82c7d4 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -14,7 +14,7 @@ applications/gui/** @skotopes @DrZlo13 applications/gui-test/** @skotopes @DrZlo13 applications/ibutton/** @skotopes @DrZlo13 applications/input/** @skotopes @DrZlo13 -applications/irda/** @skotopes @DrZlo13 @albkharisov +applications/infrared/** @skotopes @DrZlo13 applications/lf-rfid/** @skotopes @DrZlo13 applications/menu/** @skotopes @DrZlo13 applications/music-player/** @skotopes @DrZlo13 diff --git a/Makefile b/Makefile index 7e0104a6..6c01e76e 100644 --- a/Makefile +++ b/Makefile @@ -13,7 +13,7 @@ PROJECT_SOURCE_DIRECTORIES := \ $(PROJECT_ROOT)/lib/cyfral \ $(PROJECT_ROOT)/lib/drivers \ $(PROJECT_ROOT)/lib/flipper_file \ - $(PROJECT_ROOT)/lib/irda \ + $(PROJECT_ROOT)/lib/infrared \ $(PROJECT_ROOT)/lib/nfc_protocols \ $(PROJECT_ROOT)/lib/ST25RFAL002 \ $(PROJECT_ROOT)/lib/onewire \ diff --git a/applications/ReadMe.md b/applications/ReadMe.md index 022092c6..a1fbb5d6 100644 --- a/applications/ReadMe.md +++ b/applications/ReadMe.md @@ -15,8 +15,8 @@ - `gui` - GUI service and API - `ibutton` - iButton application, onewire keys and more - `input` - Input service -- `irda` - Irda application, controls your IR devices -- `irda_monitor` - Irda debug tool +- `infrared` - Infrared application, controls your IR devices +- `infrared_monitor` - Infrared debug tool - `lfrfid` - LF RFID application - `lfrfid_debug` - LF RFID debug tool - `loader` - Application loader service diff --git a/applications/applications.c b/applications/applications.c index 8153dcfa..b4df86a9 100644 --- a/applications/applications.c +++ b/applications/applications.c @@ -27,8 +27,8 @@ extern int32_t delay_test_app(void* p); extern int32_t display_test_app(void* p); extern int32_t gpio_app(void* p); extern int32_t ibutton_app(void* p); -extern int32_t irda_app(void* p); -extern int32_t irda_monitor_app(void* p); +extern int32_t infrared_app(void* p); +extern int32_t infrared_monitor_app(void* p); extern int32_t keypad_test_app(void* p); extern int32_t lfrfid_app(void* p); extern int32_t lfrfid_debug_app(void* p); @@ -51,7 +51,7 @@ extern int32_t snake_game_app(void* p); extern void bt_on_system_start(); extern void crypto_on_system_start(); extern void ibutton_on_system_start(); -extern void irda_on_system_start(); +extern void infrared_on_system_start(); extern void lfrfid_on_system_start(); extern void nfc_on_system_start(); extern void storage_on_system_start(); @@ -136,8 +136,8 @@ const FlipperApplication FLIPPER_APPS[] = { {.app = nfc_app, .name = "NFC", .stack_size = 4096, .icon = &A_NFC_14}, #endif -#ifdef APP_IRDA - {.app = irda_app, .name = "Infrared", .stack_size = 1024 * 3, .icon = &A_Infrared_14}, +#ifdef APP_INFRARED + {.app = infrared_app, .name = "Infrared", .stack_size = 1024 * 3, .icon = &A_Infrared_14}, #endif #ifdef APP_GPIO @@ -164,8 +164,8 @@ const size_t FLIPPER_APPS_COUNT = sizeof(FLIPPER_APPS) / sizeof(FlipperApplicati const FlipperOnStartHook FLIPPER_ON_SYSTEM_START[] = { crypto_on_system_start, -#ifdef APP_IRDA - irda_on_system_start, +#ifdef APP_INFRARED + infrared_on_system_start, #endif #ifdef APP_NFC @@ -251,8 +251,8 @@ const FlipperApplication FLIPPER_DEBUG_APPS[] = { {.app = uart_echo_app, .name = "Uart Echo", .stack_size = 2048, .icon = NULL}, #endif -#ifdef APP_IRDA_MONITOR - {.app = irda_monitor_app, .name = "Irda Monitor", .stack_size = 1024, .icon = NULL}, +#ifdef APP_INFRARED_MONITOR + {.app = infrared_monitor_app, .name = "Infrared Monitor", .stack_size = 1024, .icon = NULL}, #endif #ifdef APP_SCENED diff --git a/applications/applications.mk b/applications/applications.mk index 5733e761..954ec647 100644 --- a/applications/applications.mk +++ b/applications/applications.mk @@ -26,7 +26,7 @@ SRV_DESKTOP = 1 APP_ARCHIVE = 1 APP_GPIO = 1 APP_IBUTTON = 1 -APP_IRDA = 1 +APP_INFRARED = 1 APP_LF_RFID = 1 APP_NFC = 1 APP_SUBGHZ = 1 @@ -40,7 +40,7 @@ APP_SNAKE_GAME = 1 # Debug APP_ACCESSOR = 1 APP_BLINK = 1 -APP_IRDA_MONITOR = 1 +APP_INFRARED_MONITOR = 1 APP_KEYPAD_TEST = 1 APP_SD_TEST = 1 APP_VIBRO_TEST = 1 @@ -59,9 +59,9 @@ endif # Prefix with APP_* -APP_IRDA_MONITOR ?= 0 -ifeq ($(APP_IRDA_MONITOR), 1) -CFLAGS += -DAPP_IRDA_MONITOR +APP_INFRARED_MONITOR ?= 0 +ifeq ($(APP_INFRARED_MONITOR), 1) +CFLAGS += -DAPP_INFRARED_MONITOR SRV_GUI = 1 endif @@ -122,9 +122,9 @@ SRV_GUI = 1 endif -APP_IRDA ?= 0 -ifeq ($(APP_IRDA), 1) -CFLAGS += -DAPP_IRDA +APP_INFRARED ?= 0 +ifeq ($(APP_INFRARED), 1) +CFLAGS += -DAPP_INFRARED SRV_GUI = 1 endif diff --git a/applications/archive/helpers/archive_browser.h b/applications/archive/helpers/archive_browser.h index 6486967f..aa42a34a 100644 --- a/applications/archive/helpers/archive_browser.h +++ b/applications/archive/helpers/archive_browser.h @@ -10,7 +10,7 @@ static const char* tab_default_paths[] = { [ArchiveTabNFC] = "/any/nfc", [ArchiveTabSubGhz] = "/any/subghz", [ArchiveTabLFRFID] = "/any/lfrfid", - [ArchiveTabIrda] = "/any/irda", + [ArchiveTabInfrared] = "/any/infrared", [ArchiveTabBadUsb] = "/any/badusb", [ArchiveTabU2f] = "/app:u2f", [ArchiveTabBrowser] = "/any", @@ -21,7 +21,7 @@ static const char* known_ext[] = { [ArchiveFileTypeNFC] = ".nfc", [ArchiveFileTypeSubGhz] = ".sub", [ArchiveFileTypeLFRFID] = ".rfid", - [ArchiveFileTypeIrda] = ".ir", + [ArchiveFileTypeInfrared] = ".ir", [ArchiveFileTypeBadUsb] = ".txt", [ArchiveFileTypeU2f] = "?", [ArchiveFileTypeFolder] = "?", @@ -34,7 +34,7 @@ static const ArchiveFileTypeEnum known_type[] = { [ArchiveTabNFC] = ArchiveFileTypeNFC, [ArchiveTabSubGhz] = ArchiveFileTypeSubGhz, [ArchiveTabLFRFID] = ArchiveFileTypeLFRFID, - [ArchiveTabIrda] = ArchiveFileTypeIrda, + [ArchiveTabInfrared] = ArchiveFileTypeInfrared, [ArchiveTabBadUsb] = ArchiveFileTypeBadUsb, [ArchiveTabU2f] = ArchiveFileTypeU2f, [ArchiveTabBrowser] = ArchiveFileTypeUnknown, diff --git a/applications/archive/helpers/archive_files.h b/applications/archive/helpers/archive_files.h index ff751d9b..c8b16c53 100644 --- a/applications/archive/helpers/archive_files.h +++ b/applications/archive/helpers/archive_files.h @@ -8,7 +8,7 @@ typedef enum { ArchiveFileTypeNFC, ArchiveFileTypeSubGhz, ArchiveFileTypeLFRFID, - ArchiveFileTypeIrda, + ArchiveFileTypeInfrared, ArchiveFileTypeBadUsb, ArchiveFileTypeU2f, ArchiveFileTypeFolder, diff --git a/applications/archive/scenes/archive_scene_browser.c b/applications/archive/scenes/archive_scene_browser.c index 228bb305..cee19168 100644 --- a/applications/archive/scenes/archive_scene_browser.c +++ b/applications/archive/scenes/archive_scene_browser.c @@ -12,7 +12,7 @@ static const char* flipper_app_name[] = { [ArchiveFileTypeNFC] = "NFC", [ArchiveFileTypeSubGhz] = "Sub-GHz", [ArchiveFileTypeLFRFID] = "125 kHz RFID", - [ArchiveFileTypeIrda] = "Infrared", + [ArchiveFileTypeInfrared] = "Infrared", [ArchiveFileTypeBadUsb] = "Bad USB", [ArchiveFileTypeU2f] = "U2F", }; diff --git a/applications/archive/views/archive_browser_view.c b/applications/archive/views/archive_browser_view.c index 67a4ce02..fd81124e 100644 --- a/applications/archive/views/archive_browser_view.c +++ b/applications/archive/views/archive_browser_view.c @@ -9,7 +9,7 @@ static const char* ArchiveTabNames[] = { [ArchiveTabNFC] = "NFC", [ArchiveTabSubGhz] = "Sub-GHz", [ArchiveTabLFRFID] = "RFID LF", - [ArchiveTabIrda] = "Infrared", + [ArchiveTabInfrared] = "Infrared", [ArchiveTabBadUsb] = "Bad USB", [ArchiveTabU2f] = "U2F", [ArchiveTabBrowser] = "Browser"}; @@ -19,7 +19,7 @@ static const Icon* ArchiveItemIcons[] = { [ArchiveFileTypeNFC] = &I_Nfc_10px, [ArchiveFileTypeSubGhz] = &I_sub1_10px, [ArchiveFileTypeLFRFID] = &I_125_10px, - [ArchiveFileTypeIrda] = &I_ir_10px, + [ArchiveFileTypeInfrared] = &I_ir_10px, [ArchiveFileTypeBadUsb] = &I_badusb_10px, [ArchiveFileTypeU2f] = &I_u2f_10px, [ArchiveFileTypeFolder] = &I_dir_10px, diff --git a/applications/archive/views/archive_browser_view.h b/applications/archive/views/archive_browser_view.h index af4ed85e..9fc2cdf0 100644 --- a/applications/archive/views/archive_browser_view.h +++ b/applications/archive/views/archive_browser_view.h @@ -22,7 +22,7 @@ typedef enum { ArchiveTabSubGhz, ArchiveTabLFRFID, ArchiveTabNFC, - ArchiveTabIrda, + ArchiveTabInfrared, ArchiveTabIButton, ArchiveTabBadUsb, ArchiveTabU2f, diff --git a/applications/gui/modules/button_menu.c b/applications/gui/modules/button_menu.c index 0f379b74..8f38efc4 100644 --- a/applications/gui/modules/button_menu.c +++ b/applications/gui/modules/button_menu.c @@ -108,11 +108,11 @@ static void button_menu_view_draw_callback(Canvas* canvas, void* _model) { ButtonMenuItemArray_it_t it; if(active_screen > 0) { - canvas_draw_icon(canvas, 28, 1, &I_IrdaArrowUp_4x8); + canvas_draw_icon(canvas, 28, 1, &I_InfraredArrowUp_4x8); } if(max_screen > active_screen) { - canvas_draw_icon(canvas, 28, 123, &I_IrdaArrowDown_4x8); + canvas_draw_icon(canvas, 28, 123, &I_InfraredArrowDown_4x8); } if(model->header) { diff --git a/applications/irda/cli/irda_cli.cpp b/applications/infrared/cli/infrared_cli.cpp similarity index 56% rename from applications/irda/cli/irda_cli.cpp rename to applications/infrared/cli/infrared_cli.cpp index e8a61dc3..0613ca51 100644 --- a/applications/irda/cli/irda_cli.cpp +++ b/applications/infrared/cli/infrared_cli.cpp @@ -1,52 +1,52 @@ #include -#include +#include #include #include #include -#include +#include #include -#include +#include #include #include #include -#include +#include #include -#include "../helpers/irda_parser.h" +#include "../helpers/infrared_parser.h" -static void irda_cli_start_ir_rx(Cli* cli, string_t args); -static void irda_cli_start_ir_tx(Cli* cli, string_t args); +static void infrared_cli_start_ir_rx(Cli* cli, string_t args); +static void infrared_cli_start_ir_tx(Cli* cli, string_t args); static const struct { const char* cmd; void (*process_function)(Cli* cli, string_t args); -} irda_cli_commands[] = { - {.cmd = "rx", .process_function = irda_cli_start_ir_rx}, - {.cmd = "tx", .process_function = irda_cli_start_ir_tx}, +} infrared_cli_commands[] = { + {.cmd = "rx", .process_function = infrared_cli_start_ir_rx}, + {.cmd = "tx", .process_function = infrared_cli_start_ir_tx}, }; -static void signal_received_callback(void* context, IrdaWorkerSignal* received_signal) { +static void signal_received_callback(void* context, InfraredWorkerSignal* received_signal) { furi_assert(received_signal); char buf[100]; size_t buf_cnt; Cli* cli = (Cli*)context; - if(irda_worker_signal_is_decoded(received_signal)) { - const IrdaMessage* message = irda_worker_get_decoded_signal(received_signal); + if(infrared_worker_signal_is_decoded(received_signal)) { + const InfraredMessage* message = infrared_worker_get_decoded_signal(received_signal); buf_cnt = sniprintf( buf, sizeof(buf), "%s, A:0x%0*lX, C:0x%0*lX%s\r\n", - irda_get_protocol_name(message->protocol), - ROUND_UP_TO(irda_get_protocol_address_length(message->protocol), 4), + infrared_get_protocol_name(message->protocol), + ROUND_UP_TO(infrared_get_protocol_address_length(message->protocol), 4), message->address, - ROUND_UP_TO(irda_get_protocol_command_length(message->protocol), 4), + ROUND_UP_TO(infrared_get_protocol_command_length(message->protocol), 4), message->command, message->repeat ? " R" : ""); cli_write(cli, (uint8_t*)buf, buf_cnt); } else { const uint32_t* timings; size_t timings_cnt; - irda_worker_get_raw_signal(received_signal, &timings, &timings_cnt); + infrared_worker_get_raw_signal(received_signal, &timings, &timings_cnt); buf_cnt = sniprintf(buf, sizeof(buf), "RAW, %d samples:\r\n", timings_cnt); cli_write(cli, (uint8_t*)buf, buf_cnt); @@ -59,39 +59,39 @@ static void signal_received_callback(void* context, IrdaWorkerSignal* received_s } } -static void irda_cli_start_ir_rx(Cli* cli, string_t args) { - IrdaWorker* worker = irda_worker_alloc(); - irda_worker_rx_start(worker); - irda_worker_rx_set_received_signal_callback(worker, signal_received_callback, cli); +static void infrared_cli_start_ir_rx(Cli* cli, string_t args) { + InfraredWorker* worker = infrared_worker_alloc(); + infrared_worker_rx_start(worker); + infrared_worker_rx_set_received_signal_callback(worker, signal_received_callback, cli); - printf("Receiving IRDA...\r\nPress Ctrl+C to abort\r\n"); + printf("Receiving INFRARED...\r\nPress Ctrl+C to abort\r\n"); while(!cli_cmd_interrupt_received(cli)) { delay(50); } - irda_worker_rx_stop(worker); - irda_worker_free(worker); + infrared_worker_rx_stop(worker); + infrared_worker_free(worker); } -static void irda_cli_print_usage(void) { +static void infrared_cli_print_usage(void) { printf("Usage:\r\n"); printf("\tir rx\r\n"); printf("\tir tx
\r\n"); printf("\t and
are hex-formatted\r\n"); printf("\tAvailable protocols:"); - for(int i = 0; irda_is_protocol_valid((IrdaProtocol)i); ++i) { - printf(" %s", irda_get_protocol_name((IrdaProtocol)i)); + for(int i = 0; infrared_is_protocol_valid((InfraredProtocol)i); ++i) { + printf(" %s", infrared_get_protocol_name((InfraredProtocol)i)); } printf("\r\n"); printf("\tRaw format:\r\n"); printf("\tir_tx RAW F: DC: ...\r\n"); printf( "\tFrequency (%d - %d), Duty cycle (0 - 100), max 512 samples\r\n", - IRDA_MIN_FREQUENCY, - IRDA_MAX_FREQUENCY); + INFRARED_MIN_FREQUENCY, + INFRARED_MAX_FREQUENCY); } -static bool parse_message(const char* str, IrdaMessage* message) { +static bool parse_message(const char* str, InfraredMessage* message) { char protocol_name[32]; int parsed = sscanf(str, "%31s %lX %lX", protocol_name, &message->address, &message->command); @@ -99,10 +99,10 @@ static bool parse_message(const char* str, IrdaMessage* message) { return false; } - message->protocol = irda_get_protocol_by_name(protocol_name); + message->protocol = infrared_get_protocol_by_name(protocol_name); message->repeat = false; - return irda_parser_is_parsed_signal_valid(message); + return infrared_parser_is_parsed_signal_valid(message); } static bool parse_signal_raw( @@ -136,11 +136,11 @@ static bool parse_signal_raw( ++*timings_cnt; } - return irda_parser_is_raw_signal_valid(*frequency, *duty_cycle, *timings_cnt); + return infrared_parser_is_raw_signal_valid(*frequency, *duty_cycle, *timings_cnt); } -static void irda_cli_start_ir_tx(Cli* cli, string_t args) { - IrdaMessage message; +static void infrared_cli_start_ir_tx(Cli* cli, string_t args) { + InfraredMessage message; const char* str = string_get_cstr(args); uint32_t frequency; float duty_cycle; @@ -148,27 +148,27 @@ static void irda_cli_start_ir_tx(Cli* cli, string_t args) { uint32_t* timings = (uint32_t*)malloc(sizeof(uint32_t) * timings_cnt); if(parse_message(str, &message)) { - irda_send(&message, 1); + infrared_send(&message, 1); } else if(parse_signal_raw(str, timings, &timings_cnt, &duty_cycle, &frequency)) { - irda_send_raw_ext(timings, timings_cnt, true, frequency, duty_cycle); + infrared_send_raw_ext(timings, timings_cnt, true, frequency, duty_cycle); } else { printf("Wrong arguments.\r\n"); - irda_cli_print_usage(); + infrared_cli_print_usage(); } free(timings); } -static void irda_cli_start_ir(Cli* cli, string_t args, void* context) { - if(furi_hal_irda_is_busy()) { - printf("IRDA is busy. Exit."); +static void infrared_cli_start_ir(Cli* cli, string_t args, void* context) { + if(furi_hal_infrared_is_busy()) { + printf("INFRARED is busy. Exit."); return; } size_t i = 0; - for(; i < COUNT_OF(irda_cli_commands); ++i) { - size_t size = strlen(irda_cli_commands[i].cmd); - bool cmd_found = !strncmp(string_get_cstr(args), irda_cli_commands[i].cmd, size); + for(; i < COUNT_OF(infrared_cli_commands); ++i) { + size_t size = strlen(infrared_cli_commands[i].cmd); + bool cmd_found = !strncmp(string_get_cstr(args), infrared_cli_commands[i].cmd, size); if(cmd_found) { if(string_size(args) == size) { break; @@ -180,17 +180,17 @@ static void irda_cli_start_ir(Cli* cli, string_t args, void* context) { } } - if(i < COUNT_OF(irda_cli_commands)) { - irda_cli_commands[i].process_function(cli, args); + if(i < COUNT_OF(infrared_cli_commands)) { + infrared_cli_commands[i].process_function(cli, args); } else { - irda_cli_print_usage(); + infrared_cli_print_usage(); } } -extern "C" void irda_on_system_start() { +extern "C" void infrared_on_system_start() { #ifdef SRV_CLI Cli* cli = (Cli*)furi_record_open("cli"); - cli_add_command(cli, "ir", CliCommandFlagDefault, irda_cli_start_ir, NULL); + cli_add_command(cli, "ir", CliCommandFlagDefault, infrared_cli_start_ir, NULL); furi_record_close("cli"); #endif } diff --git a/applications/irda/helpers/irda_parser.cpp b/applications/infrared/helpers/infrared_parser.cpp similarity index 78% rename from applications/irda/helpers/irda_parser.cpp rename to applications/infrared/helpers/infrared_parser.cpp index a23a9b6d..12a93924 100644 --- a/applications/irda/helpers/irda_parser.cpp +++ b/applications/infrared/helpers/infrared_parser.cpp @@ -1,19 +1,19 @@ -#include "../irda_app_signal.h" -#include "irda.h" -#include "irda/helpers/irda_parser.h" -#include "irda_worker.h" +#include "../infrared_app_signal.h" +#include "infrared.h" +#include "infrared/helpers/infrared_parser.h" +#include "infrared_worker.h" #include "m-string.h" #include #include #include -#include +#include -#define TAG "IrdaParser" +#define TAG "InfraredParser" -bool irda_parser_save_signal( +bool infrared_parser_save_signal( FlipperFormat* ff, - const IrdaAppSignal& signal, + const InfraredAppSignal& signal, const std::string& name) { furi_assert(ff); furi_assert(!name.empty()); @@ -33,7 +33,7 @@ bool irda_parser_save_signal( break; } else { auto parsed_signal = signal.get_message(); - const char* protocol_name = irda_get_protocol_name(parsed_signal.protocol); + const char* protocol_name = infrared_get_protocol_name(parsed_signal.protocol); if(!flipper_format_write_string_cstr(ff, "type", "parsed")) break; if(!flipper_format_write_string_cstr(ff, "protocol", protocol_name)) break; if(!flipper_format_write_hex(ff, "address", (uint8_t*)&parsed_signal.address, 4)) @@ -47,7 +47,7 @@ bool irda_parser_save_signal( return result; } -bool irda_parser_read_signal(FlipperFormat* ff, IrdaAppSignal& signal, std::string& name) { +bool infrared_parser_read_signal(FlipperFormat* ff, InfraredAppSignal& signal, std::string& name) { furi_assert(ff); bool result = false; @@ -75,12 +75,12 @@ bool irda_parser_read_signal(FlipperFormat* ff, IrdaAppSignal& signal, std::stri } free(timings); } else if(!string_cmp_str(read_string, "parsed")) { - IrdaMessage parsed_signal; + InfraredMessage parsed_signal; if(!flipper_format_read_string(ff, "protocol", read_string)) break; - parsed_signal.protocol = irda_get_protocol_by_name(string_get_cstr(read_string)); + parsed_signal.protocol = infrared_get_protocol_by_name(string_get_cstr(read_string)); if(!flipper_format_read_hex(ff, "address", (uint8_t*)&parsed_signal.address, 4)) break; if(!flipper_format_read_hex(ff, "command", (uint8_t*)&parsed_signal.command, 4)) break; - if(!irda_parser_is_parsed_signal_valid(&parsed_signal)) break; + if(!infrared_parser_is_parsed_signal_valid(&parsed_signal)) break; signal.set_message(&parsed_signal); result = true; } else { @@ -92,17 +92,17 @@ bool irda_parser_read_signal(FlipperFormat* ff, IrdaAppSignal& signal, std::stri return result; } -bool irda_parser_is_parsed_signal_valid(const IrdaMessage* signal) { +bool infrared_parser_is_parsed_signal_valid(const InfraredMessage* signal) { furi_assert(signal); bool result = true; - if(!irda_is_protocol_valid(signal->protocol)) { + if(!infrared_is_protocol_valid(signal->protocol)) { FURI_LOG_E(TAG, "Unknown protocol"); result = false; } if(result) { - uint32_t address_length = irda_get_protocol_address_length(signal->protocol); + uint32_t address_length = infrared_get_protocol_address_length(signal->protocol); uint32_t address_mask = (1LU << address_length) - 1; if(signal->address != (signal->address & address_mask)) { FURI_LOG_E( @@ -115,7 +115,7 @@ bool irda_parser_is_parsed_signal_valid(const IrdaMessage* signal) { } if(result) { - uint32_t command_length = irda_get_protocol_command_length(signal->protocol); + uint32_t command_length = infrared_get_protocol_command_length(signal->protocol); uint32_t command_mask = (1LU << command_length) - 1; if(signal->command != (signal->command & command_mask)) { FURI_LOG_E( @@ -130,15 +130,18 @@ bool irda_parser_is_parsed_signal_valid(const IrdaMessage* signal) { return result; } -bool irda_parser_is_raw_signal_valid(uint32_t frequency, float duty_cycle, uint32_t timings_cnt) { +bool infrared_parser_is_raw_signal_valid( + uint32_t frequency, + float duty_cycle, + uint32_t timings_cnt) { bool result = true; - if((frequency > IRDA_MAX_FREQUENCY) || (frequency < IRDA_MIN_FREQUENCY)) { + if((frequency > INFRARED_MAX_FREQUENCY) || (frequency < INFRARED_MIN_FREQUENCY)) { FURI_LOG_E( TAG, "Frequency is out of range (%lX - %lX): %lX", - IRDA_MIN_FREQUENCY, - IRDA_MAX_FREQUENCY, + INFRARED_MIN_FREQUENCY, + INFRARED_MAX_FREQUENCY, frequency); result = false; } else if((duty_cycle <= 0) || (duty_cycle > 1)) { diff --git a/applications/infrared/helpers/infrared_parser.h b/applications/infrared/helpers/infrared_parser.h new file mode 100644 index 00000000..2e790c38 --- /dev/null +++ b/applications/infrared/helpers/infrared_parser.h @@ -0,0 +1,48 @@ +/** + * @file infrared_parser.h + * Infrared: Helper file for conversion Flipper File Format + * to Infrared signal class, and backwards + */ +#pragma once + +#include "../infrared_app_signal.h" +#include +#include + +/** Save Infrared signal into file + * + * @param ff - Flipper File Format instance + * @param signal - Infrared signal to save + * @param name - name for saved signal. Every + * signal on disk has name. + */ +bool infrared_parser_save_signal( + FlipperFormat* ff, + const InfraredAppSignal& signal, + const std::string& name); + +/** Read Infrared signal from file + * + * @param ff - Flipper File Format instance + * @param signal - Infrared signal to read to + * @param name - name for saved signal. Every + * signal in file has name. + */ +bool infrared_parser_read_signal(FlipperFormat* ff, InfraredAppSignal& signal, std::string& name); + +/** Validate parsed signal + * + * @signal - signal to validate + * @retval true if valid, false otherwise + */ +bool infrared_parser_is_parsed_signal_valid(const InfraredMessage* signal); + +/** Validate raw signal + * + * @signal - signal to validate + * @retval true if valid, false otherwise + */ +bool infrared_parser_is_raw_signal_valid( + uint32_t frequency, + float duty_cycle, + uint32_t timings_cnt); diff --git a/applications/irda/irda_app.cpp b/applications/infrared/infrared_app.cpp similarity index 61% rename from applications/irda/irda_app.cpp rename to applications/infrared/infrared_app.cpp index 184ed34e..5859682d 100644 --- a/applications/irda/irda_app.cpp +++ b/applications/infrared/infrared_app.cpp @@ -1,13 +1,13 @@ -#include "irda_app.h" -#include +#include "infrared_app.h" +#include #include #include #include #include #include -int32_t IrdaApp::run(void* args) { - IrdaAppEvent event; +int32_t InfraredApp::run(void* args) { + InfraredAppEvent event; bool consumed; bool exit = false; @@ -17,7 +17,7 @@ int32_t IrdaApp::run(void* args) { remote_name.erase(remote_name.find_last_of('.')); bool result = remote_manager.load(remote_name); if(result) { - current_scene = IrdaApp::Scene::Remote; + current_scene = InfraredApp::Scene::Remote; } else { printf("Failed to load remote \'%s\'\r\n", remote_name.c_str()); return -1; @@ -29,12 +29,12 @@ int32_t IrdaApp::run(void* args) { while(!exit) { view_manager.receive_event(&event); - if(event.type == IrdaAppEvent::Type::Exit) break; + if(event.type == InfraredAppEvent::Type::Exit) break; consumed = scenes[current_scene]->on_event(this, &event); if(!consumed) { - if(event.type == IrdaAppEvent::Type::Back) { + if(event.type == InfraredAppEvent::Type::Back) { exit = switch_to_previous_scene(); } } @@ -45,36 +45,36 @@ int32_t IrdaApp::run(void* args) { return 0; }; -IrdaApp::IrdaApp() { - furi_check(IrdaAppRemoteManager::max_button_name_length < get_text_store_size()); +InfraredApp::InfraredApp() { + furi_check(InfraredAppRemoteManager::max_button_name_length < get_text_store_size()); notification = static_cast(furi_record_open("notification")); - irda_worker = irda_worker_alloc(); + infrared_worker = infrared_worker_alloc(); } -IrdaApp::~IrdaApp() { - irda_worker_free(irda_worker); +InfraredApp::~InfraredApp() { + infrared_worker_free(infrared_worker); furi_record_close("notification"); for(auto& [key, scene] : scenes) delete scene; } -IrdaAppViewManager* IrdaApp::get_view_manager() { +InfraredAppViewManager* InfraredApp::get_view_manager() { return &view_manager; } -void IrdaApp::set_learn_new_remote(bool value) { +void InfraredApp::set_learn_new_remote(bool value) { learn_new_remote = value; } -bool IrdaApp::get_learn_new_remote() { +bool InfraredApp::get_learn_new_remote() { return learn_new_remote; } -void IrdaApp::switch_to_next_scene(Scene next_scene) { +void InfraredApp::switch_to_next_scene(Scene next_scene) { previous_scenes_list.push_front(current_scene); switch_to_next_scene_without_saving(next_scene); } -void IrdaApp::switch_to_next_scene_without_saving(Scene next_scene) { +void InfraredApp::switch_to_next_scene_without_saving(Scene next_scene) { if(next_scene != Scene::Exit) { scenes[current_scene]->on_exit(this); current_scene = next_scene; @@ -83,7 +83,8 @@ void IrdaApp::switch_to_next_scene_without_saving(Scene next_scene) { } } -void IrdaApp::search_and_switch_to_previous_scene(const std::initializer_list& scenes_list) { +void InfraredApp::search_and_switch_to_previous_scene( + const std::initializer_list& scenes_list) { Scene previous_scene = Scene::Start; bool scene_found = false; @@ -101,8 +102,8 @@ void IrdaApp::search_and_switch_to_previous_scene(const std::initializer_liston_exit(this); @@ -112,7 +113,7 @@ void IrdaApp::search_and_switch_to_previous_scene(const std::initializer_list(context); - IrdaAppEvent event; - event.type = IrdaAppEvent::Type::TextEditDone; +void InfraredApp::text_input_callback(void* context) { + InfraredApp* app = static_cast(context); + InfraredAppEvent event; + event.type = InfraredAppEvent::Type::TextEditDone; app->get_view_manager()->send_event(&event); } -void IrdaApp::popup_callback(void* context) { - IrdaApp* app = static_cast(context); - IrdaAppEvent event; - event.type = IrdaAppEvent::Type::PopupTimer; +void InfraredApp::popup_callback(void* context) { + InfraredApp* app = static_cast(context); + InfraredAppEvent event; + event.type = InfraredAppEvent::Type::PopupTimer; app->get_view_manager()->send_event(&event); } -void IrdaApp::set_edit_element(IrdaApp::EditElement value) { +void InfraredApp::set_edit_element(InfraredApp::EditElement value) { element = value; } -IrdaApp::EditElement IrdaApp::get_edit_element(void) { +InfraredApp::EditElement InfraredApp::get_edit_element(void) { return element; } -void IrdaApp::set_edit_action(IrdaApp::EditAction value) { +void InfraredApp::set_edit_action(InfraredApp::EditAction value) { action = value; } -IrdaApp::EditAction IrdaApp::get_edit_action(void) { +InfraredApp::EditAction InfraredApp::get_edit_action(void) { return action; } -void IrdaApp::set_current_button(int value) { +void InfraredApp::set_current_button(int value) { current_button = value; } -int IrdaApp::get_current_button() { +int InfraredApp::get_current_button() { return current_button; } -void IrdaApp::notify_success() { +void InfraredApp::notify_success() { notification_message(notification, &sequence_success); } -void IrdaApp::notify_red_blink() { +void InfraredApp::notify_red_blink() { notification_message(notification, &sequence_blink_red_10); } -void IrdaApp::notify_sent_just_learnt() { - static const NotificationSequence sequence = { - &message_green_0, - &message_vibro_on, - &message_delay_50, - &message_vibro_off, - &message_green_255, - &message_do_not_reset, - NULL, - }; - - notification_message_block(notification, &sequence); -} - -void IrdaApp::notify_click() { +void InfraredApp::notify_click() { static const NotificationSequence sequence = { &message_click, &message_delay_1, @@ -233,7 +220,7 @@ void IrdaApp::notify_click() { notification_message_block(notification, &sequence); } -void IrdaApp::notify_click_and_green_blink() { +void InfraredApp::notify_click_and_green_blink() { static const NotificationSequence sequence = { &message_click, &message_delay_1, @@ -248,7 +235,7 @@ void IrdaApp::notify_click_and_green_blink() { notification_message_block(notification, &sequence); } -void IrdaApp::notify_blink_green() { +void InfraredApp::notify_blink_green() { static const NotificationSequence sequence = { &message_green_255, &message_delay_10, @@ -260,27 +247,27 @@ void IrdaApp::notify_blink_green() { notification_message(notification, &sequence); } -void IrdaApp::notify_green_on() { +void InfraredApp::notify_green_on() { notification_message(notification, &sequence_set_only_green_255); } -void IrdaApp::notify_green_off() { +void InfraredApp::notify_green_off() { notification_message(notification, &sequence_reset_green); } -IrdaWorker* IrdaApp::get_irda_worker() { - return irda_worker; +InfraredWorker* InfraredApp::get_infrared_worker() { + return infrared_worker; } -const IrdaAppSignal& IrdaApp::get_received_signal() const { +const InfraredAppSignal& InfraredApp::get_received_signal() const { return received_signal; } -void IrdaApp::set_received_signal(const IrdaAppSignal& signal) { +void InfraredApp::set_received_signal(const InfraredAppSignal& signal) { received_signal = signal; } -void IrdaApp::signal_sent_callback(void* context) { - IrdaApp* app = static_cast(context); +void InfraredApp::signal_sent_callback(void* context) { + InfraredApp* app = static_cast(context); app->notify_blink_green(); } diff --git a/applications/infrared/infrared_app.h b/applications/infrared/infrared_app.h new file mode 100644 index 00000000..39897272 --- /dev/null +++ b/applications/infrared/infrared_app.h @@ -0,0 +1,322 @@ +/** + * @file infrared_app.h + * Infrared: Main infrared application class + */ +#pragma once +#include +#include +#include +#include +#include +#include +#include + +#include "scene/infrared_app_scene.h" +#include "scene/infrared_app_scene.h" +#include "infrared_app_view_manager.h" +#include "infrared_app_remote_manager.h" +#include "infrared_app_view_manager.h" + +/** Main Infrared application class */ +class InfraredApp { +public: + /** Enum to save scene state: edit element */ + enum class EditElement : uint8_t { + Button, + Remote, + }; + /** Enum to save scene state: edit action */ + enum class EditAction : uint8_t { + Rename, + Delete, + }; + /** List of scenes for Infrared application */ + enum class Scene : uint8_t { + Exit, + Start, + Universal, + UniversalTV, + UniversalAudio, + UniversalAirConditioner, + Learn, + LearnSuccess, + LearnEnterName, + LearnDone, + AskBack, + Remote, + RemoteList, + Edit, + EditKeySelect, + EditRename, + EditDelete, + EditRenameDone, + EditDeleteDone, + }; + + /** Start application + * + * @param args - application arguments. + * Allowed argument is path to remote file. + * @retval 0 on success, error code otherwise + */ + int32_t run(void* args); + + /** Switch to next scene. Put current scene number on stack. + * Doesn't save scene state. + * + * @param index - next scene index + */ + void switch_to_next_scene(Scene index); + + /** Switch to next scene, but don't put current scene on + * stack. Thus calling switch_to_previous_scene() doesn't return + * to current scene. + * + * @param index - next scene index + */ + void switch_to_next_scene_without_saving(Scene index); + + /** Switch to previous scene. Pop scenes from stack and switch to last one. + * + * @param count - how many scenes should be popped + * @retval false on failed, true on success + */ + bool switch_to_previous_scene(uint8_t count = 1); + + /** Get previous scene in scene stack + * + * @retval previous scene + */ + Scene get_previous_scene(); + + /** Get view manager instance + * + * @retval view manager instance + */ + InfraredAppViewManager* get_view_manager(); + + /** Set one of text stores + * + * @param index - index of text store + * @param text - text to set + */ + void set_text_store(uint8_t index, const char* text...); + + /** Get value in text store + * + * @param index - index of text store + * @retval value in text_store + */ + char* get_text_store(uint8_t index); + + /** Get text store size + * + * @retval size of text store + */ + uint8_t get_text_store_size(); + + /** Get remote manager instance + * + * @retval remote manager instance + */ + InfraredAppRemoteManager* get_remote_manager(); + + /** Get infrared worker instance + * + * @retval infrared worker instance + */ + InfraredWorker* get_infrared_worker(); + + /** Get signal, previously got on Learn scene + * + * @retval received signal + */ + const InfraredAppSignal& get_received_signal() const; + + /** Set received signal + * + * @param signal - signal + */ + void set_received_signal(const InfraredAppSignal& signal); + + /** Switch to previous scene in one of provided in list. + * Pop scene stack, and find first scene from list. + * + * @param scenes_list - list of scenes + */ + void search_and_switch_to_previous_scene(const std::initializer_list& scenes_list); + + /** Set edit element value. It is used on edit scene to determine + * what should be deleted - remote or button. + * + * @param value - value to set + */ + void set_edit_element(EditElement value); + + /** Get edit element + * + * @retval edit element value + */ + EditElement get_edit_element(void); + + /** Set edit action value. It is used on edit scene to determine + * what action to perform - deletion or renaming. + * + * @param value - value to set + */ + void set_edit_action(EditAction value); + + /** Get edit action + * + * @retval edit action value + */ + EditAction get_edit_action(void); + + /** Get state of learning new signal. + * Adding new remote with 1 button from start scene and + * learning 1 additional button to remote have very similar + * flow, so they are joined. Difference in flow is handled + * by this boolean flag. + * + * @retval false if flow is in learning new remote, true if + * adding signal to created remote + * + */ + bool get_learn_new_remote(); + + /** Set state of learning new signal. + * Adding new remote with 1 button from start scene and + * learning 1 additional button to remote have very similar + * flow, so they are joined. Difference in flow is handled + * by this boolean flag. + * + * @param value - false if flow is in learning new remote, true if + * adding signal to created remote + */ + void set_learn_new_remote(bool value); + + /** Button is not assigned value + */ + enum : int { + ButtonNA = -1, + }; + + /** Get current button index + * + * @retval current button index + */ + int get_current_button(); + + /** Set current button index + * + * @param current button index + */ + void set_current_button(int value); + + /** Play success notification */ + void notify_success(); + /** Play red blink notification */ + void notify_red_blink(); + /** Light green */ + void notify_green_on(); + /** Disable green light */ + void notify_green_off(); + /** Play click sound */ + void notify_click(); + /** Play click and green notification */ + void notify_click_and_green_blink(); + /** Blink green light */ + void notify_blink_green(); + + /** Text input callback + * + * @param context - context to pass to callback + */ + static void text_input_callback(void* context); + + /** Popup callback + * + * @param context - context to pass to callback + */ + static void popup_callback(void* context); + + /** Signal sent callback + * + * @param context - context to pass to callback + */ + static void signal_sent_callback(void* context); + + /** Main class constructor, initializes all critical objects */ + InfraredApp(); + /** Main class destructor, deinitializes all critical objects */ + ~InfraredApp(); + + /** Path to Infrared directory */ + static constexpr const char* infrared_directory = "/any/infrared"; + /** Infrared files extension (remote files and universal databases) */ + static constexpr const char* infrared_extension = ".ir"; + /** Max Raw timings in signal */ + static constexpr const uint32_t max_raw_timings_in_signal = 512; + /** Max line length in Infrared file */ + static constexpr const uint32_t max_line_length = + (9 + 1) * InfraredApp::max_raw_timings_in_signal + 100; + +private: + /** Text store size */ + static constexpr const uint8_t text_store_size = 128; + /** Amount of text stores */ + static constexpr const uint8_t text_store_max = 2; + /** Store text here, for some views, because they doesn't + * hold ownership of text */ + char text_store[text_store_max][text_store_size + 1]; + /** + * Flag to control adding new signal flow. + * Adding new remote with 1 button from start scene and + * learning 1 additional button to remote have very similar + * flow, so they are joined. Difference in flow is handled + * by this boolean flag. + */ + bool learn_new_remote; + /** Value to control edit scene */ + EditElement element; + /** Value to control edit scene */ + EditAction action; + /** Selected button index */ + uint32_t current_button; + + /** Notification instance */ + NotificationApp* notification; + /** View manager instance */ + InfraredAppViewManager view_manager; + /** Remote manager instance */ + InfraredAppRemoteManager remote_manager; + /** Infrared worker instance */ + InfraredWorker* infrared_worker; + /** Signal received on Learn scene */ + InfraredAppSignal received_signal; + + /** Stack of previous scenes */ + std::forward_list previous_scenes_list; + /** Now acting scene */ + Scene current_scene = Scene::Start; + + /** Map of index/scene objects */ + std::map scenes = { + {Scene::Start, new InfraredAppSceneStart()}, + {Scene::Universal, new InfraredAppSceneUniversal()}, + {Scene::UniversalTV, new InfraredAppSceneUniversalTV()}, + {Scene::Learn, new InfraredAppSceneLearn()}, + {Scene::LearnSuccess, new InfraredAppSceneLearnSuccess()}, + {Scene::LearnEnterName, new InfraredAppSceneLearnEnterName()}, + {Scene::LearnDone, new InfraredAppSceneLearnDone()}, + {Scene::AskBack, new InfraredAppSceneAskBack()}, + {Scene::Remote, new InfraredAppSceneRemote()}, + {Scene::RemoteList, new InfraredAppSceneRemoteList()}, + {Scene::Edit, new InfraredAppSceneEdit()}, + {Scene::EditKeySelect, new InfraredAppSceneEditKeySelect()}, + {Scene::EditRename, new InfraredAppSceneEditRename()}, + {Scene::EditDelete, new InfraredAppSceneEditDelete()}, + {Scene::EditRenameDone, new InfraredAppSceneEditRenameDone()}, + {Scene::EditDeleteDone, new InfraredAppSceneEditDeleteDone()}, + }; +}; diff --git a/applications/irda/irda_app_brute_force.cpp b/applications/infrared/infrared_app_brute_force.cpp similarity index 78% rename from applications/irda/irda_app_brute_force.cpp rename to applications/infrared/infrared_app_brute_force.cpp index 8d7d684d..24be4d3e 100644 --- a/applications/irda/irda_app_brute_force.cpp +++ b/applications/infrared/infrared_app_brute_force.cpp @@ -1,18 +1,18 @@ -#include "helpers/irda_parser.h" -#include "irda_app_brute_force.h" -#include "irda_app_signal.h" +#include "helpers/infrared_parser.h" +#include "infrared_app_brute_force.h" +#include "infrared_app_signal.h" #include #include #include #include -void IrdaAppBruteForce::add_record(int index, const char* name) { +void InfraredAppBruteForce::add_record(int index, const char* name) { records[name].index = index; records[name].amount = 0; } -bool IrdaAppBruteForce::calculate_messages() { +bool InfraredAppBruteForce::calculate_messages() { bool result = false; Storage* storage = static_cast(furi_record_open("storage")); @@ -20,7 +20,7 @@ bool IrdaAppBruteForce::calculate_messages() { result = flipper_format_file_open_existing(ff, universal_db_filename); if(result) { - IrdaAppSignal signal; + InfraredAppSignal signal; string_t signal_name; string_init(signal_name); @@ -38,7 +38,7 @@ bool IrdaAppBruteForce::calculate_messages() { return result; } -void IrdaAppBruteForce::stop_bruteforce() { +void InfraredAppBruteForce::stop_bruteforce() { furi_assert((current_record.size())); if(current_record.size()) { @@ -49,15 +49,15 @@ void IrdaAppBruteForce::stop_bruteforce() { } } -bool IrdaAppBruteForce::send_next_bruteforce(void) { +bool InfraredAppBruteForce::send_next_bruteforce(void) { furi_assert(current_record.size()); furi_assert(ff); - IrdaAppSignal signal; + InfraredAppSignal signal; std::string signal_name; bool result = false; do { - result = irda_parser_read_signal(ff, signal, signal_name); + result = infrared_parser_read_signal(ff, signal, signal_name); } while(result && current_record.compare(signal_name)); if(result) { @@ -66,7 +66,7 @@ bool IrdaAppBruteForce::send_next_bruteforce(void) { return result; } -bool IrdaAppBruteForce::start_bruteforce(int index, int& record_amount) { +bool InfraredAppBruteForce::start_bruteforce(int index, int& record_amount) { bool result = false; record_amount = 0; diff --git a/applications/infrared/infrared_app_brute_force.h b/applications/infrared/infrared_app_brute_force.h new file mode 100644 index 00000000..2dd3ade9 --- /dev/null +++ b/applications/infrared/infrared_app_brute_force.h @@ -0,0 +1,67 @@ +/** + * @file infrared_app_brute_force.h + * Infrared: Brute Force class description + */ +#pragma once + +#include +#include +#include + +/** Class handles brute force mechanic */ +class InfraredAppBruteForce { + /** Universal database filename */ + const char* universal_db_filename; + + /** Current record name (POWER, MUTE, VOL+, etc). + * This is the name of signal to brute force. */ + std::string current_record; + + /** Flipper File Format instance */ + FlipperFormat* ff; + + /** Data about every record - index in button panel view + * and amount of signals, which is need for correct + * progress bar displaying. */ + typedef struct { + /** Index of record in button panel view model */ + int index; + /** Amount of signals of that type (POWER, MUTE, etc) */ + int amount; + } Record; + + /** Container to hold Record info. + * 'key' is record name, because we have to search by both, index and name, + * but index search has place once per button press, and should not be + * noticed, but name search should occur during entering universal menu, + * and will go through container for every record in file, that's why + * more critical to have faster search by record name. + */ + std::unordered_map records; + +public: + /** Calculate messages. Walk through the file ('universal_db_name') + * and calculate amount of records of certain type. */ + bool calculate_messages(); + + /** Start brute force */ + bool start_bruteforce(int index, int& record_amount); + + /** Stop brute force */ + void stop_bruteforce(); + + /** Send next signal during brute force */ + bool send_next_bruteforce(); + + /** Add record to container of records */ + void add_record(int index, const char* name); + + /** Initialize class, set db file */ + InfraredAppBruteForce(const char* filename) + : universal_db_filename(filename) { + } + + /** Deinitialize class */ + ~InfraredAppBruteForce() { + } +}; diff --git a/applications/infrared/infrared_app_event.h b/applications/infrared/infrared_app_event.h new file mode 100644 index 00000000..fdea826a --- /dev/null +++ b/applications/infrared/infrared_app_event.h @@ -0,0 +1,47 @@ +/** + * @file infrared_app_event.h + * Infrared: Scene events description + */ +#pragma once +#include +#include + +/** Infrared events class */ +class InfraredAppEvent { +public: + /** Type of event enum */ + enum class Type : uint8_t { + /** Tick event come after no other events came in 100 ms */ + Tick, + /** Exit application event */ + Exit, + /** Back event */ + Back, + /** Menu selected event type. Provided with payload value. */ + MenuSelected, + /** Button press event. Need for continuous signal sending. */ + MenuSelectedPress, + /** Button release event. Need for continuous signal sending. */ + MenuSelectedRelease, + /** Events from DialogEx view module */ + DialogExSelected, + /** Infrared signal received event */ + InfraredMessageReceived, + /** Text edit done event */ + TextEditDone, + /** Popup timer finished event */ + PopupTimer, + /** Button panel pressed event */ + ButtonPanelPressed, + }; + + union { + /** Menu selected event type payload. Selected index. */ + int32_t menu_index; + /** DialogEx view module event type payload */ + DialogExResult dialog_ex_result; + } payload; + + /** Type of event */ + Type type; +}; diff --git a/applications/irda/irda_app_remote_manager.cpp b/applications/infrared/infrared_app_remote_manager.cpp similarity index 69% rename from applications/irda/irda_app_remote_manager.cpp rename to applications/infrared/infrared_app_remote_manager.cpp index d2081b42..bf2483ad 100644 --- a/applications/irda/irda_app_remote_manager.cpp +++ b/applications/infrared/infrared_app_remote_manager.cpp @@ -1,25 +1,26 @@ #include #include -#include "irda_app_remote_manager.h" -#include "irda/helpers/irda_parser.h" -#include "irda/irda_app_signal.h" +#include "infrared_app_remote_manager.h" +#include "infrared/helpers/infrared_parser.h" +#include "infrared/infrared_app_signal.h" #include -#include +#include #include #include #include #include -#include "irda_app.h" +#include "infrared_app.h" static const std::string default_remote_name = "remote"; -std::string IrdaAppRemoteManager::make_full_name(const std::string& remote_name) const { - return std::string("") + IrdaApp::irda_directory + "/" + remote_name + IrdaApp::irda_extension; +std::string InfraredAppRemoteManager::make_full_name(const std::string& remote_name) const { + return std::string("") + InfraredApp::infrared_directory + "/" + remote_name + + InfraredApp::infrared_extension; } -std::string IrdaAppRemoteManager::find_vacant_remote_name(const std::string& name) { +std::string InfraredAppRemoteManager::find_vacant_remote_name(const std::string& name) { bool exist = true; FileWorkerCpp file_worker; @@ -41,14 +42,14 @@ std::string IrdaAppRemoteManager::find_vacant_remote_name(const std::string& nam return !exist ? name + std::to_string(i) : std::string(); } -bool IrdaAppRemoteManager::add_button(const char* button_name, const IrdaAppSignal& signal) { +bool InfraredAppRemoteManager::add_button(const char* button_name, const InfraredAppSignal& signal) { remote->buttons.emplace_back(button_name, signal); return store(); } -bool IrdaAppRemoteManager::add_remote_with_button( +bool InfraredAppRemoteManager::add_remote_with_button( const char* button_name, - const IrdaAppSignal& signal) { + const InfraredAppSignal& signal) { furi_check(button_name != nullptr); auto new_name = find_vacant_remote_name(default_remote_name); @@ -56,11 +57,11 @@ bool IrdaAppRemoteManager::add_remote_with_button( return false; } - remote = std::make_unique(new_name); + remote = std::make_unique(new_name); return add_button(button_name, signal); } -std::vector IrdaAppRemoteManager::get_button_list(void) const { +std::vector InfraredAppRemoteManager::get_button_list(void) const { std::vector name_vector; name_vector.reserve(remote->buttons.size()); @@ -72,7 +73,7 @@ std::vector IrdaAppRemoteManager::get_button_list(void) const { return name_vector; } -const IrdaAppSignal& IrdaAppRemoteManager::get_button_data(size_t index) const { +const InfraredAppSignal& InfraredAppRemoteManager::get_button_data(size_t index) const { furi_check(remote.get() != nullptr); auto& buttons = remote->buttons; furi_check(index < buttons.size()); @@ -80,7 +81,7 @@ const IrdaAppSignal& IrdaAppRemoteManager::get_button_data(size_t index) const { return buttons.at(index).signal; } -bool IrdaAppRemoteManager::delete_remote() { +bool InfraredAppRemoteManager::delete_remote() { bool result; FileWorkerCpp file_worker; result = file_worker.remove(make_full_name(remote->name).c_str()); @@ -89,11 +90,11 @@ bool IrdaAppRemoteManager::delete_remote() { return result; } -void IrdaAppRemoteManager::reset_remote() { +void InfraredAppRemoteManager::reset_remote() { remote.reset(); } -bool IrdaAppRemoteManager::delete_button(uint32_t index) { +bool InfraredAppRemoteManager::delete_button(uint32_t index) { furi_check(remote.get() != nullptr); auto& buttons = remote->buttons; furi_check(index < buttons.size()); @@ -102,30 +103,18 @@ bool IrdaAppRemoteManager::delete_button(uint32_t index) { return store(); } -std::string IrdaAppRemoteManager::get_button_name(uint32_t index) { +std::string InfraredAppRemoteManager::get_button_name(uint32_t index) { furi_check(remote.get() != nullptr); auto& buttons = remote->buttons; furi_check(index < buttons.size()); return buttons[index].name.c_str(); } -std::string IrdaAppRemoteManager::get_remote_name() { +std::string InfraredAppRemoteManager::get_remote_name() { return remote.get() ? remote->name : std::string(); } -int IrdaAppRemoteManager::find_remote_name(const std::vector& strings) { - furi_assert(remote.get() != nullptr); - int i = 0; - for(const auto& str : strings) { - if(!str.compare(remote->name)) { - return i; - } - ++i; - } - return -1; -} - -bool IrdaAppRemoteManager::rename_remote(const char* str) { +bool InfraredAppRemoteManager::rename_remote(const char* str) { furi_check(str != nullptr); furi_check(remote.get() != nullptr); @@ -148,7 +137,7 @@ bool IrdaAppRemoteManager::rename_remote(const char* str) { return result; } -bool IrdaAppRemoteManager::rename_button(uint32_t index, const char* str) { +bool InfraredAppRemoteManager::rename_button(uint32_t index, const char* str) { furi_check(remote.get() != nullptr); auto& buttons = remote->buttons; furi_check(index < buttons.size()); @@ -157,16 +146,16 @@ bool IrdaAppRemoteManager::rename_button(uint32_t index, const char* str) { return store(); } -size_t IrdaAppRemoteManager::get_number_of_buttons() { +size_t InfraredAppRemoteManager::get_number_of_buttons() { furi_check(remote.get() != nullptr); return remote->buttons.size(); } -bool IrdaAppRemoteManager::store(void) { +bool InfraredAppRemoteManager::store(void) { bool result = false; FileWorkerCpp file_worker; - if(!file_worker.mkdir(IrdaApp::irda_directory)) return false; + if(!file_worker.mkdir(InfraredApp::infrared_directory)) return false; Storage* storage = static_cast(furi_record_open("storage")); FlipperFormat* ff = flipper_format_file_alloc(storage); @@ -178,7 +167,7 @@ bool IrdaAppRemoteManager::store(void) { } if(result) { for(const auto& button : remote->buttons) { - result = irda_parser_save_signal(ff, button.signal, button.name.c_str()); + result = infrared_parser_save_signal(ff, button.signal, button.name.c_str()); if(!result) { break; } @@ -190,7 +179,7 @@ bool IrdaAppRemoteManager::store(void) { return result; } -bool IrdaAppRemoteManager::load(const std::string& remote_name) { +bool InfraredAppRemoteManager::load(const std::string& remote_name) { bool result = false; Storage* storage = static_cast(furi_record_open("storage")); FlipperFormat* ff = flipper_format_file_alloc(storage); @@ -208,10 +197,10 @@ bool IrdaAppRemoteManager::load(const std::string& remote_name) { string_clear(header); } if(result) { - remote = std::make_unique(remote_name); - IrdaAppSignal signal; + remote = std::make_unique(remote_name); + InfraredAppSignal signal; std::string signal_name; - while(irda_parser_read_signal(ff, signal, signal_name)) { + while(infrared_parser_read_signal(ff, signal, signal_name)) { remote->buttons.emplace_back(signal_name.c_str(), std::move(signal)); } } diff --git a/applications/infrared/infrared_app_remote_manager.h b/applications/infrared/infrared_app_remote_manager.h new file mode 100644 index 00000000..bb706f19 --- /dev/null +++ b/applications/infrared/infrared_app_remote_manager.h @@ -0,0 +1,188 @@ +/** + * @file infrared_app_remote_manager.h + * Infrared: Remote manager class. + * It holds remote, can load/save/rename remote, + * add/remove/rename buttons. + */ +#pragma once + +#include "infrared_app_signal.h" + +#include +#include + +#include +#include +#include +#include + +/** Class to handle remote button */ +class InfraredAppRemoteButton { + /** Allow field access */ + friend class InfraredAppRemoteManager; + /** Name of signal */ + std::string name; + /** Signal data */ + InfraredAppSignal signal; + +public: + /** Initialize remote button + * + * @param name - button name + * @param signal - signal to copy for remote button + */ + InfraredAppRemoteButton(const char* name, const InfraredAppSignal& signal) + : name(name) + , signal(signal) { + } + + /** Initialize remote button + * + * @param name - button name + * @param signal - signal to move for remote button + */ + InfraredAppRemoteButton(const char* name, InfraredAppSignal&& signal) + : name(name) + , signal(std::move(signal)) { + } + + /** Deinitialize remote button */ + ~InfraredAppRemoteButton() { + } +}; + +/** Class to handle remote */ +class InfraredAppRemote { + /** Allow field access */ + friend class InfraredAppRemoteManager; + /** Button container */ + std::vector buttons; + /** Name of remote */ + std::string name; + +public: + /** Initialize new remote + * + * @param name - new remote name + */ + InfraredAppRemote(const std::string& name) + : name(name) { + } +}; + +/** Class to handle remote manager */ +class InfraredAppRemoteManager { + /** Remote instance. There can be 1 remote loaded at a time. */ + std::unique_ptr remote; + /** Make full name from remote name + * + * @param remote_name name of remote + * @retval full name of remote on disk + */ + std::string make_full_name(const std::string& remote_name) const; + +public: + /** Restriction to button name length. Buttons larger are ignored. */ + static constexpr const uint32_t max_button_name_length = 22; + + /** Restriction to remote name length. Remotes larger are ignored. */ + static constexpr const uint32_t max_remote_name_length = 22; + + /** Construct button from signal, and create remote + * + * @param button_name - name of button to create + * @param signal - signal to create button from + * @retval true for success, false otherwise + * */ + bool add_remote_with_button(const char* button_name, const InfraredAppSignal& signal); + + /** Add button to current remote + * + * @param button_name - name of button to create + * @param signal - signal to create button from + * @retval true for success, false otherwise + * */ + bool add_button(const char* button_name, const InfraredAppSignal& signal); + + /** Rename button in current remote + * + * @param index - index of button to rename + * @param str - new button name + */ + bool rename_button(uint32_t index, const char* str); + + /** Rename current remote + * + * @param str - new remote name + */ + bool rename_remote(const char* str); + + /** Find vacant remote name. If suggested name is occupied, + * incremented digit(2,3,4,etc) added to name and check repeated. + * + * @param name - suggested remote name + * @retval garanteed free remote name, prefixed with suggested + */ + std::string find_vacant_remote_name(const std::string& name); + + /** Get button list + * + * @retval container of button names + */ + std::vector get_button_list() const; + + /** Get button name by index + * + * @param index - index of button to get name from + * @retval button name + */ + std::string get_button_name(uint32_t index); + + /** Get remote name + * + * @retval remote name + */ + std::string get_remote_name(); + + /** Get number of buttons + * + * @retval number of buttons + */ + size_t get_number_of_buttons(); + + /** Get button's signal + * + * @param index - index of interested button + * @retval signal + */ + const InfraredAppSignal& get_button_data(size_t index) const; + + /** Delete button + * + * @param index - index of interested button + * @retval true if success, false otherwise + */ + bool delete_button(uint32_t index); + + /** Delete remote + * + * @retval true if success, false otherwise + */ + bool delete_remote(); + + /** Clean all loaded info in current remote */ + void reset_remote(); + + /** Store current remote data on disk + * + * @retval true if success, false otherwise + */ + bool store(); + + /** Load data from disk into current remote + * + * @param name - name of remote to load + * @retval true if success, false otherwise + */ + bool load(const std::string& name); +}; diff --git a/applications/irda/irda_app_signal.cpp b/applications/infrared/infrared_app_signal.cpp similarity index 75% rename from applications/irda/irda_app_signal.cpp rename to applications/infrared/infrared_app_signal.cpp index 7e40a041..3344b3ca 100644 --- a/applications/irda/irda_app_signal.cpp +++ b/applications/infrared/infrared_app_signal.cpp @@ -1,7 +1,7 @@ -#include "irda_app_signal.h" -#include +#include "infrared_app_signal.h" +#include -void IrdaAppSignal::copy_raw_signal( +void InfraredAppSignal::copy_raw_signal( const uint32_t* timings, size_t size, uint32_t frequency, @@ -18,7 +18,7 @@ void IrdaAppSignal::copy_raw_signal( } } -void IrdaAppSignal::clear_timings() { +void InfraredAppSignal::clear_timings() { if(raw_signal) { delete[] payload.raw.timings; payload.raw.timings_cnt = 0; @@ -26,7 +26,7 @@ void IrdaAppSignal::clear_timings() { } } -IrdaAppSignal::IrdaAppSignal( +InfraredAppSignal::InfraredAppSignal( const uint32_t* timings, size_t timings_cnt, uint32_t frequency, @@ -35,12 +35,12 @@ IrdaAppSignal::IrdaAppSignal( copy_raw_signal(timings, timings_cnt, frequency, duty_cycle); } -IrdaAppSignal::IrdaAppSignal(const IrdaMessage* irda_message) { +InfraredAppSignal::InfraredAppSignal(const InfraredMessage* infrared_message) { raw_signal = false; - payload.message = *irda_message; + payload.message = *infrared_message; } -IrdaAppSignal& IrdaAppSignal::operator=(const IrdaAppSignal& other) { +InfraredAppSignal& InfraredAppSignal::operator=(const InfraredAppSignal& other) { clear_timings(); raw_signal = other.raw_signal; if(!raw_signal) { @@ -56,7 +56,7 @@ IrdaAppSignal& IrdaAppSignal::operator=(const IrdaAppSignal& other) { return *this; } -IrdaAppSignal::IrdaAppSignal(const IrdaAppSignal& other) { +InfraredAppSignal::InfraredAppSignal(const InfraredAppSignal& other) { raw_signal = other.raw_signal; if(!raw_signal) { payload.message = other.payload.message; @@ -69,7 +69,7 @@ IrdaAppSignal::IrdaAppSignal(const IrdaAppSignal& other) { } } -IrdaAppSignal::IrdaAppSignal(IrdaAppSignal&& other) { +InfraredAppSignal::InfraredAppSignal(InfraredAppSignal&& other) { raw_signal = other.raw_signal; if(!raw_signal) { payload.message = other.payload.message; @@ -86,13 +86,13 @@ IrdaAppSignal::IrdaAppSignal(IrdaAppSignal&& other) { } } -void IrdaAppSignal::set_message(const IrdaMessage* irda_message) { +void InfraredAppSignal::set_message(const InfraredMessage* infrared_message) { clear_timings(); raw_signal = false; - payload.message = *irda_message; + payload.message = *infrared_message; } -void IrdaAppSignal::set_raw_signal( +void InfraredAppSignal::set_raw_signal( uint32_t* timings, size_t timings_cnt, uint32_t frequency, @@ -102,11 +102,11 @@ void IrdaAppSignal::set_raw_signal( copy_raw_signal(timings, timings_cnt, frequency, duty_cycle); } -void IrdaAppSignal::transmit() const { +void InfraredAppSignal::transmit() const { if(!raw_signal) { - irda_send(&payload.message, 1); + infrared_send(&payload.message, 1); } else { - irda_send_raw_ext( + infrared_send_raw_ext( payload.raw.timings, payload.raw.timings_cnt, true, diff --git a/applications/infrared/infrared_app_signal.h b/applications/infrared/infrared_app_signal.h new file mode 100644 index 00000000..7b0b491b --- /dev/null +++ b/applications/infrared/infrared_app_signal.h @@ -0,0 +1,134 @@ +/** + * @file infrared_app_signal.h + * Infrared: Signal class + */ +#pragma once +#include +#include +#include +#include + +/** Infrared application signal class */ +class InfraredAppSignal { +public: + /** Raw signal structure */ + typedef struct { + /** Timings amount */ + size_t timings_cnt; + /** Samples of raw signal in ms */ + uint32_t* timings; + /** PWM Frequency of raw signal */ + uint32_t frequency; + /** PWM Duty cycle of raw signal */ + float duty_cycle; + } RawSignal; + +private: + /** if true - signal is raw, if false - signal is parsed */ + bool raw_signal; + /** signal data, either raw or parsed */ + union { + /** signal data for parsed signal */ + InfraredMessage message; + /** raw signal data */ + RawSignal raw; + } payload; + + /** Copy raw signal into object + * + * @param timings - timings (samples) of raw signal + * @param size - number of timings + * @frequency - PWM frequency of raw signal + * @duty_cycle - PWM duty cycle + */ + void + copy_raw_signal(const uint32_t* timings, size_t size, uint32_t frequency, float duty_cycle); + /** Clear and free timings data */ + void clear_timings(); + +public: + /** Construct Infrared signal class */ + InfraredAppSignal() { + raw_signal = false; + payload.message.protocol = InfraredProtocolUnknown; + } + + /** Destruct signal class and free all allocated data */ + ~InfraredAppSignal() { + clear_timings(); + } + + /** Construct object with raw signal + * + * @param timings - timings (samples) of raw signal + * @param size - number of timings + * @frequency - PWM frequency of raw signal + * @duty_cycle - PWM duty cycle + */ + InfraredAppSignal( + const uint32_t* timings, + size_t timings_cnt, + uint32_t frequency, + float duty_cycle); + + /** Construct object with parsed signal + * + * @param infrared_message - parsed_signal to construct from + */ + InfraredAppSignal(const InfraredMessage* infrared_message); + + /** Copy constructor */ + InfraredAppSignal(const InfraredAppSignal& other); + /** Move constructor */ + InfraredAppSignal(InfraredAppSignal&& other); + + /** Assignment operator */ + InfraredAppSignal& operator=(const InfraredAppSignal& signal); + + /** Set object to parsed signal + * + * @param infrared_message - parsed_signal to construct from + */ + void set_message(const InfraredMessage* infrared_message); + + /** Set object to raw signal + * + * @param timings - timings (samples) of raw signal + * @param size - number of timings + * @frequency - PWM frequency of raw signal + * @duty_cycle - PWM duty cycle + */ + void + set_raw_signal(uint32_t* timings, size_t timings_cnt, uint32_t frequency, float duty_cycle); + + /** Transmit held signal (???) */ + void transmit() const; + + /** Show is held signal raw + * + * @retval true if signal is raw, false if signal is parsed + */ + bool is_raw(void) const { + return raw_signal; + } + + /** Get parsed signal. + * User must check is_raw() signal before calling this function. + * + * @retval parsed signal pointer + */ + const InfraredMessage& get_message(void) const { + furi_assert(!raw_signal); + return payload.message; + } + + /** Get raw signal. + * User must check is_raw() signal before calling this function. + * + * @retval raw signal + */ + const RawSignal& get_raw_signal(void) const { + furi_assert(raw_signal); + return payload.raw; + } +}; diff --git a/applications/irda/irda_app_view_manager.cpp b/applications/infrared/infrared_app_view_manager.cpp similarity index 51% rename from applications/irda/irda_app_view_manager.cpp rename to applications/infrared/infrared_app_view_manager.cpp index 841a3093..1e08471d 100644 --- a/applications/irda/irda_app_view_manager.cpp +++ b/applications/infrared/infrared_app_view_manager.cpp @@ -6,16 +6,16 @@ #include #include -#include "irda/irda_app_view_manager.h" -#include "irda/view/irda_progress_view.h" -#include "irda_app.h" -#include "irda/irda_app_event.h" +#include "infrared/infrared_app_view_manager.h" +#include "infrared/view/infrared_progress_view.h" +#include "infrared_app.h" +#include "infrared/infrared_app_event.h" -IrdaAppViewManager::IrdaAppViewManager() { - event_queue = osMessageQueueNew(10, sizeof(IrdaAppEvent), NULL); +InfraredAppViewManager::InfraredAppViewManager() { + event_queue = osMessageQueueNew(10, sizeof(InfraredAppEvent), NULL); view_dispatcher = view_dispatcher_alloc(); - auto callback = cbc::obtain_connector(this, &IrdaAppViewManager::previous_view_callback); + auto callback = cbc::obtain_connector(this, &InfraredAppViewManager::previous_view_callback); gui = static_cast(furi_record_open("gui")); view_dispatcher_attach_to_gui(view_dispatcher, gui, ViewDispatcherTypeFullscreen); @@ -26,18 +26,18 @@ IrdaAppViewManager::IrdaAppViewManager() { dialog_ex = dialog_ex_alloc(); text_input = text_input_alloc(); button_panel = button_panel_alloc(); - progress_view = irda_progress_view_alloc(); + progress_view = infrared_progress_view_alloc(); loading_view = loading_alloc(); universal_view_stack = view_stack_alloc(); view_stack_add_view(universal_view_stack, button_panel_get_view(button_panel)); view_set_orientation(view_stack_get_view(universal_view_stack), ViewOrientationVertical); - add_view(ViewType::UniversalRemote, view_stack_get_view(universal_view_stack)); - add_view(ViewType::ButtonMenu, button_menu_get_view(button_menu)); - add_view(ViewType::Submenu, submenu_get_view(submenu)); - add_view(ViewType::Popup, popup_get_view(popup)); - add_view(ViewType::DialogEx, dialog_ex_get_view(dialog_ex)); - add_view(ViewType::TextInput, text_input_get_view(text_input)); + add_view(ViewId::UniversalRemote, view_stack_get_view(universal_view_stack)); + add_view(ViewId::ButtonMenu, button_menu_get_view(button_menu)); + add_view(ViewId::Submenu, submenu_get_view(submenu)); + add_view(ViewId::Popup, popup_get_view(popup)); + add_view(ViewId::DialogEx, dialog_ex_get_view(dialog_ex)); + add_view(ViewId::TextInput, text_input_get_view(text_input)); view_set_previous_callback(view_stack_get_view(universal_view_stack), callback); view_set_previous_callback(button_menu_get_view(button_menu), callback); @@ -47,19 +47,19 @@ IrdaAppViewManager::IrdaAppViewManager() { view_set_previous_callback(text_input_get_view(text_input), callback); } -IrdaAppViewManager::~IrdaAppViewManager() { +InfraredAppViewManager::~InfraredAppViewManager() { view_dispatcher_remove_view( - view_dispatcher, static_cast(IrdaAppViewManager::ViewType::UniversalRemote)); + view_dispatcher, static_cast(InfraredAppViewManager::ViewId::UniversalRemote)); view_dispatcher_remove_view( - view_dispatcher, static_cast(IrdaAppViewManager::ViewType::ButtonMenu)); + view_dispatcher, static_cast(InfraredAppViewManager::ViewId::ButtonMenu)); view_dispatcher_remove_view( - view_dispatcher, static_cast(IrdaAppViewManager::ViewType::TextInput)); + view_dispatcher, static_cast(InfraredAppViewManager::ViewId::TextInput)); view_dispatcher_remove_view( - view_dispatcher, static_cast(IrdaAppViewManager::ViewType::DialogEx)); + view_dispatcher, static_cast(InfraredAppViewManager::ViewId::DialogEx)); view_dispatcher_remove_view( - view_dispatcher, static_cast(IrdaAppViewManager::ViewType::Submenu)); + view_dispatcher, static_cast(InfraredAppViewManager::ViewId::Submenu)); view_dispatcher_remove_view( - view_dispatcher, static_cast(IrdaAppViewManager::ViewType::Popup)); + view_dispatcher, static_cast(InfraredAppViewManager::ViewId::Popup)); view_stack_remove_view(universal_view_stack, button_panel_get_view(button_panel)); view_stack_free(universal_view_stack); @@ -69,7 +69,7 @@ IrdaAppViewManager::~IrdaAppViewManager() { button_menu_free(button_menu); dialog_ex_free(dialog_ex); text_input_free(text_input); - irda_progress_view_free(progress_view); + infrared_progress_view_free(progress_view); loading_free(loading_view); view_dispatcher_free(view_dispatcher); @@ -77,70 +77,70 @@ IrdaAppViewManager::~IrdaAppViewManager() { osMessageQueueDelete(event_queue); } -void IrdaAppViewManager::switch_to(ViewType type) { +void InfraredAppViewManager::switch_to(ViewId type) { view_dispatcher_switch_to_view(view_dispatcher, static_cast(type)); } -TextInput* IrdaAppViewManager::get_text_input() { +TextInput* InfraredAppViewManager::get_text_input() { return text_input; } -DialogEx* IrdaAppViewManager::get_dialog_ex() { +DialogEx* InfraredAppViewManager::get_dialog_ex() { return dialog_ex; } -Submenu* IrdaAppViewManager::get_submenu() { +Submenu* InfraredAppViewManager::get_submenu() { return submenu; } -Popup* IrdaAppViewManager::get_popup() { +Popup* InfraredAppViewManager::get_popup() { return popup; } -ButtonMenu* IrdaAppViewManager::get_button_menu() { +ButtonMenu* InfraredAppViewManager::get_button_menu() { return button_menu; } -ButtonPanel* IrdaAppViewManager::get_button_panel() { +ButtonPanel* InfraredAppViewManager::get_button_panel() { return button_panel; } -IrdaProgressView* IrdaAppViewManager::get_progress() { +InfraredProgressView* InfraredAppViewManager::get_progress() { return progress_view; } -Loading* IrdaAppViewManager::get_loading() { +Loading* InfraredAppViewManager::get_loading() { return loading_view; } -ViewStack* IrdaAppViewManager::get_universal_view_stack() { +ViewStack* InfraredAppViewManager::get_universal_view_stack() { return universal_view_stack; } -osMessageQueueId_t IrdaAppViewManager::get_event_queue() { +osMessageQueueId_t InfraredAppViewManager::get_event_queue() { return event_queue; } -void IrdaAppViewManager::clear_events() { - IrdaAppEvent event; +void InfraredAppViewManager::clear_events() { + InfraredAppEvent event; while(osMessageQueueGet(event_queue, &event, NULL, 0) == osOK) ; } -void IrdaAppViewManager::receive_event(IrdaAppEvent* event) { +void InfraredAppViewManager::receive_event(InfraredAppEvent* event) { if(osMessageQueueGet(event_queue, event, NULL, 100) != osOK) { - event->type = IrdaAppEvent::Type::Tick; + event->type = InfraredAppEvent::Type::Tick; } } -void IrdaAppViewManager::send_event(IrdaAppEvent* event) { +void InfraredAppViewManager::send_event(InfraredAppEvent* event) { uint32_t timeout = 0; /* Rapid button hammering on signal send scenes causes queue overflow - ignore it, - * but try to keep button release event - it switches off IRDA DMA sending. */ - if(event->type == IrdaAppEvent::Type::MenuSelectedRelease) { + * but try to keep button release event - it switches off INFRARED DMA sending. */ + if(event->type == InfraredAppEvent::Type::MenuSelectedRelease) { timeout = 200; } - if((event->type == IrdaAppEvent::Type::DialogExSelected) && + if((event->type == InfraredAppEvent::Type::DialogExSelected) && (event->payload.dialog_ex_result == DialogExReleaseCenter)) { timeout = 200; } @@ -148,16 +148,16 @@ void IrdaAppViewManager::send_event(IrdaAppEvent* event) { osMessageQueuePut(event_queue, event, 0, timeout); } -uint32_t IrdaAppViewManager::previous_view_callback(void* context) { +uint32_t InfraredAppViewManager::previous_view_callback(void* context) { if(event_queue != NULL) { - IrdaAppEvent event; - event.type = IrdaAppEvent::Type::Back; + InfraredAppEvent event; + event.type = InfraredAppEvent::Type::Back; send_event(&event); } return VIEW_IGNORE; } -void IrdaAppViewManager::add_view(ViewType view_type, View* view) { +void InfraredAppViewManager::add_view(ViewId view_type, View* view) { view_dispatcher_add_view(view_dispatcher, static_cast(view_type), view); } diff --git a/applications/infrared/infrared_app_view_manager.h b/applications/infrared/infrared_app_view_manager.h new file mode 100644 index 00000000..106d2660 --- /dev/null +++ b/applications/infrared/infrared_app_view_manager.h @@ -0,0 +1,164 @@ +/** + * @file infrared_app_view_manager.h + * Infrared: Scene events description + */ +#pragma once +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "infrared_app_event.h" +#include "view/infrared_progress_view.h" + +/** Infrared View manager class */ +class InfraredAppViewManager { +public: + /** Infrared View Id enum, it is used + * to identify added views */ + enum class ViewId : uint8_t { + DialogEx, + TextInput, + Submenu, + ButtonMenu, + UniversalRemote, + Popup, + }; + + /** Class constructor */ + InfraredAppViewManager(); + /** Class destructor */ + ~InfraredAppViewManager(); + + /** Switch to another view + * + * @param id - view id to switch to + */ + void switch_to(ViewId id); + + /** Receive event from queue + * + * @param event - received event + */ + void receive_event(InfraredAppEvent* event); + + /** Send event to queue + * + * @param event - event to send + */ + void send_event(InfraredAppEvent* event); + + /** Clear events that already in queue + * + * @param event - event to send + */ + void clear_events(); + + /** Get dialog_ex view module + * + * @retval dialog_ex view module + */ + DialogEx* get_dialog_ex(); + + /** Get submenu view module + * + * @retval submenu view module + */ + Submenu* get_submenu(); + + /** Get popup view module + * + * @retval popup view module + */ + Popup* get_popup(); + + /** Get text_input view module + * + * @retval text_input view module + */ + TextInput* get_text_input(); + + /** Get button_menu view module + * + * @retval button_menu view module + */ + ButtonMenu* get_button_menu(); + + /** Get button_panel view module + * + * @retval button_panel view module + */ + ButtonPanel* get_button_panel(); + + /** Get view_stack view module used in universal remote + * + * @retval view_stack view module + */ + ViewStack* get_universal_view_stack(); + + /** Get progress view module + * + * @retval progress view module + */ + InfraredProgressView* get_progress(); + + /** Get loading view module + * + * @retval loading view module + */ + Loading* get_loading(); + + /** Get event queue + * + * @retval event queue + */ + osMessageQueueId_t get_event_queue(); + + /** Callback to handle back button + * + * @param context - context to pass to callback + * @retval always returns VIEW_IGNORE + */ + uint32_t previous_view_callback(void* context); + +private: + /** View Dispatcher instance. + * It handles view switching */ + ViewDispatcher* view_dispatcher; + /** Gui instance */ + Gui* gui; + /** Text input view module instance */ + TextInput* text_input; + /** DialogEx view module instance */ + DialogEx* dialog_ex; + /** Submenu view module instance */ + Submenu* submenu; + /** Popup view module instance */ + Popup* popup; + /** ButtonMenu view module instance */ + ButtonMenu* button_menu; + /** ButtonPanel view module instance */ + ButtonPanel* button_panel; + /** ViewStack view module instance */ + ViewStack* universal_view_stack; + /** ProgressView view module instance */ + InfraredProgressView* progress_view; + /** Loading view module instance */ + Loading* loading_view; + + /** Queue to handle events, which are processed in scenes */ + osMessageQueueId_t event_queue; + + /** Add View to pull of views + * + * @param view_id - id to identify view + * @param view - view to add + */ + void add_view(ViewId view_id, View* view); +}; diff --git a/applications/infrared/infrared_runner.cpp b/applications/infrared/infrared_runner.cpp new file mode 100644 index 00000000..650b0fcd --- /dev/null +++ b/applications/infrared/infrared_runner.cpp @@ -0,0 +1,9 @@ +#include "infrared_app.h" + +extern "C" int32_t infrared_app(void* p) { + InfraredApp* app = new InfraredApp(); + int32_t result = app->run(p); + delete app; + + return result; +} diff --git a/applications/infrared/scene/infrared_app_scene.h b/applications/infrared/scene/infrared_app_scene.h new file mode 100644 index 00000000..9c2e20e9 --- /dev/null +++ b/applications/infrared/scene/infrared_app_scene.h @@ -0,0 +1,305 @@ +/** + * @file infrared_app_scene.h + * Infrared: Application scenes + */ +#pragma once +#include "../infrared_app_event.h" +#include +#include "infrared.h" +#include +#include +#include "../infrared_app_brute_force.h" + +/** Anonymous class */ +class InfraredApp; + +/** Base Scene class */ +class InfraredAppScene { +public: + /** Called when enter scene */ + virtual void on_enter(InfraredApp* app) = 0; + /** Events handler callback */ + virtual bool on_event(InfraredApp* app, InfraredAppEvent* event) = 0; + /** Called when exit scene */ + virtual void on_exit(InfraredApp* app) = 0; + /** Virtual destructor of base class */ + virtual ~InfraredAppScene(){}; + +private: +}; + +/** Start scene + * Main Infrared application menu + */ +class InfraredAppSceneStart : public InfraredAppScene { +public: + /** Called when enter scene */ + void on_enter(InfraredApp* app) final; + /** Events handler callback */ + bool on_event(InfraredApp* app, InfraredAppEvent* event) final; + /** Called when exit scene */ + void on_exit(InfraredApp* app) final; + +private: + /** Save previously selected submenu index + * to highlight it when get back */ + uint32_t submenu_item_selected = 0; +}; + +/** Universal menu scene + * Scene to select universal remote + */ +class InfraredAppSceneUniversal : public InfraredAppScene { +public: + /** Called when enter scene */ + void on_enter(InfraredApp* app) final; + /** Events handler callback */ + bool on_event(InfraredApp* app, InfraredAppEvent* event) final; + /** Called when exit scene */ + void on_exit(InfraredApp* app) final; + +private: + /** Save previously selected submenu index + * to highlight it when get back */ + uint32_t submenu_item_selected = 0; +}; + +/** Learn new signal scene + * On this scene catching new IR signal performed. + */ +class InfraredAppSceneLearn : public InfraredAppScene { +public: + /** Called when enter scene */ + void on_enter(InfraredApp* app) final; + /** Events handler callback */ + bool on_event(InfraredApp* app, InfraredAppEvent* event) final; + /** Called when exit scene */ + void on_exit(InfraredApp* app) final; +}; + +/** New signal learn succeeded scene + */ +class InfraredAppSceneLearnSuccess : public InfraredAppScene { +public: + /** Called when enter scene */ + void on_enter(InfraredApp* app) final; + /** Events handler callback */ + bool on_event(InfraredApp* app, InfraredAppEvent* event) final; + /** Called when exit scene */ + void on_exit(InfraredApp* app) final; + bool button_pressed = false; +}; + +/** Scene to enter name for new button in remote + */ +class InfraredAppSceneLearnEnterName : public InfraredAppScene { +public: + /** Called when enter scene */ + void on_enter(InfraredApp* app) final; + /** Events handler callback */ + bool on_event(InfraredApp* app, InfraredAppEvent* event) final; + /** Called when exit scene */ + void on_exit(InfraredApp* app) final; +}; + +/** Scene where signal is learnt + */ +class InfraredAppSceneLearnDone : public InfraredAppScene { +public: + /** Called when enter scene */ + void on_enter(InfraredApp* app) final; + /** Events handler callback */ + bool on_event(InfraredApp* app, InfraredAppEvent* event) final; + /** Called when exit scene */ + void on_exit(InfraredApp* app) final; +}; + +/** Remote interface scene + * On this scene you can send IR signals from selected remote + */ +class InfraredAppSceneRemote : public InfraredAppScene { +public: + /** Called when enter scene */ + void on_enter(InfraredApp* app) final; + /** Events handler callback */ + bool on_event(InfraredApp* app, InfraredAppEvent* event) final; + /** Called when exit scene */ + void on_exit(InfraredApp* app) final; + +private: + /** container of button names in current remote. */ + std::vector buttons_names; + /** Save previously selected index + * to highlight it when get back */ + uint32_t buttonmenu_item_selected = 0; + /** state flag to show button is pressed. + * As long as send-signal button pressed no other button + * events are handled. */ + bool button_pressed = false; +}; + +/** List of remotes scene + * Every remote is a file, located on internal/external storage. + * Every file has same format, and same extension. + * Files are parsed as you enter 'Remote scene' and showed + * as a buttons. + */ +class InfraredAppSceneRemoteList : public InfraredAppScene { +public: + /** Called when enter scene */ + void on_enter(InfraredApp* app) final; + /** Events handler callback */ + bool on_event(InfraredApp* app, InfraredAppEvent* event) final; + /** Called when exit scene */ + void on_exit(InfraredApp* app) final; + +private: + /** Save previously selected index + * to highlight it when get back */ + uint32_t submenu_item_selected = 0; + /** Remote names to show them in submenu */ + std::vector remote_names; +}; + +class InfraredAppSceneAskBack : public InfraredAppScene { +public: + /** Called when enter scene */ + void on_enter(InfraredApp* app) final; + /** Events handler callback */ + bool on_event(InfraredApp* app, InfraredAppEvent* event) final; + /** Called when exit scene */ + void on_exit(InfraredApp* app) final; +}; + +class InfraredAppSceneEdit : public InfraredAppScene { +public: + /** Called when enter scene */ + void on_enter(InfraredApp* app) final; + /** Events handler callback */ + bool on_event(InfraredApp* app, InfraredAppEvent* event) final; + /** Called when exit scene */ + void on_exit(InfraredApp* app) final; + +private: + /** Save previously selected index + * to highlight it when get back */ + uint32_t submenu_item_selected = 0; +}; + +class InfraredAppSceneEditKeySelect : public InfraredAppScene { +public: + /** Called when enter scene */ + void on_enter(InfraredApp* app) final; + /** Events handler callback */ + bool on_event(InfraredApp* app, InfraredAppEvent* event) final; + /** Called when exit scene */ + void on_exit(InfraredApp* app) final; + +private: + /** Button names to show them in submenu */ + std::vector buttons_names; +}; + +class InfraredAppSceneEditRename : public InfraredAppScene { +public: + /** Called when enter scene */ + void on_enter(InfraredApp* app) final; + /** Events handler callback */ + bool on_event(InfraredApp* app, InfraredAppEvent* event) final; + /** Called when exit scene */ + void on_exit(InfraredApp* app) final; +}; + +class InfraredAppSceneEditDelete : public InfraredAppScene { +public: + /** Called when enter scene */ + void on_enter(InfraredApp* app) final; + /** Events handler callback */ + bool on_event(InfraredApp* app, InfraredAppEvent* event) final; + /** Called when exit scene */ + void on_exit(InfraredApp* app) final; +}; + +class InfraredAppSceneEditRenameDone : public InfraredAppScene { +public: + /** Called when enter scene */ + void on_enter(InfraredApp* app) final; + /** Events handler callback */ + bool on_event(InfraredApp* app, InfraredAppEvent* event) final; + /** Called when exit scene */ + void on_exit(InfraredApp* app) final; +}; + +class InfraredAppSceneEditDeleteDone : public InfraredAppScene { +public: + /** Called when enter scene */ + void on_enter(InfraredApp* app) final; + /** Events handler callback */ + bool on_event(InfraredApp* app, InfraredAppEvent* event) final; + /** Called when exit scene */ + void on_exit(InfraredApp* app) final; +}; + +class InfraredAppSceneUniversalCommon : public InfraredAppScene { + /** Brute force started flag */ + bool brute_force_started = false; + +protected: + /** Events handler callback */ + bool on_event(InfraredApp* app, InfraredAppEvent* event) final; + /** Called when exit scene */ + void on_exit(InfraredApp* app) final; + + /** Show popup window + * + * @param app - application instance + */ + void show_popup(InfraredApp* app, int record_amount); + + /** Hide popup window + * + * @param app - application instance + */ + void hide_popup(InfraredApp* app); + + /** Propagate progress in popup window + * + * @param app - application instance + */ + bool progress_popup(InfraredApp* app); + + /** Item selected callback + * + * @param context - context + * @param index - selected item index + */ + static void infrared_app_item_callback(void* context, uint32_t index); + + /** Brute Force instance */ + InfraredAppBruteForce brute_force; + + /** Constructor */ + InfraredAppSceneUniversalCommon(const char* filename) + : brute_force(filename) { + } + + /** Destructor */ + ~InfraredAppSceneUniversalCommon() { + } +}; + +class InfraredAppSceneUniversalTV : public InfraredAppSceneUniversalCommon { +public: + /** Called when enter scene */ + void on_enter(InfraredApp* app) final; + + /** Constructor + * Specifies path to brute force db library */ + InfraredAppSceneUniversalTV() + : InfraredAppSceneUniversalCommon("/ext/infrared/assets/tv.ir") { + } + + /** Destructor */ + ~InfraredAppSceneUniversalTV() { + } +}; diff --git a/applications/irda/scene/irda_app_scene_ask_back.cpp b/applications/infrared/scene/infrared_app_scene_ask_back.cpp similarity index 65% rename from applications/irda/scene/irda_app_scene_ask_back.cpp rename to applications/infrared/scene/infrared_app_scene_ask_back.cpp index f7c37110..751816af 100644 --- a/applications/irda/scene/irda_app_scene_ask_back.cpp +++ b/applications/infrared/scene/infrared_app_scene_ask_back.cpp @@ -1,21 +1,21 @@ -#include "../irda_app.h" +#include "../infrared_app.h" #include "gui/modules/dialog_ex.h" -#include "irda.h" -#include "irda/scene/irda_app_scene.h" +#include "infrared.h" +#include "infrared/scene/infrared_app_scene.h" #include static void dialog_result_callback(DialogExResult result, void* context) { - auto app = static_cast(context); - IrdaAppEvent event; + auto app = static_cast(context); + InfraredAppEvent event; - event.type = IrdaAppEvent::Type::DialogExSelected; + event.type = InfraredAppEvent::Type::DialogExSelected; event.payload.dialog_ex_result = result; app->get_view_manager()->send_event(&event); } -void IrdaAppSceneAskBack::on_enter(IrdaApp* app) { - IrdaAppViewManager* view_manager = app->get_view_manager(); +void InfraredAppSceneAskBack::on_enter(InfraredApp* app) { + InfraredAppViewManager* view_manager = app->get_view_manager(); DialogEx* dialog_ex = view_manager->get_dialog_ex(); if(app->get_learn_new_remote()) { @@ -33,21 +33,21 @@ void IrdaAppSceneAskBack::on_enter(IrdaApp* app) { dialog_ex_set_result_callback(dialog_ex, dialog_result_callback); dialog_ex_set_context(dialog_ex, app); - view_manager->switch_to(IrdaAppViewManager::ViewType::DialogEx); + view_manager->switch_to(InfraredAppViewManager::ViewId::DialogEx); } -bool IrdaAppSceneAskBack::on_event(IrdaApp* app, IrdaAppEvent* event) { +bool InfraredAppSceneAskBack::on_event(InfraredApp* app, InfraredAppEvent* event) { bool consumed = false; - if(event->type == IrdaAppEvent::Type::DialogExSelected) { + if(event->type == InfraredAppEvent::Type::DialogExSelected) { switch(event->payload.dialog_ex_result) { case DialogExResultLeft: consumed = true; if(app->get_learn_new_remote()) { - app->search_and_switch_to_previous_scene({IrdaApp::Scene::Start}); + app->search_and_switch_to_previous_scene({InfraredApp::Scene::Start}); } else { app->search_and_switch_to_previous_scene( - {IrdaApp::Scene::Edit, IrdaApp::Scene::Remote}); + {InfraredApp::Scene::Edit, InfraredApp::Scene::Remote}); } break; case DialogExResultCenter: @@ -62,12 +62,12 @@ bool IrdaAppSceneAskBack::on_event(IrdaApp* app, IrdaAppEvent* event) { } } - if(event->type == IrdaAppEvent::Type::Back) { + if(event->type == InfraredAppEvent::Type::Back) { consumed = true; } return consumed; } -void IrdaAppSceneAskBack::on_exit(IrdaApp* app) { +void InfraredAppSceneAskBack::on_exit(InfraredApp* app) { } diff --git a/applications/irda/scene/irda_app_scene_edit.cpp b/applications/infrared/scene/infrared_app_scene_edit.cpp similarity index 50% rename from applications/irda/scene/irda_app_scene_edit.cpp rename to applications/infrared/scene/infrared_app_scene_edit.cpp index bb26ca11..3d9aafe7 100644 --- a/applications/irda/scene/irda_app_scene_edit.cpp +++ b/applications/infrared/scene/infrared_app_scene_edit.cpp @@ -1,4 +1,4 @@ -#include "../irda_app.h" +#include "../infrared_app.h" #include "gui/modules/submenu.h" typedef enum { @@ -10,17 +10,17 @@ typedef enum { } SubmenuIndex; static void submenu_callback(void* context, uint32_t index) { - IrdaApp* app = static_cast(context); - IrdaAppEvent event; + InfraredApp* app = static_cast(context); + InfraredAppEvent event; - event.type = IrdaAppEvent::Type::MenuSelected; + event.type = InfraredAppEvent::Type::MenuSelected; event.payload.menu_index = index; app->get_view_manager()->send_event(&event); } -void IrdaAppSceneEdit::on_enter(IrdaApp* app) { - IrdaAppViewManager* view_manager = app->get_view_manager(); +void InfraredAppSceneEdit::on_enter(InfraredApp* app) { + InfraredAppViewManager* view_manager = app->get_view_manager(); Submenu* submenu = view_manager->get_submenu(); submenu_add_item(submenu, "Add key", SubmenuIndexAddKey, submenu_callback, app); @@ -31,38 +31,38 @@ void IrdaAppSceneEdit::on_enter(IrdaApp* app) { submenu_set_selected_item(submenu, submenu_item_selected); submenu_item_selected = 0; - view_manager->switch_to(IrdaAppViewManager::ViewType::Submenu); + view_manager->switch_to(InfraredAppViewManager::ViewId::Submenu); } -bool IrdaAppSceneEdit::on_event(IrdaApp* app, IrdaAppEvent* event) { +bool InfraredAppSceneEdit::on_event(InfraredApp* app, InfraredAppEvent* event) { bool consumed = false; - if(event->type == IrdaAppEvent::Type::MenuSelected) { + if(event->type == InfraredAppEvent::Type::MenuSelected) { submenu_item_selected = event->payload.menu_index; switch(event->payload.menu_index) { case SubmenuIndexAddKey: app->set_learn_new_remote(false); - app->switch_to_next_scene(IrdaApp::Scene::Learn); + app->switch_to_next_scene(InfraredApp::Scene::Learn); break; case SubmenuIndexRenameKey: - app->set_edit_action(IrdaApp::EditAction::Rename); - app->set_edit_element(IrdaApp::EditElement::Button); - app->switch_to_next_scene(IrdaApp::Scene::EditKeySelect); + app->set_edit_action(InfraredApp::EditAction::Rename); + app->set_edit_element(InfraredApp::EditElement::Button); + app->switch_to_next_scene(InfraredApp::Scene::EditKeySelect); break; case SubmenuIndexDeleteKey: - app->set_edit_action(IrdaApp::EditAction::Delete); - app->set_edit_element(IrdaApp::EditElement::Button); - app->switch_to_next_scene(IrdaApp::Scene::EditKeySelect); + app->set_edit_action(InfraredApp::EditAction::Delete); + app->set_edit_element(InfraredApp::EditElement::Button); + app->switch_to_next_scene(InfraredApp::Scene::EditKeySelect); break; case SubmenuIndexRenameRemote: - app->set_edit_action(IrdaApp::EditAction::Rename); - app->set_edit_element(IrdaApp::EditElement::Remote); - app->switch_to_next_scene(IrdaApp::Scene::EditRename); + app->set_edit_action(InfraredApp::EditAction::Rename); + app->set_edit_element(InfraredApp::EditElement::Remote); + app->switch_to_next_scene(InfraredApp::Scene::EditRename); break; case SubmenuIndexDeleteRemote: - app->set_edit_action(IrdaApp::EditAction::Delete); - app->set_edit_element(IrdaApp::EditElement::Remote); - app->switch_to_next_scene(IrdaApp::Scene::EditDelete); + app->set_edit_action(InfraredApp::EditAction::Delete); + app->set_edit_element(InfraredApp::EditElement::Remote); + app->switch_to_next_scene(InfraredApp::Scene::EditDelete); break; } consumed = true; @@ -71,8 +71,8 @@ bool IrdaAppSceneEdit::on_event(IrdaApp* app, IrdaAppEvent* event) { return consumed; } -void IrdaAppSceneEdit::on_exit(IrdaApp* app) { - IrdaAppViewManager* view_manager = app->get_view_manager(); +void InfraredAppSceneEdit::on_exit(InfraredApp* app) { + InfraredAppViewManager* view_manager = app->get_view_manager(); Submenu* submenu = view_manager->get_submenu(); submenu_reset(submenu); diff --git a/applications/irda/scene/irda_app_scene_edit_delete.cpp b/applications/infrared/scene/infrared_app_scene_edit_delete.cpp similarity index 66% rename from applications/irda/scene/irda_app_scene_edit_delete.cpp rename to applications/infrared/scene/infrared_app_scene_edit_delete.cpp index 26204801..0818b6fb 100644 --- a/applications/irda/scene/irda_app_scene_edit_delete.cpp +++ b/applications/infrared/scene/infrared_app_scene_edit_delete.cpp @@ -1,25 +1,25 @@ -#include "../irda_app.h" -#include "irda.h" -#include "irda/scene/irda_app_scene.h" +#include "../infrared_app.h" +#include "infrared.h" +#include "infrared/scene/infrared_app_scene.h" #include static void dialog_result_callback(DialogExResult result, void* context) { - auto app = static_cast(context); - IrdaAppEvent event; + auto app = static_cast(context); + InfraredAppEvent event; - event.type = IrdaAppEvent::Type::DialogExSelected; + event.type = InfraredAppEvent::Type::DialogExSelected; event.payload.dialog_ex_result = result; app->get_view_manager()->send_event(&event); } -void IrdaAppSceneEditDelete::on_enter(IrdaApp* app) { - IrdaAppViewManager* view_manager = app->get_view_manager(); +void InfraredAppSceneEditDelete::on_enter(InfraredApp* app) { + InfraredAppViewManager* view_manager = app->get_view_manager(); DialogEx* dialog_ex = view_manager->get_dialog_ex(); auto remote_manager = app->get_remote_manager(); - if(app->get_edit_element() == IrdaApp::EditElement::Button) { + if(app->get_edit_element() == InfraredApp::EditElement::Button) { auto signal = remote_manager->get_button_data(app->get_current_button()); dialog_ex_set_header(dialog_ex, "Delete button?", 64, 0, AlignCenter, AlignTop); if(!signal.is_raw()) { @@ -28,10 +28,10 @@ void IrdaAppSceneEditDelete::on_enter(IrdaApp* app) { 0, "%s\n%s\nA=0x%0*lX C=0x%0*lX", remote_manager->get_button_name(app->get_current_button()).c_str(), - irda_get_protocol_name(message->protocol), - ROUND_UP_TO(irda_get_protocol_address_length(message->protocol), 4), + infrared_get_protocol_name(message->protocol), + ROUND_UP_TO(infrared_get_protocol_address_length(message->protocol), 4), message->address, - ROUND_UP_TO(irda_get_protocol_command_length(message->protocol), 4), + ROUND_UP_TO(infrared_get_protocol_command_length(message->protocol), 4), message->command); } else { app->set_text_store( @@ -56,13 +56,13 @@ void IrdaAppSceneEditDelete::on_enter(IrdaApp* app) { dialog_ex_set_result_callback(dialog_ex, dialog_result_callback); dialog_ex_set_context(dialog_ex, app); - view_manager->switch_to(IrdaAppViewManager::ViewType::DialogEx); + view_manager->switch_to(InfraredAppViewManager::ViewId::DialogEx); } -bool IrdaAppSceneEditDelete::on_event(IrdaApp* app, IrdaAppEvent* event) { +bool InfraredAppSceneEditDelete::on_event(InfraredApp* app, InfraredAppEvent* event) { bool consumed = false; - if(event->type == IrdaAppEvent::Type::DialogExSelected) { + if(event->type == InfraredAppEvent::Type::DialogExSelected) { switch(event->payload.dialog_ex_result) { case DialogExResultLeft: app->switch_to_previous_scene(); @@ -73,18 +73,18 @@ bool IrdaAppSceneEditDelete::on_event(IrdaApp* app, IrdaAppEvent* event) { case DialogExResultRight: { auto remote_manager = app->get_remote_manager(); bool result = false; - if(app->get_edit_element() == IrdaApp::EditElement::Remote) { + if(app->get_edit_element() == InfraredApp::EditElement::Remote) { result = remote_manager->delete_remote(); } else { result = remote_manager->delete_button(app->get_current_button()); - app->set_current_button(IrdaApp::ButtonNA); + app->set_current_button(InfraredApp::ButtonNA); } if(!result) { app->search_and_switch_to_previous_scene( - {IrdaApp::Scene::RemoteList, IrdaApp::Scene::Start}); + {InfraredApp::Scene::RemoteList, InfraredApp::Scene::Start}); } else { - app->switch_to_next_scene(IrdaApp::Scene::EditDeleteDone); + app->switch_to_next_scene(InfraredApp::Scene::EditDeleteDone); } break; } @@ -96,5 +96,5 @@ bool IrdaAppSceneEditDelete::on_event(IrdaApp* app, IrdaAppEvent* event) { return consumed; } -void IrdaAppSceneEditDelete::on_exit(IrdaApp* app) { +void InfraredAppSceneEditDelete::on_exit(InfraredApp* app) { } diff --git a/applications/infrared/scene/infrared_app_scene_edit_delete_done.cpp b/applications/infrared/scene/infrared_app_scene_edit_delete_done.cpp new file mode 100644 index 00000000..3f9800e1 --- /dev/null +++ b/applications/infrared/scene/infrared_app_scene_edit_delete_done.cpp @@ -0,0 +1,38 @@ +#include "../infrared_app.h" + +void InfraredAppSceneEditDeleteDone::on_enter(InfraredApp* app) { + InfraredAppViewManager* view_manager = app->get_view_manager(); + Popup* popup = view_manager->get_popup(); + + popup_set_icon(popup, 0, 2, &I_DolphinMafia_115x62); + popup_set_header(popup, "Deleted", 83, 19, AlignLeft, AlignBottom); + + popup_set_callback(popup, InfraredApp::popup_callback); + popup_set_context(popup, app); + popup_set_timeout(popup, 1500); + popup_enable_timeout(popup); + + view_manager->switch_to(InfraredAppViewManager::ViewId::Popup); +} + +bool InfraredAppSceneEditDeleteDone::on_event(InfraredApp* app, InfraredAppEvent* event) { + bool consumed = false; + + if(event->type == InfraredAppEvent::Type::PopupTimer) { + if(app->get_edit_element() == InfraredApp::EditElement::Remote) { + app->search_and_switch_to_previous_scene( + {InfraredApp::Scene::Start, InfraredApp::Scene::RemoteList}); + } else { + app->search_and_switch_to_previous_scene({InfraredApp::Scene::Remote}); + } + consumed = true; + } + + return consumed; +} + +void InfraredAppSceneEditDeleteDone::on_exit(InfraredApp* app) { + InfraredAppViewManager* view_manager = app->get_view_manager(); + Popup* popup = view_manager->get_popup(); + popup_set_header(popup, nullptr, 0, 0, AlignLeft, AlignTop); +} diff --git a/applications/infrared/scene/infrared_app_scene_edit_key_select.cpp b/applications/infrared/scene/infrared_app_scene_edit_key_select.cpp new file mode 100644 index 00000000..7f94fb15 --- /dev/null +++ b/applications/infrared/scene/infrared_app_scene_edit_key_select.cpp @@ -0,0 +1,57 @@ +#include "../infrared_app.h" +#include "gui/modules/submenu.h" + +static void submenu_callback(void* context, uint32_t index) { + InfraredApp* app = static_cast(context); + InfraredAppEvent event; + + event.type = InfraredAppEvent::Type::MenuSelected; + event.payload.menu_index = index; + + app->get_view_manager()->send_event(&event); +} + +void InfraredAppSceneEditKeySelect::on_enter(InfraredApp* app) { + InfraredAppViewManager* view_manager = app->get_view_manager(); + Submenu* submenu = view_manager->get_submenu(); + int item_number = 0; + + const char* header = + app->get_edit_action() == InfraredApp::EditAction::Rename ? "Rename key:" : "Delete key:"; + submenu_set_header(submenu, header); + + auto remote_manager = app->get_remote_manager(); + buttons_names = remote_manager->get_button_list(); + for(const auto& it : buttons_names) { + submenu_add_item(submenu, it.c_str(), item_number++, submenu_callback, app); + } + if((item_number > 0) && (app->get_current_button() != InfraredApp::ButtonNA)) { + submenu_set_selected_item(submenu, app->get_current_button()); + app->set_current_button(InfraredApp::ButtonNA); + } + + view_manager->switch_to(InfraredAppViewManager::ViewId::Submenu); +} + +bool InfraredAppSceneEditKeySelect::on_event(InfraredApp* app, InfraredAppEvent* event) { + bool consumed = false; + + if(event->type == InfraredAppEvent::Type::MenuSelected) { + app->set_current_button(event->payload.menu_index); + consumed = true; + if(app->get_edit_action() == InfraredApp::EditAction::Rename) { + app->switch_to_next_scene(InfraredApp::Scene::EditRename); + } else { + app->switch_to_next_scene(InfraredApp::Scene::EditDelete); + } + } + + return consumed; +} + +void InfraredAppSceneEditKeySelect::on_exit(InfraredApp* app) { + InfraredAppViewManager* view_manager = app->get_view_manager(); + Submenu* submenu = view_manager->get_submenu(); + + submenu_reset(submenu); +} diff --git a/applications/irda/scene/irda_app_scene_edit_rename.cpp b/applications/infrared/scene/infrared_app_scene_edit_rename.cpp similarity index 60% rename from applications/irda/scene/irda_app_scene_edit_rename.cpp rename to applications/infrared/scene/infrared_app_scene_edit_rename.cpp index 28c13456..4b3578fa 100644 --- a/applications/irda/scene/irda_app_scene_edit_rename.cpp +++ b/applications/infrared/scene/infrared_app_scene_edit_rename.cpp @@ -1,16 +1,16 @@ -#include "../irda_app.h" +#include "../infrared_app.h" -void IrdaAppSceneEditRename::on_enter(IrdaApp* app) { - IrdaAppViewManager* view_manager = app->get_view_manager(); +void InfraredAppSceneEditRename::on_enter(InfraredApp* app) { + InfraredAppViewManager* view_manager = app->get_view_manager(); TextInput* text_input = view_manager->get_text_input(); size_t enter_name_length = 0; auto remote_manager = app->get_remote_manager(); - if(app->get_edit_element() == IrdaApp::EditElement::Button) { - furi_assert(app->get_current_button() != IrdaApp::ButtonNA); + if(app->get_edit_element() == InfraredApp::EditElement::Button) { + furi_assert(app->get_current_button() != InfraredApp::ButtonNA); auto button_name = remote_manager->get_button_name(app->get_current_button()); char* buffer_str = app->get_text_store(0); - size_t max_len = IrdaAppRemoteManager::max_button_name_length; + size_t max_len = InfraredAppRemoteManager::max_button_name_length; strncpy(buffer_str, button_name.c_str(), max_len); buffer_str[max_len + 1] = 0; enter_name_length = max_len; @@ -18,43 +18,43 @@ void IrdaAppSceneEditRename::on_enter(IrdaApp* app) { } else { auto remote_name = remote_manager->get_remote_name(); strncpy(app->get_text_store(0), remote_name.c_str(), app->get_text_store_size()); - enter_name_length = IrdaAppRemoteManager::max_remote_name_length; + enter_name_length = InfraredAppRemoteManager::max_remote_name_length; text_input_set_header_text(text_input, "Name the remote"); ValidatorIsFile* validator_is_file = - validator_is_file_alloc_init(app->irda_directory, app->irda_extension); + validator_is_file_alloc_init(app->infrared_directory, app->infrared_extension); text_input_set_validator(text_input, validator_is_file_callback, validator_is_file); } text_input_set_result_callback( text_input, - IrdaApp::text_input_callback, + InfraredApp::text_input_callback, app, app->get_text_store(0), enter_name_length, false); - view_manager->switch_to(IrdaAppViewManager::ViewType::TextInput); + view_manager->switch_to(InfraredAppViewManager::ViewId::TextInput); } -bool IrdaAppSceneEditRename::on_event(IrdaApp* app, IrdaAppEvent* event) { +bool InfraredAppSceneEditRename::on_event(InfraredApp* app, InfraredAppEvent* event) { bool consumed = false; - if(event->type == IrdaAppEvent::Type::TextEditDone) { + if(event->type == InfraredAppEvent::Type::TextEditDone) { auto remote_manager = app->get_remote_manager(); bool result = false; - if(app->get_edit_element() == IrdaApp::EditElement::Button) { + if(app->get_edit_element() == InfraredApp::EditElement::Button) { result = remote_manager->rename_button(app->get_current_button(), app->get_text_store(0)); - app->set_current_button(IrdaApp::ButtonNA); + app->set_current_button(InfraredApp::ButtonNA); } else { result = remote_manager->rename_remote(app->get_text_store(0)); } if(!result) { app->search_and_switch_to_previous_scene( - {IrdaApp::Scene::Start, IrdaApp::Scene::RemoteList}); + {InfraredApp::Scene::Start, InfraredApp::Scene::RemoteList}); } else { - app->switch_to_next_scene_without_saving(IrdaApp::Scene::EditRenameDone); + app->switch_to_next_scene_without_saving(InfraredApp::Scene::EditRenameDone); } consumed = true; } @@ -62,7 +62,7 @@ bool IrdaAppSceneEditRename::on_event(IrdaApp* app, IrdaAppEvent* event) { return consumed; } -void IrdaAppSceneEditRename::on_exit(IrdaApp* app) { +void InfraredAppSceneEditRename::on_exit(InfraredApp* app) { TextInput* text_input = app->get_view_manager()->get_text_input(); void* validator_context = text_input_get_validator_callback_context(text_input); diff --git a/applications/infrared/scene/infrared_app_scene_edit_rename_done.cpp b/applications/infrared/scene/infrared_app_scene_edit_rename_done.cpp new file mode 100644 index 00000000..47ef343b --- /dev/null +++ b/applications/infrared/scene/infrared_app_scene_edit_rename_done.cpp @@ -0,0 +1,31 @@ +#include "../infrared_app.h" + +void InfraredAppSceneEditRenameDone::on_enter(InfraredApp* app) { + InfraredAppViewManager* view_manager = app->get_view_manager(); + Popup* popup = view_manager->get_popup(); + + popup_set_icon(popup, 32, 5, &I_DolphinNice_96x59); + + popup_set_header(popup, "Saved!", 5, 7, AlignLeft, AlignTop); + + popup_set_callback(popup, InfraredApp::popup_callback); + popup_set_context(popup, app); + popup_set_timeout(popup, 1500); + popup_enable_timeout(popup); + + view_manager->switch_to(InfraredAppViewManager::ViewId::Popup); +} + +bool InfraredAppSceneEditRenameDone::on_event(InfraredApp* app, InfraredAppEvent* event) { + bool consumed = false; + + if(event->type == InfraredAppEvent::Type::PopupTimer) { + app->switch_to_next_scene(InfraredApp::Scene::Remote); + consumed = true; + } + + return consumed; +} + +void InfraredAppSceneEditRenameDone::on_exit(InfraredApp* app) { +} diff --git a/applications/infrared/scene/infrared_app_scene_learn.cpp b/applications/infrared/scene/infrared_app_scene_learn.cpp new file mode 100644 index 00000000..1ae3b92c --- /dev/null +++ b/applications/infrared/scene/infrared_app_scene_learn.cpp @@ -0,0 +1,75 @@ +#include "../infrared_app.h" +#include "../infrared_app_event.h" +#include "infrared.h" +#include + +static void signal_received_callback(void* context, InfraredWorkerSignal* received_signal) { + furi_assert(context); + furi_assert(received_signal); + + InfraredApp* app = static_cast(context); + + if(infrared_worker_signal_is_decoded(received_signal)) { + InfraredAppSignal signal(infrared_worker_get_decoded_signal(received_signal)); + app->set_received_signal(signal); + } else { + const uint32_t* timings; + size_t timings_cnt; + infrared_worker_get_raw_signal(received_signal, &timings, &timings_cnt); + InfraredAppSignal signal( + timings, timings_cnt, INFRARED_COMMON_CARRIER_FREQUENCY, INFRARED_COMMON_DUTY_CYCLE); + app->set_received_signal(signal); + } + + infrared_worker_rx_set_received_signal_callback(app->get_infrared_worker(), NULL, NULL); + InfraredAppEvent event; + event.type = InfraredAppEvent::Type::InfraredMessageReceived; + auto view_manager = app->get_view_manager(); + view_manager->send_event(&event); +} + +void InfraredAppSceneLearn::on_enter(InfraredApp* app) { + auto view_manager = app->get_view_manager(); + auto popup = view_manager->get_popup(); + + auto worker = app->get_infrared_worker(); + infrared_worker_rx_set_received_signal_callback(worker, signal_received_callback, app); + infrared_worker_rx_start(worker); + + popup_set_icon(popup, 0, 32, &I_InfraredLearnShort_128x31); + popup_set_text( + popup, "Point the remote at IR port\nand push the button", 5, 10, AlignLeft, AlignCenter); + popup_set_callback(popup, NULL); + + view_manager->switch_to(InfraredAppViewManager::ViewId::Popup); +} + +bool InfraredAppSceneLearn::on_event(InfraredApp* app, InfraredAppEvent* event) { + bool consumed = false; + + switch(event->type) { + case InfraredAppEvent::Type::Tick: + consumed = true; + app->notify_red_blink(); + break; + case InfraredAppEvent::Type::InfraredMessageReceived: + app->notify_success(); + app->switch_to_next_scene_without_saving(InfraredApp::Scene::LearnSuccess); + break; + case InfraredAppEvent::Type::Back: + consumed = true; + app->switch_to_previous_scene(); + break; + default: + furi_assert(0); + } + + return consumed; +} + +void InfraredAppSceneLearn::on_exit(InfraredApp* app) { + infrared_worker_rx_stop(app->get_infrared_worker()); + auto view_manager = app->get_view_manager(); + auto popup = view_manager->get_popup(); + popup_set_text(popup, NULL, 0, 0, AlignCenter, AlignCenter); +} diff --git a/applications/irda/scene/irda_app_scene_learn_done.cpp b/applications/infrared/scene/infrared_app_scene_learn_done.cpp similarity index 53% rename from applications/irda/scene/irda_app_scene_learn_done.cpp rename to applications/infrared/scene/infrared_app_scene_learn_done.cpp index f2669baa..6ee13b43 100644 --- a/applications/irda/scene/irda_app_scene_learn_done.cpp +++ b/applications/infrared/scene/infrared_app_scene_learn_done.cpp @@ -1,8 +1,8 @@ -#include "../irda_app.h" +#include "../infrared_app.h" #include -void IrdaAppSceneLearnDone::on_enter(IrdaApp* app) { - IrdaAppViewManager* view_manager = app->get_view_manager(); +void InfraredAppSceneLearnDone::on_enter(InfraredApp* app) { + InfraredAppViewManager* view_manager = app->get_view_manager(); Popup* popup = view_manager->get_popup(); popup_set_icon(popup, 32, 5, &I_DolphinNice_96x59); @@ -14,28 +14,28 @@ void IrdaAppSceneLearnDone::on_enter(IrdaApp* app) { popup_set_header(popup, "Saved!", 5, 7, AlignLeft, AlignTop); } - popup_set_callback(popup, IrdaApp::popup_callback); + popup_set_callback(popup, InfraredApp::popup_callback); popup_set_context(popup, app); popup_set_timeout(popup, 1500); popup_enable_timeout(popup); - view_manager->switch_to(IrdaAppViewManager::ViewType::Popup); + view_manager->switch_to(InfraredAppViewManager::ViewId::Popup); } -bool IrdaAppSceneLearnDone::on_event(IrdaApp* app, IrdaAppEvent* event) { +bool InfraredAppSceneLearnDone::on_event(InfraredApp* app, InfraredAppEvent* event) { bool consumed = false; - if(event->type == IrdaAppEvent::Type::PopupTimer) { - app->switch_to_next_scene(IrdaApp::Scene::Remote); + if(event->type == InfraredAppEvent::Type::PopupTimer) { + app->switch_to_next_scene(InfraredApp::Scene::Remote); consumed = true; } return consumed; } -void IrdaAppSceneLearnDone::on_exit(IrdaApp* app) { +void InfraredAppSceneLearnDone::on_exit(InfraredApp* app) { app->set_learn_new_remote(false); - IrdaAppViewManager* view_manager = app->get_view_manager(); + InfraredAppViewManager* view_manager = app->get_view_manager(); Popup* popup = view_manager->get_popup(); popup_set_header(popup, nullptr, 0, 0, AlignLeft, AlignTop); } diff --git a/applications/irda/scene/irda_app_scene_learn_enter_name.cpp b/applications/infrared/scene/infrared_app_scene_learn_enter_name.cpp similarity index 58% rename from applications/irda/scene/irda_app_scene_learn_enter_name.cpp rename to applications/infrared/scene/infrared_app_scene_learn_enter_name.cpp index 3c871553..e0f2ebd1 100644 --- a/applications/irda/scene/irda_app_scene_learn_enter_name.cpp +++ b/applications/infrared/scene/infrared_app_scene_learn_enter_name.cpp @@ -1,8 +1,8 @@ -#include "../irda_app.h" +#include "../infrared_app.h" #include "gui/modules/text_input.h" -void IrdaAppSceneLearnEnterName::on_enter(IrdaApp* app) { - IrdaAppViewManager* view_manager = app->get_view_manager(); +void InfraredAppSceneLearnEnterName::on_enter(InfraredApp* app) { + InfraredAppViewManager* view_manager = app->get_view_manager(); TextInput* text_input = view_manager->get_text_input(); auto signal = app->get_received_signal(); @@ -12,8 +12,8 @@ void IrdaAppSceneLearnEnterName::on_enter(IrdaApp* app) { app->set_text_store( 0, "%.4s_%0*lX", - irda_get_protocol_name(message->protocol), - ROUND_UP_TO(irda_get_protocol_command_length(message->protocol), 4), + infrared_get_protocol_name(message->protocol), + ROUND_UP_TO(infrared_get_protocol_command_length(message->protocol), 4), message->command); } else { auto raw_signal = signal.get_raw_signal(); @@ -23,19 +23,19 @@ void IrdaAppSceneLearnEnterName::on_enter(IrdaApp* app) { text_input_set_header_text(text_input, "Name the key"); text_input_set_result_callback( text_input, - IrdaApp::text_input_callback, + InfraredApp::text_input_callback, app, app->get_text_store(0), - IrdaAppRemoteManager::max_button_name_length, + InfraredAppRemoteManager::max_button_name_length, true); - view_manager->switch_to(IrdaAppViewManager::ViewType::TextInput); + view_manager->switch_to(InfraredAppViewManager::ViewId::TextInput); } -bool IrdaAppSceneLearnEnterName::on_event(IrdaApp* app, IrdaAppEvent* event) { +bool InfraredAppSceneLearnEnterName::on_event(InfraredApp* app, InfraredAppEvent* event) { bool consumed = false; - if(event->type == IrdaAppEvent::Type::TextEditDone) { + if(event->type == InfraredAppEvent::Type::TextEditDone) { auto remote_manager = app->get_remote_manager(); bool result = false; if(app->get_learn_new_remote()) { @@ -48,13 +48,13 @@ bool IrdaAppSceneLearnEnterName::on_event(IrdaApp* app, IrdaAppEvent* event) { if(!result) { app->search_and_switch_to_previous_scene( - {IrdaApp::Scene::Start, IrdaApp::Scene::RemoteList}); + {InfraredApp::Scene::Start, InfraredApp::Scene::RemoteList}); } else { - app->switch_to_next_scene_without_saving(IrdaApp::Scene::LearnDone); + app->switch_to_next_scene_without_saving(InfraredApp::Scene::LearnDone); } } return consumed; } -void IrdaAppSceneLearnEnterName::on_exit(IrdaApp* app) { +void InfraredAppSceneLearnEnterName::on_exit(InfraredApp* app) { } diff --git a/applications/irda/scene/irda_app_scene_learn_success.cpp b/applications/infrared/scene/infrared_app_scene_learn_success.cpp similarity index 61% rename from applications/irda/scene/irda_app_scene_learn_success.cpp rename to applications/infrared/scene/infrared_app_scene_learn_success.cpp index dfb889b0..61d60ab5 100644 --- a/applications/irda/scene/irda_app_scene_learn_success.cpp +++ b/applications/infrared/scene/infrared_app_scene_learn_success.cpp @@ -3,42 +3,44 @@ #include #include -#include "../irda_app.h" -#include "irda.h" +#include "../infrared_app.h" +#include "infrared.h" static void dialog_result_callback(DialogExResult result, void* context) { - auto app = static_cast(context); - IrdaAppEvent event; + auto app = static_cast(context); + InfraredAppEvent event; - event.type = IrdaAppEvent::Type::DialogExSelected; + event.type = InfraredAppEvent::Type::DialogExSelected; event.payload.dialog_ex_result = result; app->get_view_manager()->send_event(&event); } -void IrdaAppSceneLearnSuccess::on_enter(IrdaApp* app) { - IrdaAppViewManager* view_manager = app->get_view_manager(); +void InfraredAppSceneLearnSuccess::on_enter(InfraredApp* app) { + InfraredAppViewManager* view_manager = app->get_view_manager(); DialogEx* dialog_ex = view_manager->get_dialog_ex(); DOLPHIN_DEED(DolphinDeedIrLearnSuccess); app->notify_green_on(); - irda_worker_tx_set_get_signal_callback( - app->get_irda_worker(), irda_worker_tx_get_signal_steady_callback, app); - irda_worker_tx_set_signal_sent_callback( - app->get_irda_worker(), IrdaApp::signal_sent_callback, app); + infrared_worker_tx_set_get_signal_callback( + app->get_infrared_worker(), infrared_worker_tx_get_signal_steady_callback, app); + infrared_worker_tx_set_signal_sent_callback( + app->get_infrared_worker(), InfraredApp::signal_sent_callback, app); auto signal = app->get_received_signal(); if(!signal.is_raw()) { auto message = &signal.get_message(); - uint8_t adr_digits = ROUND_UP_TO(irda_get_protocol_address_length(message->protocol), 4); - uint8_t cmd_digits = ROUND_UP_TO(irda_get_protocol_command_length(message->protocol), 4); + uint8_t adr_digits = + ROUND_UP_TO(infrared_get_protocol_address_length(message->protocol), 4); + uint8_t cmd_digits = + ROUND_UP_TO(infrared_get_protocol_command_length(message->protocol), 4); uint8_t max_digits = MAX(adr_digits, cmd_digits); max_digits = MIN(max_digits, 7); size_t label_x_offset = 63 + (7 - max_digits) * 3; - app->set_text_store(0, "%s", irda_get_protocol_name(message->protocol)); + app->set_text_store(0, "%s", infrared_get_protocol_name(message->protocol)); app->set_text_store( 1, "A: 0x%0*lX\nC: 0x%0*lX\n", @@ -64,24 +66,24 @@ void IrdaAppSceneLearnSuccess::on_enter(IrdaApp* app) { dialog_ex_set_context(dialog_ex, app); dialog_ex_enable_extended_events(dialog_ex); - view_manager->switch_to(IrdaAppViewManager::ViewType::DialogEx); + view_manager->switch_to(InfraredAppViewManager::ViewId::DialogEx); } -bool IrdaAppSceneLearnSuccess::on_event(IrdaApp* app, IrdaAppEvent* event) { +bool InfraredAppSceneLearnSuccess::on_event(InfraredApp* app, InfraredAppEvent* event) { bool consumed = false; - if(event->type == IrdaAppEvent::Type::Tick) { + if(event->type == InfraredAppEvent::Type::Tick) { /* Send event every tick to suppress any switching off green light */ if(!button_pressed) { app->notify_green_on(); } } - if(event->type == IrdaAppEvent::Type::DialogExSelected) { + if(event->type == InfraredAppEvent::Type::DialogExSelected) { switch(event->payload.dialog_ex_result) { case DialogExResultLeft: consumed = true; if(!button_pressed) { - app->switch_to_next_scene_without_saving(IrdaApp::Scene::Learn); + app->switch_to_next_scene_without_saving(InfraredApp::Scene::Learn); } break; case DialogExResultRight: { @@ -89,7 +91,7 @@ bool IrdaAppSceneLearnSuccess::on_event(IrdaApp* app, IrdaAppEvent* event) { FileWorkerCpp file_worker; if(!button_pressed) { if(file_worker.check_errors()) { - app->switch_to_next_scene(IrdaApp::Scene::LearnEnterName); + app->switch_to_next_scene(InfraredApp::Scene::LearnEnterName); } else { app->switch_to_previous_scene(); } @@ -103,21 +105,22 @@ bool IrdaAppSceneLearnSuccess::on_event(IrdaApp* app, IrdaAppEvent* event) { auto signal = app->get_received_signal(); if(signal.is_raw()) { - irda_worker_set_raw_signal( - app->get_irda_worker(), + infrared_worker_set_raw_signal( + app->get_infrared_worker(), signal.get_raw_signal().timings, signal.get_raw_signal().timings_cnt); } else { - irda_worker_set_decoded_signal(app->get_irda_worker(), &signal.get_message()); + infrared_worker_set_decoded_signal( + app->get_infrared_worker(), &signal.get_message()); } - irda_worker_tx_start(app->get_irda_worker()); + infrared_worker_tx_start(app->get_infrared_worker()); } break; case DialogExReleaseCenter: if(button_pressed) { button_pressed = false; - irda_worker_tx_stop(app->get_irda_worker()); + infrared_worker_tx_stop(app->get_infrared_worker()); app->notify_green_off(); } break; @@ -126,9 +129,9 @@ bool IrdaAppSceneLearnSuccess::on_event(IrdaApp* app, IrdaAppEvent* event) { } } - if(event->type == IrdaAppEvent::Type::Back) { + if(event->type == InfraredAppEvent::Type::Back) { if(!button_pressed) { - app->switch_to_next_scene(IrdaApp::Scene::AskBack); + app->switch_to_next_scene(InfraredApp::Scene::AskBack); } consumed = true; } @@ -136,11 +139,11 @@ bool IrdaAppSceneLearnSuccess::on_event(IrdaApp* app, IrdaAppEvent* event) { return consumed; } -void IrdaAppSceneLearnSuccess::on_exit(IrdaApp* app) { - IrdaAppViewManager* view_manager = app->get_view_manager(); +void InfraredAppSceneLearnSuccess::on_exit(InfraredApp* app) { + InfraredAppViewManager* view_manager = app->get_view_manager(); DialogEx* dialog_ex = view_manager->get_dialog_ex(); dialog_ex_reset(dialog_ex); app->notify_green_off(); - irda_worker_tx_set_get_signal_callback(app->get_irda_worker(), nullptr, nullptr); - irda_worker_tx_set_signal_sent_callback(app->get_irda_worker(), nullptr, nullptr); + infrared_worker_tx_set_get_signal_callback(app->get_infrared_worker(), nullptr, nullptr); + infrared_worker_tx_set_signal_sent_callback(app->get_infrared_worker(), nullptr, nullptr); } diff --git a/applications/irda/scene/irda_app_scene_remote.cpp b/applications/infrared/scene/infrared_app_scene_remote.cpp similarity index 54% rename from applications/irda/scene/irda_app_scene_remote.cpp rename to applications/infrared/scene/infrared_app_scene_remote.cpp index 5f928b41..b99f1c98 100644 --- a/applications/irda/scene/irda_app_scene_remote.cpp +++ b/applications/infrared/scene/infrared_app_scene_remote.cpp @@ -1,9 +1,9 @@ #include #include -#include +#include #include -#include "../irda_app.h" -#include "../irda_app_view_manager.h" +#include "../infrared_app.h" +#include "../infrared_app_view_manager.h" typedef enum { ButtonIndexPlus = -2, @@ -12,15 +12,15 @@ typedef enum { } ButtonIndex; static void button_menu_callback(void* context, int32_t index, InputType type) { - IrdaApp* app = static_cast(context); - IrdaAppEvent event; + InfraredApp* app = static_cast(context); + InfraredAppEvent event; if(type == InputTypePress) { - event.type = IrdaAppEvent::Type::MenuSelectedPress; + event.type = InfraredAppEvent::Type::MenuSelectedPress; } else if(type == InputTypeRelease) { - event.type = IrdaAppEvent::Type::MenuSelectedRelease; + event.type = InfraredAppEvent::Type::MenuSelectedRelease; } else if(type == InputTypeShort) { - event.type = IrdaAppEvent::Type::MenuSelected; + event.type = InfraredAppEvent::Type::MenuSelected; } else { furi_assert(0); } @@ -30,17 +30,17 @@ static void button_menu_callback(void* context, int32_t index, InputType type) { app->get_view_manager()->send_event(&event); } -void IrdaAppSceneRemote::on_enter(IrdaApp* app) { - IrdaAppViewManager* view_manager = app->get_view_manager(); +void InfraredAppSceneRemote::on_enter(InfraredApp* app) { + InfraredAppViewManager* view_manager = app->get_view_manager(); ButtonMenu* button_menu = view_manager->get_button_menu(); auto remote_manager = app->get_remote_manager(); int i = 0; button_pressed = false; - irda_worker_tx_set_get_signal_callback( - app->get_irda_worker(), irda_worker_tx_get_signal_steady_callback, app); - irda_worker_tx_set_signal_sent_callback( - app->get_irda_worker(), IrdaApp::signal_sent_callback, app); + infrared_worker_tx_set_get_signal_callback( + app->get_infrared_worker(), infrared_worker_tx_get_signal_steady_callback, app); + infrared_worker_tx_set_signal_sent_callback( + app->get_infrared_worker(), InfraredApp::signal_sent_callback, app); buttons_names = remote_manager->get_button_list(); i = 0; @@ -60,32 +60,32 @@ void IrdaAppSceneRemote::on_enter(IrdaApp* app) { button_menu_set_selected_item(button_menu, buttonmenu_item_selected); buttonmenu_item_selected = ButtonIndexNA; } - view_manager->switch_to(IrdaAppViewManager::ViewType::ButtonMenu); + view_manager->switch_to(InfraredAppViewManager::ViewId::ButtonMenu); } -bool IrdaAppSceneRemote::on_event(IrdaApp* app, IrdaAppEvent* event) { +bool InfraredAppSceneRemote::on_event(InfraredApp* app, InfraredAppEvent* event) { bool consumed = true; - if((event->type == IrdaAppEvent::Type::MenuSelected) || - (event->type == IrdaAppEvent::Type::MenuSelectedPress) || - (event->type == IrdaAppEvent::Type::MenuSelectedRelease)) { + if((event->type == InfraredAppEvent::Type::MenuSelected) || + (event->type == InfraredAppEvent::Type::MenuSelectedPress) || + (event->type == InfraredAppEvent::Type::MenuSelectedRelease)) { switch(event->payload.menu_index) { case ButtonIndexPlus: - furi_assert(event->type == IrdaAppEvent::Type::MenuSelected); + furi_assert(event->type == InfraredAppEvent::Type::MenuSelected); app->notify_click(); buttonmenu_item_selected = event->payload.menu_index; app->set_learn_new_remote(false); - app->switch_to_next_scene(IrdaApp::Scene::Learn); + app->switch_to_next_scene(InfraredApp::Scene::Learn); break; case ButtonIndexEdit: - furi_assert(event->type == IrdaAppEvent::Type::MenuSelected); + furi_assert(event->type == InfraredAppEvent::Type::MenuSelected); app->notify_click(); buttonmenu_item_selected = event->payload.menu_index; - app->switch_to_next_scene(IrdaApp::Scene::Edit); + app->switch_to_next_scene(InfraredApp::Scene::Edit); break; default: - furi_assert(event->type != IrdaAppEvent::Type::MenuSelected); - bool pressed = (event->type == IrdaAppEvent::Type::MenuSelectedPress); + furi_assert(event->type != InfraredAppEvent::Type::MenuSelected); + bool pressed = (event->type == InfraredAppEvent::Type::MenuSelectedPress); if(pressed && !button_pressed) { button_pressed = true; @@ -94,28 +94,28 @@ bool IrdaAppSceneRemote::on_event(IrdaApp* app, IrdaAppEvent* event) { auto button_signal = app->get_remote_manager()->get_button_data(event->payload.menu_index); if(button_signal.is_raw()) { - irda_worker_set_raw_signal( - app->get_irda_worker(), + infrared_worker_set_raw_signal( + app->get_infrared_worker(), button_signal.get_raw_signal().timings, button_signal.get_raw_signal().timings_cnt); } else { - irda_worker_set_decoded_signal( - app->get_irda_worker(), &button_signal.get_message()); + infrared_worker_set_decoded_signal( + app->get_infrared_worker(), &button_signal.get_message()); } DOLPHIN_DEED(DolphinDeedIrSend); - irda_worker_tx_start(app->get_irda_worker()); + infrared_worker_tx_start(app->get_infrared_worker()); } else if(!pressed && button_pressed) { button_pressed = false; - irda_worker_tx_stop(app->get_irda_worker()); + infrared_worker_tx_stop(app->get_infrared_worker()); app->notify_green_off(); } break; } - } else if(event->type == IrdaAppEvent::Type::Back) { + } else if(event->type == InfraredAppEvent::Type::Back) { if(!button_pressed) { app->search_and_switch_to_previous_scene( - {IrdaApp::Scene::Start, IrdaApp::Scene::RemoteList}); + {InfraredApp::Scene::Start, InfraredApp::Scene::RemoteList}); } } else { consumed = false; @@ -124,10 +124,10 @@ bool IrdaAppSceneRemote::on_event(IrdaApp* app, IrdaAppEvent* event) { return consumed; } -void IrdaAppSceneRemote::on_exit(IrdaApp* app) { - irda_worker_tx_set_get_signal_callback(app->get_irda_worker(), nullptr, nullptr); - irda_worker_tx_set_signal_sent_callback(app->get_irda_worker(), nullptr, nullptr); - IrdaAppViewManager* view_manager = app->get_view_manager(); +void InfraredAppSceneRemote::on_exit(InfraredApp* app) { + infrared_worker_tx_set_get_signal_callback(app->get_infrared_worker(), nullptr, nullptr); + infrared_worker_tx_set_signal_sent_callback(app->get_infrared_worker(), nullptr, nullptr); + InfraredAppViewManager* view_manager = app->get_view_manager(); ButtonMenu* button_menu = view_manager->get_button_menu(); button_menu_reset(button_menu); diff --git a/applications/irda/scene/irda_app_scene_remote_list.cpp b/applications/infrared/scene/infrared_app_scene_remote_list.cpp similarity index 57% rename from applications/irda/scene/irda_app_scene_remote_list.cpp rename to applications/infrared/scene/infrared_app_scene_remote_list.cpp index c20fbafb..13962587 100644 --- a/applications/irda/scene/irda_app_scene_remote_list.cpp +++ b/applications/infrared/scene/infrared_app_scene_remote_list.cpp @@ -1,9 +1,9 @@ -#include "../irda_app.h" -#include "irda/irda_app_event.h" +#include "../infrared_app.h" +#include "infrared/infrared_app_event.h" #include #include -void IrdaAppSceneRemoteList::on_enter(IrdaApp* app) { +void InfraredAppSceneRemoteList::on_enter(InfraredApp* app) { furi_assert(app); FileWorkerCpp file_worker; @@ -13,23 +13,24 @@ void IrdaAppSceneRemoteList::on_enter(IrdaApp* app) { auto last_selected_remote = remote_manager->get_remote_name(); const char* last_selected_remote_name = last_selected_remote.size() ? last_selected_remote.c_str() : nullptr; - auto filename_ts = std::make_unique(IrdaAppRemoteManager::max_remote_name_length); + auto filename_ts = + std::make_unique(InfraredAppRemoteManager::max_remote_name_length); - IrdaAppViewManager* view_manager = app->get_view_manager(); + InfraredAppViewManager* view_manager = app->get_view_manager(); ButtonMenu* button_menu = view_manager->get_button_menu(); button_menu_reset(button_menu); - view_manager->switch_to(IrdaAppViewManager::ViewType::ButtonMenu); + view_manager->switch_to(InfraredAppViewManager::ViewId::ButtonMenu); file_select_result = file_worker.file_select( - IrdaApp::irda_directory, - IrdaApp::irda_extension, + InfraredApp::infrared_directory, + InfraredApp::infrared_extension, filename_ts->text, filename_ts->text_size, last_selected_remote_name); if(file_select_result) { if(remote_manager->load(std::string(filename_ts->text))) { - app->switch_to_next_scene(IrdaApp::Scene::Remote); + app->switch_to_next_scene(InfraredApp::Scene::Remote); result = true; } } @@ -39,11 +40,11 @@ void IrdaAppSceneRemoteList::on_enter(IrdaApp* app) { } } -bool IrdaAppSceneRemoteList::on_event(IrdaApp* app, IrdaAppEvent* event) { +bool InfraredAppSceneRemoteList::on_event(InfraredApp* app, InfraredAppEvent* event) { bool consumed = false; return consumed; } -void IrdaAppSceneRemoteList::on_exit(IrdaApp* app) { +void InfraredAppSceneRemoteList::on_exit(InfraredApp* app) { } diff --git a/applications/irda/scene/irda_app_scene_start.cpp b/applications/infrared/scene/infrared_app_scene_start.cpp similarity index 62% rename from applications/irda/scene/irda_app_scene_start.cpp rename to applications/infrared/scene/infrared_app_scene_start.cpp index 62dcbbc5..dd9a2c15 100644 --- a/applications/irda/scene/irda_app_scene_start.cpp +++ b/applications/infrared/scene/infrared_app_scene_start.cpp @@ -1,4 +1,4 @@ -#include "../irda_app.h" +#include "../infrared_app.h" typedef enum { SubmenuIndexUniversalLibrary, @@ -7,17 +7,17 @@ typedef enum { } SubmenuIndex; static void submenu_callback(void* context, uint32_t index) { - IrdaApp* app = static_cast(context); - IrdaAppEvent event; + InfraredApp* app = static_cast(context); + InfraredAppEvent event; - event.type = IrdaAppEvent::Type::MenuSelected; + event.type = InfraredAppEvent::Type::MenuSelected; event.payload.menu_index = index; app->get_view_manager()->send_event(&event); } -void IrdaAppSceneStart::on_enter(IrdaApp* app) { - IrdaAppViewManager* view_manager = app->get_view_manager(); +void InfraredAppSceneStart::on_enter(InfraredApp* app) { + InfraredAppViewManager* view_manager = app->get_view_manager(); Submenu* submenu = view_manager->get_submenu(); submenu_add_item( @@ -28,24 +28,24 @@ void IrdaAppSceneStart::on_enter(IrdaApp* app) { submenu_set_selected_item(submenu, submenu_item_selected); submenu_item_selected = 0; - view_manager->switch_to(IrdaAppViewManager::ViewType::Submenu); + view_manager->switch_to(InfraredAppViewManager::ViewId::Submenu); } -bool IrdaAppSceneStart::on_event(IrdaApp* app, IrdaAppEvent* event) { +bool InfraredAppSceneStart::on_event(InfraredApp* app, InfraredAppEvent* event) { bool consumed = false; - if(event->type == IrdaAppEvent::Type::MenuSelected) { + if(event->type == InfraredAppEvent::Type::MenuSelected) { submenu_item_selected = event->payload.menu_index; switch(event->payload.menu_index) { case SubmenuIndexUniversalLibrary: - app->switch_to_next_scene(IrdaApp::Scene::Universal); + app->switch_to_next_scene(InfraredApp::Scene::Universal); break; case SubmenuIndexLearnNewRemote: app->set_learn_new_remote(true); - app->switch_to_next_scene(IrdaApp::Scene::Learn); + app->switch_to_next_scene(InfraredApp::Scene::Learn); break; case SubmenuIndexSavedRemotes: - app->switch_to_next_scene(IrdaApp::Scene::RemoteList); + app->switch_to_next_scene(InfraredApp::Scene::RemoteList); break; default: furi_assert(0); @@ -57,8 +57,8 @@ bool IrdaAppSceneStart::on_event(IrdaApp* app, IrdaAppEvent* event) { return consumed; } -void IrdaAppSceneStart::on_exit(IrdaApp* app) { - IrdaAppViewManager* view_manager = app->get_view_manager(); +void InfraredAppSceneStart::on_exit(InfraredApp* app) { + InfraredAppViewManager* view_manager = app->get_view_manager(); Submenu* submenu = view_manager->get_submenu(); app->get_remote_manager()->reset_remote(); diff --git a/applications/irda/scene/irda_app_scene_universal.cpp b/applications/infrared/scene/infrared_app_scene_universal.cpp similarity index 52% rename from applications/irda/scene/irda_app_scene_universal.cpp rename to applications/infrared/scene/infrared_app_scene_universal.cpp index 01134400..b97724fc 100644 --- a/applications/irda/scene/irda_app_scene_universal.cpp +++ b/applications/infrared/scene/infrared_app_scene_universal.cpp @@ -1,4 +1,4 @@ -#include "../irda_app.h" +#include "../infrared_app.h" typedef enum { SubmenuIndexUniversalTV, @@ -7,40 +7,40 @@ typedef enum { } SubmenuIndex; static void submenu_callback(void* context, uint32_t index) { - IrdaApp* app = static_cast(context); - IrdaAppEvent event; + InfraredApp* app = static_cast(context); + InfraredAppEvent event; - event.type = IrdaAppEvent::Type::MenuSelected; + event.type = InfraredAppEvent::Type::MenuSelected; event.payload.menu_index = index; app->get_view_manager()->send_event(&event); } -void IrdaAppSceneUniversal::on_enter(IrdaApp* app) { - IrdaAppViewManager* view_manager = app->get_view_manager(); +void InfraredAppSceneUniversal::on_enter(InfraredApp* app) { + InfraredAppViewManager* view_manager = app->get_view_manager(); Submenu* submenu = view_manager->get_submenu(); submenu_add_item(submenu, "TV's", SubmenuIndexUniversalTV, submenu_callback, app); submenu_set_selected_item(submenu, submenu_item_selected); submenu_item_selected = 0; - view_manager->switch_to(IrdaAppViewManager::ViewType::Submenu); + view_manager->switch_to(InfraredAppViewManager::ViewId::Submenu); } -bool IrdaAppSceneUniversal::on_event(IrdaApp* app, IrdaAppEvent* event) { +bool InfraredAppSceneUniversal::on_event(InfraredApp* app, InfraredAppEvent* event) { bool consumed = false; - if(event->type == IrdaAppEvent::Type::MenuSelected) { + if(event->type == InfraredAppEvent::Type::MenuSelected) { submenu_item_selected = event->payload.menu_index; switch(event->payload.menu_index) { case SubmenuIndexUniversalTV: - app->switch_to_next_scene(IrdaApp::Scene::UniversalTV); + app->switch_to_next_scene(InfraredApp::Scene::UniversalTV); break; case SubmenuIndexUniversalAudio: - // app->switch_to_next_scene(IrdaApp::Scene::UniversalAudio); + // app->switch_to_next_scene(InfraredApp::Scene::UniversalAudio); break; case SubmenuIndexUniversalAirConditioner: - // app->switch_to_next_scene(IrdaApp::Scene::UniversalAirConditioner); + // app->switch_to_next_scene(InfraredApp::Scene::UniversalAirConditioner); break; } consumed = true; @@ -49,8 +49,8 @@ bool IrdaAppSceneUniversal::on_event(IrdaApp* app, IrdaAppEvent* event) { return consumed; } -void IrdaAppSceneUniversal::on_exit(IrdaApp* app) { - IrdaAppViewManager* view_manager = app->get_view_manager(); +void InfraredAppSceneUniversal::on_exit(InfraredApp* app) { + InfraredAppViewManager* view_manager = app->get_view_manager(); Submenu* submenu = view_manager->get_submenu(); submenu_reset(submenu); diff --git a/applications/infrared/scene/infrared_app_scene_universal_common.cpp b/applications/infrared/scene/infrared_app_scene_universal_common.cpp new file mode 100644 index 00000000..459401d3 --- /dev/null +++ b/applications/infrared/scene/infrared_app_scene_universal_common.cpp @@ -0,0 +1,101 @@ +#include +#include +#include +#include +#include + +#include "../infrared_app.h" +#include "infrared/infrared_app_event.h" +#include "infrared/infrared_app_view_manager.h" +#include "infrared/scene/infrared_app_scene.h" +#include "../view/infrared_progress_view.h" + +void InfraredAppSceneUniversalCommon::infrared_app_item_callback(void* context, uint32_t index) { + InfraredApp* app = static_cast(context); + InfraredAppEvent event; + + event.type = InfraredAppEvent::Type::ButtonPanelPressed; + event.payload.menu_index = index; + + app->get_view_manager()->send_event(&event); +} + +static void infrared_progress_back_callback(void* context) { + furi_assert(context); + auto app = static_cast(context); + + InfraredAppEvent infrared_event = { + .type = InfraredAppEvent::Type::Back, + }; + app->get_view_manager()->clear_events(); + app->get_view_manager()->send_event(&infrared_event); +} + +void InfraredAppSceneUniversalCommon::hide_popup(InfraredApp* app) { + auto stack_view = app->get_view_manager()->get_universal_view_stack(); + auto progress_view = app->get_view_manager()->get_progress(); + view_stack_remove_view(stack_view, infrared_progress_view_get_view(progress_view)); +} + +void InfraredAppSceneUniversalCommon::show_popup(InfraredApp* app, int record_amount) { + auto stack_view = app->get_view_manager()->get_universal_view_stack(); + auto progress_view = app->get_view_manager()->get_progress(); + infrared_progress_view_set_progress_total(progress_view, record_amount); + infrared_progress_view_set_back_callback(progress_view, infrared_progress_back_callback, app); + view_stack_add_view(stack_view, infrared_progress_view_get_view(progress_view)); +} + +bool InfraredAppSceneUniversalCommon::progress_popup(InfraredApp* app) { + auto progress_view = app->get_view_manager()->get_progress(); + return infrared_progress_view_increase_progress(progress_view); +} + +bool InfraredAppSceneUniversalCommon::on_event(InfraredApp* app, InfraredAppEvent* event) { + bool consumed = false; + + if(brute_force_started) { + if(event->type == InfraredAppEvent::Type::Tick) { + auto view_manager = app->get_view_manager(); + InfraredAppEvent tick_event = {.type = InfraredAppEvent::Type::Tick}; + view_manager->send_event(&tick_event); + bool result = brute_force.send_next_bruteforce(); + if(result) { + result = progress_popup(app); + } + if(!result) { + brute_force.stop_bruteforce(); + brute_force_started = false; + hide_popup(app); + } + consumed = true; + } else if(event->type == InfraredAppEvent::Type::Back) { + brute_force_started = false; + brute_force.stop_bruteforce(); + hide_popup(app); + consumed = true; + } + } else { + if(event->type == InfraredAppEvent::Type::ButtonPanelPressed) { + int record_amount = 0; + if(brute_force.start_bruteforce(event->payload.menu_index, record_amount)) { + DOLPHIN_DEED(DolphinDeedIrBruteForce); + brute_force_started = true; + show_popup(app, record_amount); + } else { + app->switch_to_previous_scene(); + } + consumed = true; + } else if(event->type == InfraredAppEvent::Type::Back) { + app->switch_to_previous_scene(); + consumed = true; + } + } + + return consumed; +} + +void InfraredAppSceneUniversalCommon::on_exit(InfraredApp* app) { + InfraredAppViewManager* view_manager = app->get_view_manager(); + ButtonPanel* button_panel = view_manager->get_button_panel(); + button_panel_reset(button_panel); +} diff --git a/applications/irda/scene/irda_app_scene_universal_tv.cpp b/applications/infrared/scene/infrared_app_scene_universal_tv.cpp similarity index 80% rename from applications/irda/scene/irda_app_scene_universal_tv.cpp rename to applications/infrared/scene/infrared_app_scene_universal_tv.cpp index 563d59df..a12481ec 100644 --- a/applications/irda/scene/irda_app_scene_universal_tv.cpp +++ b/applications/infrared/scene/infrared_app_scene_universal_tv.cpp @@ -1,11 +1,11 @@ #include #include #include -#include "irda/scene/irda_app_scene.h" -#include "irda/irda_app.h" +#include "infrared/scene/infrared_app_scene.h" +#include "infrared/infrared_app.h" -void IrdaAppSceneUniversalTV::on_enter(IrdaApp* app) { - IrdaAppViewManager* view_manager = app->get_view_manager(); +void InfraredAppSceneUniversalTV::on_enter(InfraredApp* app) { + InfraredAppViewManager* view_manager = app->get_view_manager(); ButtonPanel* button_panel = view_manager->get_button_panel(); button_panel_reserve(button_panel, 2, 3); @@ -19,7 +19,7 @@ void IrdaAppSceneUniversalTV::on_enter(IrdaApp* app) { 19, &I_Power_25x27, &I_Power_hvr_25x27, - irda_app_item_callback, + infrared_app_item_callback, app); brute_force.add_record(i, "POWER"); ++i; @@ -32,7 +32,7 @@ void IrdaAppSceneUniversalTV::on_enter(IrdaApp* app) { 19, &I_Mute_25x27, &I_Mute_hvr_25x27, - irda_app_item_callback, + infrared_app_item_callback, app); brute_force.add_record(i, "MUTE"); ++i; @@ -45,12 +45,21 @@ void IrdaAppSceneUniversalTV::on_enter(IrdaApp* app) { 66, &I_Vol_up_25x27, &I_Vol_up_hvr_25x27, - irda_app_item_callback, + infrared_app_item_callback, app); brute_force.add_record(i, "VOL+"); ++i; button_panel_add_item( - button_panel, i, 1, 1, 36, 66, &I_Up_25x27, &I_Up_hvr_25x27, irda_app_item_callback, app); + button_panel, + i, + 1, + 1, + 36, + 66, + &I_Up_25x27, + &I_Up_hvr_25x27, + infrared_app_item_callback, + app); brute_force.add_record(i, "CH+"); ++i; button_panel_add_item( @@ -62,7 +71,7 @@ void IrdaAppSceneUniversalTV::on_enter(IrdaApp* app) { 98, &I_Vol_down_25x27, &I_Vol_down_hvr_25x27, - irda_app_item_callback, + infrared_app_item_callback, app); brute_force.add_record(i, "VOL-"); ++i; @@ -75,7 +84,7 @@ void IrdaAppSceneUniversalTV::on_enter(IrdaApp* app) { 98, &I_Down_25x27, &I_Down_hvr_25x27, - irda_app_item_callback, + infrared_app_item_callback, app); brute_force.add_record(i, "CH-"); @@ -83,7 +92,7 @@ void IrdaAppSceneUniversalTV::on_enter(IrdaApp* app) { button_panel_add_label(button_panel, 9, 64, FontSecondary, "Vol"); button_panel_add_label(button_panel, 43, 64, FontSecondary, "Ch"); - view_manager->switch_to(IrdaAppViewManager::ViewType::UniversalRemote); + view_manager->switch_to(InfraredAppViewManager::ViewId::UniversalRemote); auto stack_view = app->get_view_manager()->get_universal_view_stack(); auto loading_view = app->get_view_manager()->get_loading(); diff --git a/applications/irda/view/irda_progress_view.c b/applications/infrared/view/infrared_progress_view.c similarity index 62% rename from applications/irda/view/irda_progress_view.c rename to applications/infrared/view/infrared_progress_view.c index 4a914a17..c9075147 100644 --- a/applications/irda/view/irda_progress_view.c +++ b/applications/infrared/view/infrared_progress_view.c @@ -7,26 +7,26 @@ #include "m-string.h" #include #include -#include "irda_progress_view.h" +#include "infrared_progress_view.h" #include "gui/modules/button_panel.h" #include -struct IrdaProgressView { +struct InfraredProgressView { View* view; - IrdaProgressViewBackCallback back_callback; + InfraredProgressViewBackCallback back_callback; void* context; }; typedef struct { size_t progress; size_t progress_total; -} IrdaProgressViewModel; +} InfraredProgressViewModel; -bool irda_progress_view_increase_progress(IrdaProgressView* progress) { +bool infrared_progress_view_increase_progress(InfraredProgressView* progress) { furi_assert(progress); bool result = false; - IrdaProgressViewModel* model = view_get_model(progress->view); + InfraredProgressViewModel* model = view_get_model(progress->view); if(model->progress < model->progress_total) { ++model->progress; result = model->progress < model->progress_total; @@ -36,8 +36,8 @@ bool irda_progress_view_increase_progress(IrdaProgressView* progress) { return result; } -static void irda_progress_view_draw_callback(Canvas* canvas, void* _model) { - IrdaProgressViewModel* model = (IrdaProgressViewModel*)_model; +static void infrared_progress_view_draw_callback(Canvas* canvas, void* _model) { + InfraredProgressViewModel* model = (InfraredProgressViewModel*)_model; uint8_t x = 0; uint8_t y = 36; @@ -63,16 +63,18 @@ static void irda_progress_view_draw_callback(Canvas* canvas, void* _model) { canvas_draw_str(canvas, x + 30, y + height - 6, "= stop"); } -void irda_progress_view_set_progress_total(IrdaProgressView* progress, uint16_t progress_total) { +void infrared_progress_view_set_progress_total( + InfraredProgressView* progress, + uint16_t progress_total) { furi_assert(progress); - IrdaProgressViewModel* model = view_get_model(progress->view); + InfraredProgressViewModel* model = view_get_model(progress->view); model->progress = 0; model->progress_total = progress_total; view_commit_model(progress->view, false); } -bool irda_progress_view_input_callback(InputEvent* event, void* context) { - IrdaProgressView* instance = context; +bool infrared_progress_view_input_callback(InputEvent* event, void* context) { + InfraredProgressView* instance = context; if((event->type == InputTypeShort) && (event->key == InputKeyBack)) { if(instance->back_callback) { @@ -83,36 +85,36 @@ bool irda_progress_view_input_callback(InputEvent* event, void* context) { return true; } -IrdaProgressView* irda_progress_view_alloc(void) { - IrdaProgressView* instance = malloc(sizeof(IrdaProgressView)); +InfraredProgressView* infrared_progress_view_alloc(void) { + InfraredProgressView* instance = malloc(sizeof(InfraredProgressView)); instance->view = view_alloc(); - view_allocate_model(instance->view, ViewModelTypeLocking, sizeof(IrdaProgressViewModel)); - IrdaProgressViewModel* model = view_get_model(instance->view); + view_allocate_model(instance->view, ViewModelTypeLocking, sizeof(InfraredProgressViewModel)); + InfraredProgressViewModel* model = view_get_model(instance->view); model->progress = 0; model->progress_total = 0; view_commit_model(instance->view, false); - view_set_draw_callback(instance->view, irda_progress_view_draw_callback); - view_set_input_callback(instance->view, irda_progress_view_input_callback); + view_set_draw_callback(instance->view, infrared_progress_view_draw_callback); + view_set_input_callback(instance->view, infrared_progress_view_input_callback); view_set_context(instance->view, instance); return instance; } -void irda_progress_view_free(IrdaProgressView* progress) { +void infrared_progress_view_free(InfraredProgressView* progress) { view_free(progress->view); free(progress); } -void irda_progress_view_set_back_callback( - IrdaProgressView* instance, - IrdaProgressViewBackCallback callback, +void infrared_progress_view_set_back_callback( + InfraredProgressView* instance, + InfraredProgressViewBackCallback callback, void* context) { furi_assert(instance); instance->back_callback = callback; instance->context = context; } -View* irda_progress_view_get_view(IrdaProgressView* instance) { +View* infrared_progress_view_get_view(InfraredProgressView* instance) { furi_assert(instance); furi_assert(instance->view); return instance->view; diff --git a/applications/infrared/view/infrared_progress_view.h b/applications/infrared/view/infrared_progress_view.h new file mode 100644 index 00000000..e8f76ba1 --- /dev/null +++ b/applications/infrared/view/infrared_progress_view.h @@ -0,0 +1,68 @@ +/** + * @file infrared_progress_view.h + * Infrared: Custom Infrared view module. + * It shows popup progress bar during brute force. + */ +#pragma once +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** Anonumous instance */ +typedef struct InfraredProgressView InfraredProgressView; + +/** Callback for back button handling */ +typedef void (*InfraredProgressViewBackCallback)(void*); + +/** Allocate and initialize Infrared view + * + * @retval new allocated instance + */ +InfraredProgressView* infrared_progress_view_alloc(); + +/** Free previously allocated Progress view module instance + * + * @param instance to free + */ +void infrared_progress_view_free(InfraredProgressView* instance); + +/** Get progress view module view + * + * @param instance view module + * @retval view + */ +View* infrared_progress_view_get_view(InfraredProgressView* instance); + +/** Increase progress on progress view module + * + * @param instance view module + * @retval true - value is incremented and maximum is reached, + * false - value is incremented and maximum is not reached + */ +bool infrared_progress_view_increase_progress(InfraredProgressView* instance); + +/** Set maximum progress value + * + * @param instance - view module + * @param progress_max - maximum value of progress + */ +void infrared_progress_view_set_progress_total( + InfraredProgressView* instance, + uint16_t progress_max); + +/** Set back button callback + * + * @param instance - view module + * @param callback - callback to call for back button + * @param context - context to pass to callback + */ +void infrared_progress_view_set_back_callback( + InfraredProgressView* instance, + InfraredProgressViewBackCallback callback, + void* context); + +#ifdef __cplusplus +} +#endif diff --git a/applications/infrared_monitor/infrared_monitor.c b/applications/infrared_monitor/infrared_monitor.c new file mode 100644 index 00000000..08691dfa --- /dev/null +++ b/applications/infrared_monitor/infrared_monitor.c @@ -0,0 +1,140 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define INFRARED_TIMINGS_SIZE 700 + +typedef struct { + uint32_t timing_cnt; + struct { + uint8_t level; + uint32_t duration; + } timing[INFRARED_TIMINGS_SIZE]; +} InfraredDelaysArray; + +typedef struct { + char display_text[64]; + osMessageQueueId_t event_queue; + InfraredDelaysArray delays; + InfraredWorker* worker; + ViewPort* view_port; +} InfraredMonitor; + +void infrared_monitor_input_callback(InputEvent* input_event, void* ctx) { + furi_assert(ctx); + InfraredMonitor* infrared_monitor = (InfraredMonitor*)ctx; + + if((input_event->type == InputTypeShort) && (input_event->key == InputKeyBack)) { + osMessageQueuePut(infrared_monitor->event_queue, input_event, 0, 0); + } +} + +static void infrared_monitor_draw_callback(Canvas* canvas, void* ctx) { + furi_assert(canvas); + furi_assert(ctx); + InfraredMonitor* infrared_monitor = (InfraredMonitor*)ctx; + + canvas_clear(canvas); + canvas_set_font(canvas, FontPrimary); + elements_multiline_text_aligned(canvas, 64, 0, AlignCenter, AlignTop, "INFRARED monitor\n"); + canvas_set_font(canvas, FontKeyboard); + if(strlen(infrared_monitor->display_text)) { + elements_multiline_text_aligned( + canvas, 64, 43, AlignCenter, AlignCenter, infrared_monitor->display_text); + } +} + +static void signal_received_callback(void* context, InfraredWorkerSignal* received_signal) { + furi_assert(context); + furi_assert(received_signal); + InfraredMonitor* infrared_monitor = context; + + if(infrared_worker_signal_is_decoded(received_signal)) { + const InfraredMessage* message = infrared_worker_get_decoded_signal(received_signal); + snprintf( + infrared_monitor->display_text, + sizeof(infrared_monitor->display_text), + "%s\nA:0x%0*lX\nC:0x%0*lX\n%s\n", + infrared_get_protocol_name(message->protocol), + ROUND_UP_TO(infrared_get_protocol_address_length(message->protocol), 4), + message->address, + ROUND_UP_TO(infrared_get_protocol_command_length(message->protocol), 4), + message->command, + message->repeat ? " R" : ""); + view_port_update(infrared_monitor->view_port); + printf( + "== %s, A:0x%0*lX, C:0x%0*lX%s ==\r\n", + infrared_get_protocol_name(message->protocol), + ROUND_UP_TO(infrared_get_protocol_address_length(message->protocol), 4), + message->address, + ROUND_UP_TO(infrared_get_protocol_command_length(message->protocol), 4), + message->command, + message->repeat ? " R" : ""); + } else { + const uint32_t* timings; + size_t timings_cnt; + infrared_worker_get_raw_signal(received_signal, &timings, &timings_cnt); + snprintf( + infrared_monitor->display_text, + sizeof(infrared_monitor->display_text), + "RAW\n%d samples\n", + timings_cnt); + view_port_update(infrared_monitor->view_port); + printf("RAW, %d samples:\r\n", timings_cnt); + for(size_t i = 0; i < timings_cnt; ++i) { + printf("%lu ", timings[i]); + } + printf("\r\n"); + } +} + +int32_t infrared_monitor_app(void* p) { + (void)p; + + InfraredMonitor* infrared_monitor = malloc(sizeof(InfraredMonitor)); + infrared_monitor->display_text[0] = 0; + infrared_monitor->event_queue = osMessageQueueNew(1, sizeof(InputEvent), NULL); + infrared_monitor->view_port = view_port_alloc(); + Gui* gui = furi_record_open("gui"); + + view_port_draw_callback_set( + infrared_monitor->view_port, infrared_monitor_draw_callback, infrared_monitor); + view_port_input_callback_set( + infrared_monitor->view_port, infrared_monitor_input_callback, infrared_monitor); + + gui_add_view_port(gui, infrared_monitor->view_port, GuiLayerFullscreen); + + infrared_monitor->worker = infrared_worker_alloc(); + infrared_worker_rx_start(infrared_monitor->worker); + infrared_worker_rx_set_received_signal_callback( + infrared_monitor->worker, signal_received_callback, infrared_monitor); + infrared_worker_rx_enable_blink_on_receiving(infrared_monitor->worker, true); + + while(1) { + InputEvent event; + if(osOK == osMessageQueueGet(infrared_monitor->event_queue, &event, NULL, 50)) { + if((event.type == InputTypeShort) && (event.key == InputKeyBack)) { + break; + } + } + } + + infrared_worker_rx_stop(infrared_monitor->worker); + infrared_worker_free(infrared_monitor->worker); + osMessageQueueDelete(infrared_monitor->event_queue); + view_port_enabled_set(infrared_monitor->view_port, false); + gui_remove_view_port(gui, infrared_monitor->view_port); + view_port_free(infrared_monitor->view_port); + furi_record_close("gui"); + free(infrared_monitor); + + return 0; +} diff --git a/applications/irda/helpers/irda_parser.h b/applications/irda/helpers/irda_parser.h deleted file mode 100644 index d8065607..00000000 --- a/applications/irda/helpers/irda_parser.h +++ /dev/null @@ -1,13 +0,0 @@ -#pragma once - -#include "../irda_app_signal.h" -#include -#include - -bool irda_parser_save_signal( - FlipperFormat* ff, - const IrdaAppSignal& signal, - const std::string& name); -bool irda_parser_read_signal(FlipperFormat* ff, IrdaAppSignal& signal, std::string& name); -bool irda_parser_is_parsed_signal_valid(const IrdaMessage* signal); -bool irda_parser_is_raw_signal_valid(uint32_t frequency, float duty_cycle, uint32_t timings_cnt); diff --git a/applications/irda/irda_app.h b/applications/irda/irda_app.h deleted file mode 100644 index 195aff34..00000000 --- a/applications/irda/irda_app.h +++ /dev/null @@ -1,138 +0,0 @@ -#pragma once -#include -#include -#include -#include "scene/irda_app_scene.h" -#include "scene/irda_app_scene.h" -#include "irda_app_view_manager.h" -#include "irda_app_remote_manager.h" -#include -#include -#include -#include -#include "irda_app_view_manager.h" - -class IrdaApp { -public: - enum class EditElement : uint8_t { - Button, - Remote, - }; - enum class EditAction : uint8_t { - Rename, - Delete, - }; - enum class Scene : uint8_t { - Exit, - Start, - Universal, - UniversalTV, - UniversalAudio, - UniversalAirConditioner, - Learn, - LearnSuccess, - LearnEnterName, - LearnDone, - AskBack, - Remote, - RemoteList, - Edit, - EditKeySelect, - EditRename, - EditDelete, - EditRenameDone, - EditDeleteDone, - }; - - int32_t run(void* args); - void switch_to_next_scene(Scene index); - void switch_to_next_scene_without_saving(Scene index); - bool switch_to_previous_scene(uint8_t count = 1); - Scene get_previous_scene(); - IrdaAppViewManager* get_view_manager(); - void set_text_store(uint8_t index, const char* text...); - char* get_text_store(uint8_t index); - uint8_t get_text_store_size(); - IrdaAppRemoteManager* get_remote_manager(); - - IrdaWorker* get_irda_worker(); - const IrdaAppSignal& get_received_signal() const; - void set_received_signal(const IrdaAppSignal& signal); - - void search_and_switch_to_previous_scene(const std::initializer_list& scenes_list); - - void set_edit_element(EditElement value); - EditElement get_edit_element(void); - - void set_edit_action(EditAction value); - EditAction get_edit_action(void); - - bool get_learn_new_remote(); - void set_learn_new_remote(bool value); - - enum : int { - ButtonNA = -1, - }; - int get_current_button(); - void set_current_button(int value); - - void notify_success(); - void notify_red_blink(); - void notify_sent_just_learnt(); - void notify_green_on(); - void notify_green_off(); - void notify_click(); - void notify_click_and_green_blink(); - void notify_blink_green(); - - static void text_input_callback(void* context); - static void popup_callback(void* context); - static void signal_sent_callback(void* context); - - IrdaApp(); - ~IrdaApp(); - - static constexpr const char* irda_directory = "/any/irda"; - static constexpr const char* irda_extension = ".ir"; - static constexpr const uint32_t max_raw_timings_in_signal = 512; - static constexpr const uint32_t max_line_length = - (9 + 1) * IrdaApp::max_raw_timings_in_signal + 100; - -private: - static constexpr const uint8_t text_store_size = 128; - static constexpr const uint8_t text_store_max = 2; - char text_store[text_store_max][text_store_size + 1]; - bool learn_new_remote; - EditElement element; - EditAction action; - uint32_t current_button; - - NotificationApp* notification; - IrdaAppViewManager view_manager; - IrdaAppRemoteManager remote_manager; - IrdaWorker* irda_worker; - IrdaAppSignal received_signal; - - std::forward_list previous_scenes_list; - Scene current_scene = Scene::Start; - - std::map scenes = { - {Scene::Start, new IrdaAppSceneStart()}, - {Scene::Universal, new IrdaAppSceneUniversal()}, - {Scene::UniversalTV, new IrdaAppSceneUniversalTV()}, - // {Scene::UniversalAudio, new IrdaAppSceneUniversalAudio()}, - {Scene::Learn, new IrdaAppSceneLearn()}, - {Scene::LearnSuccess, new IrdaAppSceneLearnSuccess()}, - {Scene::LearnEnterName, new IrdaAppSceneLearnEnterName()}, - {Scene::LearnDone, new IrdaAppSceneLearnDone()}, - {Scene::AskBack, new IrdaAppSceneAskBack()}, - {Scene::Remote, new IrdaAppSceneRemote()}, - {Scene::RemoteList, new IrdaAppSceneRemoteList()}, - {Scene::Edit, new IrdaAppSceneEdit()}, - {Scene::EditKeySelect, new IrdaAppSceneEditKeySelect()}, - {Scene::EditRename, new IrdaAppSceneEditRename()}, - {Scene::EditDelete, new IrdaAppSceneEditDelete()}, - {Scene::EditRenameDone, new IrdaAppSceneEditRenameDone()}, - {Scene::EditDeleteDone, new IrdaAppSceneEditDeleteDone()}, - }; -}; diff --git a/applications/irda/irda_app_brute_force.h b/applications/irda/irda_app_brute_force.h deleted file mode 100644 index 97d78dc6..00000000 --- a/applications/irda/irda_app_brute_force.h +++ /dev/null @@ -1,36 +0,0 @@ -#pragma once - -#include -#include -#include - -class IrdaAppBruteForce { - const char* universal_db_filename; - std::string current_record; - FlipperFormat* ff; - - typedef struct { - int index; - int amount; - } Record; - - // 'key' is record name, because we have to search by both, index and name, - // but index search has place once per button press, and should not be - // noticed, but name search should occur during entering universal menu, - // and will go through container for every record in file, that's why - // more critical to have faster search by record name. - std::unordered_map records; - -public: - bool calculate_messages(); - void stop_bruteforce(); - bool send_next_bruteforce(); - bool start_bruteforce(int index, int& record_amount); - void add_record(int index, const char* name); - - IrdaAppBruteForce(const char* filename) - : universal_db_filename(filename) { - } - ~IrdaAppBruteForce() { - } -}; diff --git a/applications/irda/irda_app_event.h b/applications/irda/irda_app_event.h deleted file mode 100644 index 752ce09f..00000000 --- a/applications/irda/irda_app_event.h +++ /dev/null @@ -1,28 +0,0 @@ -#pragma once -#include -#include - -class IrdaAppEvent { -public: - enum class Type : uint8_t { - Tick, - Exit, - Back, - MenuSelected, - MenuSelectedPress, - MenuSelectedRelease, - DialogExSelected, - NextScene, - IrdaMessageReceived, - TextEditDone, - PopupTimer, - ButtonPanelPressed, - }; - - union { - int32_t menu_index; - DialogExResult dialog_ex_result; - } payload; - - Type type; -}; diff --git a/applications/irda/irda_app_remote_manager.h b/applications/irda/irda_app_remote_manager.h deleted file mode 100644 index 10f1fb12..00000000 --- a/applications/irda/irda_app_remote_manager.h +++ /dev/null @@ -1,76 +0,0 @@ -#pragma once - -#include "irda_app_signal.h" - -#include -#include - -#include -#include -#include -#include - -class IrdaAppRemoteButton { - friend class IrdaAppRemoteManager; - std::string name; - IrdaAppSignal signal; - -public: - IrdaAppRemoteButton(const char* name, const IrdaAppSignal& signal) - : name(name) - , signal(signal) { - } - - IrdaAppRemoteButton(const char* name, IrdaAppSignal&& signal) - : name(name) - , signal(std::move(signal)) { - } - ~IrdaAppRemoteButton() { - } -}; - -class IrdaAppRemote { - friend class IrdaAppRemoteManager; - std::vector buttons; - std::string name; - -public: - IrdaAppRemote(const std::string& name) - : name(name) { - } - - IrdaAppRemote& operator=(std::string& new_name) noexcept { - name = new_name; - buttons.clear(); - return *this; - } -}; - -class IrdaAppRemoteManager { - std::unique_ptr remote; - std::string make_full_name(const std::string& remote_name) const; - std::string make_remote_name(const std::string& full_name) const; - -public: - static constexpr const uint32_t max_button_name_length = 22; - static constexpr const uint32_t max_remote_name_length = 22; - bool add_remote_with_button(const char* button_name, const IrdaAppSignal& signal); - bool add_button(const char* button_name, const IrdaAppSignal& signal); - - int find_remote_name(const std::vector& strings); - bool rename_button(uint32_t index, const char* str); - bool rename_remote(const char* str); - std::string find_vacant_remote_name(const std::string& name); - - std::vector get_button_list() const; - std::string get_button_name(uint32_t index); - std::string get_remote_name(); - size_t get_number_of_buttons(); - const IrdaAppSignal& get_button_data(size_t index) const; - bool delete_button(uint32_t index); - bool delete_remote(); - void reset_remote(); - - bool store(); - bool load(const std::string& name); -}; diff --git a/applications/irda/irda_app_signal.h b/applications/irda/irda_app_signal.h deleted file mode 100644 index 3f922f06..00000000 --- a/applications/irda/irda_app_signal.h +++ /dev/null @@ -1,68 +0,0 @@ -#pragma once -#include -#include -#include -#include - -class IrdaAppSignal { -public: - typedef struct { - size_t timings_cnt; - uint32_t* timings; - uint32_t frequency; - float duty_cycle; - } RawSignal; - -private: - bool raw_signal; - union { - IrdaMessage message; - RawSignal raw; - } payload; - - void - copy_raw_signal(const uint32_t* timings, size_t size, uint32_t frequency, float duty_cycle); - void clear_timings(); - -public: - IrdaAppSignal() { - raw_signal = false; - payload.message.protocol = IrdaProtocolUnknown; - } - - ~IrdaAppSignal() { - clear_timings(); - } - - IrdaAppSignal( - const uint32_t* timings, - size_t timings_cnt, - uint32_t frequency, - float duty_cycle); - IrdaAppSignal(const IrdaMessage* irda_message); - - IrdaAppSignal(const IrdaAppSignal& other); - IrdaAppSignal(IrdaAppSignal&& other); - - IrdaAppSignal& operator=(const IrdaAppSignal& signal); - - void set_message(const IrdaMessage* irda_message); - void - set_raw_signal(uint32_t* timings, size_t timings_cnt, uint32_t frequency, float duty_cycle); - - void transmit() const; - - bool is_raw(void) const { - return raw_signal; - } - - const IrdaMessage& get_message(void) const { - furi_assert(!raw_signal); - return payload.message; - } - - const RawSignal& get_raw_signal(void) const { - furi_assert(raw_signal); - return payload.raw; - } -}; diff --git a/applications/irda/irda_app_view_manager.h b/applications/irda/irda_app_view_manager.h deleted file mode 100644 index 358a3839..00000000 --- a/applications/irda/irda_app_view_manager.h +++ /dev/null @@ -1,66 +0,0 @@ -#pragma once -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "irda_app_event.h" -#include "view/irda_progress_view.h" - -class IrdaAppViewManager { -public: - enum class ViewType : uint8_t { - DialogEx, - TextInput, - Submenu, - ButtonMenu, - UniversalRemote, - Popup, - }; - - IrdaAppViewManager(); - ~IrdaAppViewManager(); - - void switch_to(ViewType type); - - void receive_event(IrdaAppEvent* event); - void send_event(IrdaAppEvent* event); - void clear_events(); - - DialogEx* get_dialog_ex(); - Submenu* get_submenu(); - Popup* get_popup(); - TextInput* get_text_input(); - ButtonMenu* get_button_menu(); - ButtonPanel* get_button_panel(); - ViewStack* get_universal_view_stack(); - IrdaProgressView* get_progress(); - Loading* get_loading(); - - osMessageQueueId_t get_event_queue(); - - uint32_t previous_view_callback(void* context); - -private: - ViewDispatcher* view_dispatcher; - Gui* gui; - TextInput* text_input; - DialogEx* dialog_ex; - Submenu* submenu; - Popup* popup; - ButtonMenu* button_menu; - ButtonPanel* button_panel; - ViewStack* universal_view_stack; - IrdaProgressView* progress_view; - Loading* loading_view; - - osMessageQueueId_t event_queue; - - void add_view(ViewType view_type, View* view); -}; diff --git a/applications/irda/irda_runner.cpp b/applications/irda/irda_runner.cpp deleted file mode 100644 index d8cf9b67..00000000 --- a/applications/irda/irda_runner.cpp +++ /dev/null @@ -1,9 +0,0 @@ -#include "irda_app.h" - -extern "C" int32_t irda_app(void* p) { - IrdaApp* app = new IrdaApp(); - int32_t result = app->run(p); - delete app; - - return result; -} diff --git a/applications/irda/scene/irda_app_scene.h b/applications/irda/scene/irda_app_scene.h deleted file mode 100644 index 458a92ad..00000000 --- a/applications/irda/scene/irda_app_scene.h +++ /dev/null @@ -1,184 +0,0 @@ -#pragma once -#include "../irda_app_event.h" -#include -#include "irda.h" -#include -#include -#include "../irda_app_brute_force.h" - -class IrdaApp; - -class IrdaAppScene { -public: - virtual void on_enter(IrdaApp* app) = 0; - virtual bool on_event(IrdaApp* app, IrdaAppEvent* event) = 0; - virtual void on_exit(IrdaApp* app) = 0; - virtual ~IrdaAppScene(){}; - -private: -}; - -class IrdaAppSceneStart : public IrdaAppScene { -public: - void on_enter(IrdaApp* app) final; - bool on_event(IrdaApp* app, IrdaAppEvent* event) final; - void on_exit(IrdaApp* app) final; - -private: - uint32_t submenu_item_selected = 0; -}; - -class IrdaAppSceneUniversal : public IrdaAppScene { -public: - void on_enter(IrdaApp* app) final; - bool on_event(IrdaApp* app, IrdaAppEvent* event) final; - void on_exit(IrdaApp* app) final; - -private: - uint32_t submenu_item_selected = 0; -}; - -class IrdaAppSceneLearn : public IrdaAppScene { -public: - void on_enter(IrdaApp* app) final; - bool on_event(IrdaApp* app, IrdaAppEvent* event) final; - void on_exit(IrdaApp* app) final; -}; - -class IrdaAppSceneLearnSuccess : public IrdaAppScene { -public: - void on_enter(IrdaApp* app) final; - bool on_event(IrdaApp* app, IrdaAppEvent* event) final; - void on_exit(IrdaApp* app) final; - bool button_pressed = false; -}; - -class IrdaAppSceneLearnEnterName : public IrdaAppScene { -public: - void on_enter(IrdaApp* app) final; - bool on_event(IrdaApp* app, IrdaAppEvent* event) final; - void on_exit(IrdaApp* app) final; -}; - -class IrdaAppSceneLearnDone : public IrdaAppScene { -public: - void on_enter(IrdaApp* app) final; - bool on_event(IrdaApp* app, IrdaAppEvent* event) final; - void on_exit(IrdaApp* app) final; -}; - -class IrdaAppSceneRemote : public IrdaAppScene { -public: - void on_enter(IrdaApp* app) final; - bool on_event(IrdaApp* app, IrdaAppEvent* event) final; - void on_exit(IrdaApp* app) final; - -private: - std::vector buttons_names; - uint32_t buttonmenu_item_selected = 0; - bool button_pressed = false; -}; - -class IrdaAppSceneRemoteList : public IrdaAppScene { -public: - void on_enter(IrdaApp* app) final; - bool on_event(IrdaApp* app, IrdaAppEvent* event) final; - void on_exit(IrdaApp* app) final; - -private: - uint32_t submenu_item_selected = 0; - std::vector remote_names; -}; - -class IrdaAppSceneAskBack : public IrdaAppScene { -public: - void on_enter(IrdaApp* app) final; - bool on_event(IrdaApp* app, IrdaAppEvent* event) final; - void on_exit(IrdaApp* app) final; -}; - -class IrdaAppSceneEdit : public IrdaAppScene { -public: - void on_enter(IrdaApp* app) final; - bool on_event(IrdaApp* app, IrdaAppEvent* event) final; - void on_exit(IrdaApp* app) final; - -private: - uint32_t submenu_item_selected = 0; -}; - -class IrdaAppSceneEditKeySelect : public IrdaAppScene { -public: - void on_enter(IrdaApp* app) final; - bool on_event(IrdaApp* app, IrdaAppEvent* event) final; - void on_exit(IrdaApp* app) final; - -private: - std::vector buttons_names; -}; - -class IrdaAppSceneEditRename : public IrdaAppScene { -public: - void on_enter(IrdaApp* app) final; - bool on_event(IrdaApp* app, IrdaAppEvent* event) final; - void on_exit(IrdaApp* app) final; -}; - -class IrdaAppSceneEditDelete : public IrdaAppScene { -public: - void on_enter(IrdaApp* app) final; - bool on_event(IrdaApp* app, IrdaAppEvent* event) final; - void on_exit(IrdaApp* app) final; -}; - -class IrdaAppSceneEditRenameDone : public IrdaAppScene { -public: - void on_enter(IrdaApp* app) final; - bool on_event(IrdaApp* app, IrdaAppEvent* event) final; - void on_exit(IrdaApp* app) final; -}; - -class IrdaAppSceneEditDeleteDone : public IrdaAppScene { -public: - void on_enter(IrdaApp* app) final; - bool on_event(IrdaApp* app, IrdaAppEvent* event) final; - void on_exit(IrdaApp* app) final; -}; - -class IrdaAppSceneUniversalCommon : public IrdaAppScene { - bool brute_force_started = false; - -protected: - bool on_event(IrdaApp* app, IrdaAppEvent* event) final; - void on_exit(IrdaApp* app) final; - IrdaAppBruteForce brute_force; - void remove_popup(IrdaApp* app); - void show_popup(IrdaApp* app, int record_amount); - bool progress_popup(IrdaApp* app); - static void irda_app_item_callback(void* context, uint32_t index); - IrdaAppSceneUniversalCommon(const char* filename) - : brute_force(filename) { - } - ~IrdaAppSceneUniversalCommon() { - } -}; - -class IrdaAppSceneUniversalTV : public IrdaAppSceneUniversalCommon { -public: - void on_enter(IrdaApp* app) final; - IrdaAppSceneUniversalTV() - : IrdaAppSceneUniversalCommon("/ext/irda/assets/tv.ir") { - } - ~IrdaAppSceneUniversalTV() { - } -}; - -class IrdaAppSceneUniversalAudio : public IrdaAppSceneUniversalCommon { -public: - void on_enter(IrdaApp* app) final; - IrdaAppSceneUniversalAudio() - : IrdaAppSceneUniversalCommon("/ext/irda/assets/audio.ir") { - } - ~IrdaAppSceneUniversalAudio() { - } -}; diff --git a/applications/irda/scene/irda_app_scene_edit_delete_done.cpp b/applications/irda/scene/irda_app_scene_edit_delete_done.cpp deleted file mode 100644 index e429e72d..00000000 --- a/applications/irda/scene/irda_app_scene_edit_delete_done.cpp +++ /dev/null @@ -1,38 +0,0 @@ -#include "../irda_app.h" - -void IrdaAppSceneEditDeleteDone::on_enter(IrdaApp* app) { - IrdaAppViewManager* view_manager = app->get_view_manager(); - Popup* popup = view_manager->get_popup(); - - popup_set_icon(popup, 0, 2, &I_DolphinMafia_115x62); - popup_set_header(popup, "Deleted", 83, 19, AlignLeft, AlignBottom); - - popup_set_callback(popup, IrdaApp::popup_callback); - popup_set_context(popup, app); - popup_set_timeout(popup, 1500); - popup_enable_timeout(popup); - - view_manager->switch_to(IrdaAppViewManager::ViewType::Popup); -} - -bool IrdaAppSceneEditDeleteDone::on_event(IrdaApp* app, IrdaAppEvent* event) { - bool consumed = false; - - if(event->type == IrdaAppEvent::Type::PopupTimer) { - if(app->get_edit_element() == IrdaApp::EditElement::Remote) { - app->search_and_switch_to_previous_scene( - {IrdaApp::Scene::Start, IrdaApp::Scene::RemoteList}); - } else { - app->search_and_switch_to_previous_scene({IrdaApp::Scene::Remote}); - } - consumed = true; - } - - return consumed; -} - -void IrdaAppSceneEditDeleteDone::on_exit(IrdaApp* app) { - IrdaAppViewManager* view_manager = app->get_view_manager(); - Popup* popup = view_manager->get_popup(); - popup_set_header(popup, nullptr, 0, 0, AlignLeft, AlignTop); -} diff --git a/applications/irda/scene/irda_app_scene_edit_key_select.cpp b/applications/irda/scene/irda_app_scene_edit_key_select.cpp deleted file mode 100644 index 7d805cd6..00000000 --- a/applications/irda/scene/irda_app_scene_edit_key_select.cpp +++ /dev/null @@ -1,57 +0,0 @@ -#include "../irda_app.h" -#include "gui/modules/submenu.h" - -static void submenu_callback(void* context, uint32_t index) { - IrdaApp* app = static_cast(context); - IrdaAppEvent event; - - event.type = IrdaAppEvent::Type::MenuSelected; - event.payload.menu_index = index; - - app->get_view_manager()->send_event(&event); -} - -void IrdaAppSceneEditKeySelect::on_enter(IrdaApp* app) { - IrdaAppViewManager* view_manager = app->get_view_manager(); - Submenu* submenu = view_manager->get_submenu(); - int item_number = 0; - - const char* header = app->get_edit_action() == IrdaApp::EditAction::Rename ? "Rename key:" : - "Delete key:"; - submenu_set_header(submenu, header); - - auto remote_manager = app->get_remote_manager(); - buttons_names = remote_manager->get_button_list(); - for(const auto& it : buttons_names) { - submenu_add_item(submenu, it.c_str(), item_number++, submenu_callback, app); - } - if((item_number > 0) && (app->get_current_button() != IrdaApp::ButtonNA)) { - submenu_set_selected_item(submenu, app->get_current_button()); - app->set_current_button(IrdaApp::ButtonNA); - } - - view_manager->switch_to(IrdaAppViewManager::ViewType::Submenu); -} - -bool IrdaAppSceneEditKeySelect::on_event(IrdaApp* app, IrdaAppEvent* event) { - bool consumed = false; - - if(event->type == IrdaAppEvent::Type::MenuSelected) { - app->set_current_button(event->payload.menu_index); - consumed = true; - if(app->get_edit_action() == IrdaApp::EditAction::Rename) { - app->switch_to_next_scene(IrdaApp::Scene::EditRename); - } else { - app->switch_to_next_scene(IrdaApp::Scene::EditDelete); - } - } - - return consumed; -} - -void IrdaAppSceneEditKeySelect::on_exit(IrdaApp* app) { - IrdaAppViewManager* view_manager = app->get_view_manager(); - Submenu* submenu = view_manager->get_submenu(); - - submenu_reset(submenu); -} diff --git a/applications/irda/scene/irda_app_scene_edit_rename_done.cpp b/applications/irda/scene/irda_app_scene_edit_rename_done.cpp deleted file mode 100644 index 181b9670..00000000 --- a/applications/irda/scene/irda_app_scene_edit_rename_done.cpp +++ /dev/null @@ -1,31 +0,0 @@ -#include "../irda_app.h" - -void IrdaAppSceneEditRenameDone::on_enter(IrdaApp* app) { - IrdaAppViewManager* view_manager = app->get_view_manager(); - Popup* popup = view_manager->get_popup(); - - popup_set_icon(popup, 32, 5, &I_DolphinNice_96x59); - - popup_set_header(popup, "Saved!", 5, 7, AlignLeft, AlignTop); - - popup_set_callback(popup, IrdaApp::popup_callback); - popup_set_context(popup, app); - popup_set_timeout(popup, 1500); - popup_enable_timeout(popup); - - view_manager->switch_to(IrdaAppViewManager::ViewType::Popup); -} - -bool IrdaAppSceneEditRenameDone::on_event(IrdaApp* app, IrdaAppEvent* event) { - bool consumed = false; - - if(event->type == IrdaAppEvent::Type::PopupTimer) { - app->switch_to_next_scene(IrdaApp::Scene::Remote); - consumed = true; - } - - return consumed; -} - -void IrdaAppSceneEditRenameDone::on_exit(IrdaApp* app) { -} diff --git a/applications/irda/scene/irda_app_scene_learn.cpp b/applications/irda/scene/irda_app_scene_learn.cpp deleted file mode 100644 index 7075f0f8..00000000 --- a/applications/irda/scene/irda_app_scene_learn.cpp +++ /dev/null @@ -1,75 +0,0 @@ -#include "../irda_app.h" -#include "../irda_app_event.h" -#include "irda.h" -#include - -static void signal_received_callback(void* context, IrdaWorkerSignal* received_signal) { - furi_assert(context); - furi_assert(received_signal); - - IrdaApp* app = static_cast(context); - - if(irda_worker_signal_is_decoded(received_signal)) { - IrdaAppSignal signal(irda_worker_get_decoded_signal(received_signal)); - app->set_received_signal(signal); - } else { - const uint32_t* timings; - size_t timings_cnt; - irda_worker_get_raw_signal(received_signal, &timings, &timings_cnt); - IrdaAppSignal signal( - timings, timings_cnt, IRDA_COMMON_CARRIER_FREQUENCY, IRDA_COMMON_DUTY_CYCLE); - app->set_received_signal(signal); - } - - irda_worker_rx_set_received_signal_callback(app->get_irda_worker(), NULL, NULL); - IrdaAppEvent event; - event.type = IrdaAppEvent::Type::IrdaMessageReceived; - auto view_manager = app->get_view_manager(); - view_manager->send_event(&event); -} - -void IrdaAppSceneLearn::on_enter(IrdaApp* app) { - auto view_manager = app->get_view_manager(); - auto popup = view_manager->get_popup(); - - auto worker = app->get_irda_worker(); - irda_worker_rx_set_received_signal_callback(worker, signal_received_callback, app); - irda_worker_rx_start(worker); - - popup_set_icon(popup, 0, 32, &I_IrdaLearnShort_128x31); - popup_set_text( - popup, "Point the remote at IR port\nand push the button", 5, 10, AlignLeft, AlignCenter); - popup_set_callback(popup, NULL); - - view_manager->switch_to(IrdaAppViewManager::ViewType::Popup); -} - -bool IrdaAppSceneLearn::on_event(IrdaApp* app, IrdaAppEvent* event) { - bool consumed = false; - - switch(event->type) { - case IrdaAppEvent::Type::Tick: - consumed = true; - app->notify_red_blink(); - break; - case IrdaAppEvent::Type::IrdaMessageReceived: - app->notify_success(); - app->switch_to_next_scene_without_saving(IrdaApp::Scene::LearnSuccess); - break; - case IrdaAppEvent::Type::Back: - consumed = true; - app->switch_to_previous_scene(); - break; - default: - furi_assert(0); - } - - return consumed; -} - -void IrdaAppSceneLearn::on_exit(IrdaApp* app) { - irda_worker_rx_stop(app->get_irda_worker()); - auto view_manager = app->get_view_manager(); - auto popup = view_manager->get_popup(); - popup_set_text(popup, NULL, 0, 0, AlignCenter, AlignCenter); -} diff --git a/applications/irda/scene/irda_app_scene_universal_common.cpp b/applications/irda/scene/irda_app_scene_universal_common.cpp deleted file mode 100644 index 5a020ea7..00000000 --- a/applications/irda/scene/irda_app_scene_universal_common.cpp +++ /dev/null @@ -1,101 +0,0 @@ -#include -#include -#include -#include -#include - -#include "../irda_app.h" -#include "irda/irda_app_event.h" -#include "irda/irda_app_view_manager.h" -#include "irda/scene/irda_app_scene.h" -#include "../view/irda_progress_view.h" - -void IrdaAppSceneUniversalCommon::irda_app_item_callback(void* context, uint32_t index) { - IrdaApp* app = static_cast(context); - IrdaAppEvent event; - - event.type = IrdaAppEvent::Type::ButtonPanelPressed; - event.payload.menu_index = index; - - app->get_view_manager()->send_event(&event); -} - -static void irda_progress_back_callback(void* context) { - furi_assert(context); - auto app = static_cast(context); - - IrdaAppEvent irda_event = { - .type = IrdaAppEvent::Type::Back, - }; - app->get_view_manager()->clear_events(); - app->get_view_manager()->send_event(&irda_event); -} - -void IrdaAppSceneUniversalCommon::remove_popup(IrdaApp* app) { - auto stack_view = app->get_view_manager()->get_universal_view_stack(); - auto progress_view = app->get_view_manager()->get_progress(); - view_stack_remove_view(stack_view, irda_progress_view_get_view(progress_view)); -} - -void IrdaAppSceneUniversalCommon::show_popup(IrdaApp* app, int record_amount) { - auto stack_view = app->get_view_manager()->get_universal_view_stack(); - auto progress_view = app->get_view_manager()->get_progress(); - irda_progress_view_set_progress_total(progress_view, record_amount); - irda_progress_view_set_back_callback(progress_view, irda_progress_back_callback, app); - view_stack_add_view(stack_view, irda_progress_view_get_view(progress_view)); -} - -bool IrdaAppSceneUniversalCommon::progress_popup(IrdaApp* app) { - auto progress_view = app->get_view_manager()->get_progress(); - return irda_progress_view_increase_progress(progress_view); -} - -bool IrdaAppSceneUniversalCommon::on_event(IrdaApp* app, IrdaAppEvent* event) { - bool consumed = false; - - if(brute_force_started) { - if(event->type == IrdaAppEvent::Type::Tick) { - auto view_manager = app->get_view_manager(); - IrdaAppEvent tick_event = {.type = IrdaAppEvent::Type::Tick}; - view_manager->send_event(&tick_event); - bool result = brute_force.send_next_bruteforce(); - if(result) { - result = progress_popup(app); - } - if(!result) { - brute_force.stop_bruteforce(); - brute_force_started = false; - remove_popup(app); - } - consumed = true; - } else if(event->type == IrdaAppEvent::Type::Back) { - brute_force_started = false; - brute_force.stop_bruteforce(); - remove_popup(app); - consumed = true; - } - } else { - if(event->type == IrdaAppEvent::Type::ButtonPanelPressed) { - int record_amount = 0; - if(brute_force.start_bruteforce(event->payload.menu_index, record_amount)) { - DOLPHIN_DEED(DolphinDeedIrBruteForce); - brute_force_started = true; - show_popup(app, record_amount); - } else { - app->switch_to_previous_scene(); - } - consumed = true; - } else if(event->type == IrdaAppEvent::Type::Back) { - app->switch_to_previous_scene(); - consumed = true; - } - } - - return consumed; -} - -void IrdaAppSceneUniversalCommon::on_exit(IrdaApp* app) { - IrdaAppViewManager* view_manager = app->get_view_manager(); - ButtonPanel* button_panel = view_manager->get_button_panel(); - button_panel_reset(button_panel); -} diff --git a/applications/irda/view/irda_progress_view.h b/applications/irda/view/irda_progress_view.h deleted file mode 100644 index f0e41928..00000000 --- a/applications/irda/view/irda_progress_view.h +++ /dev/null @@ -1,25 +0,0 @@ -#pragma once -#include - -#ifdef __cplusplus -extern "C" { -#endif - -typedef struct IrdaProgressView IrdaProgressView; - -typedef void (*IrdaProgressViewBackCallback)(void*); - -IrdaProgressView* irda_progress_view_alloc(); -void irda_progress_view_free(IrdaProgressView* progress); -View* irda_progress_view_get_view(IrdaProgressView* progress); - -bool irda_progress_view_increase_progress(IrdaProgressView* progress); -void irda_progress_view_set_progress_total(IrdaProgressView* progress, uint16_t progress_max); -void irda_progress_view_set_back_callback( - IrdaProgressView* instance, - IrdaProgressViewBackCallback callback, - void* context); - -#ifdef __cplusplus -} -#endif diff --git a/applications/irda_monitor/irda_monitor.c b/applications/irda_monitor/irda_monitor.c deleted file mode 100644 index 5325d192..00000000 --- a/applications/irda_monitor/irda_monitor.c +++ /dev/null @@ -1,139 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define IRDA_TIMINGS_SIZE 700 - -typedef struct { - uint32_t timing_cnt; - struct { - uint8_t level; - uint32_t duration; - } timing[IRDA_TIMINGS_SIZE]; -} IrdaDelaysArray; - -typedef struct { - char display_text[64]; - osMessageQueueId_t event_queue; - IrdaDelaysArray delays; - IrdaWorker* worker; - ViewPort* view_port; -} IrdaMonitor; - -void irda_monitor_input_callback(InputEvent* input_event, void* ctx) { - furi_assert(ctx); - IrdaMonitor* irda_monitor = (IrdaMonitor*)ctx; - - if((input_event->type == InputTypeShort) && (input_event->key == InputKeyBack)) { - osMessageQueuePut(irda_monitor->event_queue, input_event, 0, 0); - } -} - -static void irda_monitor_draw_callback(Canvas* canvas, void* ctx) { - furi_assert(canvas); - furi_assert(ctx); - IrdaMonitor* irda_monitor = (IrdaMonitor*)ctx; - - canvas_clear(canvas); - canvas_set_font(canvas, FontPrimary); - elements_multiline_text_aligned(canvas, 64, 0, AlignCenter, AlignTop, "IRDA monitor\n"); - canvas_set_font(canvas, FontKeyboard); - if(strlen(irda_monitor->display_text)) { - elements_multiline_text_aligned( - canvas, 64, 43, AlignCenter, AlignCenter, irda_monitor->display_text); - } -} - -static void signal_received_callback(void* context, IrdaWorkerSignal* received_signal) { - furi_assert(context); - furi_assert(received_signal); - IrdaMonitor* irda_monitor = context; - - if(irda_worker_signal_is_decoded(received_signal)) { - const IrdaMessage* message = irda_worker_get_decoded_signal(received_signal); - snprintf( - irda_monitor->display_text, - sizeof(irda_monitor->display_text), - "%s\nA:0x%0*lX\nC:0x%0*lX\n%s\n", - irda_get_protocol_name(message->protocol), - ROUND_UP_TO(irda_get_protocol_address_length(message->protocol), 4), - message->address, - ROUND_UP_TO(irda_get_protocol_command_length(message->protocol), 4), - message->command, - message->repeat ? " R" : ""); - view_port_update(irda_monitor->view_port); - printf( - "== %s, A:0x%0*lX, C:0x%0*lX%s ==\r\n", - irda_get_protocol_name(message->protocol), - ROUND_UP_TO(irda_get_protocol_address_length(message->protocol), 4), - message->address, - ROUND_UP_TO(irda_get_protocol_command_length(message->protocol), 4), - message->command, - message->repeat ? " R" : ""); - } else { - const uint32_t* timings; - size_t timings_cnt; - irda_worker_get_raw_signal(received_signal, &timings, &timings_cnt); - snprintf( - irda_monitor->display_text, - sizeof(irda_monitor->display_text), - "RAW\n%d samples\n", - timings_cnt); - view_port_update(irda_monitor->view_port); - printf("RAW, %d samples:\r\n", timings_cnt); - for(size_t i = 0; i < timings_cnt; ++i) { - printf("%lu ", timings[i]); - } - printf("\r\n"); - } -} - -int32_t irda_monitor_app(void* p) { - (void)p; - - IrdaMonitor* irda_monitor = malloc(sizeof(IrdaMonitor)); - irda_monitor->display_text[0] = 0; - irda_monitor->event_queue = osMessageQueueNew(1, sizeof(InputEvent), NULL); - irda_monitor->view_port = view_port_alloc(); - Gui* gui = furi_record_open("gui"); - - view_port_draw_callback_set(irda_monitor->view_port, irda_monitor_draw_callback, irda_monitor); - view_port_input_callback_set( - irda_monitor->view_port, irda_monitor_input_callback, irda_monitor); - - gui_add_view_port(gui, irda_monitor->view_port, GuiLayerFullscreen); - - irda_monitor->worker = irda_worker_alloc(); - irda_worker_rx_start(irda_monitor->worker); - irda_worker_rx_set_received_signal_callback( - irda_monitor->worker, signal_received_callback, irda_monitor); - irda_worker_rx_enable_blink_on_receiving(irda_monitor->worker, true); - - while(1) { - InputEvent event; - if(osOK == osMessageQueueGet(irda_monitor->event_queue, &event, NULL, 50)) { - if((event.type == InputTypeShort) && (event.key == InputKeyBack)) { - break; - } - } - } - - irda_worker_rx_stop(irda_monitor->worker); - irda_worker_free(irda_monitor->worker); - osMessageQueueDelete(irda_monitor->event_queue); - view_port_enabled_set(irda_monitor->view_port, false); - gui_remove_view_port(gui, irda_monitor->view_port); - view_port_free(irda_monitor->view_port); - furi_record_close("gui"); - free(irda_monitor); - - return 0; -} diff --git a/applications/tests/irda_decoder_encoder/irda_decoder_encoder_test.c b/applications/tests/infrared_decoder_encoder/infrared_decoder_encoder_test.c similarity index 77% rename from applications/tests/irda_decoder_encoder/irda_decoder_encoder_test.c rename to applications/tests/infrared_decoder_encoder/infrared_decoder_encoder_test.c index 7ab27430..ca9120ed 100644 --- a/applications/tests/irda_decoder_encoder/irda_decoder_encoder_test.c +++ b/applications/tests/infrared_decoder_encoder/infrared_decoder_encoder_test.c @@ -1,13 +1,13 @@ #include #include "../minunit.h" -#include "irda.h" -#include "common/irda_common_i.h" -#include "test_data/irda_nec_test_data.srcdata" -#include "test_data/irda_necext_test_data.srcdata" -#include "test_data/irda_samsung_test_data.srcdata" -#include "test_data/irda_rc6_test_data.srcdata" -#include "test_data/irda_rc5_test_data.srcdata" -#include "test_data/irda_sirc_test_data.srcdata" +#include "infrared.h" +#include "common/infrared_common_i.h" +#include "test_data/infrared_nec_test_data.srcdata" +#include "test_data/infrared_necext_test_data.srcdata" +#include "test_data/infrared_samsung_test_data.srcdata" +#include "test_data/infrared_rc6_test_data.srcdata" +#include "test_data/infrared_rc5_test_data.srcdata" +#include "test_data/infrared_sirc_test_data.srcdata" #define RUN_ENCODER(data, expected) \ run_encoder((data), COUNT_OF(data), (expected), COUNT_OF(expected)) @@ -17,28 +17,28 @@ #define RUN_ENCODER_DECODER(data) run_encoder_decoder((data), COUNT_OF(data)) -static IrdaDecoderHandler* decoder_handler; -static IrdaEncoderHandler* encoder_handler; +static InfraredDecoderHandler* decoder_handler; +static InfraredEncoderHandler* encoder_handler; static void test_setup(void) { - decoder_handler = irda_alloc_decoder(); - encoder_handler = irda_alloc_encoder(); + decoder_handler = infrared_alloc_decoder(); + encoder_handler = infrared_alloc_encoder(); } static void test_teardown(void) { - irda_free_decoder(decoder_handler); - irda_free_encoder(encoder_handler); + infrared_free_decoder(decoder_handler); + infrared_free_encoder(encoder_handler); } static void compare_message_results( - const IrdaMessage* message_decoded, - const IrdaMessage* message_expected) { + const InfraredMessage* message_decoded, + const InfraredMessage* message_expected) { mu_check(message_decoded->protocol == message_expected->protocol); mu_check(message_decoded->command == message_expected->command); mu_check(message_decoded->address == message_expected->address); - if((message_expected->protocol == IrdaProtocolSIRC) || - (message_expected->protocol == IrdaProtocolSIRC15) || - (message_expected->protocol == IrdaProtocolSIRC20)) { + if((message_expected->protocol == InfraredProtocolSIRC) || + (message_expected->protocol == InfraredProtocolSIRC15) || + (message_expected->protocol == InfraredProtocolSIRC20)) { mu_check(message_decoded->repeat == false); } else { mu_check(message_decoded->repeat == message_expected->repeat); @@ -47,19 +47,19 @@ static void compare_message_results( /* Encodes signal and merges same levels (high+high, low+low) */ static void run_encoder_fill_array( - IrdaEncoderHandler* handler, + InfraredEncoderHandler* handler, uint32_t* timings, uint32_t* timings_len, bool* start_level) { uint32_t duration = 0; bool level = false; bool level_read; - IrdaStatus status = IrdaStatusError; + InfraredStatus status = InfraredStatusError; int i = 0; bool first = true; while(1) { - status = irda_encode(handler, &duration, &level_read); + status = infrared_encode(handler, &duration, &level_read); if(first) { if(start_level) *start_level = level_read; first = false; @@ -72,8 +72,8 @@ static void run_encoder_fill_array( level = level_read; timings[i] += duration; - furi_check((status == IrdaStatusOk) || (status == IrdaStatusDone)); - if(status == IrdaStatusDone) break; + furi_check((status == InfraredStatusOk) || (status == InfraredStatusDone)); + if(status == InfraredStatusDone) break; } *timings_len = i + 1; @@ -81,7 +81,7 @@ static void run_encoder_fill_array( // messages in input array for encoder should have one protocol static void run_encoder( - const IrdaMessage input_messages[], + const InfraredMessage input_messages[], uint32_t input_messages_len, const uint32_t expected_timings[], uint32_t expected_timings_len) { @@ -91,9 +91,9 @@ static void run_encoder( timings = malloc(sizeof(uint32_t) * timings_len); for(uint32_t message_counter = 0; message_counter < input_messages_len; ++message_counter) { - const IrdaMessage* message = &input_messages[message_counter]; + const InfraredMessage* message = &input_messages[message_counter]; if(!message->repeat) { - irda_reset_encoder(encoder_handler, message); + infrared_reset_encoder(encoder_handler, message); } timings_len = 200; @@ -109,25 +109,26 @@ static void run_encoder( mu_assert(j == expected_timings_len, "encoded less timings than expected"); } -static void run_encoder_decoder(const IrdaMessage input_messages[], uint32_t input_messages_len) { +static void + run_encoder_decoder(const InfraredMessage input_messages[], uint32_t input_messages_len) { uint32_t* timings = 0; uint32_t timings_len = 200; bool level = false; timings = malloc(sizeof(uint32_t) * timings_len); for(uint32_t message_counter = 0; message_counter < input_messages_len; ++message_counter) { - const IrdaMessage* message_encoded = &input_messages[message_counter]; + const InfraredMessage* message_encoded = &input_messages[message_counter]; if(!message_encoded->repeat) { - irda_reset_encoder(encoder_handler, message_encoded); + infrared_reset_encoder(encoder_handler, message_encoded); } timings_len = 200; run_encoder_fill_array(encoder_handler, timings, &timings_len, &level); furi_check(timings_len <= 200); - const IrdaMessage* message_decoded = 0; + const InfraredMessage* message_decoded = 0; for(int i = 0; i < timings_len; ++i) { - message_decoded = irda_decode(decoder_handler, level, timings[i]); + message_decoded = infrared_decode(decoder_handler, level, timings[i]); if((i == timings_len - 2) && level && message_decoded) { /* In case we end with space timing - message can be decoded at last mark */ break; @@ -135,7 +136,7 @@ static void run_encoder_decoder(const IrdaMessage input_messages[], uint32_t inp mu_check(!message_decoded); } else { if(!message_decoded) { - message_decoded = irda_check_decoder_ready(decoder_handler); + message_decoded = infrared_check_decoder_ready(decoder_handler); } mu_check(message_decoded); } @@ -153,32 +154,32 @@ static void run_encoder_decoder(const IrdaMessage input_messages[], uint32_t inp static void run_decoder( const uint32_t* input_delays, uint32_t input_delays_len, - const IrdaMessage* message_expected, + const InfraredMessage* message_expected, uint32_t message_expected_len) { - IrdaMessage message_decoded_check_local; + InfraredMessage message_decoded_check_local; bool level = 0; uint32_t message_counter = 0; - const IrdaMessage* message_decoded = 0; + const InfraredMessage* message_decoded = 0; for(uint32_t i = 0; i < input_delays_len; ++i) { - const IrdaMessage* message_decoded_check = 0; + const InfraredMessage* message_decoded_check = 0; - if(input_delays[i] > IRDA_RAW_RX_TIMING_DELAY_US) { - message_decoded_check = irda_check_decoder_ready(decoder_handler); + if(input_delays[i] > INFRARED_RAW_RX_TIMING_DELAY_US) { + message_decoded_check = infrared_check_decoder_ready(decoder_handler); if(message_decoded_check) { - /* irda_decode() can reset message, but we have to call irda_decode() to perform real - * simulation: irda_check() by timeout, then irda_decode() when meet edge */ + /* infrared_decode() can reset message, but we have to call infrared_decode() to perform real + * simulation: infrared_check() by timeout, then infrared_decode() when meet edge */ message_decoded_check_local = *message_decoded_check; message_decoded_check = &message_decoded_check_local; } } - message_decoded = irda_decode(decoder_handler, level, input_delays[i]); + message_decoded = infrared_decode(decoder_handler, level, input_delays[i]); if(message_decoded_check || message_decoded) { mu_assert( !(message_decoded_check && message_decoded), - "both messages decoded: check_ready() and irda_decode()"); + "both messages decoded: check_ready() and infrared_decode()"); if(message_decoded_check) { message_decoded = message_decoded_check; @@ -192,7 +193,7 @@ static void run_decoder( level = !level; } - message_decoded = irda_check_decoder_ready(decoder_handler); + message_decoded = infrared_check_decoder_ready(decoder_handler); if(message_decoded) { compare_message_results(message_decoded, &message_expected[message_counter]); ++message_counter; @@ -304,7 +305,7 @@ MU_TEST(test_encoder_decoder_all) { RUN_ENCODER_DECODER(test_sirc); } -MU_TEST_SUITE(test_irda_decoder_encoder) { +MU_TEST_SUITE(test_infrared_decoder_encoder) { MU_SUITE_CONFIGURE(&test_setup, &test_teardown); MU_RUN_TEST(test_encoder_sirc); @@ -323,8 +324,8 @@ MU_TEST_SUITE(test_irda_decoder_encoder) { MU_RUN_TEST(test_encoder_decoder_all); } -int run_minunit_test_irda_decoder_encoder() { - MU_RUN_SUITE(test_irda_decoder_encoder); +int run_minunit_test_infrared_decoder_encoder() { + MU_RUN_SUITE(test_infrared_decoder_encoder); return MU_EXIT_CODE; } diff --git a/applications/tests/irda_decoder_encoder/test_data/irda_nec_test_data.srcdata b/applications/tests/infrared_decoder_encoder/test_data/infrared_nec_test_data.srcdata similarity index 66% rename from applications/tests/irda_decoder_encoder/test_data/irda_nec_test_data.srcdata rename to applications/tests/infrared_decoder_encoder/test_data/infrared_nec_test_data.srcdata index 1214ae9b..ec9a86a6 100644 --- a/applications/tests/irda_decoder_encoder/test_data/irda_nec_test_data.srcdata +++ b/applications/tests/infrared_decoder_encoder/test_data/infrared_nec_test_data.srcdata @@ -10,10 +10,10 @@ const uint32_t test_decoder_nec_input1[] = { /* message */ 1415838, 9080, 4436, 611, 494, 600, 505, 578, 500, 608, 501, 602, 502, 580, 498, 606, 508, 605, 500, 583, 1633, 608, 1608, 611, 1631, 578, 1638, 602, 1614, 606, 1637, 583, 1633, 607, 1609, 611, 494, 600, 505, 570, 500, 604, 501, 602, 502, 581, 497, 606, 499, 605, 499, 583, 1633, 617, 1608, 611, 1631, 579, 1638, 602}; -const IrdaMessage test_decoder_nec_expected1[] = { - {IrdaProtocolNEC, 0x00, 0, false}, - {IrdaProtocolNEC, 0x00, 0, true}, - {IrdaProtocolNEC, 0x00, 0, false}, +const InfraredMessage test_decoder_nec_expected1[] = { + {InfraredProtocolNEC, 0x00, 0, false}, + {InfraredProtocolNEC, 0x00, 0, true}, + {InfraredProtocolNEC, 0x00, 0, false}, }; const uint32_t test_decoder_nec_input2[] = { @@ -123,59 +123,59 @@ const uint32_t test_decoder_nec_input2[] = { 40069,9025,2221,588 }; -const IrdaMessage test_decoder_nec_expected2[] = { - {IrdaProtocolNEC, 0x00, 0x02, false}, - {IrdaProtocolNEC, 0x00, 0x02, true}, - {IrdaProtocolNEC, 0x00, 0x02, false}, - {IrdaProtocolNEC, 0x00, 0x02, true}, - {IrdaProtocolNEC, 0x00, 0x02, true}, - {IrdaProtocolNEC, 0x00, 0x02, true}, - {IrdaProtocolNEC, 0x00, 0x02, true}, - {IrdaProtocolNEC, 0x00, 0x02, true}, - {IrdaProtocolNEC, 0x00, 0x02, true}, - {IrdaProtocolNEC, 0x00, 0x02, true}, - {IrdaProtocolNEC, 0x00, 0x02, true}, - {IrdaProtocolNEC, 0x00, 0x02, true}, - {IrdaProtocolNEC, 0x00, 0x02, true}, - {IrdaProtocolNEC, 0x00, 0x02, true}, - {IrdaProtocolNEC, 0x00, 0x02, true}, - {IrdaProtocolNEC, 0x00, 0x02, true}, - {IrdaProtocolNEC, 0x00, 0x02, true}, - {IrdaProtocolNEC, 0x00, 0x02, true}, - {IrdaProtocolNEC, 0x00, 0x02, true}, - {IrdaProtocolNEC, 0x00, 0x06, false}, - {IrdaProtocolNEC, 0x00, 0x06, true}, - {IrdaProtocolNEC, 0x00, 0x04, false}, - {IrdaProtocolNEC, 0x00, 0x04, true}, - {IrdaProtocolNEC, 0x00, 0x08, false}, - {IrdaProtocolNEC, 0x00, 0x08, true}, - {IrdaProtocolNEC, 0x00, 0x08, false}, - {IrdaProtocolNEC, 0x00, 0x08, true}, - {IrdaProtocolNEC, 0x00, 0x08, false}, - {IrdaProtocolNEC, 0x00, 0x08, false}, - {IrdaProtocolNEC, 0x00, 0x08, false}, - {IrdaProtocolNEC, 0x00, 0x08, false}, - {IrdaProtocolNEC, 0x00, 0x08, false}, - {IrdaProtocolNEC, 0x00, 0x08, false}, - {IrdaProtocolNEC, 0x00, 0x08, false}, - {IrdaProtocolNEC, 0x00, 0x08, false}, - {IrdaProtocolNEC, 0x00, 0x08, false}, - {IrdaProtocolNEC, 0x00, 0x08, false}, - {IrdaProtocolNEC, 0x00, 0x08, false}, - {IrdaProtocolNEC, 0x00, 0x09, false}, - {IrdaProtocolNEC, 0x00, 0x09, false}, - {IrdaProtocolNEC, 0x00, 0x09, false}, - {IrdaProtocolNEC, 0x00, 0x08, false}, - {IrdaProtocolNEC, 0x00, 0x0A, false}, - {IrdaProtocolNEC, 0x00, 0x08, false}, - {IrdaProtocolNEC, 0x00, 0x08, true}, - {IrdaProtocolNEC, 0x00, 0x08, false}, - {IrdaProtocolNEC, 0x00, 0x08, true}, - {IrdaProtocolNEC, 0x00, 0x08, false}, - {IrdaProtocolNEC, 0x00, 0x0A, false}, - {IrdaProtocolNEC, 0x00, 0x08, false}, - {IrdaProtocolNEC, 0x00, 0x0A, false}, - {IrdaProtocolNEC, 0x00, 0x0A, true}, +const InfraredMessage test_decoder_nec_expected2[] = { + {InfraredProtocolNEC, 0x00, 0x02, false}, + {InfraredProtocolNEC, 0x00, 0x02, true}, + {InfraredProtocolNEC, 0x00, 0x02, false}, + {InfraredProtocolNEC, 0x00, 0x02, true}, + {InfraredProtocolNEC, 0x00, 0x02, true}, + {InfraredProtocolNEC, 0x00, 0x02, true}, + {InfraredProtocolNEC, 0x00, 0x02, true}, + {InfraredProtocolNEC, 0x00, 0x02, true}, + {InfraredProtocolNEC, 0x00, 0x02, true}, + {InfraredProtocolNEC, 0x00, 0x02, true}, + {InfraredProtocolNEC, 0x00, 0x02, true}, + {InfraredProtocolNEC, 0x00, 0x02, true}, + {InfraredProtocolNEC, 0x00, 0x02, true}, + {InfraredProtocolNEC, 0x00, 0x02, true}, + {InfraredProtocolNEC, 0x00, 0x02, true}, + {InfraredProtocolNEC, 0x00, 0x02, true}, + {InfraredProtocolNEC, 0x00, 0x02, true}, + {InfraredProtocolNEC, 0x00, 0x02, true}, + {InfraredProtocolNEC, 0x00, 0x02, true}, + {InfraredProtocolNEC, 0x00, 0x06, false}, + {InfraredProtocolNEC, 0x00, 0x06, true}, + {InfraredProtocolNEC, 0x00, 0x04, false}, + {InfraredProtocolNEC, 0x00, 0x04, true}, + {InfraredProtocolNEC, 0x00, 0x08, false}, + {InfraredProtocolNEC, 0x00, 0x08, true}, + {InfraredProtocolNEC, 0x00, 0x08, false}, + {InfraredProtocolNEC, 0x00, 0x08, true}, + {InfraredProtocolNEC, 0x00, 0x08, false}, + {InfraredProtocolNEC, 0x00, 0x08, false}, + {InfraredProtocolNEC, 0x00, 0x08, false}, + {InfraredProtocolNEC, 0x00, 0x08, false}, + {InfraredProtocolNEC, 0x00, 0x08, false}, + {InfraredProtocolNEC, 0x00, 0x08, false}, + {InfraredProtocolNEC, 0x00, 0x08, false}, + {InfraredProtocolNEC, 0x00, 0x08, false}, + {InfraredProtocolNEC, 0x00, 0x08, false}, + {InfraredProtocolNEC, 0x00, 0x08, false}, + {InfraredProtocolNEC, 0x00, 0x08, false}, + {InfraredProtocolNEC, 0x00, 0x09, false}, + {InfraredProtocolNEC, 0x00, 0x09, false}, + {InfraredProtocolNEC, 0x00, 0x09, false}, + {InfraredProtocolNEC, 0x00, 0x08, false}, + {InfraredProtocolNEC, 0x00, 0x0A, false}, + {InfraredProtocolNEC, 0x00, 0x08, false}, + {InfraredProtocolNEC, 0x00, 0x08, true}, + {InfraredProtocolNEC, 0x00, 0x08, false}, + {InfraredProtocolNEC, 0x00, 0x08, true}, + {InfraredProtocolNEC, 0x00, 0x08, false}, + {InfraredProtocolNEC, 0x00, 0x0A, false}, + {InfraredProtocolNEC, 0x00, 0x08, false}, + {InfraredProtocolNEC, 0x00, 0x0A, false}, + {InfraredProtocolNEC, 0x00, 0x0A, true}, }; const uint32_t test_decoder_nec_input3[] = { @@ -198,112 +198,112 @@ const uint32_t test_decoder_nec_input3[] = { 92592, 8861, 4414, 538, }; -const IrdaMessage test_decoder_nec_expected3[] = { - {IrdaProtocolNECext, 0x286, 0xB649, false}, - {IrdaProtocolNECext, 0x286, 0xB649, false}, - {IrdaProtocolNECext, 0x6880, 0xB649, false}, - {IrdaProtocolNECext, 0x6880, 0xB649, false}, - {IrdaProtocolNECext, 0x6380, 0x150F, false}, - {IrdaProtocolNECext, 0x6380, 0x150F, false}, - {IrdaProtocolNECext, 0x6480, 0x849, false}, - {IrdaProtocolNECext, 0x6480, 0x849, false}, - {IrdaProtocolNECext, 0x7A83, 0x8, false}, - {IrdaProtocolNECext, 0x7A83, 0x8, false}, - {IrdaProtocolNEC, 0x71, 0x4A, false}, - {IrdaProtocolNEC, 0x71, 0x4A, false}, - {IrdaProtocolNEC42, 0x7B, 0x0, false}, - {IrdaProtocolNEC42, 0x7B, 0x0, false}, - {IrdaProtocolNEC42, 0x11C, 0x12, false}, +const InfraredMessage test_decoder_nec_expected3[] = { + {InfraredProtocolNECext, 0x286, 0xB649, false}, + {InfraredProtocolNECext, 0x286, 0xB649, false}, + {InfraredProtocolNECext, 0x6880, 0xB649, false}, + {InfraredProtocolNECext, 0x6880, 0xB649, false}, + {InfraredProtocolNECext, 0x6380, 0x150F, false}, + {InfraredProtocolNECext, 0x6380, 0x150F, false}, + {InfraredProtocolNECext, 0x6480, 0x849, false}, + {InfraredProtocolNECext, 0x6480, 0x849, false}, + {InfraredProtocolNECext, 0x7A83, 0x8, false}, + {InfraredProtocolNECext, 0x7A83, 0x8, false}, + {InfraredProtocolNEC, 0x71, 0x4A, false}, + {InfraredProtocolNEC, 0x71, 0x4A, false}, + {InfraredProtocolNEC42, 0x7B, 0x0, false}, + {InfraredProtocolNEC42, 0x7B, 0x0, false}, + {InfraredProtocolNEC42, 0x11C, 0x12, false}, }; -const IrdaMessage test_nec[] = { - {IrdaProtocolNEC, 0x00, 0x00, false}, - {IrdaProtocolNEC, 0x01, 0x00, false}, - {IrdaProtocolNEC, 0x01, 0x80, false}, - {IrdaProtocolNEC, 0x00, 0x80, false}, - {IrdaProtocolNEC, 0x00, 0x00, false}, - {IrdaProtocolNEC, 0x00, 0x00, true}, - {IrdaProtocolNEC, 0x00, 0x00, false}, - {IrdaProtocolNEC, 0x00, 0x00, true}, - {IrdaProtocolNEC, 0xFF, 0xFF, false}, - {IrdaProtocolNEC, 0xFE, 0xFF, false}, - {IrdaProtocolNEC, 0xFE, 0x7F, false}, - {IrdaProtocolNEC, 0xFF, 0x7F, false}, - {IrdaProtocolNEC, 0xFF, 0xFF, false}, - {IrdaProtocolNEC, 0xFF, 0xFF, true}, - {IrdaProtocolNEC, 0xAA, 0x55, false}, - {IrdaProtocolNEC, 0x55, 0xAA, false}, - {IrdaProtocolNEC, 0x55, 0x55, false}, - {IrdaProtocolNEC, 0xAA, 0xAA, false}, - {IrdaProtocolNEC, 0xAA, 0xAA, true}, +const InfraredMessage test_nec[] = { + {InfraredProtocolNEC, 0x00, 0x00, false}, + {InfraredProtocolNEC, 0x01, 0x00, false}, + {InfraredProtocolNEC, 0x01, 0x80, false}, + {InfraredProtocolNEC, 0x00, 0x80, false}, + {InfraredProtocolNEC, 0x00, 0x00, false}, + {InfraredProtocolNEC, 0x00, 0x00, true}, + {InfraredProtocolNEC, 0x00, 0x00, false}, + {InfraredProtocolNEC, 0x00, 0x00, true}, + {InfraredProtocolNEC, 0xFF, 0xFF, false}, + {InfraredProtocolNEC, 0xFE, 0xFF, false}, + {InfraredProtocolNEC, 0xFE, 0x7F, false}, + {InfraredProtocolNEC, 0xFF, 0x7F, false}, + {InfraredProtocolNEC, 0xFF, 0xFF, false}, + {InfraredProtocolNEC, 0xFF, 0xFF, true}, + {InfraredProtocolNEC, 0xAA, 0x55, false}, + {InfraredProtocolNEC, 0x55, 0xAA, false}, + {InfraredProtocolNEC, 0x55, 0x55, false}, + {InfraredProtocolNEC, 0xAA, 0xAA, false}, + {InfraredProtocolNEC, 0xAA, 0xAA, true}, - {IrdaProtocolNEC, 0xAA, 0xAA, false}, - {IrdaProtocolNEC, 0xAA, 0xAA, true}, - {IrdaProtocolNEC, 0xAA, 0xAA, true}, + {InfraredProtocolNEC, 0xAA, 0xAA, false}, + {InfraredProtocolNEC, 0xAA, 0xAA, true}, + {InfraredProtocolNEC, 0xAA, 0xAA, true}, - {IrdaProtocolNEC, 0x55, 0x55, false}, - {IrdaProtocolNEC, 0x55, 0x55, true}, - {IrdaProtocolNEC, 0x55, 0x55, true}, - {IrdaProtocolNEC, 0x55, 0x55, true}, + {InfraredProtocolNEC, 0x55, 0x55, false}, + {InfraredProtocolNEC, 0x55, 0x55, true}, + {InfraredProtocolNEC, 0x55, 0x55, true}, + {InfraredProtocolNEC, 0x55, 0x55, true}, }; -const IrdaMessage test_nec42[] = { - {IrdaProtocolNEC42, 0x0000, 0x00, false}, - {IrdaProtocolNEC42, 0x0001, 0x00, false}, - {IrdaProtocolNEC42, 0x0001, 0x80, false}, - {IrdaProtocolNEC42, 0x0000, 0x80, false}, - {IrdaProtocolNEC42, 0x0000, 0x00, false}, - {IrdaProtocolNEC42, 0x0000, 0x00, true}, - {IrdaProtocolNEC42, 0x0000, 0x00, false}, - {IrdaProtocolNEC42, 0x0000, 0x00, true}, - {IrdaProtocolNEC42, 0x1FFF, 0xFF, false}, - {IrdaProtocolNEC42, 0x1FFE, 0xFF, false}, - {IrdaProtocolNEC42, 0x1FFE, 0x7F, false}, - {IrdaProtocolNEC42, 0x1FFF, 0x7F, false}, - {IrdaProtocolNEC42, 0x1FFF, 0xFF, false}, - {IrdaProtocolNEC42, 0x1FFF, 0xFF, true}, - {IrdaProtocolNEC42, 0x0AAA, 0x55, false}, - {IrdaProtocolNEC42, 0x1555, 0xAA, false}, - {IrdaProtocolNEC42, 0x1555, 0x55, false}, - {IrdaProtocolNEC42, 0x0AAA, 0xAA, false}, - {IrdaProtocolNEC42, 0x0AAA, 0xAA, true}, - {IrdaProtocolNEC42, 0x0AAA, 0xAA, false}, - {IrdaProtocolNEC42, 0x0AAA, 0xAA, true}, - {IrdaProtocolNEC42, 0x0AAA, 0xAA, true}, - {IrdaProtocolNEC42, 0x1555, 0x55, false}, - {IrdaProtocolNEC42, 0x1555, 0x55, true}, - {IrdaProtocolNEC42, 0x1555, 0x55, true}, - {IrdaProtocolNEC42, 0x1555, 0x55, true}, +const InfraredMessage test_nec42[] = { + {InfraredProtocolNEC42, 0x0000, 0x00, false}, + {InfraredProtocolNEC42, 0x0001, 0x00, false}, + {InfraredProtocolNEC42, 0x0001, 0x80, false}, + {InfraredProtocolNEC42, 0x0000, 0x80, false}, + {InfraredProtocolNEC42, 0x0000, 0x00, false}, + {InfraredProtocolNEC42, 0x0000, 0x00, true}, + {InfraredProtocolNEC42, 0x0000, 0x00, false}, + {InfraredProtocolNEC42, 0x0000, 0x00, true}, + {InfraredProtocolNEC42, 0x1FFF, 0xFF, false}, + {InfraredProtocolNEC42, 0x1FFE, 0xFF, false}, + {InfraredProtocolNEC42, 0x1FFE, 0x7F, false}, + {InfraredProtocolNEC42, 0x1FFF, 0x7F, false}, + {InfraredProtocolNEC42, 0x1FFF, 0xFF, false}, + {InfraredProtocolNEC42, 0x1FFF, 0xFF, true}, + {InfraredProtocolNEC42, 0x0AAA, 0x55, false}, + {InfraredProtocolNEC42, 0x1555, 0xAA, false}, + {InfraredProtocolNEC42, 0x1555, 0x55, false}, + {InfraredProtocolNEC42, 0x0AAA, 0xAA, false}, + {InfraredProtocolNEC42, 0x0AAA, 0xAA, true}, + {InfraredProtocolNEC42, 0x0AAA, 0xAA, false}, + {InfraredProtocolNEC42, 0x0AAA, 0xAA, true}, + {InfraredProtocolNEC42, 0x0AAA, 0xAA, true}, + {InfraredProtocolNEC42, 0x1555, 0x55, false}, + {InfraredProtocolNEC42, 0x1555, 0x55, true}, + {InfraredProtocolNEC42, 0x1555, 0x55, true}, + {InfraredProtocolNEC42, 0x1555, 0x55, true}, }; -const IrdaMessage test_nec42ext[] = { - {IrdaProtocolNEC42ext, 0x0000000, 0x0000, false}, - {IrdaProtocolNEC42ext, 0x0000001, 0x0000, false}, - {IrdaProtocolNEC42ext, 0x0000001, 0x8000, false}, - {IrdaProtocolNEC42ext, 0x0000000, 0x8000, false}, - {IrdaProtocolNEC42ext, 0x0000000, 0x0000, false}, - {IrdaProtocolNEC42ext, 0x0000000, 0x0000, true}, - {IrdaProtocolNEC42ext, 0x0000000, 0x0000, false}, - {IrdaProtocolNEC42ext, 0x0000000, 0x0000, true}, - {IrdaProtocolNEC42ext, 0x3F000FF, 0xF00F, false}, - {IrdaProtocolNEC42ext, 0x3F000FE, 0xF00F, false}, - {IrdaProtocolNEC42ext, 0x3F000FE, 0x700F, false}, - {IrdaProtocolNEC42ext, 0x3F000FF, 0x700F, false}, - {IrdaProtocolNEC42ext, 0x3F000FF, 0xF00F, false}, - {IrdaProtocolNEC42ext, 0x3F000FF, 0xF00F, true}, - {IrdaProtocolNEC42ext, 0x2AAAAAA, 0x5555, false}, - {IrdaProtocolNEC42ext, 0x1555555, 0xAAAA, false}, - {IrdaProtocolNEC42ext, 0x1555555, 0x5555, false}, - {IrdaProtocolNEC42ext, 0x2AAAAAA, 0xAAAA, false}, - {IrdaProtocolNEC42ext, 0x2AAAAAA, 0xAAAA, true}, - {IrdaProtocolNEC42ext, 0x2AAAAAA, 0xAAAA, false}, - {IrdaProtocolNEC42ext, 0x2AAAAAA, 0xAAAA, true}, - {IrdaProtocolNEC42ext, 0x2AAAAAA, 0xAAAA, true}, - {IrdaProtocolNEC42ext, 0x1555555, 0x5555, false}, - {IrdaProtocolNEC42ext, 0x1555555, 0x5555, true}, - {IrdaProtocolNEC42ext, 0x1555555, 0x5555, true}, - {IrdaProtocolNEC42ext, 0x1555555, 0x5555, true}, +const InfraredMessage test_nec42ext[] = { + {InfraredProtocolNEC42ext, 0x0000000, 0x0000, false}, + {InfraredProtocolNEC42ext, 0x0000001, 0x0000, false}, + {InfraredProtocolNEC42ext, 0x0000001, 0x8000, false}, + {InfraredProtocolNEC42ext, 0x0000000, 0x8000, false}, + {InfraredProtocolNEC42ext, 0x0000000, 0x0000, false}, + {InfraredProtocolNEC42ext, 0x0000000, 0x0000, true}, + {InfraredProtocolNEC42ext, 0x0000000, 0x0000, false}, + {InfraredProtocolNEC42ext, 0x0000000, 0x0000, true}, + {InfraredProtocolNEC42ext, 0x3F000FF, 0xF00F, false}, + {InfraredProtocolNEC42ext, 0x3F000FE, 0xF00F, false}, + {InfraredProtocolNEC42ext, 0x3F000FE, 0x700F, false}, + {InfraredProtocolNEC42ext, 0x3F000FF, 0x700F, false}, + {InfraredProtocolNEC42ext, 0x3F000FF, 0xF00F, false}, + {InfraredProtocolNEC42ext, 0x3F000FF, 0xF00F, true}, + {InfraredProtocolNEC42ext, 0x2AAAAAA, 0x5555, false}, + {InfraredProtocolNEC42ext, 0x1555555, 0xAAAA, false}, + {InfraredProtocolNEC42ext, 0x1555555, 0x5555, false}, + {InfraredProtocolNEC42ext, 0x2AAAAAA, 0xAAAA, false}, + {InfraredProtocolNEC42ext, 0x2AAAAAA, 0xAAAA, true}, + {InfraredProtocolNEC42ext, 0x2AAAAAA, 0xAAAA, false}, + {InfraredProtocolNEC42ext, 0x2AAAAAA, 0xAAAA, true}, + {InfraredProtocolNEC42ext, 0x2AAAAAA, 0xAAAA, true}, + {InfraredProtocolNEC42ext, 0x1555555, 0x5555, false}, + {InfraredProtocolNEC42ext, 0x1555555, 0x5555, true}, + {InfraredProtocolNEC42ext, 0x1555555, 0x5555, true}, + {InfraredProtocolNEC42ext, 0x1555555, 0x5555, true}, }; const uint32_t test_decoder_nec42ext_input1[] = { @@ -331,11 +331,11 @@ const uint32_t test_decoder_nec42ext_input2[] = { 560, 560, 560, 560, 560, 10000, 560, // 42 OK + 1 failed }; -const IrdaMessage test_decoder_nec42ext_expected1[] = { - {IrdaProtocolNEC42ext, 0x00, 0, false}, +const InfraredMessage test_decoder_nec42ext_expected1[] = { + {InfraredProtocolNEC42ext, 0x00, 0, false}, }; -const IrdaMessage test_decoder_nec42ext_expected2[] = { - {IrdaProtocolNEC42ext, 0x00, 0, false}, +const InfraredMessage test_decoder_nec42ext_expected2[] = { + {InfraredProtocolNEC42ext, 0x00, 0, false}, }; diff --git a/applications/tests/irda_decoder_encoder/test_data/irda_necext_test_data.srcdata b/applications/tests/infrared_decoder_encoder/test_data/infrared_necext_test_data.srcdata similarity index 56% rename from applications/tests/irda_decoder_encoder/test_data/irda_necext_test_data.srcdata rename to applications/tests/infrared_decoder_encoder/test_data/infrared_necext_test_data.srcdata index edd60768..22ccf40b 100644 --- a/applications/tests/irda_decoder_encoder/test_data/irda_necext_test_data.srcdata +++ b/applications/tests/infrared_decoder_encoder/test_data/infrared_necext_test_data.srcdata @@ -110,146 +110,146 @@ const uint32_t test_decoder_necext_input1[] = { 261924, 8965, 4465, 585, 529, 588, 525, 592, 1638, 588, 525, 592, 523, 584, 530, 587, 526, 591, 1639, 587, 1642, 583, 529, 587, 527, 590, 1639, 587, 1643, 584, 1646, 590, }; -const IrdaMessage test_decoder_necext_expected1[] = { - {IrdaProtocolNECext, 0x7984, 0xed12, false}, - {IrdaProtocolNECext, 0x7984, 0xed12, true}, - {IrdaProtocolNECext, 0x7984, 0xed12, false}, - {IrdaProtocolNECext, 0x7984, 0xed12, true}, - {IrdaProtocolNECext, 0x7984, 0xed12, true}, - {IrdaProtocolNECext, 0x7984, 0xed12, true}, - {IrdaProtocolNECext, 0x7984, 0xed12, true}, - {IrdaProtocolNECext, 0x7984, 0xed12, true}, - {IrdaProtocolNECext, 0x7984, 0xed12, true}, - {IrdaProtocolNECext, 0x7984, 0xed12, true}, - {IrdaProtocolNECext, 0x7984, 0xed12, true}, - {IrdaProtocolNECext, 0x7984, 0xed12, true}, - {IrdaProtocolNECext, 0x7984, 0xed12, true}, - {IrdaProtocolNECext, 0x7984, 0xed12, true}, - {IrdaProtocolNECext, 0x7984, 0xed12, true}, - {IrdaProtocolNECext, 0x7984, 0xed12, true}, - {IrdaProtocolNECext, 0x7984, 0xed12, true}, - {IrdaProtocolNECext, 0x7984, 0xed12, true}, - {IrdaProtocolNECext, 0x7984, 0xed12, true}, - {IrdaProtocolNECext, 0x7984, 0xed12, true}, - {IrdaProtocolNECext, 0x7984, 0xed12, true}, - {IrdaProtocolNECext, 0x7984, 0xed12, true}, - {IrdaProtocolNECext, 0x7984, 0xed12, false}, - {IrdaProtocolNECext, 0x7984, 0xed12, true}, - {IrdaProtocolNECext, 0x7984, 0xed12, true}, - {IrdaProtocolNECext, 0x7984, 0xed12, true}, - {IrdaProtocolNECext, 0x7984, 0xed12, false}, - {IrdaProtocolNECext, 0x7984, 0xed12, true}, - {IrdaProtocolNECext, 0x7984, 0xed12, true}, - {IrdaProtocolNECext, 0x7984, 0xed12, true}, - {IrdaProtocolNECext, 0x7984, 0xed12, false}, - {IrdaProtocolNECext, 0x7984, 0xed12, true}, - {IrdaProtocolNECext, 0x7984, 0xed12, true}, - {IrdaProtocolNECext, 0x7984, 0xed12, true}, - {IrdaProtocolNECext, 0x7984, 0xed12, false}, - {IrdaProtocolNECext, 0x7984, 0xed12, true}, - {IrdaProtocolNECext, 0x7984, 0xed12, true}, - {IrdaProtocolNECext, 0x7984, 0xed12, true}, - {IrdaProtocolNECext, 0x7984, 0xed12, false}, - {IrdaProtocolNECext, 0x7984, 0xed12, true}, - {IrdaProtocolNECext, 0x7984, 0xed12, true}, - {IrdaProtocolNECext, 0x7984, 0xed12, true}, - {IrdaProtocolNECext, 0x7984, 0xed12, false}, - {IrdaProtocolNECext, 0x7984, 0xed12, true}, - {IrdaProtocolNECext, 0x7984, 0xed12, true}, - {IrdaProtocolNECext, 0x7984, 0xed12, true}, - {IrdaProtocolNECext, 0x7984, 0xed12, false}, - {IrdaProtocolNECext, 0x7984, 0xed12, true}, - {IrdaProtocolNECext, 0x7984, 0xed12, true}, - {IrdaProtocolNECext, 0x7984, 0xed12, true}, - {IrdaProtocolNECext, 0x7984, 0xed12, false}, - {IrdaProtocolNECext, 0x7984, 0xed12, true}, - {IrdaProtocolNECext, 0x7984, 0xed12, true}, - {IrdaProtocolNECext, 0x7984, 0xed12, false}, - {IrdaProtocolNECext, 0x7984, 0xed12, true}, - {IrdaProtocolNECext, 0x7984, 0xed12, true}, - {IrdaProtocolNECext, 0x7984, 0xed12, true}, - {IrdaProtocolNECext, 0x7984, 0xed12, false}, - {IrdaProtocolNECext, 0x7984, 0xed12, true}, - {IrdaProtocolNECext, 0x7984, 0xed12, true}, - {IrdaProtocolNECext, 0x7984, 0xed12, true}, - {IrdaProtocolNECext, 0x7984, 0xed12, false}, - {IrdaProtocolNECext, 0x7984, 0xed12, true}, - {IrdaProtocolNECext, 0x7984, 0xed12, true}, - {IrdaProtocolNECext, 0x7984, 0xed12, true}, - {IrdaProtocolNECext, 0x7984, 0xed12, false}, - {IrdaProtocolNECext, 0x7984, 0xed12, true}, - {IrdaProtocolNECext, 0x7984, 0xed12, true}, - {IrdaProtocolNECext, 0x7984, 0xed12, true}, - {IrdaProtocolNECext, 0x7984, 0xed12, false}, - {IrdaProtocolNECext, 0x7984, 0xed12, true}, - {IrdaProtocolNECext, 0x7984, 0xed12, true}, - {IrdaProtocolNECext, 0x7984, 0xed12, true}, - {IrdaProtocolNECext, 0x7984, 0xed12, false}, - {IrdaProtocolNECext, 0x7984, 0xed12, true}, - {IrdaProtocolNECext, 0x7984, 0xed12, true}, - {IrdaProtocolNECext, 0x7984, 0xed12, true}, - {IrdaProtocolNECext, 0x7984, 0xed12, false}, - {IrdaProtocolNECext, 0x7984, 0xed12, true}, - {IrdaProtocolNECext, 0x7984, 0xed12, true}, - {IrdaProtocolNECext, 0x7984, 0xed12, true}, - {IrdaProtocolNECext, 0x7984, 0xed12, false}, - {IrdaProtocolNECext, 0x7984, 0xed12, true}, - {IrdaProtocolNECext, 0x7984, 0xed12, true}, - {IrdaProtocolNECext, 0x7984, 0xed12, true}, - {IrdaProtocolNECext, 0x7984, 0xed12, false}, - {IrdaProtocolNECext, 0x7984, 0xed12, true}, - {IrdaProtocolNECext, 0x7984, 0xed12, true}, - {IrdaProtocolNECext, 0x7984, 0xed12, true}, - {IrdaProtocolNECext, 0x7984, 0xed12, false}, - {IrdaProtocolNECext, 0x7984, 0xed12, true}, - {IrdaProtocolNECext, 0x7984, 0xed12, true}, - {IrdaProtocolNECext, 0x7984, 0xed12, true}, - {IrdaProtocolNECext, 0x7984, 0xed12, false}, - {IrdaProtocolNECext, 0x7984, 0xed12, true}, - {IrdaProtocolNECext, 0x7984, 0xed12, true}, - {IrdaProtocolNECext, 0x7984, 0xed12, true}, - {IrdaProtocolNECext, 0x7984, 0xed12, false}, - {IrdaProtocolNECext, 0x7984, 0xed12, true}, - {IrdaProtocolNECext, 0x7984, 0xed12, true}, - {IrdaProtocolNECext, 0x7984, 0xed12, true}, - {IrdaProtocolNECext, 0x7984, 0xed12, false}, - {IrdaProtocolNECext, 0x7984, 0xed12, true}, - {IrdaProtocolNECext, 0x7984, 0xed12, true}, - {IrdaProtocolNECext, 0x7984, 0xed12, true}, - {IrdaProtocolNECext, 0x7984, 0xed12, false}, - {IrdaProtocolNECext, 0x7984, 0xed12, true}, - {IrdaProtocolNECext, 0x7984, 0xed12, true}, +const InfraredMessage test_decoder_necext_expected1[] = { + {InfraredProtocolNECext, 0x7984, 0xed12, false}, + {InfraredProtocolNECext, 0x7984, 0xed12, true}, + {InfraredProtocolNECext, 0x7984, 0xed12, false}, + {InfraredProtocolNECext, 0x7984, 0xed12, true}, + {InfraredProtocolNECext, 0x7984, 0xed12, true}, + {InfraredProtocolNECext, 0x7984, 0xed12, true}, + {InfraredProtocolNECext, 0x7984, 0xed12, true}, + {InfraredProtocolNECext, 0x7984, 0xed12, true}, + {InfraredProtocolNECext, 0x7984, 0xed12, true}, + {InfraredProtocolNECext, 0x7984, 0xed12, true}, + {InfraredProtocolNECext, 0x7984, 0xed12, true}, + {InfraredProtocolNECext, 0x7984, 0xed12, true}, + {InfraredProtocolNECext, 0x7984, 0xed12, true}, + {InfraredProtocolNECext, 0x7984, 0xed12, true}, + {InfraredProtocolNECext, 0x7984, 0xed12, true}, + {InfraredProtocolNECext, 0x7984, 0xed12, true}, + {InfraredProtocolNECext, 0x7984, 0xed12, true}, + {InfraredProtocolNECext, 0x7984, 0xed12, true}, + {InfraredProtocolNECext, 0x7984, 0xed12, true}, + {InfraredProtocolNECext, 0x7984, 0xed12, true}, + {InfraredProtocolNECext, 0x7984, 0xed12, true}, + {InfraredProtocolNECext, 0x7984, 0xed12, true}, + {InfraredProtocolNECext, 0x7984, 0xed12, false}, + {InfraredProtocolNECext, 0x7984, 0xed12, true}, + {InfraredProtocolNECext, 0x7984, 0xed12, true}, + {InfraredProtocolNECext, 0x7984, 0xed12, true}, + {InfraredProtocolNECext, 0x7984, 0xed12, false}, + {InfraredProtocolNECext, 0x7984, 0xed12, true}, + {InfraredProtocolNECext, 0x7984, 0xed12, true}, + {InfraredProtocolNECext, 0x7984, 0xed12, true}, + {InfraredProtocolNECext, 0x7984, 0xed12, false}, + {InfraredProtocolNECext, 0x7984, 0xed12, true}, + {InfraredProtocolNECext, 0x7984, 0xed12, true}, + {InfraredProtocolNECext, 0x7984, 0xed12, true}, + {InfraredProtocolNECext, 0x7984, 0xed12, false}, + {InfraredProtocolNECext, 0x7984, 0xed12, true}, + {InfraredProtocolNECext, 0x7984, 0xed12, true}, + {InfraredProtocolNECext, 0x7984, 0xed12, true}, + {InfraredProtocolNECext, 0x7984, 0xed12, false}, + {InfraredProtocolNECext, 0x7984, 0xed12, true}, + {InfraredProtocolNECext, 0x7984, 0xed12, true}, + {InfraredProtocolNECext, 0x7984, 0xed12, true}, + {InfraredProtocolNECext, 0x7984, 0xed12, false}, + {InfraredProtocolNECext, 0x7984, 0xed12, true}, + {InfraredProtocolNECext, 0x7984, 0xed12, true}, + {InfraredProtocolNECext, 0x7984, 0xed12, true}, + {InfraredProtocolNECext, 0x7984, 0xed12, false}, + {InfraredProtocolNECext, 0x7984, 0xed12, true}, + {InfraredProtocolNECext, 0x7984, 0xed12, true}, + {InfraredProtocolNECext, 0x7984, 0xed12, true}, + {InfraredProtocolNECext, 0x7984, 0xed12, false}, + {InfraredProtocolNECext, 0x7984, 0xed12, true}, + {InfraredProtocolNECext, 0x7984, 0xed12, true}, + {InfraredProtocolNECext, 0x7984, 0xed12, false}, + {InfraredProtocolNECext, 0x7984, 0xed12, true}, + {InfraredProtocolNECext, 0x7984, 0xed12, true}, + {InfraredProtocolNECext, 0x7984, 0xed12, true}, + {InfraredProtocolNECext, 0x7984, 0xed12, false}, + {InfraredProtocolNECext, 0x7984, 0xed12, true}, + {InfraredProtocolNECext, 0x7984, 0xed12, true}, + {InfraredProtocolNECext, 0x7984, 0xed12, true}, + {InfraredProtocolNECext, 0x7984, 0xed12, false}, + {InfraredProtocolNECext, 0x7984, 0xed12, true}, + {InfraredProtocolNECext, 0x7984, 0xed12, true}, + {InfraredProtocolNECext, 0x7984, 0xed12, true}, + {InfraredProtocolNECext, 0x7984, 0xed12, false}, + {InfraredProtocolNECext, 0x7984, 0xed12, true}, + {InfraredProtocolNECext, 0x7984, 0xed12, true}, + {InfraredProtocolNECext, 0x7984, 0xed12, true}, + {InfraredProtocolNECext, 0x7984, 0xed12, false}, + {InfraredProtocolNECext, 0x7984, 0xed12, true}, + {InfraredProtocolNECext, 0x7984, 0xed12, true}, + {InfraredProtocolNECext, 0x7984, 0xed12, true}, + {InfraredProtocolNECext, 0x7984, 0xed12, false}, + {InfraredProtocolNECext, 0x7984, 0xed12, true}, + {InfraredProtocolNECext, 0x7984, 0xed12, true}, + {InfraredProtocolNECext, 0x7984, 0xed12, true}, + {InfraredProtocolNECext, 0x7984, 0xed12, false}, + {InfraredProtocolNECext, 0x7984, 0xed12, true}, + {InfraredProtocolNECext, 0x7984, 0xed12, true}, + {InfraredProtocolNECext, 0x7984, 0xed12, true}, + {InfraredProtocolNECext, 0x7984, 0xed12, false}, + {InfraredProtocolNECext, 0x7984, 0xed12, true}, + {InfraredProtocolNECext, 0x7984, 0xed12, true}, + {InfraredProtocolNECext, 0x7984, 0xed12, true}, + {InfraredProtocolNECext, 0x7984, 0xed12, false}, + {InfraredProtocolNECext, 0x7984, 0xed12, true}, + {InfraredProtocolNECext, 0x7984, 0xed12, true}, + {InfraredProtocolNECext, 0x7984, 0xed12, true}, + {InfraredProtocolNECext, 0x7984, 0xed12, false}, + {InfraredProtocolNECext, 0x7984, 0xed12, true}, + {InfraredProtocolNECext, 0x7984, 0xed12, true}, + {InfraredProtocolNECext, 0x7984, 0xed12, true}, + {InfraredProtocolNECext, 0x7984, 0xed12, false}, + {InfraredProtocolNECext, 0x7984, 0xed12, true}, + {InfraredProtocolNECext, 0x7984, 0xed12, true}, + {InfraredProtocolNECext, 0x7984, 0xed12, true}, + {InfraredProtocolNECext, 0x7984, 0xed12, false}, + {InfraredProtocolNECext, 0x7984, 0xed12, true}, + {InfraredProtocolNECext, 0x7984, 0xed12, true}, + {InfraredProtocolNECext, 0x7984, 0xed12, true}, + {InfraredProtocolNECext, 0x7984, 0xed12, false}, + {InfraredProtocolNECext, 0x7984, 0xed12, true}, + {InfraredProtocolNECext, 0x7984, 0xed12, true}, + {InfraredProtocolNECext, 0x7984, 0xed12, true}, + {InfraredProtocolNECext, 0x7984, 0xed12, false}, + {InfraredProtocolNECext, 0x7984, 0xed12, true}, + {InfraredProtocolNECext, 0x7984, 0xed12, true}, }; -const IrdaMessage test_necext[] = { - {IrdaProtocolNECext, 0x0000, 0x0000, false}, - {IrdaProtocolNECext, 0x0001, 0x0000, false}, - {IrdaProtocolNECext, 0x0001, 0x8000, false}, - {IrdaProtocolNECext, 0x0000, 0x8000, false}, - {IrdaProtocolNECext, 0x0000, 0x0000, false}, - {IrdaProtocolNECext, 0x0000, 0x0000, true}, - {IrdaProtocolNECext, 0x0000, 0x0000, false}, - {IrdaProtocolNECext, 0x0000, 0x0000, true}, - {IrdaProtocolNECext, 0xFFFF, 0xFFFF, false}, - {IrdaProtocolNECext, 0xFFFE, 0xFFFF, false}, - {IrdaProtocolNECext, 0xFFFE, 0x7FFF, false}, - {IrdaProtocolNECext, 0xFFFF, 0x7FFF, false}, - {IrdaProtocolNECext, 0xFFFF, 0xFFFF, false}, - {IrdaProtocolNECext, 0xFFFF, 0xFFFF, true}, - {IrdaProtocolNECext, 0xAAAA, 0x5555, false}, - {IrdaProtocolNECext, 0x5555, 0xAAAA, false}, - {IrdaProtocolNECext, 0x5555, 0x5555, false}, - {IrdaProtocolNECext, 0xAAAA, 0xAAAA, false}, - {IrdaProtocolNECext, 0xAAAA, 0xAAAA, true}, +const InfraredMessage test_necext[] = { + {InfraredProtocolNECext, 0x0000, 0x0000, false}, + {InfraredProtocolNECext, 0x0001, 0x0000, false}, + {InfraredProtocolNECext, 0x0001, 0x8000, false}, + {InfraredProtocolNECext, 0x0000, 0x8000, false}, + {InfraredProtocolNECext, 0x0000, 0x0000, false}, + {InfraredProtocolNECext, 0x0000, 0x0000, true}, + {InfraredProtocolNECext, 0x0000, 0x0000, false}, + {InfraredProtocolNECext, 0x0000, 0x0000, true}, + {InfraredProtocolNECext, 0xFFFF, 0xFFFF, false}, + {InfraredProtocolNECext, 0xFFFE, 0xFFFF, false}, + {InfraredProtocolNECext, 0xFFFE, 0x7FFF, false}, + {InfraredProtocolNECext, 0xFFFF, 0x7FFF, false}, + {InfraredProtocolNECext, 0xFFFF, 0xFFFF, false}, + {InfraredProtocolNECext, 0xFFFF, 0xFFFF, true}, + {InfraredProtocolNECext, 0xAAAA, 0x5555, false}, + {InfraredProtocolNECext, 0x5555, 0xAAAA, false}, + {InfraredProtocolNECext, 0x5555, 0x5555, false}, + {InfraredProtocolNECext, 0xAAAA, 0xAAAA, false}, + {InfraredProtocolNECext, 0xAAAA, 0xAAAA, true}, - {IrdaProtocolNECext, 0xAAAA, 0xAAAA, false}, - {IrdaProtocolNECext, 0xAAAA, 0xAAAA, true}, - {IrdaProtocolNECext, 0xAAAA, 0xAAAA, true}, + {InfraredProtocolNECext, 0xAAAA, 0xAAAA, false}, + {InfraredProtocolNECext, 0xAAAA, 0xAAAA, true}, + {InfraredProtocolNECext, 0xAAAA, 0xAAAA, true}, - {IrdaProtocolNECext, 0x5555, 0x5555, false}, - {IrdaProtocolNECext, 0x5555, 0x5555, true}, - {IrdaProtocolNECext, 0x5555, 0x5555, true}, - {IrdaProtocolNECext, 0x5555, 0x5555, true}, + {InfraredProtocolNECext, 0x5555, 0x5555, false}, + {InfraredProtocolNECext, 0x5555, 0x5555, true}, + {InfraredProtocolNECext, 0x5555, 0x5555, true}, + {InfraredProtocolNECext, 0x5555, 0x5555, true}, }; diff --git a/applications/tests/irda_decoder_encoder/test_data/irda_rc5_test_data.srcdata b/applications/tests/infrared_decoder_encoder/test_data/infrared_rc5_test_data.srcdata similarity index 56% rename from applications/tests/irda_decoder_encoder/test_data/irda_rc5_test_data.srcdata rename to applications/tests/infrared_decoder_encoder/test_data/infrared_rc5_test_data.srcdata index 4dd43bed..07241555 100644 --- a/applications/tests/irda_decoder_encoder/test_data/irda_rc5_test_data.srcdata +++ b/applications/tests/infrared_decoder_encoder/test_data/infrared_rc5_test_data.srcdata @@ -8,8 +8,8 @@ const uint32_t test_decoder_rc5x_input1[] = { 27000 + 888, 1776, 888, 888, 1776, 1776, 888, 888, 1776, 888, 888, 1776, 1776, 1776, 888, 888, 888, 888, 888, 888, }; -const IrdaMessage test_decoder_rc5x_expected1[] = { - {IrdaProtocolRC5X, 0x13, 0x10, false}, // toggle 0 +const InfraredMessage test_decoder_rc5x_expected1[] = { + {InfraredProtocolRC5X, 0x13, 0x10, false}, // toggle 0 }; /* @@ -22,8 +22,8 @@ const uint32_t test_decoder_rc5_input1[] = { 27000 + 888, 888, 888, 1776, 1776, 1776, 888, 888, 1776, 888, 888, 1776, 1776, 1776, 888, 888, 888, 888, 888, 888, }; -const IrdaMessage test_decoder_rc5_expected1[] = { - {IrdaProtocolRC5, 0x13, 0x10, false}, // toggle 0 +const InfraredMessage test_decoder_rc5_expected1[] = { + {InfraredProtocolRC5, 0x13, 0x10, false}, // toggle 0 }; @@ -37,8 +37,8 @@ const uint32_t test_decoder_rc5_input2[] = { 27000 + 888, 888, 888, 888, 888, 888, 888, 1776, 888, 888, 1776, 888, 888, 1776, 1776, 1776, 888, 888, 888, 888, 888, 888, }; -const IrdaMessage test_decoder_rc5_expected2[] = { - {IrdaProtocolRC5, 0x13, 0x10, false}, // toggle 1 +const InfraredMessage test_decoder_rc5_expected2[] = { + {InfraredProtocolRC5, 0x13, 0x10, false}, // toggle 1 }; /* @@ -51,8 +51,8 @@ const uint32_t test_decoder_rc5_input3[] = { 27000 + 888, 888, 888, 1776, 1776, 1776, 888, 888, 1776, 888, 888, 1776, 1776, 1776, 888, 888, 888, 888, 1776, 888, }; -const IrdaMessage test_decoder_rc5_expected3[] = { - {IrdaProtocolRC5, 0x13, 0x11, false}, // toggle 0 +const InfraredMessage test_decoder_rc5_expected3[] = { + {InfraredProtocolRC5, 0x13, 0x11, false}, // toggle 0 }; @@ -66,8 +66,8 @@ const uint32_t test_decoder_rc5_input4[] = { 27000 + 888, 888, 888, 888, 888, 888, 888, 1776, 888, 888, 1776, 888, 888, 1776, 1776, 1776, 888, 888, 888, 888, 1776, 888, }; -const IrdaMessage test_decoder_rc5_expected4[] = { - {IrdaProtocolRC5, 0x13, 0x11, false}, // toggle 1 +const InfraredMessage test_decoder_rc5_expected4[] = { + {InfraredProtocolRC5, 0x13, 0x11, false}, // toggle 1 }; /* @@ -80,8 +80,8 @@ const uint32_t test_decoder_rc5_input5[] = { 27000 + 888, 888, 888, 1776, 1776, 888, 888, 888, 888, 888, 888, 888, 888, 888, 888, 888, 888, 888, 888, 888, 888, 888, 888, 888, 888, 888, }; -const IrdaMessage test_decoder_rc5_expected5[] = { - {IrdaProtocolRC5, 0x1F, 0x3F, false}, // toggle 0 +const InfraredMessage test_decoder_rc5_expected5[] = { + {InfraredProtocolRC5, 0x1F, 0x3F, false}, // toggle 0 }; /* @@ -94,8 +94,8 @@ const uint32_t test_decoder_rc5_input6[] = { 27000 + 888, 888, 888, 888, 888, 888, 888, 888, 888, 888, 888, 888, 888, 888, 888, 888, 888, 888, 888, 888, 888, 888, 888, 888, 888, 888, 888, 888, }; -const IrdaMessage test_decoder_rc5_expected6[] = { - {IrdaProtocolRC5, 0x1F, 0x3F, false}, // toggle 1 +const InfraredMessage test_decoder_rc5_expected6[] = { + {InfraredProtocolRC5, 0x1F, 0x3F, false}, // toggle 1 }; @@ -113,48 +113,48 @@ const uint32_t test_decoder_rc5_input_all_repeats[] = { 27000 + 888, 888, 888, 1776, 1776, 888, 888, 888, 888, 888, 888, 888, 888, 888, 888, 888, 888, 888, 888, 888, 888, 888, 888, 888, 888, 888, }; -const IrdaMessage test_decoder_rc5_expected_all_repeats[] = { - {IrdaProtocolRC5, 0x13, 0x11, false}, // toggle 0 - {IrdaProtocolRC5, 0x13, 0x11, false}, // toggle 1 - {IrdaProtocolRC5, 0x13, 0x11, true}, // toggle 1 - {IrdaProtocolRC5, 0x13, 0x11, true}, // toggle 1 - {IrdaProtocolRC5, 0x13, 0x11, false}, // toggle 0 - {IrdaProtocolRC5, 0x13, 0x10, false}, // toggle 1 - {IrdaProtocolRC5, 0x13, 0x10, false}, // toggle 0 - {IrdaProtocolRC5, 0x13, 0x10, true}, // toggle 0 - {IrdaProtocolRC5, 0x1F, 0x3F, false}, // toggle 1 - {IrdaProtocolRC5, 0x1F, 0x3F, false}, // toggle 0 - {IrdaProtocolRC5, 0x1F, 0x3F, true}, // toggle 0 +const InfraredMessage test_decoder_rc5_expected_all_repeats[] = { + {InfraredProtocolRC5, 0x13, 0x11, false}, // toggle 0 + {InfraredProtocolRC5, 0x13, 0x11, false}, // toggle 1 + {InfraredProtocolRC5, 0x13, 0x11, true}, // toggle 1 + {InfraredProtocolRC5, 0x13, 0x11, true}, // toggle 1 + {InfraredProtocolRC5, 0x13, 0x11, false}, // toggle 0 + {InfraredProtocolRC5, 0x13, 0x10, false}, // toggle 1 + {InfraredProtocolRC5, 0x13, 0x10, false}, // toggle 0 + {InfraredProtocolRC5, 0x13, 0x10, true}, // toggle 0 + {InfraredProtocolRC5, 0x1F, 0x3F, false}, // toggle 1 + {InfraredProtocolRC5, 0x1F, 0x3F, false}, // toggle 0 + {InfraredProtocolRC5, 0x1F, 0x3F, true}, // toggle 0 }; -const IrdaMessage test_rc5[] = { - {IrdaProtocolRC5, 0x1F, 0x3F, false}, - {IrdaProtocolRC5, 0x00, 0x00, false}, - {IrdaProtocolRC5, 0x10, 0x01, false}, - {IrdaProtocolRC5, 0x01, 0x20, false}, - {IrdaProtocolRC5, 0x01, 0x20, false}, - {IrdaProtocolRC5, 0x01, 0x20, true}, - {IrdaProtocolRC5, 0x01, 0x20, true}, - {IrdaProtocolRC5, 0x01, 0x20, true}, - {IrdaProtocolRC5, 0x01, 0x20, true}, - {IrdaProtocolRC5, 0x1F, 0x3F, false}, - {IrdaProtocolRC5, 0x0A, 0x2A, false}, - {IrdaProtocolRC5, 0x15, 0x15, false}, - {IrdaProtocolRC5, 0x15, 0x15, true}, +const InfraredMessage test_rc5[] = { + {InfraredProtocolRC5, 0x1F, 0x3F, false}, + {InfraredProtocolRC5, 0x00, 0x00, false}, + {InfraredProtocolRC5, 0x10, 0x01, false}, + {InfraredProtocolRC5, 0x01, 0x20, false}, + {InfraredProtocolRC5, 0x01, 0x20, false}, + {InfraredProtocolRC5, 0x01, 0x20, true}, + {InfraredProtocolRC5, 0x01, 0x20, true}, + {InfraredProtocolRC5, 0x01, 0x20, true}, + {InfraredProtocolRC5, 0x01, 0x20, true}, + {InfraredProtocolRC5, 0x1F, 0x3F, false}, + {InfraredProtocolRC5, 0x0A, 0x2A, false}, + {InfraredProtocolRC5, 0x15, 0x15, false}, + {InfraredProtocolRC5, 0x15, 0x15, true}, - {IrdaProtocolRC5X, 0x1F, 0x3F, false}, - {IrdaProtocolRC5X, 0x00, 0x00, false}, - {IrdaProtocolRC5X, 0x10, 0x01, false}, - {IrdaProtocolRC5X, 0x01, 0x20, false}, - {IrdaProtocolRC5X, 0x01, 0x20, false}, - {IrdaProtocolRC5X, 0x01, 0x20, true}, - {IrdaProtocolRC5X, 0x01, 0x20, true}, - {IrdaProtocolRC5X, 0x01, 0x20, true}, - {IrdaProtocolRC5X, 0x01, 0x20, true}, - {IrdaProtocolRC5X, 0x1F, 0x3F, false}, - {IrdaProtocolRC5X, 0x0A, 0x2A, false}, - {IrdaProtocolRC5X, 0x15, 0x15, false}, - {IrdaProtocolRC5X, 0x15, 0x15, true}, + {InfraredProtocolRC5X, 0x1F, 0x3F, false}, + {InfraredProtocolRC5X, 0x00, 0x00, false}, + {InfraredProtocolRC5X, 0x10, 0x01, false}, + {InfraredProtocolRC5X, 0x01, 0x20, false}, + {InfraredProtocolRC5X, 0x01, 0x20, false}, + {InfraredProtocolRC5X, 0x01, 0x20, true}, + {InfraredProtocolRC5X, 0x01, 0x20, true}, + {InfraredProtocolRC5X, 0x01, 0x20, true}, + {InfraredProtocolRC5X, 0x01, 0x20, true}, + {InfraredProtocolRC5X, 0x1F, 0x3F, false}, + {InfraredProtocolRC5X, 0x0A, 0x2A, false}, + {InfraredProtocolRC5X, 0x15, 0x15, false}, + {InfraredProtocolRC5X, 0x15, 0x15, true}, }; diff --git a/applications/tests/irda_decoder_encoder/test_data/irda_rc6_test_data.srcdata b/applications/tests/infrared_decoder_encoder/test_data/infrared_rc6_test_data.srcdata similarity index 65% rename from applications/tests/irda_decoder_encoder/test_data/irda_rc6_test_data.srcdata rename to applications/tests/infrared_decoder_encoder/test_data/infrared_rc6_test_data.srcdata index 25010b0c..94b9be5a 100644 --- a/applications/tests/irda_decoder_encoder/test_data/irda_rc6_test_data.srcdata +++ b/applications/tests/infrared_decoder_encoder/test_data/infrared_rc6_test_data.srcdata @@ -79,28 +79,28 @@ const uint32_t test_decoder_rc6_input1[] = { 27000, 2666, 889, 444, 888, 444, 444, 444, 444, 444 + 888, 888, 444, 888, 444, 444, 888, 888, 888, 888, 888, 444, 444, 888, 888, 888, 444, 444, 444, 444, 444, 444, 444, 444, 444, }; -const IrdaMessage test_decoder_rc6_expected1[] = { - {IrdaProtocolRC6, 0x94, 0xA0, false}, // toggle 0 - {IrdaProtocolRC6, 0x93, 0xA0, false}, // toggle 1 -// {IrdaProtocolRC6, 0x95, 0xA0, false}, failed - {IrdaProtocolRC6, 0x93, 0xA0, false}, // toggle 0 - {IrdaProtocolRC6, 0x94, 0xA0, false}, // toggle 1 - {IrdaProtocolRC6, 0x95, 0xA0, false}, // toggle 0 -// {IrdaProtocolRC6, 0x93, 0xA0, false}, failed -// {IrdaProtocolRC6, 0x93, 0xA0, false}, failed -// {IrdaProtocolRC6, 0x93, 0xA0, false}, failed - {IrdaProtocolRC6, 0x95, 0xA0, false}, // toggle 1 +const InfraredMessage test_decoder_rc6_expected1[] = { + {InfraredProtocolRC6, 0x94, 0xA0, false}, // toggle 0 + {InfraredProtocolRC6, 0x93, 0xA0, false}, // toggle 1 +// {InfraredProtocolRC6, 0x95, 0xA0, false}, failed + {InfraredProtocolRC6, 0x93, 0xA0, false}, // toggle 0 + {InfraredProtocolRC6, 0x94, 0xA0, false}, // toggle 1 + {InfraredProtocolRC6, 0x95, 0xA0, false}, // toggle 0 +// {InfraredProtocolRC6, 0x93, 0xA0, false}, failed +// {InfraredProtocolRC6, 0x93, 0xA0, false}, failed +// {InfraredProtocolRC6, 0x93, 0xA0, false}, failed + {InfraredProtocolRC6, 0x95, 0xA0, false}, // toggle 1 }; -const IrdaMessage test_encoder_rc6_input1[] = { - {IrdaProtocolRC6, 0x93, 0xA0, false}, // Toggle 0 - {IrdaProtocolRC6, 0x93, 0xA0, true}, // Toggle 0 - {IrdaProtocolRC6, 0x93, 0xA1, false}, // Toggle 1 - {IrdaProtocolRC6, 0x93, 0xA1, true}, // Toggle 1 - {IrdaProtocolRC6, 0x93, 0xA1, true}, // Toggle 1 - {IrdaProtocolRC6, 0x93, 0xA0, false}, // Toggle 0 - {IrdaProtocolRC6, 0x93, 0xA0, false}, // Toggle 1 - {IrdaProtocolRC6, 0x93, 0xA0, true}, // Toggle 1 +const InfraredMessage test_encoder_rc6_input1[] = { + {InfraredProtocolRC6, 0x93, 0xA0, false}, // Toggle 0 + {InfraredProtocolRC6, 0x93, 0xA0, true}, // Toggle 0 + {InfraredProtocolRC6, 0x93, 0xA1, false}, // Toggle 1 + {InfraredProtocolRC6, 0x93, 0xA1, true}, // Toggle 1 + {InfraredProtocolRC6, 0x93, 0xA1, true}, // Toggle 1 + {InfraredProtocolRC6, 0x93, 0xA0, false}, // Toggle 0 + {InfraredProtocolRC6, 0x93, 0xA0, false}, // Toggle 1 + {InfraredProtocolRC6, 0x93, 0xA0, true}, // Toggle 1 }; const uint32_t test_encoder_rc6_expected1[] = { @@ -115,48 +115,48 @@ const uint32_t test_encoder_rc6_expected1[] = { }; -const IrdaMessage test_rc6[] = { - {IrdaProtocolRC6, 0x00, 0x00, false}, // t 0 - {IrdaProtocolRC6, 0x80, 0x00, false}, // t 1 - {IrdaProtocolRC6, 0x80, 0x01, false}, // t 0 - {IrdaProtocolRC6, 0x00, 0x01, false}, // t 1 - {IrdaProtocolRC6, 0x00, 0x00, false}, // t 0 - {IrdaProtocolRC6, 0x00, 0x00, true}, // t 0 - {IrdaProtocolRC6, 0x00, 0x00, false}, // t 1 - {IrdaProtocolRC6, 0x00, 0x00, true}, // t 1 - {IrdaProtocolRC6, 0xFF, 0xFF, false}, // t 0 - {IrdaProtocolRC6, 0x7F, 0xFF, false}, // t 1 - {IrdaProtocolRC6, 0x7F, 0xFE, false}, // t 0 - {IrdaProtocolRC6, 0xFF, 0xFE, false}, // t 1 - {IrdaProtocolRC6, 0xFF, 0xFF, false}, // t 0 - {IrdaProtocolRC6, 0xFF, 0xFF, true}, // t 0 - {IrdaProtocolRC6, 0xAA, 0x55, false}, // t 1 - {IrdaProtocolRC6, 0x55, 0xAA, false}, // t 0 - {IrdaProtocolRC6, 0x55, 0x55, false}, // t 1 - {IrdaProtocolRC6, 0xAA, 0xAA, false}, // t 0 - {IrdaProtocolRC6, 0xAA, 0xAA, true}, // t 0 +const InfraredMessage test_rc6[] = { + {InfraredProtocolRC6, 0x00, 0x00, false}, // t 0 + {InfraredProtocolRC6, 0x80, 0x00, false}, // t 1 + {InfraredProtocolRC6, 0x80, 0x01, false}, // t 0 + {InfraredProtocolRC6, 0x00, 0x01, false}, // t 1 + {InfraredProtocolRC6, 0x00, 0x00, false}, // t 0 + {InfraredProtocolRC6, 0x00, 0x00, true}, // t 0 + {InfraredProtocolRC6, 0x00, 0x00, false}, // t 1 + {InfraredProtocolRC6, 0x00, 0x00, true}, // t 1 + {InfraredProtocolRC6, 0xFF, 0xFF, false}, // t 0 + {InfraredProtocolRC6, 0x7F, 0xFF, false}, // t 1 + {InfraredProtocolRC6, 0x7F, 0xFE, false}, // t 0 + {InfraredProtocolRC6, 0xFF, 0xFE, false}, // t 1 + {InfraredProtocolRC6, 0xFF, 0xFF, false}, // t 0 + {InfraredProtocolRC6, 0xFF, 0xFF, true}, // t 0 + {InfraredProtocolRC6, 0xAA, 0x55, false}, // t 1 + {InfraredProtocolRC6, 0x55, 0xAA, false}, // t 0 + {InfraredProtocolRC6, 0x55, 0x55, false}, // t 1 + {InfraredProtocolRC6, 0xAA, 0xAA, false}, // t 0 + {InfraredProtocolRC6, 0xAA, 0xAA, true}, // t 0 // same with inverted toggle bit - {IrdaProtocolRC6, 0x00, 0x00, false}, // t 1 - {IrdaProtocolRC6, 0x80, 0x00, false}, // t 0 - {IrdaProtocolRC6, 0x80, 0x01, false}, // t 1 - {IrdaProtocolRC6, 0x00, 0x01, false}, // t 0 - {IrdaProtocolRC6, 0x00, 0x00, false}, // t 1 - {IrdaProtocolRC6, 0x00, 0x00, true}, // t 1 - {IrdaProtocolRC6, 0x00, 0x00, false}, // t 0 - {IrdaProtocolRC6, 0x00, 0x00, true}, // t 0 - {IrdaProtocolRC6, 0xFF, 0xFF, false}, // t 1 - {IrdaProtocolRC6, 0x7F, 0xFF, false}, // t 0 - {IrdaProtocolRC6, 0x7F, 0xFE, false}, // t 1 - {IrdaProtocolRC6, 0xFF, 0xFE, false}, // t 0 - {IrdaProtocolRC6, 0xFF, 0xFF, false}, // t 1 - {IrdaProtocolRC6, 0xFF, 0xFF, true}, // t 1 - {IrdaProtocolRC6, 0xAA, 0x55, false}, // t 0 - {IrdaProtocolRC6, 0x55, 0xAA, false}, // t 1 - {IrdaProtocolRC6, 0x55, 0x55, false}, // t 0 - {IrdaProtocolRC6, 0xAA, 0xAA, false}, // t 1 - {IrdaProtocolRC6, 0xAA, 0xAA, true}, // t 1 + {InfraredProtocolRC6, 0x00, 0x00, false}, // t 1 + {InfraredProtocolRC6, 0x80, 0x00, false}, // t 0 + {InfraredProtocolRC6, 0x80, 0x01, false}, // t 1 + {InfraredProtocolRC6, 0x00, 0x01, false}, // t 0 + {InfraredProtocolRC6, 0x00, 0x00, false}, // t 1 + {InfraredProtocolRC6, 0x00, 0x00, true}, // t 1 + {InfraredProtocolRC6, 0x00, 0x00, false}, // t 0 + {InfraredProtocolRC6, 0x00, 0x00, true}, // t 0 + {InfraredProtocolRC6, 0xFF, 0xFF, false}, // t 1 + {InfraredProtocolRC6, 0x7F, 0xFF, false}, // t 0 + {InfraredProtocolRC6, 0x7F, 0xFE, false}, // t 1 + {InfraredProtocolRC6, 0xFF, 0xFE, false}, // t 0 + {InfraredProtocolRC6, 0xFF, 0xFF, false}, // t 1 + {InfraredProtocolRC6, 0xFF, 0xFF, true}, // t 1 + {InfraredProtocolRC6, 0xAA, 0x55, false}, // t 0 + {InfraredProtocolRC6, 0x55, 0xAA, false}, // t 1 + {InfraredProtocolRC6, 0x55, 0x55, false}, // t 0 + {InfraredProtocolRC6, 0xAA, 0xAA, false}, // t 1 + {InfraredProtocolRC6, 0xAA, 0xAA, true}, // t 1 - {IrdaProtocolRC6, 0x93, 0xA0, false}, // t 0 - {IrdaProtocolRC6, 0x93, 0xA1, false}, // t 1 + {InfraredProtocolRC6, 0x93, 0xA0, false}, // t 0 + {InfraredProtocolRC6, 0x93, 0xA1, false}, // t 1 }; diff --git a/applications/tests/irda_decoder_encoder/test_data/irda_samsung_test_data.srcdata b/applications/tests/infrared_decoder_encoder/test_data/infrared_samsung_test_data.srcdata similarity index 71% rename from applications/tests/irda_decoder_encoder/test_data/irda_samsung_test_data.srcdata rename to applications/tests/infrared_decoder_encoder/test_data/infrared_samsung_test_data.srcdata index 077a4a94..aea867b9 100644 --- a/applications/tests/irda_decoder_encoder/test_data/irda_samsung_test_data.srcdata +++ b/applications/tests/infrared_decoder_encoder/test_data/infrared_samsung_test_data.srcdata @@ -179,76 +179,76 @@ const uint32_t test_decoder_samsung32_input1[] = { 532, 584, }; -const IrdaMessage test_decoder_samsung32_expected1[] = { - {IrdaProtocolSamsung32, 0x0E, 0x0C, false}, {IrdaProtocolSamsung32, 0x0E, 0x0C, true}, - {IrdaProtocolSamsung32, 0x0E, 0x81, false}, {IrdaProtocolSamsung32, 0x0E, 0x81, true}, - {IrdaProtocolSamsung32, 0x0E, 0x01, false}, {IrdaProtocolSamsung32, 0x0E, 0x01, true}, - {IrdaProtocolSamsung32, 0x0E, 0x02, false}, {IrdaProtocolSamsung32, 0x0E, 0x02, true}, - {IrdaProtocolSamsung32, 0x0E, 0x03, false}, {IrdaProtocolSamsung32, 0x0E, 0x03, true}, - {IrdaProtocolSamsung32, 0x0E, 0x0C, false}, {IrdaProtocolSamsung32, 0x0E, 0x0C, true}, - {IrdaProtocolSamsung32, 0x0E, 0x0C, true}, {IrdaProtocolSamsung32, 0x0E, 0x0C, true}, - {IrdaProtocolSamsung32, 0x0E, 0x0C, true}, {IrdaProtocolSamsung32, 0x0E, 0x0C, true}, - {IrdaProtocolSamsung32, 0x0E, 0x0C, true}, {IrdaProtocolSamsung32, 0x0E, 0x0C, true}, - {IrdaProtocolSamsung32, 0x0E, 0x0C, true}, {IrdaProtocolSamsung32, 0x0E, 0x0C, true}, - {IrdaProtocolSamsung32, 0x0E, 0x0C, true}, {IrdaProtocolSamsung32, 0x0E, 0x0C, true}, - {IrdaProtocolSamsung32, 0x0E, 0x0C, true}, {IrdaProtocolSamsung32, 0x0E, 0x0C, true}, - {IrdaProtocolSamsung32, 0x0E, 0x0C, true}, {IrdaProtocolSamsung32, 0x0E, 0x0C, true}, - {IrdaProtocolSamsung32, 0x0E, 0x0C, true}, {IrdaProtocolSamsung32, 0x0E, 0x0C, true}, - {IrdaProtocolSamsung32, 0x0E, 0x0C, true}, {IrdaProtocolSamsung32, 0x0E, 0x0C, true}, - {IrdaProtocolSamsung32, 0x0E, 0x0C, true}, {IrdaProtocolSamsung32, 0x0E, 0x0C, true}, - {IrdaProtocolSamsung32, 0x0E, 0x0C, true}, {IrdaProtocolSamsung32, 0x0E, 0x0C, true}, - {IrdaProtocolSamsung32, 0x0E, 0x0C, true}, {IrdaProtocolSamsung32, 0x0E, 0x0C, true}, - {IrdaProtocolSamsung32, 0x0E, 0x0C, true}, {IrdaProtocolSamsung32, 0x0E, 0x0C, true}, - {IrdaProtocolSamsung32, 0x0E, 0x0C, true}, {IrdaProtocolSamsung32, 0x0E, 0x0C, true}, - {IrdaProtocolSamsung32, 0x0E, 0x0C, true}, {IrdaProtocolSamsung32, 0x0E, 0x0C, true}, - {IrdaProtocolSamsung32, 0x0E, 0x0C, true}, {IrdaProtocolSamsung32, 0x0E, 0x0C, true}, - {IrdaProtocolSamsung32, 0x0E, 0x0C, true}, {IrdaProtocolSamsung32, 0x0E, 0x0C, true}, - {IrdaProtocolSamsung32, 0x0E, 0x0C, true}, {IrdaProtocolSamsung32, 0x0E, 0x0C, true}, - {IrdaProtocolSamsung32, 0x0E, 0x0C, true}, {IrdaProtocolSamsung32, 0x0E, 0x0C, true}, - {IrdaProtocolSamsung32, 0x0E, 0x0C, true}, {IrdaProtocolSamsung32, 0x0E, 0x0C, false}, - {IrdaProtocolSamsung32, 0x0E, 0x0C, false}, {IrdaProtocolSamsung32, 0x0E, 0x0C, false}, - {IrdaProtocolSamsung32, 0x0E, 0x0C, false}, {IrdaProtocolSamsung32, 0x0E, 0x0C, true}, - {IrdaProtocolSamsung32, 0x0E, 0x0C, false}, {IrdaProtocolSamsung32, 0x0E, 0x0C, false}, - {IrdaProtocolSamsung32, 0x0E, 0x0C, true}, {IrdaProtocolSamsung32, 0x0E, 0x0C, false}, - {IrdaProtocolSamsung32, 0x0E, 0x0C, true}, {IrdaProtocolSamsung32, 0x0E, 0x0C, false}, - {IrdaProtocolSamsung32, 0x0E, 0x01, false}, {IrdaProtocolSamsung32, 0x0E, 0x01, true}, - {IrdaProtocolSamsung32, 0x0E, 0x01, false}, {IrdaProtocolSamsung32, 0x0E, 0x01, true}, - {IrdaProtocolSamsung32, 0x0E, 0x01, false}, {IrdaProtocolSamsung32, 0x0E, 0x01, false}, - {IrdaProtocolSamsung32, 0x0E, 0x01, false}, {IrdaProtocolSamsung32, 0x0E, 0x01, true}, - {IrdaProtocolSamsung32, 0x0E, 0x01, false}, {IrdaProtocolSamsung32, 0x0E, 0x01, false}, - {IrdaProtocolSamsung32, 0x0E, 0x01, true}, {IrdaProtocolSamsung32, 0x0E, 0x01, false}, - {IrdaProtocolSamsung32, 0x0E, 0x01, true}, {IrdaProtocolSamsung32, 0x0E, 0x01, false}, - {IrdaProtocolSamsung32, 0x0E, 0x01, false}, {IrdaProtocolSamsung32, 0x0E, 0x01, true}, +const InfraredMessage test_decoder_samsung32_expected1[] = { + {InfraredProtocolSamsung32, 0x0E, 0x0C, false}, {InfraredProtocolSamsung32, 0x0E, 0x0C, true}, + {InfraredProtocolSamsung32, 0x0E, 0x81, false}, {InfraredProtocolSamsung32, 0x0E, 0x81, true}, + {InfraredProtocolSamsung32, 0x0E, 0x01, false}, {InfraredProtocolSamsung32, 0x0E, 0x01, true}, + {InfraredProtocolSamsung32, 0x0E, 0x02, false}, {InfraredProtocolSamsung32, 0x0E, 0x02, true}, + {InfraredProtocolSamsung32, 0x0E, 0x03, false}, {InfraredProtocolSamsung32, 0x0E, 0x03, true}, + {InfraredProtocolSamsung32, 0x0E, 0x0C, false}, {InfraredProtocolSamsung32, 0x0E, 0x0C, true}, + {InfraredProtocolSamsung32, 0x0E, 0x0C, true}, {InfraredProtocolSamsung32, 0x0E, 0x0C, true}, + {InfraredProtocolSamsung32, 0x0E, 0x0C, true}, {InfraredProtocolSamsung32, 0x0E, 0x0C, true}, + {InfraredProtocolSamsung32, 0x0E, 0x0C, true}, {InfraredProtocolSamsung32, 0x0E, 0x0C, true}, + {InfraredProtocolSamsung32, 0x0E, 0x0C, true}, {InfraredProtocolSamsung32, 0x0E, 0x0C, true}, + {InfraredProtocolSamsung32, 0x0E, 0x0C, true}, {InfraredProtocolSamsung32, 0x0E, 0x0C, true}, + {InfraredProtocolSamsung32, 0x0E, 0x0C, true}, {InfraredProtocolSamsung32, 0x0E, 0x0C, true}, + {InfraredProtocolSamsung32, 0x0E, 0x0C, true}, {InfraredProtocolSamsung32, 0x0E, 0x0C, true}, + {InfraredProtocolSamsung32, 0x0E, 0x0C, true}, {InfraredProtocolSamsung32, 0x0E, 0x0C, true}, + {InfraredProtocolSamsung32, 0x0E, 0x0C, true}, {InfraredProtocolSamsung32, 0x0E, 0x0C, true}, + {InfraredProtocolSamsung32, 0x0E, 0x0C, true}, {InfraredProtocolSamsung32, 0x0E, 0x0C, true}, + {InfraredProtocolSamsung32, 0x0E, 0x0C, true}, {InfraredProtocolSamsung32, 0x0E, 0x0C, true}, + {InfraredProtocolSamsung32, 0x0E, 0x0C, true}, {InfraredProtocolSamsung32, 0x0E, 0x0C, true}, + {InfraredProtocolSamsung32, 0x0E, 0x0C, true}, {InfraredProtocolSamsung32, 0x0E, 0x0C, true}, + {InfraredProtocolSamsung32, 0x0E, 0x0C, true}, {InfraredProtocolSamsung32, 0x0E, 0x0C, true}, + {InfraredProtocolSamsung32, 0x0E, 0x0C, true}, {InfraredProtocolSamsung32, 0x0E, 0x0C, true}, + {InfraredProtocolSamsung32, 0x0E, 0x0C, true}, {InfraredProtocolSamsung32, 0x0E, 0x0C, true}, + {InfraredProtocolSamsung32, 0x0E, 0x0C, true}, {InfraredProtocolSamsung32, 0x0E, 0x0C, true}, + {InfraredProtocolSamsung32, 0x0E, 0x0C, true}, {InfraredProtocolSamsung32, 0x0E, 0x0C, true}, + {InfraredProtocolSamsung32, 0x0E, 0x0C, true}, {InfraredProtocolSamsung32, 0x0E, 0x0C, true}, + {InfraredProtocolSamsung32, 0x0E, 0x0C, true}, {InfraredProtocolSamsung32, 0x0E, 0x0C, false}, + {InfraredProtocolSamsung32, 0x0E, 0x0C, false}, {InfraredProtocolSamsung32, 0x0E, 0x0C, false}, + {InfraredProtocolSamsung32, 0x0E, 0x0C, false}, {InfraredProtocolSamsung32, 0x0E, 0x0C, true}, + {InfraredProtocolSamsung32, 0x0E, 0x0C, false}, {InfraredProtocolSamsung32, 0x0E, 0x0C, false}, + {InfraredProtocolSamsung32, 0x0E, 0x0C, true}, {InfraredProtocolSamsung32, 0x0E, 0x0C, false}, + {InfraredProtocolSamsung32, 0x0E, 0x0C, true}, {InfraredProtocolSamsung32, 0x0E, 0x0C, false}, + {InfraredProtocolSamsung32, 0x0E, 0x01, false}, {InfraredProtocolSamsung32, 0x0E, 0x01, true}, + {InfraredProtocolSamsung32, 0x0E, 0x01, false}, {InfraredProtocolSamsung32, 0x0E, 0x01, true}, + {InfraredProtocolSamsung32, 0x0E, 0x01, false}, {InfraredProtocolSamsung32, 0x0E, 0x01, false}, + {InfraredProtocolSamsung32, 0x0E, 0x01, false}, {InfraredProtocolSamsung32, 0x0E, 0x01, true}, + {InfraredProtocolSamsung32, 0x0E, 0x01, false}, {InfraredProtocolSamsung32, 0x0E, 0x01, false}, + {InfraredProtocolSamsung32, 0x0E, 0x01, true}, {InfraredProtocolSamsung32, 0x0E, 0x01, false}, + {InfraredProtocolSamsung32, 0x0E, 0x01, true}, {InfraredProtocolSamsung32, 0x0E, 0x01, false}, + {InfraredProtocolSamsung32, 0x0E, 0x01, false}, {InfraredProtocolSamsung32, 0x0E, 0x01, true}, }; -const IrdaMessage test_samsung32[] = { - {IrdaProtocolSamsung32, 0x00, 0x00, false}, - {IrdaProtocolSamsung32, 0x01, 0x00, false}, - {IrdaProtocolSamsung32, 0x01, 0x80, false}, - {IrdaProtocolSamsung32, 0x00, 0x80, false}, - {IrdaProtocolSamsung32, 0x00, 0x00, false}, - {IrdaProtocolSamsung32, 0x00, 0x00, true}, - {IrdaProtocolSamsung32, 0x00, 0x00, false}, - {IrdaProtocolSamsung32, 0x00, 0x00, true}, - {IrdaProtocolSamsung32, 0xFF, 0xFF, false}, - {IrdaProtocolSamsung32, 0xFE, 0xFF, false}, - {IrdaProtocolSamsung32, 0xFE, 0x7F, false}, - {IrdaProtocolSamsung32, 0xFF, 0x7F, false}, - {IrdaProtocolSamsung32, 0xFF, 0xFF, false}, - {IrdaProtocolSamsung32, 0xFF, 0xFF, true}, - {IrdaProtocolSamsung32, 0xAA, 0x55, false}, - {IrdaProtocolSamsung32, 0x55, 0xAA, false}, - {IrdaProtocolSamsung32, 0x55, 0x55, false}, - {IrdaProtocolSamsung32, 0xAA, 0xAA, false}, - {IrdaProtocolSamsung32, 0xAA, 0xAA, true}, +const InfraredMessage test_samsung32[] = { + {InfraredProtocolSamsung32, 0x00, 0x00, false}, + {InfraredProtocolSamsung32, 0x01, 0x00, false}, + {InfraredProtocolSamsung32, 0x01, 0x80, false}, + {InfraredProtocolSamsung32, 0x00, 0x80, false}, + {InfraredProtocolSamsung32, 0x00, 0x00, false}, + {InfraredProtocolSamsung32, 0x00, 0x00, true}, + {InfraredProtocolSamsung32, 0x00, 0x00, false}, + {InfraredProtocolSamsung32, 0x00, 0x00, true}, + {InfraredProtocolSamsung32, 0xFF, 0xFF, false}, + {InfraredProtocolSamsung32, 0xFE, 0xFF, false}, + {InfraredProtocolSamsung32, 0xFE, 0x7F, false}, + {InfraredProtocolSamsung32, 0xFF, 0x7F, false}, + {InfraredProtocolSamsung32, 0xFF, 0xFF, false}, + {InfraredProtocolSamsung32, 0xFF, 0xFF, true}, + {InfraredProtocolSamsung32, 0xAA, 0x55, false}, + {InfraredProtocolSamsung32, 0x55, 0xAA, false}, + {InfraredProtocolSamsung32, 0x55, 0x55, false}, + {InfraredProtocolSamsung32, 0xAA, 0xAA, false}, + {InfraredProtocolSamsung32, 0xAA, 0xAA, true}, - {IrdaProtocolSamsung32, 0xAA, 0xAA, false}, - {IrdaProtocolSamsung32, 0xAA, 0xAA, true}, - {IrdaProtocolSamsung32, 0xAA, 0xAA, true}, + {InfraredProtocolSamsung32, 0xAA, 0xAA, false}, + {InfraredProtocolSamsung32, 0xAA, 0xAA, true}, + {InfraredProtocolSamsung32, 0xAA, 0xAA, true}, - {IrdaProtocolSamsung32, 0x55, 0x55, false}, - {IrdaProtocolSamsung32, 0x55, 0x55, true}, - {IrdaProtocolSamsung32, 0x55, 0x55, true}, - {IrdaProtocolSamsung32, 0x55, 0x55, true}, + {InfraredProtocolSamsung32, 0x55, 0x55, false}, + {InfraredProtocolSamsung32, 0x55, 0x55, true}, + {InfraredProtocolSamsung32, 0x55, 0x55, true}, + {InfraredProtocolSamsung32, 0x55, 0x55, true}, }; diff --git a/applications/tests/irda_decoder_encoder/test_data/irda_sirc_test_data.srcdata b/applications/tests/infrared_decoder_encoder/test_data/infrared_sirc_test_data.srcdata similarity index 75% rename from applications/tests/irda_decoder_encoder/test_data/irda_sirc_test_data.srcdata rename to applications/tests/infrared_decoder_encoder/test_data/infrared_sirc_test_data.srcdata index bacf4be5..52cc1533 100644 --- a/applications/tests/irda_decoder_encoder/test_data/irda_sirc_test_data.srcdata +++ b/applications/tests/infrared_decoder_encoder/test_data/infrared_sirc_test_data.srcdata @@ -124,128 +124,128 @@ const uint32_t test_decoder_sirc_input1[] = { /* 121 timings */ 26263, 2414, 611, 1192, 607, 544, 606, 1197, 602, 569, 606, 1197, 602, 539, 611, 540, 635, 1168, 606, 565, 610, 541, 608, 563, 587, 564, }; -const IrdaMessage test_decoder_sirc_expected1[] = { - {IrdaProtocolSIRC, 0x10, 0x15, false}, - {IrdaProtocolSIRC, 0x10, 0x15, false}, - {IrdaProtocolSIRC, 0x10, 0x15, false}, - {IrdaProtocolSIRC, 0x10, 0x15, false}, - {IrdaProtocolSIRC, 0x10, 0x15, false}, - {IrdaProtocolSIRC, 0x10, 0x15, false}, - {IrdaProtocolSIRC, 0x10, 0x60, false}, - {IrdaProtocolSIRC, 0x10, 0x60, false}, - {IrdaProtocolSIRC, 0x10, 0x60, false}, - {IrdaProtocolSIRC, 0x10, 0x65, false}, - {IrdaProtocolSIRC, 0x10, 0x65, false}, - {IrdaProtocolSIRC, 0x10, 0x65, false}, - {IrdaProtocolSIRC20, 0x410, 0x17, false}, - {IrdaProtocolSIRC20, 0x410, 0x17, false}, - {IrdaProtocolSIRC20, 0x410, 0x17, false}, - {IrdaProtocolSIRC, 0x10, 0x21, false}, - {IrdaProtocolSIRC, 0x10, 0x21, false}, - {IrdaProtocolSIRC, 0x10, 0x21, false}, - {IrdaProtocolSIRC20, 0x73A, 0x7C, false}, - {IrdaProtocolSIRC20, 0x73A, 0x7C, false}, - {IrdaProtocolSIRC20, 0x73A, 0x7C, false}, - {IrdaProtocolSIRC20, 0x73A, 0x7C, false}, - {IrdaProtocolSIRC20, 0x73A, 0x7C, false}, - {IrdaProtocolSIRC20, 0x73A, 0x7C, false}, - {IrdaProtocolSIRC20, 0x73A, 0x7C, false}, - {IrdaProtocolSIRC20, 0x73A, 0x7C, false}, - {IrdaProtocolSIRC20, 0x73A, 0x7C, false}, - {IrdaProtocolSIRC20, 0x73A, 0x7C, false}, - {IrdaProtocolSIRC20, 0x73A, 0x7C, false}, - {IrdaProtocolSIRC20, 0x73A, 0x7C, false}, - {IrdaProtocolSIRC20, 0x73A, 0x7B, false}, - {IrdaProtocolSIRC20, 0x73A, 0x7B, false}, - {IrdaProtocolSIRC20, 0x73A, 0x7B, false}, - {IrdaProtocolSIRC20, 0x73A, 0x7A, false}, - {IrdaProtocolSIRC20, 0x73A, 0x7A, false}, - {IrdaProtocolSIRC20, 0x73A, 0x7A, false}, - {IrdaProtocolSIRC20, 0x73A, 0x78, false}, - {IrdaProtocolSIRC20, 0x73A, 0x78, false}, - {IrdaProtocolSIRC20, 0x73A, 0x78, false}, - {IrdaProtocolSIRC20, 0x73A, 0x79, false}, - {IrdaProtocolSIRC20, 0x73A, 0x79, false}, - {IrdaProtocolSIRC20, 0x73A, 0x79, false}, - {IrdaProtocolSIRC20, 0x73A, 0x7A, false}, - {IrdaProtocolSIRC20, 0x73A, 0x7A, false}, - {IrdaProtocolSIRC20, 0x73A, 0x7A, false}, - {IrdaProtocolSIRC20, 0x73A, 0x7C, false}, - {IrdaProtocolSIRC20, 0x73A, 0x7C, false}, - {IrdaProtocolSIRC20, 0x73A, 0x7C, false}, - {IrdaProtocolSIRC20, 0x73A, 0x7D, false}, - {IrdaProtocolSIRC20, 0x73A, 0x7D, false}, - {IrdaProtocolSIRC20, 0x73A, 0x7D, false}, - {IrdaProtocolSIRC20, 0x73A, 0x73, false}, - {IrdaProtocolSIRC20, 0x73A, 0x73, false}, - {IrdaProtocolSIRC20, 0x73A, 0x73, false}, - {IrdaProtocolSIRC, 0x10, 0x13, false}, - {IrdaProtocolSIRC, 0x10, 0x13, false}, - {IrdaProtocolSIRC, 0x10, 0x13, false}, - {IrdaProtocolSIRC, 0x10, 0x13, false}, - {IrdaProtocolSIRC, 0x10, 0x12, false}, - {IrdaProtocolSIRC, 0x10, 0x12, false}, - {IrdaProtocolSIRC, 0x10, 0x12, false}, - {IrdaProtocolSIRC, 0x10, 0x12, false}, - {IrdaProtocolSIRC20, 0x73A, 0x30, false}, - {IrdaProtocolSIRC20, 0x73A, 0x30, false}, - {IrdaProtocolSIRC20, 0x73A, 0x30, false}, - {IrdaProtocolSIRC20, 0x73A, 0x39, false}, - {IrdaProtocolSIRC20, 0x73A, 0x39, false}, - {IrdaProtocolSIRC20, 0x73A, 0x39, false}, - {IrdaProtocolSIRC20, 0x73A, 0x31, false}, - {IrdaProtocolSIRC20, 0x73A, 0x31, false}, - {IrdaProtocolSIRC20, 0x73A, 0x31, false}, - {IrdaProtocolSIRC20, 0x73A, 0x34, false}, - {IrdaProtocolSIRC20, 0x73A, 0x34, false}, - {IrdaProtocolSIRC20, 0x73A, 0x34, false}, - {IrdaProtocolSIRC20, 0x73A, 0x32, false}, - {IrdaProtocolSIRC20, 0x73A, 0x32, false}, - {IrdaProtocolSIRC20, 0x73A, 0x32, false}, - {IrdaProtocolSIRC20, 0x73A, 0x33, false}, - {IrdaProtocolSIRC20, 0x73A, 0x33, false}, - {IrdaProtocolSIRC20, 0x73A, 0x33, false}, - {IrdaProtocolSIRC20, 0x73A, 0x0F, false}, - {IrdaProtocolSIRC20, 0x73A, 0x0F, false}, - {IrdaProtocolSIRC20, 0x73A, 0x0F, false}, - {IrdaProtocolSIRC20, 0x73A, 0x38, false}, - {IrdaProtocolSIRC20, 0x73A, 0x38, false}, - {IrdaProtocolSIRC20, 0x73A, 0x38, false}, - {IrdaProtocolSIRC, 0x10, 0x15, false}, - {IrdaProtocolSIRC, 0x10, 0x15, false}, - {IrdaProtocolSIRC, 0x10, 0x15, false}, - {IrdaProtocolSIRC, 0x10, 0x15, false}, - {IrdaProtocolSIRC, 0x10, 0x15, false}, - {IrdaProtocolSIRC, 0x10, 0x15, false}, - {IrdaProtocolSIRC, 0x10, 0x15, false}, - {IrdaProtocolSIRC, 0x10, 0x15, false}, - {IrdaProtocolSIRC, 0x10, 0x15, false}, - {IrdaProtocolSIRC, 0x10, 0x15, false}, - {IrdaProtocolSIRC, 0x10, 0x15, false}, - {IrdaProtocolSIRC, 0x10, 0x15, false}, - {IrdaProtocolSIRC, 0x10, 0x15, false}, - {IrdaProtocolSIRC, 0x10, 0x15, false}, - {IrdaProtocolSIRC, 0x10, 0x15, false}, - {IrdaProtocolSIRC, 0x10, 0x15, false}, - {IrdaProtocolSIRC, 0x10, 0x15, false}, - {IrdaProtocolSIRC, 0x10, 0x15, false}, - {IrdaProtocolSIRC, 0x10, 0x15, false}, - {IrdaProtocolSIRC, 0x10, 0x15, false}, - {IrdaProtocolSIRC, 0x10, 0x15, false}, - {IrdaProtocolSIRC, 0x10, 0x15, false}, - {IrdaProtocolSIRC, 0x10, 0x15, false}, - {IrdaProtocolSIRC, 0x10, 0x15, false}, - {IrdaProtocolSIRC, 0x10, 0x15, false}, - {IrdaProtocolSIRC, 0x10, 0x15, false}, - {IrdaProtocolSIRC, 0x10, 0x15, false}, - {IrdaProtocolSIRC, 0x10, 0x15, false}, - {IrdaProtocolSIRC, 0x10, 0x15, false}, - {IrdaProtocolSIRC, 0x01, 0x2F, false}, - {IrdaProtocolSIRC, 0x01, 0x2F, false}, - {IrdaProtocolSIRC, 0x01, 0x15, false}, - {IrdaProtocolSIRC, 0x01, 0x15, false}, - {IrdaProtocolSIRC, 0x01, 0x15, false}, - {IrdaProtocolSIRC, 0x01, 0x15, false}, +const InfraredMessage test_decoder_sirc_expected1[] = { + {InfraredProtocolSIRC, 0x10, 0x15, false}, + {InfraredProtocolSIRC, 0x10, 0x15, false}, + {InfraredProtocolSIRC, 0x10, 0x15, false}, + {InfraredProtocolSIRC, 0x10, 0x15, false}, + {InfraredProtocolSIRC, 0x10, 0x15, false}, + {InfraredProtocolSIRC, 0x10, 0x15, false}, + {InfraredProtocolSIRC, 0x10, 0x60, false}, + {InfraredProtocolSIRC, 0x10, 0x60, false}, + {InfraredProtocolSIRC, 0x10, 0x60, false}, + {InfraredProtocolSIRC, 0x10, 0x65, false}, + {InfraredProtocolSIRC, 0x10, 0x65, false}, + {InfraredProtocolSIRC, 0x10, 0x65, false}, + {InfraredProtocolSIRC20, 0x410, 0x17, false}, + {InfraredProtocolSIRC20, 0x410, 0x17, false}, + {InfraredProtocolSIRC20, 0x410, 0x17, false}, + {InfraredProtocolSIRC, 0x10, 0x21, false}, + {InfraredProtocolSIRC, 0x10, 0x21, false}, + {InfraredProtocolSIRC, 0x10, 0x21, false}, + {InfraredProtocolSIRC20, 0x73A, 0x7C, false}, + {InfraredProtocolSIRC20, 0x73A, 0x7C, false}, + {InfraredProtocolSIRC20, 0x73A, 0x7C, false}, + {InfraredProtocolSIRC20, 0x73A, 0x7C, false}, + {InfraredProtocolSIRC20, 0x73A, 0x7C, false}, + {InfraredProtocolSIRC20, 0x73A, 0x7C, false}, + {InfraredProtocolSIRC20, 0x73A, 0x7C, false}, + {InfraredProtocolSIRC20, 0x73A, 0x7C, false}, + {InfraredProtocolSIRC20, 0x73A, 0x7C, false}, + {InfraredProtocolSIRC20, 0x73A, 0x7C, false}, + {InfraredProtocolSIRC20, 0x73A, 0x7C, false}, + {InfraredProtocolSIRC20, 0x73A, 0x7C, false}, + {InfraredProtocolSIRC20, 0x73A, 0x7B, false}, + {InfraredProtocolSIRC20, 0x73A, 0x7B, false}, + {InfraredProtocolSIRC20, 0x73A, 0x7B, false}, + {InfraredProtocolSIRC20, 0x73A, 0x7A, false}, + {InfraredProtocolSIRC20, 0x73A, 0x7A, false}, + {InfraredProtocolSIRC20, 0x73A, 0x7A, false}, + {InfraredProtocolSIRC20, 0x73A, 0x78, false}, + {InfraredProtocolSIRC20, 0x73A, 0x78, false}, + {InfraredProtocolSIRC20, 0x73A, 0x78, false}, + {InfraredProtocolSIRC20, 0x73A, 0x79, false}, + {InfraredProtocolSIRC20, 0x73A, 0x79, false}, + {InfraredProtocolSIRC20, 0x73A, 0x79, false}, + {InfraredProtocolSIRC20, 0x73A, 0x7A, false}, + {InfraredProtocolSIRC20, 0x73A, 0x7A, false}, + {InfraredProtocolSIRC20, 0x73A, 0x7A, false}, + {InfraredProtocolSIRC20, 0x73A, 0x7C, false}, + {InfraredProtocolSIRC20, 0x73A, 0x7C, false}, + {InfraredProtocolSIRC20, 0x73A, 0x7C, false}, + {InfraredProtocolSIRC20, 0x73A, 0x7D, false}, + {InfraredProtocolSIRC20, 0x73A, 0x7D, false}, + {InfraredProtocolSIRC20, 0x73A, 0x7D, false}, + {InfraredProtocolSIRC20, 0x73A, 0x73, false}, + {InfraredProtocolSIRC20, 0x73A, 0x73, false}, + {InfraredProtocolSIRC20, 0x73A, 0x73, false}, + {InfraredProtocolSIRC, 0x10, 0x13, false}, + {InfraredProtocolSIRC, 0x10, 0x13, false}, + {InfraredProtocolSIRC, 0x10, 0x13, false}, + {InfraredProtocolSIRC, 0x10, 0x13, false}, + {InfraredProtocolSIRC, 0x10, 0x12, false}, + {InfraredProtocolSIRC, 0x10, 0x12, false}, + {InfraredProtocolSIRC, 0x10, 0x12, false}, + {InfraredProtocolSIRC, 0x10, 0x12, false}, + {InfraredProtocolSIRC20, 0x73A, 0x30, false}, + {InfraredProtocolSIRC20, 0x73A, 0x30, false}, + {InfraredProtocolSIRC20, 0x73A, 0x30, false}, + {InfraredProtocolSIRC20, 0x73A, 0x39, false}, + {InfraredProtocolSIRC20, 0x73A, 0x39, false}, + {InfraredProtocolSIRC20, 0x73A, 0x39, false}, + {InfraredProtocolSIRC20, 0x73A, 0x31, false}, + {InfraredProtocolSIRC20, 0x73A, 0x31, false}, + {InfraredProtocolSIRC20, 0x73A, 0x31, false}, + {InfraredProtocolSIRC20, 0x73A, 0x34, false}, + {InfraredProtocolSIRC20, 0x73A, 0x34, false}, + {InfraredProtocolSIRC20, 0x73A, 0x34, false}, + {InfraredProtocolSIRC20, 0x73A, 0x32, false}, + {InfraredProtocolSIRC20, 0x73A, 0x32, false}, + {InfraredProtocolSIRC20, 0x73A, 0x32, false}, + {InfraredProtocolSIRC20, 0x73A, 0x33, false}, + {InfraredProtocolSIRC20, 0x73A, 0x33, false}, + {InfraredProtocolSIRC20, 0x73A, 0x33, false}, + {InfraredProtocolSIRC20, 0x73A, 0x0F, false}, + {InfraredProtocolSIRC20, 0x73A, 0x0F, false}, + {InfraredProtocolSIRC20, 0x73A, 0x0F, false}, + {InfraredProtocolSIRC20, 0x73A, 0x38, false}, + {InfraredProtocolSIRC20, 0x73A, 0x38, false}, + {InfraredProtocolSIRC20, 0x73A, 0x38, false}, + {InfraredProtocolSIRC, 0x10, 0x15, false}, + {InfraredProtocolSIRC, 0x10, 0x15, false}, + {InfraredProtocolSIRC, 0x10, 0x15, false}, + {InfraredProtocolSIRC, 0x10, 0x15, false}, + {InfraredProtocolSIRC, 0x10, 0x15, false}, + {InfraredProtocolSIRC, 0x10, 0x15, false}, + {InfraredProtocolSIRC, 0x10, 0x15, false}, + {InfraredProtocolSIRC, 0x10, 0x15, false}, + {InfraredProtocolSIRC, 0x10, 0x15, false}, + {InfraredProtocolSIRC, 0x10, 0x15, false}, + {InfraredProtocolSIRC, 0x10, 0x15, false}, + {InfraredProtocolSIRC, 0x10, 0x15, false}, + {InfraredProtocolSIRC, 0x10, 0x15, false}, + {InfraredProtocolSIRC, 0x10, 0x15, false}, + {InfraredProtocolSIRC, 0x10, 0x15, false}, + {InfraredProtocolSIRC, 0x10, 0x15, false}, + {InfraredProtocolSIRC, 0x10, 0x15, false}, + {InfraredProtocolSIRC, 0x10, 0x15, false}, + {InfraredProtocolSIRC, 0x10, 0x15, false}, + {InfraredProtocolSIRC, 0x10, 0x15, false}, + {InfraredProtocolSIRC, 0x10, 0x15, false}, + {InfraredProtocolSIRC, 0x10, 0x15, false}, + {InfraredProtocolSIRC, 0x10, 0x15, false}, + {InfraredProtocolSIRC, 0x10, 0x15, false}, + {InfraredProtocolSIRC, 0x10, 0x15, false}, + {InfraredProtocolSIRC, 0x10, 0x15, false}, + {InfraredProtocolSIRC, 0x10, 0x15, false}, + {InfraredProtocolSIRC, 0x10, 0x15, false}, + {InfraredProtocolSIRC, 0x10, 0x15, false}, + {InfraredProtocolSIRC, 0x01, 0x2F, false}, + {InfraredProtocolSIRC, 0x01, 0x2F, false}, + {InfraredProtocolSIRC, 0x01, 0x15, false}, + {InfraredProtocolSIRC, 0x01, 0x15, false}, + {InfraredProtocolSIRC, 0x01, 0x15, false}, + {InfraredProtocolSIRC, 0x01, 0x15, false}, }; @@ -284,23 +284,23 @@ const uint32_t test_decoder_sirc_input2[] = { 1000000, 2400, 600, 1200, 600, 1200, 600, 600, 600, 600, 600, 1200, 600, 600, 600, 1200, 600, 1200, 600, 600, 600, 1200, 600, 1200, 600, 600, 600, }; -const IrdaMessage test_decoder_sirc_expected2[] = { - {IrdaProtocolSIRC, 0xA, 0x55, false}, - {IrdaProtocolSIRC, 0xA, 0x55, false}, - {IrdaProtocolSIRC, 0xA, 0x55, false}, +const InfraredMessage test_decoder_sirc_expected2[] = { + {InfraredProtocolSIRC, 0xA, 0x55, false}, + {InfraredProtocolSIRC, 0xA, 0x55, false}, + {InfraredProtocolSIRC, 0xA, 0x55, false}, /* failed - 13 data bits */ - {IrdaProtocolSIRC, 0x1F, 0x7F, false}, + {InfraredProtocolSIRC, 0x1F, 0x7F, false}, /* failed - 2 data bits */ - {IrdaProtocolSIRC, 0x1F, 0x7F, false}, + {InfraredProtocolSIRC, 0x1F, 0x7F, false}, /* failed - sudden end */ - {IrdaProtocolSIRC, 0x1F, 0x7F, false}, + {InfraredProtocolSIRC, 0x1F, 0x7F, false}, /* failed */ - {IrdaProtocolSIRC, 0x0A, 0x55, false}, + {InfraredProtocolSIRC, 0x0A, 0x55, false}, - {IrdaProtocolSIRC, 0x00, 0x00, false}, + {InfraredProtocolSIRC, 0x00, 0x00, false}, - {IrdaProtocolSIRC, 0x0D, 0x53, false}, + {InfraredProtocolSIRC, 0x0D, 0x53, false}, }; @@ -334,18 +334,18 @@ const uint32_t test_decoder_sirc_input3[] = { 10000, 2400, 600, 1200, 600, 1200, 600, 600, 600, 600, 600, 1200, 600, 600, 600, 600, 600, 1200, 600, 600, 600, 1200, 600, 1200, 600, 1200, 600, 1200, 600, 1200, 600, 1200, }; -const IrdaMessage test_decoder_sirc_expected3[] = { - {IrdaProtocolSIRC15, 0x7D, 0x53, false}, - {IrdaProtocolSIRC15, 0x7D, 0x53, false}, - {IrdaProtocolSIRC15, 0x7D, 0x53, false}, - {IrdaProtocolSIRC15, 0x0D, 0x53, false}, - {IrdaProtocolSIRC15, 0x0D, 0x53, false}, - {IrdaProtocolSIRC15, 0x0D, 0x53, false}, - {IrdaProtocolSIRC15, 0x0D, 0x53, false}, - {IrdaProtocolSIRC15, 0x0D, 0x53, false}, - {IrdaProtocolSIRC15, 0x7D, 0x53, false}, - {IrdaProtocolSIRC15, 0x7D, 0x53, false}, - {IrdaProtocolSIRC15, 0xFD, 0x13, false}, +const InfraredMessage test_decoder_sirc_expected3[] = { + {InfraredProtocolSIRC15, 0x7D, 0x53, false}, + {InfraredProtocolSIRC15, 0x7D, 0x53, false}, + {InfraredProtocolSIRC15, 0x7D, 0x53, false}, + {InfraredProtocolSIRC15, 0x0D, 0x53, false}, + {InfraredProtocolSIRC15, 0x0D, 0x53, false}, + {InfraredProtocolSIRC15, 0x0D, 0x53, false}, + {InfraredProtocolSIRC15, 0x0D, 0x53, false}, + {InfraredProtocolSIRC15, 0x0D, 0x53, false}, + {InfraredProtocolSIRC15, 0x7D, 0x53, false}, + {InfraredProtocolSIRC15, 0x7D, 0x53, false}, + {InfraredProtocolSIRC15, 0xFD, 0x13, false}, }; const uint32_t test_decoder_sirc_input4[] = { @@ -357,13 +357,13 @@ const uint32_t test_decoder_sirc_input4[] = { 1000000, 2400, 600, 1200, 600, 1200, 600, 600, 600, 600, 600, 1200, 600, 600, 600, 1200, 600, 1200, 600, 600, 600, 1200, 600, 600, 600, 1200, 600, 1200, 600, 600, 600, 1200, 600, 1200, 600, 1200, 600, 1200, 600, 1200, 600, 600, }; -const IrdaMessage test_decoder_sirc_expected4[] = { - {IrdaProtocolSIRC20, 0xFB5, 0x53, false}, // {IrdaProtocolSIRC20, 0x15, 0x3ED3, false}, - {IrdaProtocolSIRC20, 0xFB5, 0x53, false}, - {IrdaProtocolSIRC20, 0xFB5, 0x53, false}, - {IrdaProtocolSIRC20, 0xFB5, 0x53, false}, - {IrdaProtocolSIRC20, 0xFB5, 0x53, false}, - {IrdaProtocolSIRC20, 0xFB5, 0x53, false}, +const InfraredMessage test_decoder_sirc_expected4[] = { + {InfraredProtocolSIRC20, 0xFB5, 0x53, false}, // {InfraredProtocolSIRC20, 0x15, 0x3ED3, false}, + {InfraredProtocolSIRC20, 0xFB5, 0x53, false}, + {InfraredProtocolSIRC20, 0xFB5, 0x53, false}, + {InfraredProtocolSIRC20, 0xFB5, 0x53, false}, + {InfraredProtocolSIRC20, 0xFB5, 0x53, false}, + {InfraredProtocolSIRC20, 0xFB5, 0x53, false}, }; const uint32_t test_decoder_sirc_input5[] = { @@ -396,48 +396,48 @@ const uint32_t test_decoder_sirc_input5[] = { 10000, 2400, 600, 1200, 600, 1200, 600, 600, 600, 600, 600, 1200, 600, 600, 600, 1200, 600, 1200, 600, 600, 600, 1200, 600, 600, 600, 1200, 600, 1200, 600, 600, 600, 1200, 600, 1200, 600, 1200, 600, 1200, 600, 1200, 600, 600, }; -const IrdaMessage test_decoder_sirc_expected5[] = { - {IrdaProtocolSIRC20, 0xFB5, 0x53, false}, - {IrdaProtocolSIRC15, 0x7D, 0x53, false}, - {IrdaProtocolSIRC, 0xA, 0x55, false}, - {IrdaProtocolSIRC20, 0xFB5, 0x53, false}, - {IrdaProtocolSIRC15, 0x7D, 0x53, false}, - {IrdaProtocolSIRC, 0xA, 0x55, false}, +const InfraredMessage test_decoder_sirc_expected5[] = { + {InfraredProtocolSIRC20, 0xFB5, 0x53, false}, + {InfraredProtocolSIRC15, 0x7D, 0x53, false}, + {InfraredProtocolSIRC, 0xA, 0x55, false}, + {InfraredProtocolSIRC20, 0xFB5, 0x53, false}, + {InfraredProtocolSIRC15, 0x7D, 0x53, false}, + {InfraredProtocolSIRC, 0xA, 0x55, false}, - {IrdaProtocolSIRC20, 0xFB5, 0x53, false}, - {IrdaProtocolSIRC15, 0x7D, 0x53, false}, - {IrdaProtocolSIRC, 0xA, 0x55, false}, - {IrdaProtocolSIRC20, 0xFB5, 0x53, false}, - {IrdaProtocolSIRC15, 0x7D, 0x53, false}, - {IrdaProtocolSIRC, 0xA, 0x55, false}, + {InfraredProtocolSIRC20, 0xFB5, 0x53, false}, + {InfraredProtocolSIRC15, 0x7D, 0x53, false}, + {InfraredProtocolSIRC, 0xA, 0x55, false}, + {InfraredProtocolSIRC20, 0xFB5, 0x53, false}, + {InfraredProtocolSIRC15, 0x7D, 0x53, false}, + {InfraredProtocolSIRC, 0xA, 0x55, false}, - {IrdaProtocolSIRC20, 0xFB5, 0x53, false}, - {IrdaProtocolSIRC20, 0xFB5, 0x53, false}, - {IrdaProtocolSIRC15, 0x7D, 0x53, false}, - {IrdaProtocolSIRC15, 0x7D, 0x53, false}, - {IrdaProtocolSIRC, 0xA, 0x55, false}, - {IrdaProtocolSIRC, 0xA, 0x55, false}, + {InfraredProtocolSIRC20, 0xFB5, 0x53, false}, + {InfraredProtocolSIRC20, 0xFB5, 0x53, false}, + {InfraredProtocolSIRC15, 0x7D, 0x53, false}, + {InfraredProtocolSIRC15, 0x7D, 0x53, false}, + {InfraredProtocolSIRC, 0xA, 0x55, false}, + {InfraredProtocolSIRC, 0xA, 0x55, false}, - {IrdaProtocolSIRC, 0xA, 0x55, false}, - {IrdaProtocolSIRC15, 0x7D, 0x53, false}, - {IrdaProtocolSIRC20, 0xFB5, 0x53, false}, - {IrdaProtocolSIRC, 0xA, 0x55, false}, - {IrdaProtocolSIRC15, 0x7D, 0x53, false}, - {IrdaProtocolSIRC20, 0xFB5, 0x53, false}, + {InfraredProtocolSIRC, 0xA, 0x55, false}, + {InfraredProtocolSIRC15, 0x7D, 0x53, false}, + {InfraredProtocolSIRC20, 0xFB5, 0x53, false}, + {InfraredProtocolSIRC, 0xA, 0x55, false}, + {InfraredProtocolSIRC15, 0x7D, 0x53, false}, + {InfraredProtocolSIRC20, 0xFB5, 0x53, false}, }; -const IrdaMessage test_encoder_sirc_input1[] = { - {IrdaProtocolSIRC, 0xA, 0x55, false}, +const InfraredMessage test_encoder_sirc_input1[] = { + {InfraredProtocolSIRC, 0xA, 0x55, false}, }; const uint32_t test_encoder_sirc_expected1[] = { 10000, 2400, 600, 1200, 600, 600, 600, 1200, 600, 600, 600, 1200, 600, 600, 600, 1200, 600, 600, 600, 1200, 600, 600, 600, 1200, 600, 600, }; -const IrdaMessage test_encoder_sirc_input2[] = { - {IrdaProtocolSIRC15, 0x7D, 0x53, false}, - {IrdaProtocolSIRC15, 0x7D, 0x53, true}, - {IrdaProtocolSIRC15, 0x7D, 0x53, true}, +const InfraredMessage test_encoder_sirc_input2[] = { + {InfraredProtocolSIRC15, 0x7D, 0x53, false}, + {InfraredProtocolSIRC15, 0x7D, 0x53, true}, + {InfraredProtocolSIRC15, 0x7D, 0x53, true}, }; const uint32_t test_encoder_sirc_expected2[] = { @@ -446,34 +446,34 @@ const uint32_t test_encoder_sirc_expected2[] = { 18600, 2400, 600, 1200, 600, 1200, 600, 600, 600, 600, 600, 1200, 600, 600, 600, 1200, 600, 1200, 600, 600, 600, 1200, 600, 1200, 600, 1200, 600, 1200, 600, 1200, 600, 600, }; -const IrdaMessage test_sirc[] = { - {IrdaProtocolSIRC20, 0x1FFF, 0x7F, false}, - {IrdaProtocolSIRC20, 0x1FFF, 0x7F, true}, - {IrdaProtocolSIRC20, 0x1FFF, 0x7F, true}, - {IrdaProtocolSIRC, 0x00, 0x00, false}, - {IrdaProtocolSIRC, 0x00, 0x00, true}, - {IrdaProtocolSIRC, 0x00, 0x00, true}, +const InfraredMessage test_sirc[] = { + {InfraredProtocolSIRC20, 0x1FFF, 0x7F, false}, + {InfraredProtocolSIRC20, 0x1FFF, 0x7F, true}, + {InfraredProtocolSIRC20, 0x1FFF, 0x7F, true}, + {InfraredProtocolSIRC, 0x00, 0x00, false}, + {InfraredProtocolSIRC, 0x00, 0x00, true}, + {InfraredProtocolSIRC, 0x00, 0x00, true}, - {IrdaProtocolSIRC, 0x1A, 0x22, false}, - {IrdaProtocolSIRC, 0x1A, 0x22, true}, - {IrdaProtocolSIRC, 0x1A, 0x22, true}, - {IrdaProtocolSIRC, 0x17, 0x0A, false}, + {InfraredProtocolSIRC, 0x1A, 0x22, false}, + {InfraredProtocolSIRC, 0x1A, 0x22, true}, + {InfraredProtocolSIRC, 0x1A, 0x22, true}, + {InfraredProtocolSIRC, 0x17, 0x0A, false}, - {IrdaProtocolSIRC15, 0x7D, 0x53, false}, - {IrdaProtocolSIRC15, 0x7D, 0x53, true}, - {IrdaProtocolSIRC15, 0x7D, 0x53, true}, - {IrdaProtocolSIRC15, 0x71, 0x0, false}, - {IrdaProtocolSIRC15, 0x15, 0x01, false}, - {IrdaProtocolSIRC15, 0x01, 0x15, false}, + {InfraredProtocolSIRC15, 0x7D, 0x53, false}, + {InfraredProtocolSIRC15, 0x7D, 0x53, true}, + {InfraredProtocolSIRC15, 0x7D, 0x53, true}, + {InfraredProtocolSIRC15, 0x71, 0x0, false}, + {InfraredProtocolSIRC15, 0x15, 0x01, false}, + {InfraredProtocolSIRC15, 0x01, 0x15, false}, - {IrdaProtocolSIRC20, 0xAA, 0x55, false}, - {IrdaProtocolSIRC20, 0x331, 0x71, false}, + {InfraredProtocolSIRC20, 0xAA, 0x55, false}, + {InfraredProtocolSIRC20, 0x331, 0x71, false}, - {IrdaProtocolSIRC, 0x00, 0x00, false}, - {IrdaProtocolSIRC, 0x1F, 0x7F, false}, - {IrdaProtocolSIRC15, 0x00, 0x00, false}, - {IrdaProtocolSIRC15, 0xFF, 0x7F, false}, - {IrdaProtocolSIRC20, 0x00, 0x00, false}, - {IrdaProtocolSIRC20, 0x1FFF, 0x7F, false}, + {InfraredProtocolSIRC, 0x00, 0x00, false}, + {InfraredProtocolSIRC, 0x1F, 0x7F, false}, + {InfraredProtocolSIRC15, 0x00, 0x00, false}, + {InfraredProtocolSIRC15, 0xFF, 0x7F, false}, + {InfraredProtocolSIRC20, 0x00, 0x00, false}, + {InfraredProtocolSIRC20, 0x1FFF, 0x7F, false}, }; diff --git a/applications/tests/rpc/rpc_test.c b/applications/tests/rpc/rpc_test.c index 25f641a5..e80d36cb 100644 --- a/applications/tests/rpc/rpc_test.c +++ b/applications/tests/rpc/rpc_test.c @@ -651,7 +651,7 @@ MU_TEST(test_storage_list) { test_rpc_storage_list_run("/int", ++command_id); test_rpc_storage_list_run("/ext", ++command_id); - test_rpc_storage_list_run("/ext/irda", ++command_id); + test_rpc_storage_list_run("/ext/infrared", ++command_id); test_rpc_storage_list_run("/ext/ibutton", ++command_id); test_rpc_storage_list_run("/ext/lfrfid", ++command_id); test_rpc_storage_list_run("error_path", ++command_id); diff --git a/applications/tests/test_index.c b/applications/tests/test_index.c index 6f934318..2e567378 100644 --- a/applications/tests/test_index.c +++ b/applications/tests/test_index.c @@ -11,7 +11,7 @@ #define TAG "UnitTests" int run_minunit(); -int run_minunit_test_irda_decoder_encoder(); +int run_minunit_test_infrared_decoder_encoder(); int run_minunit_test_rpc(); int run_minunit_test_flipper_format(); int run_minunit_test_flipper_format_string(); @@ -53,7 +53,7 @@ void unit_tests_cli(Cli* cli, string_t args, void* context) { uint32_t cycle_counter = DWT->CYCCNT; test_result |= run_minunit(); - test_result |= run_minunit_test_irda_decoder_encoder(); + test_result |= run_minunit_test_infrared_decoder_encoder(); test_result |= run_minunit_test_rpc(); test_result |= run_minunit_test_stream(); test_result |= run_minunit_test_flipper_format(); diff --git a/assets/compiled/assets_icons.c b/assets/compiled/assets_icons.c index aa2f26cf..03dda94a 100644 --- a/assets/compiled/assets_icons.c +++ b/assets/compiled/assets_icons.c @@ -202,27 +202,6 @@ const uint8_t* const _I_ArrowUpEmpty_14x15[] = {_I_ArrowUpEmpty_14x15_0}; const uint8_t _I_ArrowUpFilled_14x15_0[] = {0x00,0xC0,0x00,0x20,0x01,0xD0,0x02,0xE8,0x05,0xF4,0x0B,0xFA,0x17,0x61,0x21,0xAF,0x3D,0x68,0x05,0xA8,0x05,0x68,0x05,0xA8,0x05,0xE8,0x05,0x08,0x04,0xF8,0x07,}; const uint8_t* const _I_ArrowUpFilled_14x15[] = {_I_ArrowUpFilled_14x15_0}; -const uint8_t _I_Back3_45x8_0[] = {0x00,0x04,0x00,0x10,0x00,0x40,0x00,0x06,0x00,0x18,0x00,0x60,0x00,0x7F,0x00,0xFC,0x01,0xF0,0x07,0x86,0x20,0x18,0x82,0x60,0x08,0x04,0x71,0x10,0xC4,0x41,0x10,0x00,0x21,0x00,0x84,0x00,0x10,0x80,0x00,0x00,0x02,0x00,0x08,0x7E,0x00,0xF8,0x01,0xE0,0x07,}; -const uint8_t* const _I_Back3_45x8[] = {_I_Back3_45x8_0}; - -const uint8_t _I_DoorLeft_70x55_0[] = {0x01,0x00,0x19,0x01,0x00,0x2c,0x32,0x01,0x03,0x04,0x2c,0x18,0x10,0xf0,0x40,0x47,0x82,0x06,0x81,0x03,0xff,0x80,0x08,0x1a,0x20,0x82,0x15,0x28,0x21,0x87,0x82,0x08,0x6f,0xc0,0xb1,0xe6,0x10,0x10,0x8b,0x46,0x20,0x43,0x55,0x8f,0x82,0x10,0x32,0x73,0x0a,0x09,0x89,0x6c,0x1e,0x09,0x00,0x18,0x60,0xf0,0x0c,0x84,0x93,0x82,0x03,0x18,0x0c,0x02,0x1d,0x00,0x90,0x52,0x70,0x50,0x1e,0x00,0x58,0x63,0x90,0x0a,0x06,0x4a,0x09,0x03,0xb0,0x02,0x06,0x70,0x62,0x49,0xf8,0x0c,0x66,0x3f,0xf0,0x41,0x63,0x04,0x43,0x00,0x99,0x60,0x00,0x85,0xc8,0x06,0x14,0xd0,0x80,0x3f,0xc8,0x0d,0xb8,0x10,0x70,0xf8,0x34,0x13,0x03,0x39,0x04,0x1c,0x42,0x19,0xf8,0xa0,0xc2,0x01,0x07,0xef,0x02,0x8c,0x80,0x10,0x9d,0x00,0x43,0xec,0x00,0xa3,0x10,0x04,0x25,0xce,0x19,0xfc,0x88,0x82,0x12,0x0c,0x35,0x10,0x42,0x4c,0xa1,0x90,0x3f,0xc0,0x21,0x22,0x39,0x82,0xc8,0x88,0xd2,0x11,0xf0,0x01,0x88,0xd5,0x18,0xe2,0x08,0x68,0x10,0x0c,0xa8,0x00,0x83,0x81,0xcc,0xd5,0xc3,0x80,0x84,0x82,0x0e,0xcc,0xc0,0x15,0x79,0x02,0x0b,0x98,0xf8,0x11,0x88,0x82,0x0f,0x31,0x19,0x02,0x08,0x2c,0x9f,0x6a,0x1d,0x20,0x41,0x31,0x4c,0x10,0x8d,0x73,0x04,0x23,0xa4,0xc4,0x6c,0xde,0x20,0x42,0xcc,0x01,0x07,0x07,0xff,0x80,0x06,0x3e,0x08,0x38,0x70,0x20,0xa1,0xe0,0x83,0x8e,0x01,0x0c,0xf0,0x73,0x80,0x43,0x70,0x05,0x08,0x00,0x2c,0x04,0xc4,0x46,0x53,0x09,0x98,0x24,0x80,0x65,0x80,0xb0,0xd9,0x84,0x65,0x32,0x06,0x17,0x0f,0x98,0x23,0x63,0xe1,0x88,0xc4,0x08,0x5f,0xc1,0x30,0x9d,0x84,0x4e,0x66,0x94,0x11,0x98,0x75,0x26,0x00,}; -const uint8_t* const _I_DoorLeft_70x55[] = {_I_DoorLeft_70x55_0}; - -const uint8_t _I_DoorLocked_10x56_0[] = {0x01,0x00,0x4e,0x00,0x86,0x40,0x25,0xb0,0x0b,0x6c,0x03,0x9b,0x00,0xc6,0xc0,0x65,0x90,0x10,0x3a,0xc3,0x20,0x31,0xc8,0x04,0xe2,0x01,0x70,0x80,0x78,0x20,0x1c,0x48,0x07,0x22,0x01,0xd0,0x00,0xf0,0x44,0x68,0x90,0x09,0x04,0x02,0x21,0x00,0x84,0x40,0x25,0x80,0x12,0x1e,0x88,0x14,0xc0,0x2e,0x0d,0x11,0xca,0xf8,0x60,0x1c,0x38,0x07,0x1a,0x05,0xcc,0x80,0x72,0x60,0x5c,0x38,0x10,0x1c,0xf9,0x10,0x2e,0x00,0x05,0x60,0x00,0x11,}; -const uint8_t* const _I_DoorLocked_10x56[] = {_I_DoorLocked_10x56_0}; - -const uint8_t _I_DoorRight_70x55_0[] = {0x01,0x00,0x16,0x01,0x81,0xcc,0x01,0x0f,0x60,0x04,0x3f,0x00,0x10,0xf8,0x08,0x0c,0x02,0x05,0x01,0x84,0x02,0x06,0x26,0x0a,0x10,0x8a,0xcc,0xe0,0x1d,0x68,0xe0,0x18,0xab,0xd0,0x0b,0x18,0x10,0x46,0xe6,0x16,0x1e,0x18,0x10,0x46,0xe4,0x28,0x2c,0x98,0x14,0x68,0x00,0x21,0x1d,0x10,0x8c,0x40,0x02,0x0e,0x10,0xa1,0x08,0xc8,0x40,0x42,0x62,0x11,0x94,0x03,0xfd,0xff,0x00,0x0c,0xff,0x0c,0x08,0x28,0x60,0xe4,0xc0,0x85,0x00,0x83,0x00,0x87,0xf1,0x00,0x8c,0x02,0x0b,0x07,0x24,0x84,0xff,0x04,0xc7,0x80,0xa0,0xe4,0xa0,0x81,0x41,0x04,0x17,0x02,0x41,0x49,0x81,0x0e,0x10,0xb2,0xa0,0x82,0x0e,0x9f,0xfc,0x0a,0x62,0xf2,0xc0,0x03,0x92,0xf0,0x08,0x2d,0x78,0x20,0xff,0x02,0x01,0x08,0xae,0x60,0x64,0x38,0x0d,0xb0,0x8d,0x08,0x82,0x11,0x58,0xc4,0x13,0xc0,0x35,0x68,0x62,0x68,0x81,0x09,0x08,0x84,0x40,0x81,0x0d,0x18,0x69,0x10,0x47,0x44,0x66,0x5f,0x21,0xa9,0x29,0x94,0x10,0x2f,0x23,0x53,0x14,0x60,0x42,0x3c,0x08,0xfc,0x02,0x2c,0x62,0x23,0x58,0xd0,0x22,0x00,0x83,0x3e,0x98,0x44,0x43,0x46,0x22,0x30,0x89,0xce,0x01,0x0f,0x70,0x04,0x3f,0x81,0x8a,0x3c,0x21,0xaa,0x70,0x1a,0xe3,0x44,0x1a,0xa6,0x01,0xd2,0x38,0x90,0x8a,0x40,0x20,0xe5,0x96,0x80,0x43,0x81,0x06,0x6b,0x28,0x07,0xf3,0xfe,0x00,0x19,0xf9,0x34,0xc1,0x08,0x8f,0x20,0xf1,0x3e,0x16,0x00,0xa8,0x19,0x00,0x10,0x76,0x03,0xe2,0x3e,0x90,0x45,0x38,0x01,0x42,0x05,0x88,0x44,0x67,0x15,0x70,0x41,0x38,0x04,0x10,0x24,0x03,0x00,0x10,0x20,0x4a,0x46,0xe9,0x46,0xe1,0x04,0x50,0x66,0x40,0x85,0x19,0x98,0x00,0xc0,}; -const uint8_t* const _I_DoorRight_70x55[] = {_I_DoorRight_70x55_0}; - -const uint8_t _I_PassportBottom_128x17_0[] = {0x01,0x00,0x5e,0x00,0x96,0x01,0x97,0xe1,0xff,0x00,0x2e,0x3e,0x68,0x0f,0x5a,0xc5,0x54,0x00,0xb9,0x50,0xfb,0x6a,0x35,0x40,0x05,0xcd,0x4e,0x03,0xfd,0x30,0x0f,0xf8,0x7f,0xa0,0x81,0xfe,0xf9,0x1b,0xfb,0xf3,0x01,0x47,0x66,0x02,0x1b,0x03,0x07,0xe7,0x02,0x0b,0x02,0x07,0xe5,0x82,0x0b,0xf2,0x1c,0xb0,0x01,0x67,0xf0,0x5f,0xd0,0x3f,0x23,0xf0,0x9b,0xc9,0xe5,0x80,0x03,0xd5,0xc0,0x00,0x86,0x01,0xf3,0xe6,0x1e,0x58,0x00,0x36,0xa8,0x06,0xac,0x04,0x30,0x6c,0x30,0xee,0x60,0x1f,0xe0,0x10,0xff,0x0d,0xfb,0x00,}; -const uint8_t* const _I_PassportBottom_128x17[] = {_I_PassportBottom_128x17_0}; - -const uint8_t _I_PassportLeft_6x47_0[] = {0x01,0x00,0x1c,0x00,0x9e,0x40,0xa3,0x32,0x59,0x2c,0x66,0x03,0x01,0x82,0xc2,0x62,0x32,0x50,0x16,0xc8,0x60,0x30,0x28,0x24,0x32,0x39,0x3c,0x9e,0x4d,0x25,0x80,0x1a,}; -const uint8_t* const _I_PassportLeft_6x47[] = {_I_PassportLeft_6x47_0}; - -const uint8_t _I_WarningDolphin_45x42_0[] = {0x01,0x00,0xc6,0x00,0x00,0x1c,0x22,0x04,0x05,0x7f,0xfc,0x1e,0x20,0x05,0x1e,0x04,0x02,0x30,0x05,0x29,0x84,0x02,0xc1,0x20,0x02,0x8c,0x22,0x01,0x80,0x02,0x94,0x10,0x32,0x30,0x10,0x10,0x87,0xca,0x84,0x03,0x10,0x42,0x81,0x48,0x28,0x38,0x08,0x04,0x3e,0x01,0x84,0x83,0xe0,0x30,0x11,0x08,0x05,0xa2,0x11,0x40,0xa0,0x4b,0xc6,0xc5,0x40,0xd0,0x56,0xe0,0x10,0x60,0x29,0x54,0xf0,0x10,0x18,0xf0,0x14,0x6b,0xf6,0x0c,0x04,0x3e,0x40,0x05,0x12,0x80,0xc1,0xe4,0x01,0xd2,0xf8,0x40,0xe4,0x18,0x09,0xf4,0x03,0xf1,0x01,0x90,0x40,0x28,0x30,0x0f,0xe4,0x00,0x16,0x24,0x11,0xbf,0x01,0x44,0xee,0x53,0xf0,0x29,0xf0,0x3e,0x02,0x91,0x3b,0x8c,0xc3,0x81,0x13,0x90,0x48,0x20,0x3f,0xf9,0xfc,0x42,0x60,0x05,0x10,0x98,0x81,0x56,0x11,0x38,0x02,0x9c,0x1a,0x31,0x1e,0x02,0x8f,0x02,0x03,0x1c,0x90,0xc0,0x7c,0x02,0xf1,0xce,0x02,0x07,0x01,0x1f,0x80,0x63,0xa8,0x08,0x71,0x3c,0x8e,0x39,0x24,0x40,0x51,0xc7,0x81,0x53,0x0f,0x3c,0x02,0x9d,0x1e,0x38,0x29,0x10,0x29,0x17,0xc8,0x0a,0x32,0x3a,0x00,0x14,0x4b,0xa2,0x05,0x58,0x98,0x15,0x22,0x20,0x54,0x84,0x81,0x50,}; -const uint8_t* const _I_WarningDolphin_45x42[] = {_I_WarningDolphin_45x42_0}; - const uint8_t _I_Back_15x10_0[] = {0x00,0x04,0x00,0x06,0x00,0xFF,0x0F,0x06,0x10,0x04,0x20,0x00,0x40,0x00,0x40,0x00,0x20,0x00,0x10,0xFE,0x0F,}; const uint8_t* const _I_Back_15x10[] = {_I_Back_15x10_0}; @@ -238,23 +217,23 @@ const uint8_t* const _I_Down_hvr_25x27[] = {_I_Down_hvr_25x27_0}; const uint8_t _I_Fill_marker_7x7_0[] = {0x00,0x1C,0x32,0x6F,0x5F,0x7F,0x3E,0x1C,}; const uint8_t* const _I_Fill_marker_7x7[] = {_I_Fill_marker_7x7_0}; -const uint8_t _I_IrdaArrowDown_4x8_0[] = {0x00,0xFF,0x7E,0x3C,0x18,}; -const uint8_t* const _I_IrdaArrowDown_4x8[] = {_I_IrdaArrowDown_4x8_0}; +const uint8_t _I_InfraredArrowDown_4x8_0[] = {0x00,0xFF,0x7E,0x3C,0x18,}; +const uint8_t* const _I_InfraredArrowDown_4x8[] = {_I_InfraredArrowDown_4x8_0}; -const uint8_t _I_IrdaArrowUp_4x8_0[] = {0x00,0x18,0x3C,0x7E,0xFF,}; -const uint8_t* const _I_IrdaArrowUp_4x8[] = {_I_IrdaArrowUp_4x8_0}; +const uint8_t _I_InfraredArrowUp_4x8_0[] = {0x00,0x18,0x3C,0x7E,0xFF,}; +const uint8_t* const _I_InfraredArrowUp_4x8[] = {_I_InfraredArrowUp_4x8_0}; -const uint8_t _I_IrdaLearnShort_128x31_0[] = {0x01,0x00,0x10,0x01,0x00,0x47,0xfb,0xfe,0x00,0x38,0x38,0x3e,0x20,0x20,0x54,0x84,0x03,0x9f,0xc0,0x06,0x58,0x80,0x3d,0xf2,0x00,0x65,0x90,0x03,0xde,0x90,0x06,0x5a,0x07,0xc0,0x8a,0x70,0x1a,0x04,0x02,0x51,0x80,0x03,0x94,0x02,0x3f,0x40,0x20,0x24,0x0b,0x01,0x00,0x92,0x70,0x35,0x40,0x01,0xe0,0xdf,0xf0,0x10,0x40,0x71,0x58,0x20,0x90,0x88,0x0c,0x4a,0x81,0x55,0x00,0x0f,0x87,0xf7,0x00,0x82,0x43,0x36,0x16,0xdc,0x9c,0x12,0x21,0x01,0x85,0x70,0x3f,0xc1,0xf1,0xf8,0xfc,0x60,0x20,0xf5,0x90,0x40,0xa1,0x34,0x08,0x18,0x7c,0x7e,0x24,0x91,0x07,0x8c,0xc0,0x5e,0x52,0x28,0x14,0x17,0x81,0x01,0x0f,0x8f,0xe7,0xe3,0x03,0x1f,0x8e,0x02,0xdb,0x03,0x8e,0x49,0x20,0x50,0x2e,0x04,0x72,0xbd,0x55,0xdc,0xeb,0xa0,0x7c,0x4f,0x68,0xbc,0x60,0x72,0x40,0x79,0x50,0x23,0x9a,0x6d,0x56,0x66,0x5c,0x0f,0x21,0x78,0x9b,0x04,0x1e,0x28,0x21,0x8e,0x5c,0x43,0xe6,0x2f,0x10,0xf9,0x0b,0xc7,0x04,0x99,0x18,0x06,0xe0,0x7e,0x56,0x32,0x78,0x8f,0xc4,0x08,0x32,0x20,0x79,0x48,0x2b,0x85,0xf2,0xf8,0x83,0xc4,0x5c,0x3f,0x03,0x78,0xd0,0x81,0xe3,0xc0,0xdf,0x9f,0xcb,0xf3,0x04,0xc6,0x7d,0xfb,0xdf,0x34,0x78,0xd0,0x45,0xe5,0x7e,0x4f,0x97,0xe2,0x09,0x80,0x07,0x88,0xbc,0x61,0x00,0xf3,0xd8,0x2f,0xcb,0xe0,0xcf,0x60,0x68,0xd0,0x30,0x15,0xfa,0xac,0x36,0x3f,0x60,0x77,0xb3,0x80,0x5d,0xe6,0x4b,0x20,0x03,0x03,0xc4,0x01,0xd0,0x10,0x7f,0x40,0x81,0xfc,0xa7,0x10,0x06,0x99,0xd0,0x01,0x51,0x00,0x7f,0x48,0x01,0xfd,0xc0,0x43,0x98,0x00,0x8e,0xfe,0x00,0xf0,}; -const uint8_t* const _I_IrdaLearnShort_128x31[] = {_I_IrdaLearnShort_128x31_0}; +const uint8_t _I_InfraredLearnShort_128x31_0[] = {0x01,0x00,0x10,0x01,0x00,0x47,0xfb,0xfe,0x00,0x38,0x38,0x3e,0x20,0x20,0x54,0x84,0x03,0x9f,0xc0,0x06,0x58,0x80,0x3d,0xf2,0x00,0x65,0x90,0x03,0xde,0x90,0x06,0x5a,0x07,0xc0,0x8a,0x70,0x1a,0x04,0x02,0x51,0x80,0x03,0x94,0x02,0x3f,0x40,0x20,0x24,0x0b,0x01,0x00,0x92,0x70,0x35,0x40,0x01,0xe0,0xdf,0xf0,0x10,0x40,0x71,0x58,0x20,0x90,0x88,0x0c,0x4a,0x81,0x55,0x00,0x0f,0x87,0xf7,0x00,0x82,0x43,0x36,0x16,0xdc,0x9c,0x12,0x21,0x01,0x85,0x70,0x3f,0xc1,0xf1,0xf8,0xfc,0x60,0x20,0xf5,0x90,0x40,0xa1,0x34,0x08,0x18,0x7c,0x7e,0x24,0x91,0x07,0x8c,0xc0,0x5e,0x52,0x28,0x14,0x17,0x81,0x01,0x0f,0x8f,0xe7,0xe3,0x03,0x1f,0x8e,0x02,0xdb,0x03,0x8e,0x49,0x20,0x50,0x2e,0x04,0x72,0xbd,0x55,0xdc,0xeb,0xa0,0x7c,0x4f,0x68,0xbc,0x60,0x72,0x40,0x79,0x50,0x23,0x9a,0x6d,0x56,0x66,0x5c,0x0f,0x21,0x78,0x9b,0x04,0x1e,0x28,0x21,0x8e,0x5c,0x43,0xe6,0x2f,0x10,0xf9,0x0b,0xc7,0x04,0x99,0x18,0x06,0xe0,0x7e,0x56,0x32,0x78,0x8f,0xc4,0x08,0x32,0x20,0x79,0x48,0x2b,0x85,0xf2,0xf8,0x83,0xc4,0x5c,0x3f,0x03,0x78,0xd0,0x81,0xe3,0xc0,0xdf,0x9f,0xcb,0xf3,0x04,0xc6,0x7d,0xfb,0xdf,0x34,0x78,0xd0,0x45,0xe5,0x7e,0x4f,0x97,0xe2,0x09,0x80,0x07,0x88,0xbc,0x61,0x00,0xf3,0xd8,0x2f,0xcb,0xe0,0xcf,0x60,0x68,0xd0,0x30,0x15,0xfa,0xac,0x36,0x3f,0x60,0x77,0xb3,0x80,0x5d,0xe6,0x4b,0x20,0x03,0x03,0xc4,0x01,0xd0,0x10,0x7f,0x40,0x81,0xfc,0xa7,0x10,0x06,0x99,0xd0,0x01,0x51,0x00,0x7f,0x48,0x01,0xfd,0xc0,0x43,0x98,0x00,0x8e,0xfe,0x00,0xf0,}; +const uint8_t* const _I_InfraredLearnShort_128x31[] = {_I_InfraredLearnShort_128x31_0}; -const uint8_t _I_IrdaLearn_128x64_0[] = {0x01,0x00,0xcc,0x01,0x00,0x78,0x03,0xc0,0x1e,0x00,0xf0,0x07,0x80,0x3f,0x01,0x07,0x82,0x41,0x21,0x20,0x73,0x00,0x8e,0x82,0x0f,0x00,0xa0,0x01,0x46,0x11,0x00,0x07,0xc0,0x28,0x41,0xe5,0xc8,0xba,0x63,0xa7,0x70,0x6b,0x3d,0xbb,0x99,0x19,0xee,0x68,0x71,0x16,0x3f,0x70,0x3c,0x64,0xf9,0x58,0x25,0x26,0x13,0x91,0xc9,0x64,0xa4,0x99,0x2d,0x06,0x1f,0x29,0x42,0x07,0x8c,0x80,0x1e,0x50,0xff,0x88,0x3c,0x67,0x80,0xf1,0xc1,0x03,0xde,0x03,0x11,0x07,0x8c,0x10,0x1e,0x38,0x40,0x79,0xf0,0x32,0x80,0xf1,0x83,0x58,0x72,0x58,0xc8,0xc6,0x73,0x40,0x3f,0x10,0x78,0x9e,0xf1,0x17,0xe9,0xcf,0x00,0x78,0x03,0xc0,0x1e,0x00,0xf0,0x02,0x44,0x18,0xa3,0x80,0x82,0x32,0x06,0x44,0x0f,0xf0,0x73,0x5d,0xe3,0x92,0x7e,0xcf,0x06,0x3b,0xc3,0xa4,0xdd,0xfc,0xc8,0x35,0xca,0x44,0xa5,0x34,0x5c,0x16,0x92,0x89,0x4a,0x91,0x4a,0x60,0x20,0xf7,0xa4,0x83,0xc6,0x8e,0x0f,0xba,0x88,0x3c,0x68,0x00,0xf7,0x80,0x65,0xe3,0x9c,0x7a,0x6e,0x0a,0x49,0xc3,0xb8,0xc8,0xa4,0xc0,0xf5,0x00,0x08,0x1d,0xc0,0x0e,0x0f,0xf0,0x07,0x80,0x3c,0x01,0xe0,0x0f,0x00,0x2f,0xfb,0xfe,0x00,0x38,0x39,0x97,0xa1,0x00,0xe7,0xf0,0x3b,0x1c,0x00,0xd9,0x00,0x32,0xc8,0x01,0xef,0x48,0x03,0x2d,0x03,0xe0,0x45,0x38,0x0d,0x02,0x01,0x28,0xc0,0x01,0xca,0x01,0x1f,0xa0,0x10,0x12,0x05,0x80,0x80,0x49,0x38,0x1a,0xa0,0x00,0xf0,0x6f,0xf8,0x08,0x20,0x38,0xac,0x10,0x48,0x44,0x06,0x25,0x40,0xaa,0x80,0x07,0xc3,0xfb,0x80,0x41,0x21,0x9b,0x0b,0x6e,0x4e,0x09,0x10,0x80,0xc2,0xb8,0x1f,0xe0,0xf8,0xfc,0x7e,0x30,0x10,0x7a,0xc8,0x20,0x50,0x9a,0x04,0x0c,0x3e,0x3f,0x12,0x48,0x83,0xc6,0x60,0x2f,0x29,0x14,0x0a,0x0b,0xc0,0x80,0x87,0xc7,0xf3,0xf1,0x81,0x8f,0xc7,0x01,0x6d,0x81,0xc7,0x24,0x90,0x28,0x17,0x02,0x39,0x5e,0xaa,0xee,0x75,0xd0,0x3e,0x27,0xb4,0x5e,0x30,0x39,0x20,0x3c,0xa8,0x11,0xcd,0x36,0xab,0x33,0x2e,0x07,0x90,0xbc,0x4d,0x82,0x0f,0x14,0x10,0xc7,0x2e,0x21,0xf3,0x17,0x88,0x7c,0x85,0xe3,0x82,0x4c,0x8c,0x03,0x70,0x3f,0x2b,0x19,0x3c,0x47,0xe2,0x04,0x19,0x10,0x3c,0xa4,0x15,0xc2,0xf9,0x7c,0x41,0xe2,0x2e,0x1f,0x81,0xbc,0x68,0x40,0xf1,0xe0,0x6f,0xcf,0xe5,0xf9,0x82,0x63,0x3e,0xfd,0xef,0x9a,0x3c,0x68,0x22,0xf2,0xbf,0x27,0xcb,0xf1,0x04,0xc0,0x03,0xc4,0x5e,0x30,0x80,0x79,0xec,0x17,0xe5,0xf0,0x67,0xb0,0x34,0x68,0x18,0x0a,0xfd,0x56,0x1b,0x1f,0xb0,0x3b,0xd9,0xc0,0x2e,0xf3,0x25,0x90,0x01,0x81,0xe2,0x00,0xe8,0x08,0x3f,0xa0,0x40,0xfe,0x53,0x88,0x03,0x4c,0xe8,0x00,0xa8,0x80,0x3f,0xa4,0x00,0xfe,0xe0,0x21,0xcc,0x00,0x47,0x7f,0x00,0x78,}; -const uint8_t* const _I_IrdaLearn_128x64[] = {_I_IrdaLearn_128x64_0}; +const uint8_t _I_InfraredLearn_128x64_0[] = {0x01,0x00,0xcc,0x01,0x00,0x78,0x03,0xc0,0x1e,0x00,0xf0,0x07,0x80,0x3f,0x01,0x07,0x82,0x41,0x21,0x20,0x73,0x00,0x8e,0x82,0x0f,0x00,0xa0,0x01,0x46,0x11,0x00,0x07,0xc0,0x28,0x41,0xe5,0xc8,0xba,0x63,0xa7,0x70,0x6b,0x3d,0xbb,0x99,0x19,0xee,0x68,0x71,0x16,0x3f,0x70,0x3c,0x64,0xf9,0x58,0x25,0x26,0x13,0x91,0xc9,0x64,0xa4,0x99,0x2d,0x06,0x1f,0x29,0x42,0x07,0x8c,0x80,0x1e,0x50,0xff,0x88,0x3c,0x67,0x80,0xf1,0xc1,0x03,0xde,0x03,0x11,0x07,0x8c,0x10,0x1e,0x38,0x40,0x79,0xf0,0x32,0x80,0xf1,0x83,0x58,0x72,0x58,0xc8,0xc6,0x73,0x40,0x3f,0x10,0x78,0x9e,0xf1,0x17,0xe9,0xcf,0x00,0x78,0x03,0xc0,0x1e,0x00,0xf0,0x02,0x44,0x18,0xa3,0x80,0x82,0x32,0x06,0x44,0x0f,0xf0,0x73,0x5d,0xe3,0x92,0x7e,0xcf,0x06,0x3b,0xc3,0xa4,0xdd,0xfc,0xc8,0x35,0xca,0x44,0xa5,0x34,0x5c,0x16,0x92,0x89,0x4a,0x91,0x4a,0x60,0x20,0xf7,0xa4,0x83,0xc6,0x8e,0x0f,0xba,0x88,0x3c,0x68,0x00,0xf7,0x80,0x65,0xe3,0x9c,0x7a,0x6e,0x0a,0x49,0xc3,0xb8,0xc8,0xa4,0xc0,0xf5,0x00,0x08,0x1d,0xc0,0x0e,0x0f,0xf0,0x07,0x80,0x3c,0x01,0xe0,0x0f,0x00,0x2f,0xfb,0xfe,0x00,0x38,0x39,0x97,0xa1,0x00,0xe7,0xf0,0x3b,0x1c,0x00,0xd9,0x00,0x32,0xc8,0x01,0xef,0x48,0x03,0x2d,0x03,0xe0,0x45,0x38,0x0d,0x02,0x01,0x28,0xc0,0x01,0xca,0x01,0x1f,0xa0,0x10,0x12,0x05,0x80,0x80,0x49,0x38,0x1a,0xa0,0x00,0xf0,0x6f,0xf8,0x08,0x20,0x38,0xac,0x10,0x48,0x44,0x06,0x25,0x40,0xaa,0x80,0x07,0xc3,0xfb,0x80,0x41,0x21,0x9b,0x0b,0x6e,0x4e,0x09,0x10,0x80,0xc2,0xb8,0x1f,0xe0,0xf8,0xfc,0x7e,0x30,0x10,0x7a,0xc8,0x20,0x50,0x9a,0x04,0x0c,0x3e,0x3f,0x12,0x48,0x83,0xc6,0x60,0x2f,0x29,0x14,0x0a,0x0b,0xc0,0x80,0x87,0xc7,0xf3,0xf1,0x81,0x8f,0xc7,0x01,0x6d,0x81,0xc7,0x24,0x90,0x28,0x17,0x02,0x39,0x5e,0xaa,0xee,0x75,0xd0,0x3e,0x27,0xb4,0x5e,0x30,0x39,0x20,0x3c,0xa8,0x11,0xcd,0x36,0xab,0x33,0x2e,0x07,0x90,0xbc,0x4d,0x82,0x0f,0x14,0x10,0xc7,0x2e,0x21,0xf3,0x17,0x88,0x7c,0x85,0xe3,0x82,0x4c,0x8c,0x03,0x70,0x3f,0x2b,0x19,0x3c,0x47,0xe2,0x04,0x19,0x10,0x3c,0xa4,0x15,0xc2,0xf9,0x7c,0x41,0xe2,0x2e,0x1f,0x81,0xbc,0x68,0x40,0xf1,0xe0,0x6f,0xcf,0xe5,0xf9,0x82,0x63,0x3e,0xfd,0xef,0x9a,0x3c,0x68,0x22,0xf2,0xbf,0x27,0xcb,0xf1,0x04,0xc0,0x03,0xc4,0x5e,0x30,0x80,0x79,0xec,0x17,0xe5,0xf0,0x67,0xb0,0x34,0x68,0x18,0x0a,0xfd,0x56,0x1b,0x1f,0xb0,0x3b,0xd9,0xc0,0x2e,0xf3,0x25,0x90,0x01,0x81,0xe2,0x00,0xe8,0x08,0x3f,0xa0,0x40,0xfe,0x53,0x88,0x03,0x4c,0xe8,0x00,0xa8,0x80,0x3f,0xa4,0x00,0xfe,0xe0,0x21,0xcc,0x00,0x47,0x7f,0x00,0x78,}; +const uint8_t* const _I_InfraredLearn_128x64[] = {_I_InfraredLearn_128x64_0}; -const uint8_t _I_IrdaSendShort_128x34_0[] = {0x01,0x00,0x42,0x01,0xfe,0x7f,0xc0,0x07,0x03,0x07,0xc4,0x10,0x0a,0x90,0x20,0x7f,0x83,0xfc,0x04,0x3c,0x01,0xc2,0x7f,0xf8,0x80,0x43,0x9f,0x83,0xca,0x40,0x1f,0x5e,0x27,0x7e,0xab,0x55,0xee,0x83,0xce,0x38,0x0f,0x6d,0x50,0x00,0xa5,0xc0,0xf2,0x89,0x03,0xda,0xfe,0x1f,0x1f,0xa8,0x7c,0x48,0xc3,0x09,0x07,0xb6,0xae,0x54,0x1f,0x19,0xd4,0x08,0x40,0x30,0x5f,0x81,0x1c,0x63,0xfe,0x08,0x1f,0x12,0xbe,0x3f,0x49,0x0e,0x02,0x09,0x58,0x04,0x0c,0xd7,0xf1,0x0f,0x1f,0x8e,0x2b,0x11,0xaa,0x95,0x40,0xa2,0x34,0x08,0x16,0xa0,0x4e,0x32,0xab,0xe4,0x7f,0x89,0x77,0x0b,0x0d,0xd6,0x7f,0x82,0x84,0x50,0x20,0x3d,0x81,0x48,0xcd,0x67,0xd3,0xe1,0xf8,0xc8,0xb4,0x43,0xf1,0xc1,0x62,0x24,0x10,0x1b,0x46,0x80,0x3e,0x3f,0xe9,0xf8,0xfc,0xfa,0xa1,0xf1,0xa4,0x68,0x20,0x13,0x8a,0x00,0x7c,0x67,0xf7,0xe3,0xfa,0x4a,0x81,0xe3,0x40,0x80,0x66,0x38,0x66,0xa1,0xeb,0xdd,0x47,0xec,0x0f,0x2c,0x47,0x0e,0xa9,0x35,0xe9,0xd9,0x47,0xe2,0x1f,0x21,0xf8,0xd2,0x17,0xc3,0x88,0x91,0xeb,0x83,0xe6,0xbf,0x42,0x78,0xc4,0x20,0x10,0x88,0x05,0x5c,0x7e,0x7a,0xe1,0xfa,0x42,0x01,0xe5,0x84,0x1f,0x89,0x7c,0xbf,0xf7,0x7b,0xaf,0xdd,0x3e,0x31,0x10,0xe8,0xc2,0x3f,0x01,0xf1,0x3f,0x98,0x7c,0xa7,0x6a,0xf1,0x07,0x97,0x03,0x5e,0x9f,0x36,0x28,0xf7,0x7f,0xa1,0xf1,0x81,0x03,0xca,0x01,0x56,0x5f,0x9f,0xb8,0x3c,0x3e,0xa7,0xf8,0xc1,0x01,0xe5,0xf0,0x15,0x0f,0x85,0xbe,0x21,0xf1,0x00,0x08,0x7c,0x60,0x04,0xf1,0x77,0x96,0x7e,0x02,0xff,0x10,0x7c,0x00,0x16,0x08,0x05,0x40,0x78,0xa3,0xc4,0x00,0xb2,0x40,0x7b,0x2b,0xc4,0x00,0xb5,0x48,0x78,0x3d,0x70,0x01,0xf7,0x07,0xb4,0x00,0x94,0x23,0xfc,0x01,0x18,0x00,0xff,0x85,0xf3,0xff,0xc0,0xc3,0x0f,0x00,0xf0,0x09,0xce,0xf0,0x03,0x2f,0xc0,0x61,0x3f,0xe0,0xf8,0x00,0x30,0x3f,0xc0,}; -const uint8_t* const _I_IrdaSendShort_128x34[] = {_I_IrdaSendShort_128x34_0}; +const uint8_t _I_InfraredSendShort_128x34_0[] = {0x01,0x00,0x42,0x01,0xfe,0x7f,0xc0,0x07,0x03,0x07,0xc4,0x10,0x0a,0x90,0x20,0x7f,0x83,0xfc,0x04,0x3c,0x01,0xc2,0x7f,0xf8,0x80,0x43,0x9f,0x83,0xca,0x40,0x1f,0x5e,0x27,0x7e,0xab,0x55,0xee,0x83,0xce,0x38,0x0f,0x6d,0x50,0x00,0xa5,0xc0,0xf2,0x89,0x03,0xda,0xfe,0x1f,0x1f,0xa8,0x7c,0x48,0xc3,0x09,0x07,0xb6,0xae,0x54,0x1f,0x19,0xd4,0x08,0x40,0x30,0x5f,0x81,0x1c,0x63,0xfe,0x08,0x1f,0x12,0xbe,0x3f,0x49,0x0e,0x02,0x09,0x58,0x04,0x0c,0xd7,0xf1,0x0f,0x1f,0x8e,0x2b,0x11,0xaa,0x95,0x40,0xa2,0x34,0x08,0x16,0xa0,0x4e,0x32,0xab,0xe4,0x7f,0x89,0x77,0x0b,0x0d,0xd6,0x7f,0x82,0x84,0x50,0x20,0x3d,0x81,0x48,0xcd,0x67,0xd3,0xe1,0xf8,0xc8,0xb4,0x43,0xf1,0xc1,0x62,0x24,0x10,0x1b,0x46,0x80,0x3e,0x3f,0xe9,0xf8,0xfc,0xfa,0xa1,0xf1,0xa4,0x68,0x20,0x13,0x8a,0x00,0x7c,0x67,0xf7,0xe3,0xfa,0x4a,0x81,0xe3,0x40,0x80,0x66,0x38,0x66,0xa1,0xeb,0xdd,0x47,0xec,0x0f,0x2c,0x47,0x0e,0xa9,0x35,0xe9,0xd9,0x47,0xe2,0x1f,0x21,0xf8,0xd2,0x17,0xc3,0x88,0x91,0xeb,0x83,0xe6,0xbf,0x42,0x78,0xc4,0x20,0x10,0x88,0x05,0x5c,0x7e,0x7a,0xe1,0xfa,0x42,0x01,0xe5,0x84,0x1f,0x89,0x7c,0xbf,0xf7,0x7b,0xaf,0xdd,0x3e,0x31,0x10,0xe8,0xc2,0x3f,0x01,0xf1,0x3f,0x98,0x7c,0xa7,0x6a,0xf1,0x07,0x97,0x03,0x5e,0x9f,0x36,0x28,0xf7,0x7f,0xa1,0xf1,0x81,0x03,0xca,0x01,0x56,0x5f,0x9f,0xb8,0x3c,0x3e,0xa7,0xf8,0xc1,0x01,0xe5,0xf0,0x15,0x0f,0x85,0xbe,0x21,0xf1,0x00,0x08,0x7c,0x60,0x04,0xf1,0x77,0x96,0x7e,0x02,0xff,0x10,0x7c,0x00,0x16,0x08,0x05,0x40,0x78,0xa3,0xc4,0x00,0xb2,0x40,0x7b,0x2b,0xc4,0x00,0xb5,0x48,0x78,0x3d,0x70,0x01,0xf7,0x07,0xb4,0x00,0x94,0x23,0xfc,0x01,0x18,0x00,0xff,0x85,0xf3,0xff,0xc0,0xc3,0x0f,0x00,0xf0,0x09,0xce,0xf0,0x03,0x2f,0xc0,0x61,0x3f,0xe0,0xf8,0x00,0x30,0x3f,0xc0,}; +const uint8_t* const _I_InfraredSendShort_128x34[] = {_I_InfraredSendShort_128x34_0}; -const uint8_t _I_IrdaSend_128x64_0[] = {0x01,0x00,0xe2,0x01,0x00,0x78,0x03,0xc0,0x1e,0x00,0xfe,0x04,0x0e,0x05,0x82,0xd7,0x81,0xca,0x21,0x08,0x01,0x8c,0x10,0x0e,0x54,0x00,0x20,0xe0,0xa4,0x00,0xfb,0xb2,0x4e,0xb0,0xfa,0x0e,0x74,0xc7,0x0f,0x3b,0xce,0x4e,0xec,0xf0,0xe1,0x79,0xe4,0xe9,0x58,0x2d,0x3d,0x4a,0x95,0x41,0x89,0x52,0x31,0x59,0x40,0xfa,0x64,0x01,0xe3,0xa0,0xa9,0x5e,0x81,0xe7,0xf4,0x07,0xcc,0x28,0x1e,0x71,0x40,0x7a,0x58,0x01,0xe4,0x3f,0x1c,0x0c,0x4f,0x11,0x0b,0xb3,0x83,0xcc,0x00,0x94,0x20,0x2a,0x03,0xa0,0x1e,0xd0,0x34,0xdf,0x80,0x3c,0x01,0xe0,0x0f,0x00,0x4c,0xf0,0x17,0x4c,0x81,0xa0,0x18,0x18,0x1f,0x39,0x90,0x6c,0x60,0x27,0x70,0xe9,0x3f,0x67,0x03,0x3c,0x80,0x83,0xde,0x81,0x4a,0x84,0xca,0x68,0xb8,0x2b,0xf0,0x3f,0x29,0x20,0xfe,0xa8,0xe0,0x85,0xf3,0x80,0xa5,0xc3,0xb8,0xf4,0xd8,0x11,0x3e,0x40,0x04,0x1b,0x23,0x7d,0x83,0xcd,0x1f,0x60,0x0f,0x00,0x78,0x03,0x7f,0x9f,0xf0,0x01,0xc0,0xc1,0xf1,0x04,0x02,0xa4,0x08,0x1f,0xe0,0xff,0x01,0x0f,0x00,0x70,0x9f,0xfe,0x20,0x10,0xe7,0xe0,0xf2,0x90,0x07,0xd7,0x89,0xdf,0xaa,0xd5,0x7b,0xa0,0xf3,0x8e,0x03,0xdb,0x54,0x00,0x29,0x70,0x3c,0xa2,0x40,0xf6,0xbf,0x87,0xc7,0xea,0x1f,0x12,0x30,0xc2,0x41,0xed,0xab,0x95,0x07,0xc6,0x75,0x02,0x10,0x0c,0x17,0xe0,0x47,0x18,0xff,0x82,0x07,0xc4,0xaf,0x8f,0xd2,0x43,0x80,0x82,0x56,0x01,0x03,0x35,0xfc,0x43,0xc7,0xe3,0x8a,0xc4,0x6a,0xa5,0x50,0x28,0x8d,0x02,0x05,0xa8,0x13,0x8c,0xaa,0xf9,0x1f,0xe2,0x5d,0xc2,0xc3,0x75,0x9f,0xe0,0xa1,0x14,0x08,0x0f,0x60,0x52,0x33,0x59,0xf4,0xf8,0x7e,0x32,0x2d,0x10,0xfc,0x70,0x58,0x89,0x04,0x06,0xd1,0xa0,0x0f,0x8f,0xfa,0x7e,0x3f,0x3e,0xa8,0x7c,0x69,0x1a,0x08,0x04,0xe2,0x80,0x1f,0x19,0xfd,0xf8,0xfe,0x92,0xa0,0x78,0xd0,0x20,0x19,0x8e,0x19,0xa8,0x7a,0xf7,0x51,0xfb,0x03,0xcb,0x11,0xc3,0xaa,0x4d,0x7a,0x76,0x51,0xf8,0x87,0xc8,0x7e,0x34,0x85,0xf0,0xe2,0x24,0x7a,0xe0,0xf9,0xaf,0xd0,0x9e,0x31,0x08,0x04,0x22,0x01,0x57,0x1f,0x9e,0xb8,0x7e,0x90,0x80,0x79,0x61,0x07,0xe2,0x5f,0x2f,0xfd,0xde,0xeb,0xf7,0x4f,0x8c,0x44,0x3a,0x30,0x8f,0xc0,0x7c,0x4f,0xe6,0x1f,0x29,0xda,0xbc,0x41,0xe5,0xc0,0xd7,0xa7,0xcd,0x8a,0x3d,0xdf,0xe8,0x7c,0x60,0x40,0xf2,0x80,0x55,0x97,0xe7,0xee,0x0f,0x0f,0xa9,0xfe,0x30,0x40,0x79,0x7c,0x05,0x43,0xe1,0x6f,0x88,0x7c,0x40,0x02,0x1f,0x18,0x01,0x3c,0x5d,0xe5,0x9f,0x80,0xbf,0xc4,0x1f,0x00,0x05,0x82,0x01,0x50,0x1e,0x28,0xf1,0x00,0x2c,0x90,0x1e,0xca,0xf1,0x00,0x2d,0x52,0x1e,0x0f,0x5c,0x00,0x7d,0xc1,0xed,0x00,0x25,0x08,0xff,0x00,0x46,0x00,0x3f,0xe1,0x7c,0xff,0xf0,0x30,0xc3,0xc0,0x3c,0x02,0x73,0xbc,0x00,0xcb,0xf0,0x18,0x4f,0xf8,0x3e,0x00,0x0c,0x0f,0xf0,}; -const uint8_t* const _I_IrdaSend_128x64[] = {_I_IrdaSend_128x64_0}; +const uint8_t _I_InfraredSend_128x64_0[] = {0x01,0x00,0xe2,0x01,0x00,0x78,0x03,0xc0,0x1e,0x00,0xfe,0x04,0x0e,0x05,0x82,0xd7,0x81,0xca,0x21,0x08,0x01,0x8c,0x10,0x0e,0x54,0x00,0x20,0xe0,0xa4,0x00,0xfb,0xb2,0x4e,0xb0,0xfa,0x0e,0x74,0xc7,0x0f,0x3b,0xce,0x4e,0xec,0xf0,0xe1,0x79,0xe4,0xe9,0x58,0x2d,0x3d,0x4a,0x95,0x41,0x89,0x52,0x31,0x59,0x40,0xfa,0x64,0x01,0xe3,0xa0,0xa9,0x5e,0x81,0xe7,0xf4,0x07,0xcc,0x28,0x1e,0x71,0x40,0x7a,0x58,0x01,0xe4,0x3f,0x1c,0x0c,0x4f,0x11,0x0b,0xb3,0x83,0xcc,0x00,0x94,0x20,0x2a,0x03,0xa0,0x1e,0xd0,0x34,0xdf,0x80,0x3c,0x01,0xe0,0x0f,0x00,0x4c,0xf0,0x17,0x4c,0x81,0xa0,0x18,0x18,0x1f,0x39,0x90,0x6c,0x60,0x27,0x70,0xe9,0x3f,0x67,0x03,0x3c,0x80,0x83,0xde,0x81,0x4a,0x84,0xca,0x68,0xb8,0x2b,0xf0,0x3f,0x29,0x20,0xfe,0xa8,0xe0,0x85,0xf3,0x80,0xa5,0xc3,0xb8,0xf4,0xd8,0x11,0x3e,0x40,0x04,0x1b,0x23,0x7d,0x83,0xcd,0x1f,0x60,0x0f,0x00,0x78,0x03,0x7f,0x9f,0xf0,0x01,0xc0,0xc1,0xf1,0x04,0x02,0xa4,0x08,0x1f,0xe0,0xff,0x01,0x0f,0x00,0x70,0x9f,0xfe,0x20,0x10,0xe7,0xe0,0xf2,0x90,0x07,0xd7,0x89,0xdf,0xaa,0xd5,0x7b,0xa0,0xf3,0x8e,0x03,0xdb,0x54,0x00,0x29,0x70,0x3c,0xa2,0x40,0xf6,0xbf,0x87,0xc7,0xea,0x1f,0x12,0x30,0xc2,0x41,0xed,0xab,0x95,0x07,0xc6,0x75,0x02,0x10,0x0c,0x17,0xe0,0x47,0x18,0xff,0x82,0x07,0xc4,0xaf,0x8f,0xd2,0x43,0x80,0x82,0x56,0x01,0x03,0x35,0xfc,0x43,0xc7,0xe3,0x8a,0xc4,0x6a,0xa5,0x50,0x28,0x8d,0x02,0x05,0xa8,0x13,0x8c,0xaa,0xf9,0x1f,0xe2,0x5d,0xc2,0xc3,0x75,0x9f,0xe0,0xa1,0x14,0x08,0x0f,0x60,0x52,0x33,0x59,0xf4,0xf8,0x7e,0x32,0x2d,0x10,0xfc,0x70,0x58,0x89,0x04,0x06,0xd1,0xa0,0x0f,0x8f,0xfa,0x7e,0x3f,0x3e,0xa8,0x7c,0x69,0x1a,0x08,0x04,0xe2,0x80,0x1f,0x19,0xfd,0xf8,0xfe,0x92,0xa0,0x78,0xd0,0x20,0x19,0x8e,0x19,0xa8,0x7a,0xf7,0x51,0xfb,0x03,0xcb,0x11,0xc3,0xaa,0x4d,0x7a,0x76,0x51,0xf8,0x87,0xc8,0x7e,0x34,0x85,0xf0,0xe2,0x24,0x7a,0xe0,0xf9,0xaf,0xd0,0x9e,0x31,0x08,0x04,0x22,0x01,0x57,0x1f,0x9e,0xb8,0x7e,0x90,0x80,0x79,0x61,0x07,0xe2,0x5f,0x2f,0xfd,0xde,0xeb,0xf7,0x4f,0x8c,0x44,0x3a,0x30,0x8f,0xc0,0x7c,0x4f,0xe6,0x1f,0x29,0xda,0xbc,0x41,0xe5,0xc0,0xd7,0xa7,0xcd,0x8a,0x3d,0xdf,0xe8,0x7c,0x60,0x40,0xf2,0x80,0x55,0x97,0xe7,0xee,0x0f,0x0f,0xa9,0xfe,0x30,0x40,0x79,0x7c,0x05,0x43,0xe1,0x6f,0x88,0x7c,0x40,0x02,0x1f,0x18,0x01,0x3c,0x5d,0xe5,0x9f,0x80,0xbf,0xc4,0x1f,0x00,0x05,0x82,0x01,0x50,0x1e,0x28,0xf1,0x00,0x2c,0x90,0x1e,0xca,0xf1,0x00,0x2d,0x52,0x1e,0x0f,0x5c,0x00,0x7d,0xc1,0xed,0x00,0x25,0x08,0xff,0x00,0x46,0x00,0x3f,0xe1,0x7c,0xff,0xf0,0x30,0xc3,0xc0,0x3c,0x02,0x73,0xbc,0x00,0xcb,0xf0,0x18,0x4f,0xf8,0x3e,0x00,0x0c,0x0f,0xf0,}; +const uint8_t* const _I_InfraredSend_128x64[] = {_I_InfraredSend_128x64_0}; const uint8_t _I_Mute_25x27_0[] = {0x01,0x00,0x51,0x00,0xfc,0x7f,0xe7,0xf0,0x08,0x24,0x02,0x81,0x00,0x81,0x40,0x30,0x10,0x08,0x08,0x38,0x60,0x20,0x31,0x81,0xc0,0x64,0x38,0x08,0xa4,0x06,0x83,0x40,0x86,0x40,0x70,0x32,0x08,0x20,0x3c,0x63,0xf0,0x60,0x38,0xc0,0xa0,0xa0,0x31,0xc2,0x02,0xc7,0x03,0x48,0x01,0x94,0xc0,0x06,0xc0,0xb3,0x09,0x98,0x6c,0x84,0x68,0x2b,0x21,0x99,0x8e,0xcc,0x86,0x64,0xb3,0x81,0x94,0xc6,0x03,0x06,0x80,0x70,0x20,0x1f,0xcf,0xfd,0xfc,0xce,0x80,}; const uint8_t* const _I_Mute_25x27[] = {_I_Mute_25x27_0}; @@ -286,6 +265,27 @@ const uint8_t* const _I_Vol_up_25x27[] = {_I_Vol_up_25x27_0}; const uint8_t _I_Vol_up_hvr_25x27_0[] = {0x01,0x00,0x28,0x00,0xfc,0x7f,0xe7,0xf0,0x0f,0xe7,0xfe,0xff,0x00,0xff,0x7f,0xff,0xf0,0x00,0x10,0xff,0xe0,0x20,0x38,0xf7,0x80,0xfc,0x06,0xa2,0xd1,0xfc,0x00,0xd0,0x2f,0xe0,0x38,0x21,0xd8,0x0c,0x8a,0xe6,0x5f,0x33,0x39,0x80,}; const uint8_t* const _I_Vol_up_hvr_25x27[] = {_I_Vol_up_hvr_25x27_0}; +const uint8_t _I_Back3_45x8_0[] = {0x00,0x04,0x00,0x10,0x00,0x40,0x00,0x06,0x00,0x18,0x00,0x60,0x00,0x7F,0x00,0xFC,0x01,0xF0,0x07,0x86,0x20,0x18,0x82,0x60,0x08,0x04,0x71,0x10,0xC4,0x41,0x10,0x00,0x21,0x00,0x84,0x00,0x10,0x80,0x00,0x00,0x02,0x00,0x08,0x7E,0x00,0xF8,0x01,0xE0,0x07,}; +const uint8_t* const _I_Back3_45x8[] = {_I_Back3_45x8_0}; + +const uint8_t _I_DoorLeft_70x55_0[] = {0x01,0x00,0x19,0x01,0x00,0x2c,0x32,0x01,0x03,0x04,0x2c,0x18,0x10,0xf0,0x40,0x47,0x82,0x06,0x81,0x03,0xff,0x80,0x08,0x1a,0x20,0x82,0x15,0x28,0x21,0x87,0x82,0x08,0x6f,0xc0,0xb1,0xe6,0x10,0x10,0x8b,0x46,0x20,0x43,0x55,0x8f,0x82,0x10,0x32,0x73,0x0a,0x09,0x89,0x6c,0x1e,0x09,0x00,0x18,0x60,0xf0,0x0c,0x84,0x93,0x82,0x03,0x18,0x0c,0x02,0x1d,0x00,0x90,0x52,0x70,0x50,0x1e,0x00,0x58,0x63,0x90,0x0a,0x06,0x4a,0x09,0x03,0xb0,0x02,0x06,0x70,0x62,0x49,0xf8,0x0c,0x66,0x3f,0xf0,0x41,0x63,0x04,0x43,0x00,0x99,0x60,0x00,0x85,0xc8,0x06,0x14,0xd0,0x80,0x3f,0xc8,0x0d,0xb8,0x10,0x70,0xf8,0x34,0x13,0x03,0x39,0x04,0x1c,0x42,0x19,0xf8,0xa0,0xc2,0x01,0x07,0xef,0x02,0x8c,0x80,0x10,0x9d,0x00,0x43,0xec,0x00,0xa3,0x10,0x04,0x25,0xce,0x19,0xfc,0x88,0x82,0x12,0x0c,0x35,0x10,0x42,0x4c,0xa1,0x90,0x3f,0xc0,0x21,0x22,0x39,0x82,0xc8,0x88,0xd2,0x11,0xf0,0x01,0x88,0xd5,0x18,0xe2,0x08,0x68,0x10,0x0c,0xa8,0x00,0x83,0x81,0xcc,0xd5,0xc3,0x80,0x84,0x82,0x0e,0xcc,0xc0,0x15,0x79,0x02,0x0b,0x98,0xf8,0x11,0x88,0x82,0x0f,0x31,0x19,0x02,0x08,0x2c,0x9f,0x6a,0x1d,0x20,0x41,0x31,0x4c,0x10,0x8d,0x73,0x04,0x23,0xa4,0xc4,0x6c,0xde,0x20,0x42,0xcc,0x01,0x07,0x07,0xff,0x80,0x06,0x3e,0x08,0x38,0x70,0x20,0xa1,0xe0,0x83,0x8e,0x01,0x0c,0xf0,0x73,0x80,0x43,0x70,0x05,0x08,0x00,0x2c,0x04,0xc4,0x46,0x53,0x09,0x98,0x24,0x80,0x65,0x80,0xb0,0xd9,0x84,0x65,0x32,0x06,0x17,0x0f,0x98,0x23,0x63,0xe1,0x88,0xc4,0x08,0x5f,0xc1,0x30,0x9d,0x84,0x4e,0x66,0x94,0x11,0x98,0x75,0x26,0x00,}; +const uint8_t* const _I_DoorLeft_70x55[] = {_I_DoorLeft_70x55_0}; + +const uint8_t _I_DoorLocked_10x56_0[] = {0x01,0x00,0x4e,0x00,0x86,0x40,0x25,0xb0,0x0b,0x6c,0x03,0x9b,0x00,0xc6,0xc0,0x65,0x90,0x10,0x3a,0xc3,0x20,0x31,0xc8,0x04,0xe2,0x01,0x70,0x80,0x78,0x20,0x1c,0x48,0x07,0x22,0x01,0xd0,0x00,0xf0,0x44,0x68,0x90,0x09,0x04,0x02,0x21,0x00,0x84,0x40,0x25,0x80,0x12,0x1e,0x88,0x14,0xc0,0x2e,0x0d,0x11,0xca,0xf8,0x60,0x1c,0x38,0x07,0x1a,0x05,0xcc,0x80,0x72,0x60,0x5c,0x38,0x10,0x1c,0xf9,0x10,0x2e,0x00,0x05,0x60,0x00,0x11,}; +const uint8_t* const _I_DoorLocked_10x56[] = {_I_DoorLocked_10x56_0}; + +const uint8_t _I_DoorRight_70x55_0[] = {0x01,0x00,0x16,0x01,0x81,0xcc,0x01,0x0f,0x60,0x04,0x3f,0x00,0x10,0xf8,0x08,0x0c,0x02,0x05,0x01,0x84,0x02,0x06,0x26,0x0a,0x10,0x8a,0xcc,0xe0,0x1d,0x68,0xe0,0x18,0xab,0xd0,0x0b,0x18,0x10,0x46,0xe6,0x16,0x1e,0x18,0x10,0x46,0xe4,0x28,0x2c,0x98,0x14,0x68,0x00,0x21,0x1d,0x10,0x8c,0x40,0x02,0x0e,0x10,0xa1,0x08,0xc8,0x40,0x42,0x62,0x11,0x94,0x03,0xfd,0xff,0x00,0x0c,0xff,0x0c,0x08,0x28,0x60,0xe4,0xc0,0x85,0x00,0x83,0x00,0x87,0xf1,0x00,0x8c,0x02,0x0b,0x07,0x24,0x84,0xff,0x04,0xc7,0x80,0xa0,0xe4,0xa0,0x81,0x41,0x04,0x17,0x02,0x41,0x49,0x81,0x0e,0x10,0xb2,0xa0,0x82,0x0e,0x9f,0xfc,0x0a,0x62,0xf2,0xc0,0x03,0x92,0xf0,0x08,0x2d,0x78,0x20,0xff,0x02,0x01,0x08,0xae,0x60,0x64,0x38,0x0d,0xb0,0x8d,0x08,0x82,0x11,0x58,0xc4,0x13,0xc0,0x35,0x68,0x62,0x68,0x81,0x09,0x08,0x84,0x40,0x81,0x0d,0x18,0x69,0x10,0x47,0x44,0x66,0x5f,0x21,0xa9,0x29,0x94,0x10,0x2f,0x23,0x53,0x14,0x60,0x42,0x3c,0x08,0xfc,0x02,0x2c,0x62,0x23,0x58,0xd0,0x22,0x00,0x83,0x3e,0x98,0x44,0x43,0x46,0x22,0x30,0x89,0xce,0x01,0x0f,0x70,0x04,0x3f,0x81,0x8a,0x3c,0x21,0xaa,0x70,0x1a,0xe3,0x44,0x1a,0xa6,0x01,0xd2,0x38,0x90,0x8a,0x40,0x20,0xe5,0x96,0x80,0x43,0x81,0x06,0x6b,0x28,0x07,0xf3,0xfe,0x00,0x19,0xf9,0x34,0xc1,0x08,0x8f,0x20,0xf1,0x3e,0x16,0x00,0xa8,0x19,0x00,0x10,0x76,0x03,0xe2,0x3e,0x90,0x45,0x38,0x01,0x42,0x05,0x88,0x44,0x67,0x15,0x70,0x41,0x38,0x04,0x10,0x24,0x03,0x00,0x10,0x20,0x4a,0x46,0xe9,0x46,0xe1,0x04,0x50,0x66,0x40,0x85,0x19,0x98,0x00,0xc0,}; +const uint8_t* const _I_DoorRight_70x55[] = {_I_DoorRight_70x55_0}; + +const uint8_t _I_PassportBottom_128x17_0[] = {0x01,0x00,0x5e,0x00,0x96,0x01,0x97,0xe1,0xff,0x00,0x2e,0x3e,0x68,0x0f,0x5a,0xc5,0x54,0x00,0xb9,0x50,0xfb,0x6a,0x35,0x40,0x05,0xcd,0x4e,0x03,0xfd,0x30,0x0f,0xf8,0x7f,0xa0,0x81,0xfe,0xf9,0x1b,0xfb,0xf3,0x01,0x47,0x66,0x02,0x1b,0x03,0x07,0xe7,0x02,0x0b,0x02,0x07,0xe5,0x82,0x0b,0xf2,0x1c,0xb0,0x01,0x67,0xf0,0x5f,0xd0,0x3f,0x23,0xf0,0x9b,0xc9,0xe5,0x80,0x03,0xd5,0xc0,0x00,0x86,0x01,0xf3,0xe6,0x1e,0x58,0x00,0x36,0xa8,0x06,0xac,0x04,0x30,0x6c,0x30,0xee,0x60,0x1f,0xe0,0x10,0xff,0x0d,0xfb,0x00,}; +const uint8_t* const _I_PassportBottom_128x17[] = {_I_PassportBottom_128x17_0}; + +const uint8_t _I_PassportLeft_6x47_0[] = {0x01,0x00,0x1c,0x00,0x9e,0x40,0xa3,0x32,0x59,0x2c,0x66,0x03,0x01,0x82,0xc2,0x62,0x32,0x50,0x16,0xc8,0x60,0x30,0x28,0x24,0x32,0x39,0x3c,0x9e,0x4d,0x25,0x80,0x1a,}; +const uint8_t* const _I_PassportLeft_6x47[] = {_I_PassportLeft_6x47_0}; + +const uint8_t _I_WarningDolphin_45x42_0[] = {0x01,0x00,0xc6,0x00,0x00,0x1c,0x22,0x04,0x05,0x7f,0xfc,0x1e,0x20,0x05,0x1e,0x04,0x02,0x30,0x05,0x29,0x84,0x02,0xc1,0x20,0x02,0x8c,0x22,0x01,0x80,0x02,0x94,0x10,0x32,0x30,0x10,0x10,0x87,0xca,0x84,0x03,0x10,0x42,0x81,0x48,0x28,0x38,0x08,0x04,0x3e,0x01,0x84,0x83,0xe0,0x30,0x11,0x08,0x05,0xa2,0x11,0x40,0xa0,0x4b,0xc6,0xc5,0x40,0xd0,0x56,0xe0,0x10,0x60,0x29,0x54,0xf0,0x10,0x18,0xf0,0x14,0x6b,0xf6,0x0c,0x04,0x3e,0x40,0x05,0x12,0x80,0xc1,0xe4,0x01,0xd2,0xf8,0x40,0xe4,0x18,0x09,0xf4,0x03,0xf1,0x01,0x90,0x40,0x28,0x30,0x0f,0xe4,0x00,0x16,0x24,0x11,0xbf,0x01,0x44,0xee,0x53,0xf0,0x29,0xf0,0x3e,0x02,0x91,0x3b,0x8c,0xc3,0x81,0x13,0x90,0x48,0x20,0x3f,0xf9,0xfc,0x42,0x60,0x05,0x10,0x98,0x81,0x56,0x11,0x38,0x02,0x9c,0x1a,0x31,0x1e,0x02,0x8f,0x02,0x03,0x1c,0x90,0xc0,0x7c,0x02,0xf1,0xce,0x02,0x07,0x01,0x1f,0x80,0x63,0xa8,0x08,0x71,0x3c,0x8e,0x39,0x24,0x40,0x51,0xc7,0x81,0x53,0x0f,0x3c,0x02,0x9d,0x1e,0x38,0x29,0x10,0x29,0x17,0xc8,0x0a,0x32,0x3a,0x00,0x14,0x4b,0xa2,0x05,0x58,0x98,0x15,0x22,0x20,0x54,0x84,0x81,0x50,}; +const uint8_t* const _I_WarningDolphin_45x42[] = {_I_WarningDolphin_45x42_0}; + const uint8_t _I_KeyBackspaceSelected_16x9_0[] = {0x00,0xFE,0x7F,0xFF,0xFF,0xEF,0xFF,0xE7,0xFF,0x03,0xC0,0xE7,0xFF,0xEF,0xFF,0xFF,0xFF,0xFE,0x7F,}; const uint8_t* const _I_KeyBackspaceSelected_16x9[] = {_I_KeyBackspaceSelected_16x9_0}; @@ -718,24 +718,17 @@ const Icon I_ArrowDownEmpty_14x15 = {.width=14,.height=15,.frame_count=1,.frame_ const Icon I_ArrowDownFilled_14x15 = {.width=14,.height=15,.frame_count=1,.frame_rate=0,.frames=_I_ArrowDownFilled_14x15}; const Icon I_ArrowUpEmpty_14x15 = {.width=14,.height=15,.frame_count=1,.frame_rate=0,.frames=_I_ArrowUpEmpty_14x15}; const Icon I_ArrowUpFilled_14x15 = {.width=14,.height=15,.frame_count=1,.frame_rate=0,.frames=_I_ArrowUpFilled_14x15}; -const Icon I_Back3_45x8 = {.width=45,.height=8,.frame_count=1,.frame_rate=0,.frames=_I_Back3_45x8}; -const Icon I_DoorLeft_70x55 = {.width=70,.height=55,.frame_count=1,.frame_rate=0,.frames=_I_DoorLeft_70x55}; -const Icon I_DoorLocked_10x56 = {.width=10,.height=56,.frame_count=1,.frame_rate=0,.frames=_I_DoorLocked_10x56}; -const Icon I_DoorRight_70x55 = {.width=70,.height=55,.frame_count=1,.frame_rate=0,.frames=_I_DoorRight_70x55}; -const Icon I_PassportBottom_128x17 = {.width=128,.height=17,.frame_count=1,.frame_rate=0,.frames=_I_PassportBottom_128x17}; -const Icon I_PassportLeft_6x47 = {.width=6,.height=47,.frame_count=1,.frame_rate=0,.frames=_I_PassportLeft_6x47}; -const Icon I_WarningDolphin_45x42 = {.width=45,.height=42,.frame_count=1,.frame_rate=0,.frames=_I_WarningDolphin_45x42}; const Icon I_Back_15x10 = {.width=15,.height=10,.frame_count=1,.frame_rate=0,.frames=_I_Back_15x10}; const Icon I_DolphinReadingSuccess_59x63 = {.width=59,.height=63,.frame_count=1,.frame_rate=0,.frames=_I_DolphinReadingSuccess_59x63}; const Icon I_Down_25x27 = {.width=25,.height=27,.frame_count=1,.frame_rate=0,.frames=_I_Down_25x27}; const Icon I_Down_hvr_25x27 = {.width=25,.height=27,.frame_count=1,.frame_rate=0,.frames=_I_Down_hvr_25x27}; const Icon I_Fill_marker_7x7 = {.width=7,.height=7,.frame_count=1,.frame_rate=0,.frames=_I_Fill_marker_7x7}; -const Icon I_IrdaArrowDown_4x8 = {.width=8,.height=4,.frame_count=1,.frame_rate=0,.frames=_I_IrdaArrowDown_4x8}; -const Icon I_IrdaArrowUp_4x8 = {.width=8,.height=4,.frame_count=1,.frame_rate=0,.frames=_I_IrdaArrowUp_4x8}; -const Icon I_IrdaLearnShort_128x31 = {.width=128,.height=31,.frame_count=1,.frame_rate=0,.frames=_I_IrdaLearnShort_128x31}; -const Icon I_IrdaLearn_128x64 = {.width=128,.height=64,.frame_count=1,.frame_rate=0,.frames=_I_IrdaLearn_128x64}; -const Icon I_IrdaSendShort_128x34 = {.width=128,.height=34,.frame_count=1,.frame_rate=0,.frames=_I_IrdaSendShort_128x34}; -const Icon I_IrdaSend_128x64 = {.width=128,.height=64,.frame_count=1,.frame_rate=0,.frames=_I_IrdaSend_128x64}; +const Icon I_InfraredArrowDown_4x8 = {.width=8,.height=4,.frame_count=1,.frame_rate=0,.frames=_I_InfraredArrowDown_4x8}; +const Icon I_InfraredArrowUp_4x8 = {.width=8,.height=4,.frame_count=1,.frame_rate=0,.frames=_I_InfraredArrowUp_4x8}; +const Icon I_InfraredLearnShort_128x31 = {.width=128,.height=31,.frame_count=1,.frame_rate=0,.frames=_I_InfraredLearnShort_128x31}; +const Icon I_InfraredLearn_128x64 = {.width=128,.height=64,.frame_count=1,.frame_rate=0,.frames=_I_InfraredLearn_128x64}; +const Icon I_InfraredSendShort_128x34 = {.width=128,.height=34,.frame_count=1,.frame_rate=0,.frames=_I_InfraredSendShort_128x34}; +const Icon I_InfraredSend_128x64 = {.width=128,.height=64,.frame_count=1,.frame_rate=0,.frames=_I_InfraredSend_128x64}; const Icon I_Mute_25x27 = {.width=25,.height=27,.frame_count=1,.frame_rate=0,.frames=_I_Mute_25x27}; const Icon I_Mute_hvr_25x27 = {.width=25,.height=27,.frame_count=1,.frame_rate=0,.frames=_I_Mute_hvr_25x27}; const Icon I_Power_25x27 = {.width=25,.height=27,.frame_count=1,.frame_rate=0,.frames=_I_Power_25x27}; @@ -746,6 +739,13 @@ const Icon I_Vol_down_25x27 = {.width=25,.height=27,.frame_count=1,.frame_rate=0 const Icon I_Vol_down_hvr_25x27 = {.width=25,.height=27,.frame_count=1,.frame_rate=0,.frames=_I_Vol_down_hvr_25x27}; const Icon I_Vol_up_25x27 = {.width=25,.height=27,.frame_count=1,.frame_rate=0,.frames=_I_Vol_up_25x27}; const Icon I_Vol_up_hvr_25x27 = {.width=25,.height=27,.frame_count=1,.frame_rate=0,.frames=_I_Vol_up_hvr_25x27}; +const Icon I_Back3_45x8 = {.width=45,.height=8,.frame_count=1,.frame_rate=0,.frames=_I_Back3_45x8}; +const Icon I_DoorLeft_70x55 = {.width=70,.height=55,.frame_count=1,.frame_rate=0,.frames=_I_DoorLeft_70x55}; +const Icon I_DoorLocked_10x56 = {.width=10,.height=56,.frame_count=1,.frame_rate=0,.frames=_I_DoorLocked_10x56}; +const Icon I_DoorRight_70x55 = {.width=70,.height=55,.frame_count=1,.frame_rate=0,.frames=_I_DoorRight_70x55}; +const Icon I_PassportBottom_128x17 = {.width=128,.height=17,.frame_count=1,.frame_rate=0,.frames=_I_PassportBottom_128x17}; +const Icon I_PassportLeft_6x47 = {.width=6,.height=47,.frame_count=1,.frame_rate=0,.frames=_I_PassportLeft_6x47}; +const Icon I_WarningDolphin_45x42 = {.width=45,.height=42,.frame_count=1,.frame_rate=0,.frames=_I_WarningDolphin_45x42}; const Icon I_KeyBackspaceSelected_16x9 = {.width=16,.height=9,.frame_count=1,.frame_rate=0,.frames=_I_KeyBackspaceSelected_16x9}; const Icon I_KeyBackspace_16x9 = {.width=16,.height=9,.frame_count=1,.frame_rate=0,.frames=_I_KeyBackspace_16x9}; const Icon I_KeySaveSelected_24x11 = {.width=24,.height=11,.frame_count=1,.frame_rate=0,.frames=_I_KeySaveSelected_24x11}; diff --git a/assets/compiled/assets_icons.h b/assets/compiled/assets_icons.h index 7c964e1c..e80fdd2f 100644 --- a/assets/compiled/assets_icons.h +++ b/assets/compiled/assets_icons.h @@ -59,24 +59,17 @@ extern const Icon I_ArrowDownEmpty_14x15; extern const Icon I_ArrowDownFilled_14x15; extern const Icon I_ArrowUpEmpty_14x15; extern const Icon I_ArrowUpFilled_14x15; -extern const Icon I_Back3_45x8; -extern const Icon I_DoorLeft_70x55; -extern const Icon I_DoorLocked_10x56; -extern const Icon I_DoorRight_70x55; -extern const Icon I_PassportBottom_128x17; -extern const Icon I_PassportLeft_6x47; -extern const Icon I_WarningDolphin_45x42; extern const Icon I_Back_15x10; extern const Icon I_DolphinReadingSuccess_59x63; extern const Icon I_Down_25x27; extern const Icon I_Down_hvr_25x27; extern const Icon I_Fill_marker_7x7; -extern const Icon I_IrdaArrowDown_4x8; -extern const Icon I_IrdaArrowUp_4x8; -extern const Icon I_IrdaLearnShort_128x31; -extern const Icon I_IrdaLearn_128x64; -extern const Icon I_IrdaSendShort_128x34; -extern const Icon I_IrdaSend_128x64; +extern const Icon I_InfraredArrowDown_4x8; +extern const Icon I_InfraredArrowUp_4x8; +extern const Icon I_InfraredLearnShort_128x31; +extern const Icon I_InfraredLearn_128x64; +extern const Icon I_InfraredSendShort_128x34; +extern const Icon I_InfraredSend_128x64; extern const Icon I_Mute_25x27; extern const Icon I_Mute_hvr_25x27; extern const Icon I_Power_25x27; @@ -87,6 +80,13 @@ extern const Icon I_Vol_down_25x27; extern const Icon I_Vol_down_hvr_25x27; extern const Icon I_Vol_up_25x27; extern const Icon I_Vol_up_hvr_25x27; +extern const Icon I_Back3_45x8; +extern const Icon I_DoorLeft_70x55; +extern const Icon I_DoorLocked_10x56; +extern const Icon I_DoorRight_70x55; +extern const Icon I_PassportBottom_128x17; +extern const Icon I_PassportLeft_6x47; +extern const Icon I_WarningDolphin_45x42; extern const Icon I_KeyBackspaceSelected_16x9; extern const Icon I_KeyBackspace_16x9; extern const Icon I_KeySaveSelected_24x11; diff --git a/assets/icons/Irda/Back_15x10.png b/assets/icons/Infrared/Back_15x10.png similarity index 100% rename from assets/icons/Irda/Back_15x10.png rename to assets/icons/Infrared/Back_15x10.png diff --git a/assets/icons/Irda/DolphinReadingSuccess_59x63.png b/assets/icons/Infrared/DolphinReadingSuccess_59x63.png similarity index 100% rename from assets/icons/Irda/DolphinReadingSuccess_59x63.png rename to assets/icons/Infrared/DolphinReadingSuccess_59x63.png diff --git a/assets/icons/Irda/Down_25x27.png b/assets/icons/Infrared/Down_25x27.png similarity index 100% rename from assets/icons/Irda/Down_25x27.png rename to assets/icons/Infrared/Down_25x27.png diff --git a/assets/icons/Irda/Down_hvr_25x27.png b/assets/icons/Infrared/Down_hvr_25x27.png similarity index 100% rename from assets/icons/Irda/Down_hvr_25x27.png rename to assets/icons/Infrared/Down_hvr_25x27.png diff --git a/assets/icons/Irda/Fill-marker_7x7.png b/assets/icons/Infrared/Fill-marker_7x7.png similarity index 100% rename from assets/icons/Irda/Fill-marker_7x7.png rename to assets/icons/Infrared/Fill-marker_7x7.png diff --git a/assets/icons/Irda/IrdaArrowDown_4x8.png b/assets/icons/Infrared/InfraredArrowDown_4x8.png similarity index 100% rename from assets/icons/Irda/IrdaArrowDown_4x8.png rename to assets/icons/Infrared/InfraredArrowDown_4x8.png diff --git a/assets/icons/Irda/IrdaArrowUp_4x8.png b/assets/icons/Infrared/InfraredArrowUp_4x8.png similarity index 100% rename from assets/icons/Irda/IrdaArrowUp_4x8.png rename to assets/icons/Infrared/InfraredArrowUp_4x8.png diff --git a/assets/icons/Irda/IrdaLearnShort_128x31.png b/assets/icons/Infrared/InfraredLearnShort_128x31.png similarity index 100% rename from assets/icons/Irda/IrdaLearnShort_128x31.png rename to assets/icons/Infrared/InfraredLearnShort_128x31.png diff --git a/assets/icons/Irda/IrdaLearn_128x64.png b/assets/icons/Infrared/InfraredLearn_128x64.png similarity index 100% rename from assets/icons/Irda/IrdaLearn_128x64.png rename to assets/icons/Infrared/InfraredLearn_128x64.png diff --git a/assets/icons/Irda/IrdaSendShort_128x34.png b/assets/icons/Infrared/InfraredSendShort_128x34.png similarity index 100% rename from assets/icons/Irda/IrdaSendShort_128x34.png rename to assets/icons/Infrared/InfraredSendShort_128x34.png diff --git a/assets/icons/Irda/IrdaSend_128x64.png b/assets/icons/Infrared/InfraredSend_128x64.png similarity index 100% rename from assets/icons/Irda/IrdaSend_128x64.png rename to assets/icons/Infrared/InfraredSend_128x64.png diff --git a/assets/icons/Irda/Mute_25x27.png b/assets/icons/Infrared/Mute_25x27.png similarity index 100% rename from assets/icons/Irda/Mute_25x27.png rename to assets/icons/Infrared/Mute_25x27.png diff --git a/assets/icons/Irda/Mute_hvr_25x27.png b/assets/icons/Infrared/Mute_hvr_25x27.png similarity index 100% rename from assets/icons/Irda/Mute_hvr_25x27.png rename to assets/icons/Infrared/Mute_hvr_25x27.png diff --git a/assets/icons/Irda/Power_25x27.png b/assets/icons/Infrared/Power_25x27.png similarity index 100% rename from assets/icons/Irda/Power_25x27.png rename to assets/icons/Infrared/Power_25x27.png diff --git a/assets/icons/Irda/Power_hvr_25x27.png b/assets/icons/Infrared/Power_hvr_25x27.png similarity index 100% rename from assets/icons/Irda/Power_hvr_25x27.png rename to assets/icons/Infrared/Power_hvr_25x27.png diff --git a/assets/icons/Irda/Up_25x27.png b/assets/icons/Infrared/Up_25x27.png similarity index 100% rename from assets/icons/Irda/Up_25x27.png rename to assets/icons/Infrared/Up_25x27.png diff --git a/assets/icons/Irda/Up_hvr_25x27.png b/assets/icons/Infrared/Up_hvr_25x27.png similarity index 100% rename from assets/icons/Irda/Up_hvr_25x27.png rename to assets/icons/Infrared/Up_hvr_25x27.png diff --git a/assets/icons/Irda/Vol_down_25x27.png b/assets/icons/Infrared/Vol_down_25x27.png similarity index 100% rename from assets/icons/Irda/Vol_down_25x27.png rename to assets/icons/Infrared/Vol_down_25x27.png diff --git a/assets/icons/Irda/Vol_down_hvr_25x27.png b/assets/icons/Infrared/Vol_down_hvr_25x27.png similarity index 100% rename from assets/icons/Irda/Vol_down_hvr_25x27.png rename to assets/icons/Infrared/Vol_down_hvr_25x27.png diff --git a/assets/icons/Irda/Vol_up_25x27.png b/assets/icons/Infrared/Vol_up_25x27.png similarity index 100% rename from assets/icons/Irda/Vol_up_25x27.png rename to assets/icons/Infrared/Vol_up_25x27.png diff --git a/assets/icons/Irda/Vol_up_hvr_25x27.png b/assets/icons/Infrared/Vol_up_hvr_25x27.png similarity index 100% rename from assets/icons/Irda/Vol_up_hvr_25x27.png rename to assets/icons/Infrared/Vol_up_hvr_25x27.png diff --git a/assets/resources/irda/assets/tv.ir b/assets/resources/infrared/assets/tv.ir similarity index 100% rename from assets/resources/irda/assets/tv.ir rename to assets/resources/infrared/assets/tv.ir diff --git a/bootloader/targets/f6/furi_hal/furi_hal_resources.c b/bootloader/targets/f6/furi_hal/furi_hal_resources.c index 41e77347..e73b7cbc 100644 --- a/bootloader/targets/f6/furi_hal/furi_hal_resources.c +++ b/bootloader/targets/f6/furi_hal/furi_hal_resources.c @@ -34,8 +34,8 @@ const GpioPin gpio_rfid_pull = {.port = RFID_PULL_GPIO_Port, .pin = RFID_PULL_Pi const GpioPin gpio_rfid_carrier_out = {.port = RFID_OUT_GPIO_Port, .pin = RFID_OUT_Pin}; const GpioPin gpio_rfid_data_in = {.port = RFID_RF_IN_GPIO_Port, .pin = RFID_RF_IN_Pin}; -const GpioPin gpio_irda_rx = {.port = IR_RX_GPIO_Port, .pin = IR_RX_Pin}; -const GpioPin gpio_irda_tx = {.port = IR_TX_GPIO_Port, .pin = IR_TX_Pin}; +const GpioPin gpio_infrared_rx = {.port = IR_RX_GPIO_Port, .pin = IR_RX_Pin}; +const GpioPin gpio_infrared_tx = {.port = IR_TX_GPIO_Port, .pin = IR_TX_Pin}; const GpioPin gpio_usart_tx = {.port = USART1_TX_Port, .pin = USART1_TX_Pin}; const GpioPin gpio_usart_rx = {.port = USART1_RX_Port, .pin = USART1_RX_Pin}; diff --git a/bootloader/targets/f6/furi_hal/furi_hal_resources.h b/bootloader/targets/f6/furi_hal/furi_hal_resources.h index 8f923bd2..925bd5ac 100644 --- a/bootloader/targets/f6/furi_hal/furi_hal_resources.h +++ b/bootloader/targets/f6/furi_hal/furi_hal_resources.h @@ -59,8 +59,8 @@ extern const GpioPin gpio_rfid_pull; extern const GpioPin gpio_rfid_carrier_out; extern const GpioPin gpio_rfid_data_in; -extern const GpioPin gpio_irda_rx; -extern const GpioPin gpio_irda_tx; +extern const GpioPin gpio_infrared_rx; +extern const GpioPin gpio_infrared_tx; extern const GpioPin gpio_usart_tx; extern const GpioPin gpio_usart_rx; diff --git a/bootloader/targets/f7/furi_hal/furi_hal_resources.c b/bootloader/targets/f7/furi_hal/furi_hal_resources.c index 41e77347..e73b7cbc 100644 --- a/bootloader/targets/f7/furi_hal/furi_hal_resources.c +++ b/bootloader/targets/f7/furi_hal/furi_hal_resources.c @@ -34,8 +34,8 @@ const GpioPin gpio_rfid_pull = {.port = RFID_PULL_GPIO_Port, .pin = RFID_PULL_Pi const GpioPin gpio_rfid_carrier_out = {.port = RFID_OUT_GPIO_Port, .pin = RFID_OUT_Pin}; const GpioPin gpio_rfid_data_in = {.port = RFID_RF_IN_GPIO_Port, .pin = RFID_RF_IN_Pin}; -const GpioPin gpio_irda_rx = {.port = IR_RX_GPIO_Port, .pin = IR_RX_Pin}; -const GpioPin gpio_irda_tx = {.port = IR_TX_GPIO_Port, .pin = IR_TX_Pin}; +const GpioPin gpio_infrared_rx = {.port = IR_RX_GPIO_Port, .pin = IR_RX_Pin}; +const GpioPin gpio_infrared_tx = {.port = IR_TX_GPIO_Port, .pin = IR_TX_Pin}; const GpioPin gpio_usart_tx = {.port = USART1_TX_Port, .pin = USART1_TX_Pin}; const GpioPin gpio_usart_rx = {.port = USART1_RX_Port, .pin = USART1_RX_Pin}; diff --git a/bootloader/targets/f7/furi_hal/furi_hal_resources.h b/bootloader/targets/f7/furi_hal/furi_hal_resources.h index 8f923bd2..925bd5ac 100644 --- a/bootloader/targets/f7/furi_hal/furi_hal_resources.h +++ b/bootloader/targets/f7/furi_hal/furi_hal_resources.h @@ -59,8 +59,8 @@ extern const GpioPin gpio_rfid_pull; extern const GpioPin gpio_rfid_carrier_out; extern const GpioPin gpio_rfid_data_in; -extern const GpioPin gpio_irda_rx; -extern const GpioPin gpio_irda_tx; +extern const GpioPin gpio_infrared_rx; +extern const GpioPin gpio_infrared_tx; extern const GpioPin gpio_usart_tx; extern const GpioPin gpio_usart_rx; diff --git a/documentation/Doxyfile b/documentation/Doxyfile index 714f1ae9..6d6bb8aa 100644 --- a/documentation/Doxyfile +++ b/documentation/Doxyfile @@ -873,7 +873,7 @@ WARN_LOGFILE = INPUT = applications \ core \ - lib/irda \ + lib/infrared \ lib/subghz \ lib/toolbox \ lib/onewire \ diff --git a/firmware/targets/f6/Inc/main.h b/firmware/targets/f6/Inc/main.h index 3b578816..99b7c0e8 100644 --- a/firmware/targets/f6/Inc/main.h +++ b/firmware/targets/f6/Inc/main.h @@ -131,15 +131,15 @@ extern TIM_HandleTypeDef htim16; #define LFRFID_TIM htim1 #define LFRFID_CH TIM_CHANNEL_1 -#define IRDA_TX_TIM htim1 -#define IRDA_TX_CH TIM_CHANNEL_3 +#define INFRARED_TX_TIM htim1 +#define INFRARED_TX_CH TIM_CHANNEL_3 // only for reference -// IRDA RX timer dont exist in F2 +// INFRARED RX timer dont exist in F2 // and timer need more data to init (NVIC IRQn to set priority) -#define IRDA_RX_TIM htim2 -#define IRDA_RX_FALLING_CH TIM_CHANNEL_1 -#define IRDA_RX_RISING_CH TIM_CHANNEL_2 +#define INFRARED_RX_TIM htim2 +#define INFRARED_RX_FALLING_CH TIM_CHANNEL_1 +#define INFRARED_RX_RISING_CH TIM_CHANNEL_2 #define NFC_IRQ_Pin RFID_PULL_Pin #define NFC_IRQ_GPIO_Port RFID_PULL_GPIO_Port diff --git a/firmware/targets/f6/furi_hal/furi_hal_irda.c b/firmware/targets/f6/furi_hal/furi_hal_infrared.c similarity index 50% rename from firmware/targets/f6/furi_hal/furi_hal_irda.c rename to firmware/targets/f6/furi_hal/furi_hal_infrared.c index 6fe051a9..765885b9 100644 --- a/firmware/targets/f6/furi_hal/furi_hal_irda.c +++ b/firmware/targets/f6/furi_hal/furi_hal_infrared.c @@ -1,4 +1,4 @@ -#include "furi_hal_irda.h" +#include "furi_hal_infrared.h" #include "furi_hal_delay.h" #include "furi/check.h" #include "stm32wbxx_ll_dma.h" @@ -17,26 +17,27 @@ #include #include -#define IRDA_TX_DEBUG 0 +#define INFRARED_TX_DEBUG 0 -#if IRDA_TX_DEBUG == 1 -#define gpio_irda_tx gpio_irda_tx_debug -const GpioPin gpio_irda_tx_debug = {.port = GPIOA, .pin = GPIO_PIN_7}; +#if INFRARED_TX_DEBUG == 1 +#define gpio_infrared_tx gpio_infrared_tx_debug +const GpioPin gpio_infrared_tx_debug = {.port = GPIOA, .pin = GPIO_PIN_7}; #endif -#define IRDA_TIM_TX_DMA_BUFFER_SIZE 200 -#define IRDA_POLARITY_SHIFT 1 +#define INFRARED_TIM_TX_DMA_BUFFER_SIZE 200 +#define INFRARED_POLARITY_SHIFT 1 -#define IRDA_TX_CCMR_HIGH (TIM_CCMR2_OC3PE | LL_TIM_OCMODE_PWM2) /* Mark time - enable PWM2 mode */ -#define IRDA_TX_CCMR_LOW \ +#define INFRARED_TX_CCMR_HIGH \ + (TIM_CCMR2_OC3PE | LL_TIM_OCMODE_PWM2) /* Mark time - enable PWM2 mode */ +#define INFRARED_TX_CCMR_LOW \ (TIM_CCMR2_OC3PE | LL_TIM_OCMODE_FORCED_INACTIVE) /* Space time - force low */ typedef struct { - FuriHalIrdaRxCaptureCallback capture_callback; + FuriHalInfraredRxCaptureCallback capture_callback; void* capture_context; - FuriHalIrdaRxTimeoutCallback timeout_callback; + FuriHalInfraredRxTimeoutCallback timeout_callback; void* timeout_context; -} IrdaTimRx; +} InfraredTimRx; typedef struct { uint8_t* polarity; @@ -44,52 +45,52 @@ typedef struct { size_t size; bool packet_end; bool last_packet_end; -} IrdaTxBuf; +} InfraredTxBuf; typedef struct { float cycle_duration; - FuriHalIrdaTxGetDataISRCallback data_callback; - FuriHalIrdaTxSignalSentISRCallback signal_sent_callback; + FuriHalInfraredTxGetDataISRCallback data_callback; + FuriHalInfraredTxSignalSentISRCallback signal_sent_callback; void* data_context; void* signal_sent_context; - IrdaTxBuf buffer[2]; + InfraredTxBuf buffer[2]; osSemaphoreId_t stop_semaphore; uint32_t tx_timing_rest_duration; /** if timing is too long (> 0xFFFF), send it in few iterations */ bool tx_timing_rest_level; - FuriHalIrdaTxGetDataState tx_timing_rest_status; -} IrdaTimTx; + FuriHalInfraredTxGetDataState tx_timing_rest_status; +} InfraredTimTx; typedef enum { - IrdaStateIdle, /** Furi Hal Irda is ready to start RX or TX */ - IrdaStateAsyncRx, /** Async RX started */ - IrdaStateAsyncTx, /** Async TX started, DMA and timer is on */ - IrdaStateAsyncTxStopReq, /** Async TX started, async stop request received */ - IrdaStateAsyncTxStopInProgress, /** Async TX started, stop request is processed and we wait for last data to be sent */ - IrdaStateAsyncTxStopped, /** Async TX complete, cleanup needed */ - IrdaStateMAX, -} IrdaState; + InfraredStateIdle, /** Furi Hal Infrared is ready to start RX or TX */ + InfraredStateAsyncRx, /** Async RX started */ + InfraredStateAsyncTx, /** Async TX started, DMA and timer is on */ + InfraredStateAsyncTxStopReq, /** Async TX started, async stop request received */ + InfraredStateAsyncTxStopInProgress, /** Async TX started, stop request is processed and we wait for last data to be sent */ + InfraredStateAsyncTxStopped, /** Async TX complete, cleanup needed */ + InfraredStateMAX, +} InfraredState; -static volatile IrdaState furi_hal_irda_state = IrdaStateIdle; -static IrdaTimTx irda_tim_tx; -static IrdaTimRx irda_tim_rx; +static volatile InfraredState furi_hal_infrared_state = InfraredStateIdle; +static InfraredTimTx infrared_tim_tx; +static InfraredTimRx infrared_tim_rx; -static void furi_hal_irda_tx_fill_buffer(uint8_t buf_num, uint8_t polarity_shift); -static void furi_hal_irda_async_tx_free_resources(void); -static void furi_hal_irda_tx_dma_set_polarity(uint8_t buf_num, uint8_t polarity_shift); -static void furi_hal_irda_tx_dma_set_buffer(uint8_t buf_num); -static void furi_hal_irda_tx_fill_buffer_last(uint8_t buf_num); -static uint8_t furi_hal_irda_get_current_dma_tx_buffer(void); -static void furi_hal_irda_tx_dma_polarity_isr(); -static void furi_hal_irda_tx_dma_isr(); +static void furi_hal_infrared_tx_fill_buffer(uint8_t buf_num, uint8_t polarity_shift); +static void furi_hal_infrared_async_tx_free_resources(void); +static void furi_hal_infrared_tx_dma_set_polarity(uint8_t buf_num, uint8_t polarity_shift); +static void furi_hal_infrared_tx_dma_set_buffer(uint8_t buf_num); +static void furi_hal_infrared_tx_fill_buffer_last(uint8_t buf_num); +static uint8_t furi_hal_infrared_get_current_dma_tx_buffer(void); +static void furi_hal_infrared_tx_dma_polarity_isr(); +static void furi_hal_infrared_tx_dma_isr(); -static void furi_hal_irda_tim_rx_isr() { +static void furi_hal_infrared_tim_rx_isr() { static uint32_t previous_captured_ch2 = 0; /* Timeout */ if(LL_TIM_IsActiveFlag_CC3(TIM2)) { LL_TIM_ClearFlag_CC3(TIM2); - furi_assert(furi_hal_irda_state == IrdaStateAsyncRx); + furi_assert(furi_hal_infrared_state == InfraredStateAsyncRx); /* Timers CNT register starts to counting from 0 to ARR, but it is * reseted when Channel 1 catches interrupt. It is not reseted by @@ -97,22 +98,22 @@ static void furi_hal_irda_tim_rx_isr() { * This can cause false timeout: when time is over, but we started * receiving new signal few microseconds ago, because CNT register * is reseted once per period, not per sample. */ - if(LL_GPIO_IsInputPinSet(gpio_irda_rx.port, gpio_irda_rx.pin) != 0) { - if(irda_tim_rx.timeout_callback) - irda_tim_rx.timeout_callback(irda_tim_rx.timeout_context); + if(LL_GPIO_IsInputPinSet(gpio_infrared_rx.port, gpio_infrared_rx.pin) != 0) { + if(infrared_tim_rx.timeout_callback) + infrared_tim_rx.timeout_callback(infrared_tim_rx.timeout_context); } } /* Rising Edge */ if(LL_TIM_IsActiveFlag_CC1(TIM2)) { LL_TIM_ClearFlag_CC1(TIM2); - furi_assert(furi_hal_irda_state == IrdaStateAsyncRx); + furi_assert(furi_hal_infrared_state == InfraredStateAsyncRx); if(READ_BIT(TIM2->CCMR1, TIM_CCMR1_CC1S)) { - /* Low pin level is a Mark state of IRDA signal. Invert level for further processing. */ + /* Low pin level is a Mark state of INFRARED signal. Invert level for further processing. */ uint32_t duration = LL_TIM_IC_GetCaptureCH1(TIM2) - previous_captured_ch2; - if(irda_tim_rx.capture_callback) - irda_tim_rx.capture_callback(irda_tim_rx.capture_context, 1, duration); + if(infrared_tim_rx.capture_callback) + infrared_tim_rx.capture_callback(infrared_tim_rx.capture_context, 1, duration); } else { furi_assert(0); } @@ -121,22 +122,22 @@ static void furi_hal_irda_tim_rx_isr() { /* Falling Edge */ if(LL_TIM_IsActiveFlag_CC2(TIM2)) { LL_TIM_ClearFlag_CC2(TIM2); - furi_assert(furi_hal_irda_state == IrdaStateAsyncRx); + furi_assert(furi_hal_infrared_state == InfraredStateAsyncRx); if(READ_BIT(TIM2->CCMR1, TIM_CCMR1_CC2S)) { - /* High pin level is a Space state of IRDA signal. Invert level for further processing. */ + /* High pin level is a Space state of INFRARED signal. Invert level for further processing. */ uint32_t duration = LL_TIM_IC_GetCaptureCH2(TIM2); previous_captured_ch2 = duration; - if(irda_tim_rx.capture_callback) - irda_tim_rx.capture_callback(irda_tim_rx.capture_context, 0, duration); + if(infrared_tim_rx.capture_callback) + infrared_tim_rx.capture_callback(infrared_tim_rx.capture_context, 0, duration); } else { furi_assert(0); } } } -void furi_hal_irda_async_rx_start(void) { - furi_assert(furi_hal_irda_state == IrdaStateIdle); +void furi_hal_infrared_async_rx_start(void) { + furi_assert(furi_hal_infrared_state == InfraredStateIdle); FURI_CRITICAL_ENTER(); LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_TIM2); @@ -144,7 +145,7 @@ void furi_hal_irda_async_rx_start(void) { FURI_CRITICAL_EXIT(); hal_gpio_init_ex( - &gpio_irda_rx, GpioModeAltFunctionPushPull, GpioPullNo, GpioSpeedLow, GpioAltFn1TIM2); + &gpio_infrared_rx, GpioModeAltFunctionPushPull, GpioPullNo, GpioSpeedLow, GpioAltFn1TIM2); LL_TIM_InitTypeDef TIM_InitStruct = {0}; TIM_InitStruct.Prescaler = 64 - 1; @@ -171,8 +172,8 @@ void furi_hal_irda_async_rx_start(void) { LL_TIM_IC_SetActiveInput(TIM2, LL_TIM_CHANNEL_CH2, LL_TIM_ACTIVEINPUT_INDIRECTTI); LL_TIM_IC_SetPrescaler(TIM2, LL_TIM_CHANNEL_CH2, LL_TIM_ICPSC_DIV1); - furi_hal_interrupt_set_timer_isr(TIM2, furi_hal_irda_tim_rx_isr); - furi_hal_irda_state = IrdaStateAsyncRx; + furi_hal_interrupt_set_timer_isr(TIM2, furi_hal_infrared_tim_rx_isr); + furi_hal_infrared_state = InfraredStateAsyncRx; LL_TIM_EnableIT_CC1(TIM2); LL_TIM_EnableIT_CC2(TIM2); @@ -186,15 +187,15 @@ void furi_hal_irda_async_rx_start(void) { NVIC_EnableIRQ(TIM2_IRQn); } -void furi_hal_irda_async_rx_stop(void) { - furi_assert(furi_hal_irda_state == IrdaStateAsyncRx); +void furi_hal_infrared_async_rx_stop(void) { + furi_assert(furi_hal_infrared_state == InfraredStateAsyncRx); LL_TIM_DeInit(TIM2); furi_hal_interrupt_set_timer_isr(TIM2, NULL); LL_APB1_GRP1_DisableClock(LL_APB1_GRP1_PERIPH_TIM2); - furi_hal_irda_state = IrdaStateIdle; + furi_hal_infrared_state = InfraredStateIdle; } -void furi_hal_irda_async_rx_set_timeout(uint32_t timeout_us) { +void furi_hal_infrared_async_rx_set_timeout(uint32_t timeout_us) { furi_assert(LL_APB1_GRP1_IsEnabledClock(LL_APB1_GRP1_PERIPH_TIM2)); LL_TIM_OC_SetCompareCH3(TIM2, timeout_us); @@ -203,46 +204,46 @@ void furi_hal_irda_async_rx_set_timeout(uint32_t timeout_us) { LL_TIM_EnableIT_CC3(TIM2); } -bool furi_hal_irda_is_busy(void) { - return furi_hal_irda_state != IrdaStateIdle; +bool furi_hal_infrared_is_busy(void) { + return furi_hal_infrared_state != InfraredStateIdle; } -void furi_hal_irda_async_rx_set_capture_isr_callback( - FuriHalIrdaRxCaptureCallback callback, +void furi_hal_infrared_async_rx_set_capture_isr_callback( + FuriHalInfraredRxCaptureCallback callback, void* ctx) { - irda_tim_rx.capture_callback = callback; - irda_tim_rx.capture_context = ctx; + infrared_tim_rx.capture_callback = callback; + infrared_tim_rx.capture_context = ctx; } -void furi_hal_irda_async_rx_set_timeout_isr_callback( - FuriHalIrdaRxTimeoutCallback callback, +void furi_hal_infrared_async_rx_set_timeout_isr_callback( + FuriHalInfraredRxTimeoutCallback callback, void* ctx) { - irda_tim_rx.timeout_callback = callback; - irda_tim_rx.timeout_context = ctx; + infrared_tim_rx.timeout_callback = callback; + infrared_tim_rx.timeout_context = ctx; } -static void furi_hal_irda_tx_dma_terminate(void) { +static void furi_hal_infrared_tx_dma_terminate(void) { LL_DMA_DisableIT_TC(DMA1, LL_DMA_CHANNEL_1); LL_DMA_DisableIT_HT(DMA1, LL_DMA_CHANNEL_2); LL_DMA_DisableIT_TC(DMA1, LL_DMA_CHANNEL_2); - furi_assert(furi_hal_irda_state == IrdaStateAsyncTxStopInProgress); + furi_assert(furi_hal_infrared_state == InfraredStateAsyncTxStopInProgress); LL_DMA_DisableIT_TC(DMA1, LL_DMA_CHANNEL_1); LL_DMA_DisableChannel(DMA1, LL_DMA_CHANNEL_2); LL_DMA_DisableChannel(DMA1, LL_DMA_CHANNEL_1); LL_TIM_DisableCounter(TIM1); - osStatus_t status = osSemaphoreRelease(irda_tim_tx.stop_semaphore); + osStatus_t status = osSemaphoreRelease(infrared_tim_tx.stop_semaphore); furi_check(status == osOK); - furi_hal_irda_state = IrdaStateAsyncTxStopped; + furi_hal_infrared_state = InfraredStateAsyncTxStopped; } -static uint8_t furi_hal_irda_get_current_dma_tx_buffer(void) { +static uint8_t furi_hal_infrared_get_current_dma_tx_buffer(void) { uint8_t buf_num = 0; uint32_t buffer_adr = LL_DMA_GetMemoryAddress(DMA1, LL_DMA_CHANNEL_2); - if(buffer_adr == (uint32_t)irda_tim_tx.buffer[0].data) { + if(buffer_adr == (uint32_t)infrared_tim_tx.buffer[0].data) { buf_num = 0; - } else if(buffer_adr == (uint32_t)irda_tim_tx.buffer[1].data) { + } else if(buffer_adr == (uint32_t)infrared_tim_tx.buffer[1].data) { buf_num = 1; } else { furi_assert(0); @@ -250,7 +251,7 @@ static uint8_t furi_hal_irda_get_current_dma_tx_buffer(void) { return buf_num; } -static void furi_hal_irda_tx_dma_polarity_isr() { +static void furi_hal_infrared_tx_dma_polarity_isr() { if(LL_DMA_IsActiveFlag_TE1(DMA1)) { LL_DMA_ClearFlag_TE1(DMA1); furi_crash(NULL); @@ -259,33 +260,34 @@ static void furi_hal_irda_tx_dma_polarity_isr() { LL_DMA_ClearFlag_TC1(DMA1); furi_check( - (furi_hal_irda_state == IrdaStateAsyncTx) || - (furi_hal_irda_state == IrdaStateAsyncTxStopReq) || - (furi_hal_irda_state == IrdaStateAsyncTxStopInProgress)); + (furi_hal_infrared_state == InfraredStateAsyncTx) || + (furi_hal_infrared_state == InfraredStateAsyncTxStopReq) || + (furi_hal_infrared_state == InfraredStateAsyncTxStopInProgress)); /* actually TC2 is processed and buffer is next buffer */ - uint8_t next_buf_num = furi_hal_irda_get_current_dma_tx_buffer(); - furi_hal_irda_tx_dma_set_polarity(next_buf_num, 0); + uint8_t next_buf_num = furi_hal_infrared_get_current_dma_tx_buffer(); + furi_hal_infrared_tx_dma_set_polarity(next_buf_num, 0); } } -static void furi_hal_irda_tx_dma_isr() { +static void furi_hal_infrared_tx_dma_isr() { if(LL_DMA_IsActiveFlag_TE2(DMA1)) { LL_DMA_ClearFlag_TE2(DMA1); furi_crash(NULL); } if(LL_DMA_IsActiveFlag_HT2(DMA1) && LL_DMA_IsEnabledIT_HT(DMA1, LL_DMA_CHANNEL_2)) { LL_DMA_ClearFlag_HT2(DMA1); - uint8_t buf_num = furi_hal_irda_get_current_dma_tx_buffer(); + uint8_t buf_num = furi_hal_infrared_get_current_dma_tx_buffer(); uint8_t next_buf_num = !buf_num; - if(irda_tim_tx.buffer[buf_num].last_packet_end) { + if(infrared_tim_tx.buffer[buf_num].last_packet_end) { LL_DMA_DisableIT_HT(DMA1, LL_DMA_CHANNEL_2); } else if( - !irda_tim_tx.buffer[buf_num].packet_end || (furi_hal_irda_state == IrdaStateAsyncTx)) { - furi_hal_irda_tx_fill_buffer(next_buf_num, 0); - if(irda_tim_tx.buffer[next_buf_num].last_packet_end) { + !infrared_tim_tx.buffer[buf_num].packet_end || + (furi_hal_infrared_state == InfraredStateAsyncTx)) { + furi_hal_infrared_tx_fill_buffer(next_buf_num, 0); + if(infrared_tim_tx.buffer[next_buf_num].last_packet_end) { LL_DMA_DisableIT_HT(DMA1, LL_DMA_CHANNEL_2); } - } else if(furi_hal_irda_state == IrdaStateAsyncTxStopReq) { + } else if(furi_hal_infrared_state == InfraredStateAsyncTxStopReq) { /* fallthrough */ } else { furi_crash(NULL); @@ -294,33 +296,33 @@ static void furi_hal_irda_tx_dma_isr() { if(LL_DMA_IsActiveFlag_TC2(DMA1) && LL_DMA_IsEnabledIT_TC(DMA1, LL_DMA_CHANNEL_2)) { LL_DMA_ClearFlag_TC2(DMA1); furi_check( - (furi_hal_irda_state == IrdaStateAsyncTxStopInProgress) || - (furi_hal_irda_state == IrdaStateAsyncTxStopReq) || - (furi_hal_irda_state == IrdaStateAsyncTx)); + (furi_hal_infrared_state == InfraredStateAsyncTxStopInProgress) || + (furi_hal_infrared_state == InfraredStateAsyncTxStopReq) || + (furi_hal_infrared_state == InfraredStateAsyncTx)); - uint8_t buf_num = furi_hal_irda_get_current_dma_tx_buffer(); + uint8_t buf_num = furi_hal_infrared_get_current_dma_tx_buffer(); uint8_t next_buf_num = !buf_num; - if(furi_hal_irda_state == IrdaStateAsyncTxStopInProgress) { - furi_hal_irda_tx_dma_terminate(); + if(furi_hal_infrared_state == InfraredStateAsyncTxStopInProgress) { + furi_hal_infrared_tx_dma_terminate(); } else if( - irda_tim_tx.buffer[buf_num].last_packet_end || - (irda_tim_tx.buffer[buf_num].packet_end && - (furi_hal_irda_state == IrdaStateAsyncTxStopReq))) { - furi_hal_irda_state = IrdaStateAsyncTxStopInProgress; - furi_hal_irda_tx_fill_buffer_last(next_buf_num); - furi_hal_irda_tx_dma_set_buffer(next_buf_num); + infrared_tim_tx.buffer[buf_num].last_packet_end || + (infrared_tim_tx.buffer[buf_num].packet_end && + (furi_hal_infrared_state == InfraredStateAsyncTxStopReq))) { + furi_hal_infrared_state = InfraredStateAsyncTxStopInProgress; + furi_hal_infrared_tx_fill_buffer_last(next_buf_num); + furi_hal_infrared_tx_dma_set_buffer(next_buf_num); } else { /* if it's not end of the packet - continue receiving */ - furi_hal_irda_tx_dma_set_buffer(next_buf_num); + furi_hal_infrared_tx_dma_set_buffer(next_buf_num); } - if(irda_tim_tx.signal_sent_callback && irda_tim_tx.buffer[buf_num].packet_end && - (furi_hal_irda_state != IrdaStateAsyncTxStopped)) { - irda_tim_tx.signal_sent_callback(irda_tim_tx.signal_sent_context); + if(infrared_tim_tx.signal_sent_callback && infrared_tim_tx.buffer[buf_num].packet_end && + (furi_hal_infrared_state != InfraredStateAsyncTxStopped)) { + infrared_tim_tx.signal_sent_callback(infrared_tim_tx.signal_sent_context); } } } -static void furi_hal_irda_configure_tim_pwm_tx(uint32_t freq, float duty_cycle) { +static void furi_hal_infrared_configure_tim_pwm_tx(uint32_t freq, float duty_cycle) { LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_TIM1); /* LL_DBGMCU_APB2_GRP1_FreezePeriph(LL_DBGMCU_APB2_GRP1_TIM1_STOP); */ @@ -332,7 +334,7 @@ static void furi_hal_irda_configure_tim_pwm_tx(uint32_t freq, float duty_cycle) LL_TIM_EnableARRPreload(TIM1); LL_TIM_SetAutoReload( TIM1, __LL_TIM_CALC_ARR(SystemCoreClock, LL_TIM_GetPrescaler(TIM1), freq)); -#if IRDA_TX_DEBUG == 1 +#if INFRARED_TX_DEBUG == 1 LL_TIM_OC_SetCompareCH1(TIM1, ((LL_TIM_GetAutoReload(TIM1) + 1) * (1 - duty_cycle))); LL_TIM_OC_EnablePreload(TIM1, LL_TIM_CHANNEL_CH1); /* LL_TIM_OCMODE_PWM2 set by DMA */ @@ -360,11 +362,11 @@ static void furi_hal_irda_configure_tim_pwm_tx(uint32_t freq, float duty_cycle) NVIC_EnableIRQ(TIM1_UP_TIM16_IRQn); } -static void furi_hal_irda_configure_tim_cmgr2_dma_tx(void) { +static void furi_hal_infrared_configure_tim_cmgr2_dma_tx(void) { LL_C2_AHB1_GRP1_EnableClock(LL_C2_AHB1_GRP1_PERIPH_DMA1); LL_DMA_InitTypeDef dma_config = {0}; -#if IRDA_TX_DEBUG == 1 +#if INFRARED_TX_DEBUG == 1 dma_config.PeriphOrM2MSrcAddress = (uint32_t) & (TIM1->CCMR1); #else dma_config.PeriphOrM2MSrcAddress = (uint32_t) & (TIM1->CCMR2); @@ -382,7 +384,7 @@ static void furi_hal_irda_configure_tim_cmgr2_dma_tx(void) { dma_config.Priority = LL_DMA_PRIORITY_VERYHIGH; LL_DMA_Init(DMA1, LL_DMA_CHANNEL_1, &dma_config); furi_hal_interrupt_set_dma_channel_isr( - DMA1, LL_DMA_CHANNEL_1, furi_hal_irda_tx_dma_polarity_isr); + DMA1, LL_DMA_CHANNEL_1, furi_hal_infrared_tx_dma_polarity_isr); LL_DMA_ClearFlag_TE1(DMA1); LL_DMA_ClearFlag_TC1(DMA1); LL_DMA_EnableIT_TE(DMA1, LL_DMA_CHANNEL_1); @@ -392,7 +394,7 @@ static void furi_hal_irda_configure_tim_cmgr2_dma_tx(void) { NVIC_EnableIRQ(DMA1_Channel1_IRQn); } -static void furi_hal_irda_configure_tim_rcr_dma_tx(void) { +static void furi_hal_infrared_configure_tim_rcr_dma_tx(void) { LL_C2_AHB1_GRP1_EnableClock(LL_C2_AHB1_GRP1_PERIPH_DMA1); LL_DMA_InitTypeDef dma_config = {0}; @@ -408,7 +410,7 @@ static void furi_hal_irda_configure_tim_rcr_dma_tx(void) { dma_config.PeriphRequest = LL_DMAMUX_REQ_TIM1_UP; dma_config.Priority = LL_DMA_PRIORITY_MEDIUM; LL_DMA_Init(DMA1, LL_DMA_CHANNEL_2, &dma_config); - furi_hal_interrupt_set_dma_channel_isr(DMA1, LL_DMA_CHANNEL_2, furi_hal_irda_tx_dma_isr); + furi_hal_interrupt_set_dma_channel_isr(DMA1, LL_DMA_CHANNEL_2, furi_hal_infrared_tx_dma_isr); LL_DMA_ClearFlag_TC2(DMA1); LL_DMA_ClearFlag_HT2(DMA1); LL_DMA_ClearFlag_TE2(DMA1); @@ -420,100 +422,102 @@ static void furi_hal_irda_configure_tim_rcr_dma_tx(void) { NVIC_EnableIRQ(DMA1_Channel2_IRQn); } -static void furi_hal_irda_tx_fill_buffer_last(uint8_t buf_num) { +static void furi_hal_infrared_tx_fill_buffer_last(uint8_t buf_num) { furi_assert(buf_num < 2); - furi_assert(furi_hal_irda_state != IrdaStateAsyncRx); - furi_assert(furi_hal_irda_state < IrdaStateMAX); - furi_assert(irda_tim_tx.data_callback); - IrdaTxBuf* buffer = &irda_tim_tx.buffer[buf_num]; + furi_assert(furi_hal_infrared_state != InfraredStateAsyncRx); + furi_assert(furi_hal_infrared_state < InfraredStateMAX); + furi_assert(infrared_tim_tx.data_callback); + InfraredTxBuf* buffer = &infrared_tim_tx.buffer[buf_num]; furi_assert(buffer->data != NULL); (void)buffer->data; furi_assert(buffer->polarity != NULL); (void)buffer->polarity; - irda_tim_tx.buffer[buf_num].data[0] = 0; // 1 pulse - irda_tim_tx.buffer[buf_num].polarity[0] = IRDA_TX_CCMR_LOW; - irda_tim_tx.buffer[buf_num].data[1] = 0; // 1 pulse - irda_tim_tx.buffer[buf_num].polarity[1] = IRDA_TX_CCMR_LOW; - irda_tim_tx.buffer[buf_num].size = 2; - irda_tim_tx.buffer[buf_num].last_packet_end = true; - irda_tim_tx.buffer[buf_num].packet_end = true; + infrared_tim_tx.buffer[buf_num].data[0] = 0; // 1 pulse + infrared_tim_tx.buffer[buf_num].polarity[0] = INFRARED_TX_CCMR_LOW; + infrared_tim_tx.buffer[buf_num].data[1] = 0; // 1 pulse + infrared_tim_tx.buffer[buf_num].polarity[1] = INFRARED_TX_CCMR_LOW; + infrared_tim_tx.buffer[buf_num].size = 2; + infrared_tim_tx.buffer[buf_num].last_packet_end = true; + infrared_tim_tx.buffer[buf_num].packet_end = true; } -static void furi_hal_irda_tx_fill_buffer(uint8_t buf_num, uint8_t polarity_shift) { +static void furi_hal_infrared_tx_fill_buffer(uint8_t buf_num, uint8_t polarity_shift) { furi_assert(buf_num < 2); - furi_assert(furi_hal_irda_state != IrdaStateAsyncRx); - furi_assert(furi_hal_irda_state < IrdaStateMAX); - furi_assert(irda_tim_tx.data_callback); - IrdaTxBuf* buffer = &irda_tim_tx.buffer[buf_num]; + furi_assert(furi_hal_infrared_state != InfraredStateAsyncRx); + furi_assert(furi_hal_infrared_state < InfraredStateMAX); + furi_assert(infrared_tim_tx.data_callback); + InfraredTxBuf* buffer = &infrared_tim_tx.buffer[buf_num]; furi_assert(buffer->data != NULL); furi_assert(buffer->polarity != NULL); - FuriHalIrdaTxGetDataState status = FuriHalIrdaTxGetDataStateOk; + FuriHalInfraredTxGetDataState status = FuriHalInfraredTxGetDataStateOk; uint32_t duration = 0; bool level = 0; size_t* size = &buffer->size; size_t polarity_counter = 0; while(polarity_shift--) { - buffer->polarity[polarity_counter++] = IRDA_TX_CCMR_LOW; + buffer->polarity[polarity_counter++] = INFRARED_TX_CCMR_LOW; } - for(*size = 0; - (*size < IRDA_TIM_TX_DMA_BUFFER_SIZE) && (status == FuriHalIrdaTxGetDataStateOk);) { - if(irda_tim_tx.tx_timing_rest_duration > 0) { - if(irda_tim_tx.tx_timing_rest_duration > 0xFFFF) { + for(*size = 0; (*size < INFRARED_TIM_TX_DMA_BUFFER_SIZE) && + (status == FuriHalInfraredTxGetDataStateOk);) { + if(infrared_tim_tx.tx_timing_rest_duration > 0) { + if(infrared_tim_tx.tx_timing_rest_duration > 0xFFFF) { buffer->data[*size] = 0xFFFF; - status = FuriHalIrdaTxGetDataStateOk; + status = FuriHalInfraredTxGetDataStateOk; } else { - buffer->data[*size] = irda_tim_tx.tx_timing_rest_duration; - status = irda_tim_tx.tx_timing_rest_status; + buffer->data[*size] = infrared_tim_tx.tx_timing_rest_duration; + status = infrared_tim_tx.tx_timing_rest_status; } - irda_tim_tx.tx_timing_rest_duration -= buffer->data[*size]; - buffer->polarity[polarity_counter] = - irda_tim_tx.tx_timing_rest_level ? IRDA_TX_CCMR_HIGH : IRDA_TX_CCMR_LOW; + infrared_tim_tx.tx_timing_rest_duration -= buffer->data[*size]; + buffer->polarity[polarity_counter] = infrared_tim_tx.tx_timing_rest_level ? + INFRARED_TX_CCMR_HIGH : + INFRARED_TX_CCMR_LOW; ++(*size); ++polarity_counter; continue; } - status = irda_tim_tx.data_callback(irda_tim_tx.data_context, &duration, &level); + status = infrared_tim_tx.data_callback(infrared_tim_tx.data_context, &duration, &level); - uint32_t num_of_impulses = roundf(duration / irda_tim_tx.cycle_duration); + uint32_t num_of_impulses = roundf(duration / infrared_tim_tx.cycle_duration); if(num_of_impulses == 0) { - if((*size == 0) && (status == FuriHalIrdaTxGetDataStateDone)) { + if((*size == 0) && (status == FuriHalInfraredTxGetDataStateDone)) { /* if this is one sample in current buffer, but we * have more to send - continue */ - status = FuriHalIrdaTxGetDataStateOk; + status = FuriHalInfraredTxGetDataStateOk; } } else if((num_of_impulses - 1) > 0xFFFF) { - irda_tim_tx.tx_timing_rest_duration = num_of_impulses - 1; - irda_tim_tx.tx_timing_rest_status = status; - irda_tim_tx.tx_timing_rest_level = level; - status = FuriHalIrdaTxGetDataStateOk; + infrared_tim_tx.tx_timing_rest_duration = num_of_impulses - 1; + infrared_tim_tx.tx_timing_rest_status = status; + infrared_tim_tx.tx_timing_rest_level = level; + status = FuriHalInfraredTxGetDataStateOk; } else { - buffer->polarity[polarity_counter] = level ? IRDA_TX_CCMR_HIGH : IRDA_TX_CCMR_LOW; + buffer->polarity[polarity_counter] = level ? INFRARED_TX_CCMR_HIGH : + INFRARED_TX_CCMR_LOW; buffer->data[*size] = num_of_impulses - 1; ++(*size); ++polarity_counter; } } - buffer->last_packet_end = (status == FuriHalIrdaTxGetDataStateLastDone); - buffer->packet_end = buffer->last_packet_end || (status == FuriHalIrdaTxGetDataStateDone); + buffer->last_packet_end = (status == FuriHalInfraredTxGetDataStateLastDone); + buffer->packet_end = buffer->last_packet_end || (status == FuriHalInfraredTxGetDataStateDone); if(*size == 0) { buffer->data[0] = 0; // 1 pulse - buffer->polarity[0] = IRDA_TX_CCMR_LOW; + buffer->polarity[0] = INFRARED_TX_CCMR_LOW; buffer->size = 1; } } -static void furi_hal_irda_tx_dma_set_polarity(uint8_t buf_num, uint8_t polarity_shift) { +static void furi_hal_infrared_tx_dma_set_polarity(uint8_t buf_num, uint8_t polarity_shift) { furi_assert(buf_num < 2); - furi_assert(furi_hal_irda_state < IrdaStateMAX); - IrdaTxBuf* buffer = &irda_tim_tx.buffer[buf_num]; + furi_assert(furi_hal_infrared_state < InfraredStateMAX); + InfraredTxBuf* buffer = &infrared_tim_tx.buffer[buf_num]; furi_assert(buffer->polarity != NULL); FURI_CRITICAL_ENTER(); @@ -529,10 +533,10 @@ static void furi_hal_irda_tx_dma_set_polarity(uint8_t buf_num, uint8_t polarity_ FURI_CRITICAL_EXIT(); } -static void furi_hal_irda_tx_dma_set_buffer(uint8_t buf_num) { +static void furi_hal_infrared_tx_dma_set_buffer(uint8_t buf_num) { furi_assert(buf_num < 2); - furi_assert(furi_hal_irda_state < IrdaStateMAX); - IrdaTxBuf* buffer = &irda_tim_tx.buffer[buf_num]; + furi_assert(furi_hal_infrared_state < InfraredStateMAX); + InfraredTxBuf* buffer = &infrared_tim_tx.buffer[buf_num]; furi_assert(buffer->data != NULL); /* non-circular mode requires disabled channel before setup */ @@ -549,66 +553,66 @@ static void furi_hal_irda_tx_dma_set_buffer(uint8_t buf_num) { FURI_CRITICAL_EXIT(); } -static void furi_hal_irda_async_tx_free_resources(void) { +static void furi_hal_infrared_async_tx_free_resources(void) { furi_assert( - (furi_hal_irda_state == IrdaStateIdle) || - (furi_hal_irda_state == IrdaStateAsyncTxStopped)); + (furi_hal_infrared_state == InfraredStateIdle) || + (furi_hal_infrared_state == InfraredStateAsyncTxStopped)); osStatus_t status; - hal_gpio_init(&gpio_irda_tx, GpioModeOutputOpenDrain, GpioPullDown, GpioSpeedLow); + hal_gpio_init(&gpio_infrared_tx, GpioModeOutputOpenDrain, GpioPullDown, GpioSpeedLow); furi_hal_interrupt_set_dma_channel_isr(DMA1, LL_DMA_CHANNEL_1, NULL); furi_hal_interrupt_set_dma_channel_isr(DMA1, LL_DMA_CHANNEL_2, NULL); LL_TIM_DeInit(TIM1); LL_APB2_GRP1_DisableClock(LL_APB2_GRP1_PERIPH_TIM1); LL_C2_AHB1_GRP1_DisableClock(LL_C2_AHB1_GRP1_PERIPH_DMA1); - status = osSemaphoreDelete(irda_tim_tx.stop_semaphore); + status = osSemaphoreDelete(infrared_tim_tx.stop_semaphore); furi_check(status == osOK); - free(irda_tim_tx.buffer[0].data); - free(irda_tim_tx.buffer[1].data); - free(irda_tim_tx.buffer[0].polarity); - free(irda_tim_tx.buffer[1].polarity); + free(infrared_tim_tx.buffer[0].data); + free(infrared_tim_tx.buffer[1].data); + free(infrared_tim_tx.buffer[0].polarity); + free(infrared_tim_tx.buffer[1].polarity); - irda_tim_tx.buffer[0].data = NULL; - irda_tim_tx.buffer[1].data = NULL; - irda_tim_tx.buffer[0].polarity = NULL; - irda_tim_tx.buffer[1].polarity = NULL; + infrared_tim_tx.buffer[0].data = NULL; + infrared_tim_tx.buffer[1].data = NULL; + infrared_tim_tx.buffer[0].polarity = NULL; + infrared_tim_tx.buffer[1].polarity = NULL; } -void furi_hal_irda_async_tx_start(uint32_t freq, float duty_cycle) { - if((duty_cycle > 1) || (duty_cycle <= 0) || (freq > IRDA_MAX_FREQUENCY) || - (freq < IRDA_MIN_FREQUENCY) || (irda_tim_tx.data_callback == NULL)) { +void furi_hal_infrared_async_tx_start(uint32_t freq, float duty_cycle) { + if((duty_cycle > 1) || (duty_cycle <= 0) || (freq > INFRARED_MAX_FREQUENCY) || + (freq < INFRARED_MIN_FREQUENCY) || (infrared_tim_tx.data_callback == NULL)) { furi_crash(NULL); } - furi_assert(furi_hal_irda_state == IrdaStateIdle); - furi_assert(irda_tim_tx.buffer[0].data == NULL); - furi_assert(irda_tim_tx.buffer[1].data == NULL); - furi_assert(irda_tim_tx.buffer[0].polarity == NULL); - furi_assert(irda_tim_tx.buffer[1].polarity == NULL); + furi_assert(furi_hal_infrared_state == InfraredStateIdle); + furi_assert(infrared_tim_tx.buffer[0].data == NULL); + furi_assert(infrared_tim_tx.buffer[1].data == NULL); + furi_assert(infrared_tim_tx.buffer[0].polarity == NULL); + furi_assert(infrared_tim_tx.buffer[1].polarity == NULL); - size_t alloc_size_data = IRDA_TIM_TX_DMA_BUFFER_SIZE * sizeof(uint16_t); - irda_tim_tx.buffer[0].data = malloc(alloc_size_data); - irda_tim_tx.buffer[1].data = malloc(alloc_size_data); + size_t alloc_size_data = INFRARED_TIM_TX_DMA_BUFFER_SIZE * sizeof(uint16_t); + infrared_tim_tx.buffer[0].data = malloc(alloc_size_data); + infrared_tim_tx.buffer[1].data = malloc(alloc_size_data); size_t alloc_size_polarity = - (IRDA_TIM_TX_DMA_BUFFER_SIZE + IRDA_POLARITY_SHIFT) * sizeof(uint8_t); - irda_tim_tx.buffer[0].polarity = malloc(alloc_size_polarity); - irda_tim_tx.buffer[1].polarity = malloc(alloc_size_polarity); + (INFRARED_TIM_TX_DMA_BUFFER_SIZE + INFRARED_POLARITY_SHIFT) * sizeof(uint8_t); + infrared_tim_tx.buffer[0].polarity = malloc(alloc_size_polarity); + infrared_tim_tx.buffer[1].polarity = malloc(alloc_size_polarity); - irda_tim_tx.stop_semaphore = osSemaphoreNew(1, 0, NULL); - irda_tim_tx.cycle_duration = 1000000.0 / freq; - irda_tim_tx.tx_timing_rest_duration = 0; + infrared_tim_tx.stop_semaphore = osSemaphoreNew(1, 0, NULL); + infrared_tim_tx.cycle_duration = 1000000.0 / freq; + infrared_tim_tx.tx_timing_rest_duration = 0; - furi_hal_irda_tx_fill_buffer(0, IRDA_POLARITY_SHIFT); + furi_hal_infrared_tx_fill_buffer(0, INFRARED_POLARITY_SHIFT); - furi_hal_irda_configure_tim_pwm_tx(freq, duty_cycle); - furi_hal_irda_configure_tim_cmgr2_dma_tx(); - furi_hal_irda_configure_tim_rcr_dma_tx(); - furi_hal_irda_tx_dma_set_polarity(0, IRDA_POLARITY_SHIFT); - furi_hal_irda_tx_dma_set_buffer(0); + furi_hal_infrared_configure_tim_pwm_tx(freq, duty_cycle); + furi_hal_infrared_configure_tim_cmgr2_dma_tx(); + furi_hal_infrared_configure_tim_rcr_dma_tx(); + furi_hal_infrared_tx_dma_set_polarity(0, INFRARED_POLARITY_SHIFT); + furi_hal_infrared_tx_dma_set_buffer(0); - furi_hal_irda_state = IrdaStateAsyncTx; + furi_hal_infrared_state = InfraredStateAsyncTx; LL_TIM_ClearFlag_UPDATE(TIM1); LL_DMA_EnableChannel(DMA1, LL_DMA_CHANNEL_1); @@ -617,9 +621,9 @@ void furi_hal_irda_async_tx_start(uint32_t freq, float duty_cycle) { LL_TIM_GenerateEvent_UPDATE(TIM1); /* DMA -> TIMx_RCR */ delay_us(5); LL_GPIO_ResetOutputPin( - gpio_irda_tx.port, gpio_irda_tx.pin); /* when disable it prevents false pulse */ + gpio_infrared_tx.port, gpio_infrared_tx.pin); /* when disable it prevents false pulse */ hal_gpio_init_ex( - &gpio_irda_tx, GpioModeAltFunctionPushPull, GpioPullUp, GpioSpeedHigh, GpioAltFn1TIM1); + &gpio_infrared_tx, GpioModeAltFunctionPushPull, GpioPullUp, GpioSpeedHigh, GpioAltFn1TIM1); FURI_CRITICAL_ENTER(); LL_TIM_GenerateEvent_UPDATE(TIM1); /* TIMx_RCR -> Repetition counter */ @@ -627,39 +631,40 @@ void furi_hal_irda_async_tx_start(uint32_t freq, float duty_cycle) { FURI_CRITICAL_EXIT(); } -void furi_hal_irda_async_tx_wait_termination(void) { - furi_assert(furi_hal_irda_state >= IrdaStateAsyncTx); - furi_assert(furi_hal_irda_state < IrdaStateMAX); +void furi_hal_infrared_async_tx_wait_termination(void) { + furi_assert(furi_hal_infrared_state >= InfraredStateAsyncTx); + furi_assert(furi_hal_infrared_state < InfraredStateMAX); osStatus_t status; - status = osSemaphoreAcquire(irda_tim_tx.stop_semaphore, osWaitForever); + status = osSemaphoreAcquire(infrared_tim_tx.stop_semaphore, osWaitForever); furi_check(status == osOK); - furi_hal_irda_async_tx_free_resources(); - furi_hal_irda_state = IrdaStateIdle; + furi_hal_infrared_async_tx_free_resources(); + furi_hal_infrared_state = InfraredStateIdle; } -void furi_hal_irda_async_tx_stop(void) { - furi_assert(furi_hal_irda_state >= IrdaStateAsyncTx); - furi_assert(furi_hal_irda_state < IrdaStateMAX); +void furi_hal_infrared_async_tx_stop(void) { + furi_assert(furi_hal_infrared_state >= InfraredStateAsyncTx); + furi_assert(furi_hal_infrared_state < InfraredStateMAX); FURI_CRITICAL_ENTER(); - if(furi_hal_irda_state == IrdaStateAsyncTx) furi_hal_irda_state = IrdaStateAsyncTxStopReq; + if(furi_hal_infrared_state == InfraredStateAsyncTx) + furi_hal_infrared_state = InfraredStateAsyncTxStopReq; FURI_CRITICAL_EXIT(); - furi_hal_irda_async_tx_wait_termination(); + furi_hal_infrared_async_tx_wait_termination(); } -void furi_hal_irda_async_tx_set_data_isr_callback( - FuriHalIrdaTxGetDataISRCallback callback, +void furi_hal_infrared_async_tx_set_data_isr_callback( + FuriHalInfraredTxGetDataISRCallback callback, void* context) { - furi_assert(furi_hal_irda_state == IrdaStateIdle); - irda_tim_tx.data_callback = callback; - irda_tim_tx.data_context = context; + furi_assert(furi_hal_infrared_state == InfraredStateIdle); + infrared_tim_tx.data_callback = callback; + infrared_tim_tx.data_context = context; } -void furi_hal_irda_async_tx_set_signal_sent_isr_callback( - FuriHalIrdaTxSignalSentISRCallback callback, +void furi_hal_infrared_async_tx_set_signal_sent_isr_callback( + FuriHalInfraredTxSignalSentISRCallback callback, void* context) { - irda_tim_tx.signal_sent_callback = callback; - irda_tim_tx.signal_sent_context = context; + infrared_tim_tx.signal_sent_callback = callback; + infrared_tim_tx.signal_sent_context = context; } diff --git a/firmware/targets/f6/furi_hal/furi_hal_resources.c b/firmware/targets/f6/furi_hal/furi_hal_resources.c index 670fd555..dbf9fc68 100644 --- a/firmware/targets/f6/furi_hal/furi_hal_resources.c +++ b/firmware/targets/f6/furi_hal/furi_hal_resources.c @@ -70,8 +70,8 @@ const GpioPin gpio_rfid_pull = {.port = RFID_PULL_GPIO_Port, .pin = RFID_PULL_Pi const GpioPin gpio_rfid_carrier_out = {.port = RFID_OUT_GPIO_Port, .pin = RFID_OUT_Pin}; const GpioPin gpio_rfid_data_in = {.port = RFID_RF_IN_GPIO_Port, .pin = RFID_RF_IN_Pin}; -const GpioPin gpio_irda_rx = {.port = IR_RX_GPIO_Port, .pin = IR_RX_Pin}; -const GpioPin gpio_irda_tx = {.port = IR_TX_GPIO_Port, .pin = IR_TX_Pin}; +const GpioPin gpio_infrared_rx = {.port = IR_RX_GPIO_Port, .pin = IR_RX_Pin}; +const GpioPin gpio_infrared_tx = {.port = IR_TX_GPIO_Port, .pin = IR_TX_Pin}; const GpioPin gpio_usart_tx = {.port = USART1_TX_Port, .pin = USART1_TX_Pin}; const GpioPin gpio_usart_rx = {.port = USART1_RX_Port, .pin = USART1_RX_Pin}; diff --git a/firmware/targets/f6/furi_hal/furi_hal_resources.h b/firmware/targets/f6/furi_hal/furi_hal_resources.h index f55cf44e..2a090b45 100644 --- a/firmware/targets/f6/furi_hal/furi_hal_resources.h +++ b/firmware/targets/f6/furi_hal/furi_hal_resources.h @@ -75,8 +75,8 @@ extern const GpioPin gpio_rfid_pull; extern const GpioPin gpio_rfid_carrier_out; extern const GpioPin gpio_rfid_data_in; -extern const GpioPin gpio_irda_rx; -extern const GpioPin gpio_irda_tx; +extern const GpioPin gpio_infrared_rx; +extern const GpioPin gpio_infrared_tx; extern const GpioPin gpio_usart_tx; extern const GpioPin gpio_usart_rx; diff --git a/firmware/targets/f7/Inc/main.h b/firmware/targets/f7/Inc/main.h index 8c53e34c..88325611 100644 --- a/firmware/targets/f7/Inc/main.h +++ b/firmware/targets/f7/Inc/main.h @@ -131,15 +131,15 @@ extern TIM_HandleTypeDef htim16; #define LFRFID_TIM htim1 #define LFRFID_CH TIM_CHANNEL_1 -#define IRDA_TX_TIM htim1 -#define IRDA_TX_CH TIM_CHANNEL_3 +#define INFRARED_TX_TIM htim1 +#define INFRARED_TX_CH TIM_CHANNEL_3 // only for reference -// IRDA RX timer dont exist in F2 +// INFRARED RX timer dont exist in F2 // and timer need more data to init (NVIC IRQn to set priority) -#define IRDA_RX_TIM htim2 -#define IRDA_RX_FALLING_CH TIM_CHANNEL_1 -#define IRDA_RX_RISING_CH TIM_CHANNEL_2 +#define INFRARED_RX_TIM htim2 +#define INFRARED_RX_FALLING_CH TIM_CHANNEL_1 +#define INFRARED_RX_RISING_CH TIM_CHANNEL_2 #define NFC_IRQ_Pin RFID_PULL_Pin #define NFC_IRQ_GPIO_Port RFID_PULL_GPIO_Port diff --git a/firmware/targets/f7/furi_hal/furi_hal_irda.c b/firmware/targets/f7/furi_hal/furi_hal_infrared.c similarity index 50% rename from firmware/targets/f7/furi_hal/furi_hal_irda.c rename to firmware/targets/f7/furi_hal/furi_hal_infrared.c index 6fe051a9..765885b9 100644 --- a/firmware/targets/f7/furi_hal/furi_hal_irda.c +++ b/firmware/targets/f7/furi_hal/furi_hal_infrared.c @@ -1,4 +1,4 @@ -#include "furi_hal_irda.h" +#include "furi_hal_infrared.h" #include "furi_hal_delay.h" #include "furi/check.h" #include "stm32wbxx_ll_dma.h" @@ -17,26 +17,27 @@ #include #include -#define IRDA_TX_DEBUG 0 +#define INFRARED_TX_DEBUG 0 -#if IRDA_TX_DEBUG == 1 -#define gpio_irda_tx gpio_irda_tx_debug -const GpioPin gpio_irda_tx_debug = {.port = GPIOA, .pin = GPIO_PIN_7}; +#if INFRARED_TX_DEBUG == 1 +#define gpio_infrared_tx gpio_infrared_tx_debug +const GpioPin gpio_infrared_tx_debug = {.port = GPIOA, .pin = GPIO_PIN_7}; #endif -#define IRDA_TIM_TX_DMA_BUFFER_SIZE 200 -#define IRDA_POLARITY_SHIFT 1 +#define INFRARED_TIM_TX_DMA_BUFFER_SIZE 200 +#define INFRARED_POLARITY_SHIFT 1 -#define IRDA_TX_CCMR_HIGH (TIM_CCMR2_OC3PE | LL_TIM_OCMODE_PWM2) /* Mark time - enable PWM2 mode */ -#define IRDA_TX_CCMR_LOW \ +#define INFRARED_TX_CCMR_HIGH \ + (TIM_CCMR2_OC3PE | LL_TIM_OCMODE_PWM2) /* Mark time - enable PWM2 mode */ +#define INFRARED_TX_CCMR_LOW \ (TIM_CCMR2_OC3PE | LL_TIM_OCMODE_FORCED_INACTIVE) /* Space time - force low */ typedef struct { - FuriHalIrdaRxCaptureCallback capture_callback; + FuriHalInfraredRxCaptureCallback capture_callback; void* capture_context; - FuriHalIrdaRxTimeoutCallback timeout_callback; + FuriHalInfraredRxTimeoutCallback timeout_callback; void* timeout_context; -} IrdaTimRx; +} InfraredTimRx; typedef struct { uint8_t* polarity; @@ -44,52 +45,52 @@ typedef struct { size_t size; bool packet_end; bool last_packet_end; -} IrdaTxBuf; +} InfraredTxBuf; typedef struct { float cycle_duration; - FuriHalIrdaTxGetDataISRCallback data_callback; - FuriHalIrdaTxSignalSentISRCallback signal_sent_callback; + FuriHalInfraredTxGetDataISRCallback data_callback; + FuriHalInfraredTxSignalSentISRCallback signal_sent_callback; void* data_context; void* signal_sent_context; - IrdaTxBuf buffer[2]; + InfraredTxBuf buffer[2]; osSemaphoreId_t stop_semaphore; uint32_t tx_timing_rest_duration; /** if timing is too long (> 0xFFFF), send it in few iterations */ bool tx_timing_rest_level; - FuriHalIrdaTxGetDataState tx_timing_rest_status; -} IrdaTimTx; + FuriHalInfraredTxGetDataState tx_timing_rest_status; +} InfraredTimTx; typedef enum { - IrdaStateIdle, /** Furi Hal Irda is ready to start RX or TX */ - IrdaStateAsyncRx, /** Async RX started */ - IrdaStateAsyncTx, /** Async TX started, DMA and timer is on */ - IrdaStateAsyncTxStopReq, /** Async TX started, async stop request received */ - IrdaStateAsyncTxStopInProgress, /** Async TX started, stop request is processed and we wait for last data to be sent */ - IrdaStateAsyncTxStopped, /** Async TX complete, cleanup needed */ - IrdaStateMAX, -} IrdaState; + InfraredStateIdle, /** Furi Hal Infrared is ready to start RX or TX */ + InfraredStateAsyncRx, /** Async RX started */ + InfraredStateAsyncTx, /** Async TX started, DMA and timer is on */ + InfraredStateAsyncTxStopReq, /** Async TX started, async stop request received */ + InfraredStateAsyncTxStopInProgress, /** Async TX started, stop request is processed and we wait for last data to be sent */ + InfraredStateAsyncTxStopped, /** Async TX complete, cleanup needed */ + InfraredStateMAX, +} InfraredState; -static volatile IrdaState furi_hal_irda_state = IrdaStateIdle; -static IrdaTimTx irda_tim_tx; -static IrdaTimRx irda_tim_rx; +static volatile InfraredState furi_hal_infrared_state = InfraredStateIdle; +static InfraredTimTx infrared_tim_tx; +static InfraredTimRx infrared_tim_rx; -static void furi_hal_irda_tx_fill_buffer(uint8_t buf_num, uint8_t polarity_shift); -static void furi_hal_irda_async_tx_free_resources(void); -static void furi_hal_irda_tx_dma_set_polarity(uint8_t buf_num, uint8_t polarity_shift); -static void furi_hal_irda_tx_dma_set_buffer(uint8_t buf_num); -static void furi_hal_irda_tx_fill_buffer_last(uint8_t buf_num); -static uint8_t furi_hal_irda_get_current_dma_tx_buffer(void); -static void furi_hal_irda_tx_dma_polarity_isr(); -static void furi_hal_irda_tx_dma_isr(); +static void furi_hal_infrared_tx_fill_buffer(uint8_t buf_num, uint8_t polarity_shift); +static void furi_hal_infrared_async_tx_free_resources(void); +static void furi_hal_infrared_tx_dma_set_polarity(uint8_t buf_num, uint8_t polarity_shift); +static void furi_hal_infrared_tx_dma_set_buffer(uint8_t buf_num); +static void furi_hal_infrared_tx_fill_buffer_last(uint8_t buf_num); +static uint8_t furi_hal_infrared_get_current_dma_tx_buffer(void); +static void furi_hal_infrared_tx_dma_polarity_isr(); +static void furi_hal_infrared_tx_dma_isr(); -static void furi_hal_irda_tim_rx_isr() { +static void furi_hal_infrared_tim_rx_isr() { static uint32_t previous_captured_ch2 = 0; /* Timeout */ if(LL_TIM_IsActiveFlag_CC3(TIM2)) { LL_TIM_ClearFlag_CC3(TIM2); - furi_assert(furi_hal_irda_state == IrdaStateAsyncRx); + furi_assert(furi_hal_infrared_state == InfraredStateAsyncRx); /* Timers CNT register starts to counting from 0 to ARR, but it is * reseted when Channel 1 catches interrupt. It is not reseted by @@ -97,22 +98,22 @@ static void furi_hal_irda_tim_rx_isr() { * This can cause false timeout: when time is over, but we started * receiving new signal few microseconds ago, because CNT register * is reseted once per period, not per sample. */ - if(LL_GPIO_IsInputPinSet(gpio_irda_rx.port, gpio_irda_rx.pin) != 0) { - if(irda_tim_rx.timeout_callback) - irda_tim_rx.timeout_callback(irda_tim_rx.timeout_context); + if(LL_GPIO_IsInputPinSet(gpio_infrared_rx.port, gpio_infrared_rx.pin) != 0) { + if(infrared_tim_rx.timeout_callback) + infrared_tim_rx.timeout_callback(infrared_tim_rx.timeout_context); } } /* Rising Edge */ if(LL_TIM_IsActiveFlag_CC1(TIM2)) { LL_TIM_ClearFlag_CC1(TIM2); - furi_assert(furi_hal_irda_state == IrdaStateAsyncRx); + furi_assert(furi_hal_infrared_state == InfraredStateAsyncRx); if(READ_BIT(TIM2->CCMR1, TIM_CCMR1_CC1S)) { - /* Low pin level is a Mark state of IRDA signal. Invert level for further processing. */ + /* Low pin level is a Mark state of INFRARED signal. Invert level for further processing. */ uint32_t duration = LL_TIM_IC_GetCaptureCH1(TIM2) - previous_captured_ch2; - if(irda_tim_rx.capture_callback) - irda_tim_rx.capture_callback(irda_tim_rx.capture_context, 1, duration); + if(infrared_tim_rx.capture_callback) + infrared_tim_rx.capture_callback(infrared_tim_rx.capture_context, 1, duration); } else { furi_assert(0); } @@ -121,22 +122,22 @@ static void furi_hal_irda_tim_rx_isr() { /* Falling Edge */ if(LL_TIM_IsActiveFlag_CC2(TIM2)) { LL_TIM_ClearFlag_CC2(TIM2); - furi_assert(furi_hal_irda_state == IrdaStateAsyncRx); + furi_assert(furi_hal_infrared_state == InfraredStateAsyncRx); if(READ_BIT(TIM2->CCMR1, TIM_CCMR1_CC2S)) { - /* High pin level is a Space state of IRDA signal. Invert level for further processing. */ + /* High pin level is a Space state of INFRARED signal. Invert level for further processing. */ uint32_t duration = LL_TIM_IC_GetCaptureCH2(TIM2); previous_captured_ch2 = duration; - if(irda_tim_rx.capture_callback) - irda_tim_rx.capture_callback(irda_tim_rx.capture_context, 0, duration); + if(infrared_tim_rx.capture_callback) + infrared_tim_rx.capture_callback(infrared_tim_rx.capture_context, 0, duration); } else { furi_assert(0); } } } -void furi_hal_irda_async_rx_start(void) { - furi_assert(furi_hal_irda_state == IrdaStateIdle); +void furi_hal_infrared_async_rx_start(void) { + furi_assert(furi_hal_infrared_state == InfraredStateIdle); FURI_CRITICAL_ENTER(); LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_TIM2); @@ -144,7 +145,7 @@ void furi_hal_irda_async_rx_start(void) { FURI_CRITICAL_EXIT(); hal_gpio_init_ex( - &gpio_irda_rx, GpioModeAltFunctionPushPull, GpioPullNo, GpioSpeedLow, GpioAltFn1TIM2); + &gpio_infrared_rx, GpioModeAltFunctionPushPull, GpioPullNo, GpioSpeedLow, GpioAltFn1TIM2); LL_TIM_InitTypeDef TIM_InitStruct = {0}; TIM_InitStruct.Prescaler = 64 - 1; @@ -171,8 +172,8 @@ void furi_hal_irda_async_rx_start(void) { LL_TIM_IC_SetActiveInput(TIM2, LL_TIM_CHANNEL_CH2, LL_TIM_ACTIVEINPUT_INDIRECTTI); LL_TIM_IC_SetPrescaler(TIM2, LL_TIM_CHANNEL_CH2, LL_TIM_ICPSC_DIV1); - furi_hal_interrupt_set_timer_isr(TIM2, furi_hal_irda_tim_rx_isr); - furi_hal_irda_state = IrdaStateAsyncRx; + furi_hal_interrupt_set_timer_isr(TIM2, furi_hal_infrared_tim_rx_isr); + furi_hal_infrared_state = InfraredStateAsyncRx; LL_TIM_EnableIT_CC1(TIM2); LL_TIM_EnableIT_CC2(TIM2); @@ -186,15 +187,15 @@ void furi_hal_irda_async_rx_start(void) { NVIC_EnableIRQ(TIM2_IRQn); } -void furi_hal_irda_async_rx_stop(void) { - furi_assert(furi_hal_irda_state == IrdaStateAsyncRx); +void furi_hal_infrared_async_rx_stop(void) { + furi_assert(furi_hal_infrared_state == InfraredStateAsyncRx); LL_TIM_DeInit(TIM2); furi_hal_interrupt_set_timer_isr(TIM2, NULL); LL_APB1_GRP1_DisableClock(LL_APB1_GRP1_PERIPH_TIM2); - furi_hal_irda_state = IrdaStateIdle; + furi_hal_infrared_state = InfraredStateIdle; } -void furi_hal_irda_async_rx_set_timeout(uint32_t timeout_us) { +void furi_hal_infrared_async_rx_set_timeout(uint32_t timeout_us) { furi_assert(LL_APB1_GRP1_IsEnabledClock(LL_APB1_GRP1_PERIPH_TIM2)); LL_TIM_OC_SetCompareCH3(TIM2, timeout_us); @@ -203,46 +204,46 @@ void furi_hal_irda_async_rx_set_timeout(uint32_t timeout_us) { LL_TIM_EnableIT_CC3(TIM2); } -bool furi_hal_irda_is_busy(void) { - return furi_hal_irda_state != IrdaStateIdle; +bool furi_hal_infrared_is_busy(void) { + return furi_hal_infrared_state != InfraredStateIdle; } -void furi_hal_irda_async_rx_set_capture_isr_callback( - FuriHalIrdaRxCaptureCallback callback, +void furi_hal_infrared_async_rx_set_capture_isr_callback( + FuriHalInfraredRxCaptureCallback callback, void* ctx) { - irda_tim_rx.capture_callback = callback; - irda_tim_rx.capture_context = ctx; + infrared_tim_rx.capture_callback = callback; + infrared_tim_rx.capture_context = ctx; } -void furi_hal_irda_async_rx_set_timeout_isr_callback( - FuriHalIrdaRxTimeoutCallback callback, +void furi_hal_infrared_async_rx_set_timeout_isr_callback( + FuriHalInfraredRxTimeoutCallback callback, void* ctx) { - irda_tim_rx.timeout_callback = callback; - irda_tim_rx.timeout_context = ctx; + infrared_tim_rx.timeout_callback = callback; + infrared_tim_rx.timeout_context = ctx; } -static void furi_hal_irda_tx_dma_terminate(void) { +static void furi_hal_infrared_tx_dma_terminate(void) { LL_DMA_DisableIT_TC(DMA1, LL_DMA_CHANNEL_1); LL_DMA_DisableIT_HT(DMA1, LL_DMA_CHANNEL_2); LL_DMA_DisableIT_TC(DMA1, LL_DMA_CHANNEL_2); - furi_assert(furi_hal_irda_state == IrdaStateAsyncTxStopInProgress); + furi_assert(furi_hal_infrared_state == InfraredStateAsyncTxStopInProgress); LL_DMA_DisableIT_TC(DMA1, LL_DMA_CHANNEL_1); LL_DMA_DisableChannel(DMA1, LL_DMA_CHANNEL_2); LL_DMA_DisableChannel(DMA1, LL_DMA_CHANNEL_1); LL_TIM_DisableCounter(TIM1); - osStatus_t status = osSemaphoreRelease(irda_tim_tx.stop_semaphore); + osStatus_t status = osSemaphoreRelease(infrared_tim_tx.stop_semaphore); furi_check(status == osOK); - furi_hal_irda_state = IrdaStateAsyncTxStopped; + furi_hal_infrared_state = InfraredStateAsyncTxStopped; } -static uint8_t furi_hal_irda_get_current_dma_tx_buffer(void) { +static uint8_t furi_hal_infrared_get_current_dma_tx_buffer(void) { uint8_t buf_num = 0; uint32_t buffer_adr = LL_DMA_GetMemoryAddress(DMA1, LL_DMA_CHANNEL_2); - if(buffer_adr == (uint32_t)irda_tim_tx.buffer[0].data) { + if(buffer_adr == (uint32_t)infrared_tim_tx.buffer[0].data) { buf_num = 0; - } else if(buffer_adr == (uint32_t)irda_tim_tx.buffer[1].data) { + } else if(buffer_adr == (uint32_t)infrared_tim_tx.buffer[1].data) { buf_num = 1; } else { furi_assert(0); @@ -250,7 +251,7 @@ static uint8_t furi_hal_irda_get_current_dma_tx_buffer(void) { return buf_num; } -static void furi_hal_irda_tx_dma_polarity_isr() { +static void furi_hal_infrared_tx_dma_polarity_isr() { if(LL_DMA_IsActiveFlag_TE1(DMA1)) { LL_DMA_ClearFlag_TE1(DMA1); furi_crash(NULL); @@ -259,33 +260,34 @@ static void furi_hal_irda_tx_dma_polarity_isr() { LL_DMA_ClearFlag_TC1(DMA1); furi_check( - (furi_hal_irda_state == IrdaStateAsyncTx) || - (furi_hal_irda_state == IrdaStateAsyncTxStopReq) || - (furi_hal_irda_state == IrdaStateAsyncTxStopInProgress)); + (furi_hal_infrared_state == InfraredStateAsyncTx) || + (furi_hal_infrared_state == InfraredStateAsyncTxStopReq) || + (furi_hal_infrared_state == InfraredStateAsyncTxStopInProgress)); /* actually TC2 is processed and buffer is next buffer */ - uint8_t next_buf_num = furi_hal_irda_get_current_dma_tx_buffer(); - furi_hal_irda_tx_dma_set_polarity(next_buf_num, 0); + uint8_t next_buf_num = furi_hal_infrared_get_current_dma_tx_buffer(); + furi_hal_infrared_tx_dma_set_polarity(next_buf_num, 0); } } -static void furi_hal_irda_tx_dma_isr() { +static void furi_hal_infrared_tx_dma_isr() { if(LL_DMA_IsActiveFlag_TE2(DMA1)) { LL_DMA_ClearFlag_TE2(DMA1); furi_crash(NULL); } if(LL_DMA_IsActiveFlag_HT2(DMA1) && LL_DMA_IsEnabledIT_HT(DMA1, LL_DMA_CHANNEL_2)) { LL_DMA_ClearFlag_HT2(DMA1); - uint8_t buf_num = furi_hal_irda_get_current_dma_tx_buffer(); + uint8_t buf_num = furi_hal_infrared_get_current_dma_tx_buffer(); uint8_t next_buf_num = !buf_num; - if(irda_tim_tx.buffer[buf_num].last_packet_end) { + if(infrared_tim_tx.buffer[buf_num].last_packet_end) { LL_DMA_DisableIT_HT(DMA1, LL_DMA_CHANNEL_2); } else if( - !irda_tim_tx.buffer[buf_num].packet_end || (furi_hal_irda_state == IrdaStateAsyncTx)) { - furi_hal_irda_tx_fill_buffer(next_buf_num, 0); - if(irda_tim_tx.buffer[next_buf_num].last_packet_end) { + !infrared_tim_tx.buffer[buf_num].packet_end || + (furi_hal_infrared_state == InfraredStateAsyncTx)) { + furi_hal_infrared_tx_fill_buffer(next_buf_num, 0); + if(infrared_tim_tx.buffer[next_buf_num].last_packet_end) { LL_DMA_DisableIT_HT(DMA1, LL_DMA_CHANNEL_2); } - } else if(furi_hal_irda_state == IrdaStateAsyncTxStopReq) { + } else if(furi_hal_infrared_state == InfraredStateAsyncTxStopReq) { /* fallthrough */ } else { furi_crash(NULL); @@ -294,33 +296,33 @@ static void furi_hal_irda_tx_dma_isr() { if(LL_DMA_IsActiveFlag_TC2(DMA1) && LL_DMA_IsEnabledIT_TC(DMA1, LL_DMA_CHANNEL_2)) { LL_DMA_ClearFlag_TC2(DMA1); furi_check( - (furi_hal_irda_state == IrdaStateAsyncTxStopInProgress) || - (furi_hal_irda_state == IrdaStateAsyncTxStopReq) || - (furi_hal_irda_state == IrdaStateAsyncTx)); + (furi_hal_infrared_state == InfraredStateAsyncTxStopInProgress) || + (furi_hal_infrared_state == InfraredStateAsyncTxStopReq) || + (furi_hal_infrared_state == InfraredStateAsyncTx)); - uint8_t buf_num = furi_hal_irda_get_current_dma_tx_buffer(); + uint8_t buf_num = furi_hal_infrared_get_current_dma_tx_buffer(); uint8_t next_buf_num = !buf_num; - if(furi_hal_irda_state == IrdaStateAsyncTxStopInProgress) { - furi_hal_irda_tx_dma_terminate(); + if(furi_hal_infrared_state == InfraredStateAsyncTxStopInProgress) { + furi_hal_infrared_tx_dma_terminate(); } else if( - irda_tim_tx.buffer[buf_num].last_packet_end || - (irda_tim_tx.buffer[buf_num].packet_end && - (furi_hal_irda_state == IrdaStateAsyncTxStopReq))) { - furi_hal_irda_state = IrdaStateAsyncTxStopInProgress; - furi_hal_irda_tx_fill_buffer_last(next_buf_num); - furi_hal_irda_tx_dma_set_buffer(next_buf_num); + infrared_tim_tx.buffer[buf_num].last_packet_end || + (infrared_tim_tx.buffer[buf_num].packet_end && + (furi_hal_infrared_state == InfraredStateAsyncTxStopReq))) { + furi_hal_infrared_state = InfraredStateAsyncTxStopInProgress; + furi_hal_infrared_tx_fill_buffer_last(next_buf_num); + furi_hal_infrared_tx_dma_set_buffer(next_buf_num); } else { /* if it's not end of the packet - continue receiving */ - furi_hal_irda_tx_dma_set_buffer(next_buf_num); + furi_hal_infrared_tx_dma_set_buffer(next_buf_num); } - if(irda_tim_tx.signal_sent_callback && irda_tim_tx.buffer[buf_num].packet_end && - (furi_hal_irda_state != IrdaStateAsyncTxStopped)) { - irda_tim_tx.signal_sent_callback(irda_tim_tx.signal_sent_context); + if(infrared_tim_tx.signal_sent_callback && infrared_tim_tx.buffer[buf_num].packet_end && + (furi_hal_infrared_state != InfraredStateAsyncTxStopped)) { + infrared_tim_tx.signal_sent_callback(infrared_tim_tx.signal_sent_context); } } } -static void furi_hal_irda_configure_tim_pwm_tx(uint32_t freq, float duty_cycle) { +static void furi_hal_infrared_configure_tim_pwm_tx(uint32_t freq, float duty_cycle) { LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_TIM1); /* LL_DBGMCU_APB2_GRP1_FreezePeriph(LL_DBGMCU_APB2_GRP1_TIM1_STOP); */ @@ -332,7 +334,7 @@ static void furi_hal_irda_configure_tim_pwm_tx(uint32_t freq, float duty_cycle) LL_TIM_EnableARRPreload(TIM1); LL_TIM_SetAutoReload( TIM1, __LL_TIM_CALC_ARR(SystemCoreClock, LL_TIM_GetPrescaler(TIM1), freq)); -#if IRDA_TX_DEBUG == 1 +#if INFRARED_TX_DEBUG == 1 LL_TIM_OC_SetCompareCH1(TIM1, ((LL_TIM_GetAutoReload(TIM1) + 1) * (1 - duty_cycle))); LL_TIM_OC_EnablePreload(TIM1, LL_TIM_CHANNEL_CH1); /* LL_TIM_OCMODE_PWM2 set by DMA */ @@ -360,11 +362,11 @@ static void furi_hal_irda_configure_tim_pwm_tx(uint32_t freq, float duty_cycle) NVIC_EnableIRQ(TIM1_UP_TIM16_IRQn); } -static void furi_hal_irda_configure_tim_cmgr2_dma_tx(void) { +static void furi_hal_infrared_configure_tim_cmgr2_dma_tx(void) { LL_C2_AHB1_GRP1_EnableClock(LL_C2_AHB1_GRP1_PERIPH_DMA1); LL_DMA_InitTypeDef dma_config = {0}; -#if IRDA_TX_DEBUG == 1 +#if INFRARED_TX_DEBUG == 1 dma_config.PeriphOrM2MSrcAddress = (uint32_t) & (TIM1->CCMR1); #else dma_config.PeriphOrM2MSrcAddress = (uint32_t) & (TIM1->CCMR2); @@ -382,7 +384,7 @@ static void furi_hal_irda_configure_tim_cmgr2_dma_tx(void) { dma_config.Priority = LL_DMA_PRIORITY_VERYHIGH; LL_DMA_Init(DMA1, LL_DMA_CHANNEL_1, &dma_config); furi_hal_interrupt_set_dma_channel_isr( - DMA1, LL_DMA_CHANNEL_1, furi_hal_irda_tx_dma_polarity_isr); + DMA1, LL_DMA_CHANNEL_1, furi_hal_infrared_tx_dma_polarity_isr); LL_DMA_ClearFlag_TE1(DMA1); LL_DMA_ClearFlag_TC1(DMA1); LL_DMA_EnableIT_TE(DMA1, LL_DMA_CHANNEL_1); @@ -392,7 +394,7 @@ static void furi_hal_irda_configure_tim_cmgr2_dma_tx(void) { NVIC_EnableIRQ(DMA1_Channel1_IRQn); } -static void furi_hal_irda_configure_tim_rcr_dma_tx(void) { +static void furi_hal_infrared_configure_tim_rcr_dma_tx(void) { LL_C2_AHB1_GRP1_EnableClock(LL_C2_AHB1_GRP1_PERIPH_DMA1); LL_DMA_InitTypeDef dma_config = {0}; @@ -408,7 +410,7 @@ static void furi_hal_irda_configure_tim_rcr_dma_tx(void) { dma_config.PeriphRequest = LL_DMAMUX_REQ_TIM1_UP; dma_config.Priority = LL_DMA_PRIORITY_MEDIUM; LL_DMA_Init(DMA1, LL_DMA_CHANNEL_2, &dma_config); - furi_hal_interrupt_set_dma_channel_isr(DMA1, LL_DMA_CHANNEL_2, furi_hal_irda_tx_dma_isr); + furi_hal_interrupt_set_dma_channel_isr(DMA1, LL_DMA_CHANNEL_2, furi_hal_infrared_tx_dma_isr); LL_DMA_ClearFlag_TC2(DMA1); LL_DMA_ClearFlag_HT2(DMA1); LL_DMA_ClearFlag_TE2(DMA1); @@ -420,100 +422,102 @@ static void furi_hal_irda_configure_tim_rcr_dma_tx(void) { NVIC_EnableIRQ(DMA1_Channel2_IRQn); } -static void furi_hal_irda_tx_fill_buffer_last(uint8_t buf_num) { +static void furi_hal_infrared_tx_fill_buffer_last(uint8_t buf_num) { furi_assert(buf_num < 2); - furi_assert(furi_hal_irda_state != IrdaStateAsyncRx); - furi_assert(furi_hal_irda_state < IrdaStateMAX); - furi_assert(irda_tim_tx.data_callback); - IrdaTxBuf* buffer = &irda_tim_tx.buffer[buf_num]; + furi_assert(furi_hal_infrared_state != InfraredStateAsyncRx); + furi_assert(furi_hal_infrared_state < InfraredStateMAX); + furi_assert(infrared_tim_tx.data_callback); + InfraredTxBuf* buffer = &infrared_tim_tx.buffer[buf_num]; furi_assert(buffer->data != NULL); (void)buffer->data; furi_assert(buffer->polarity != NULL); (void)buffer->polarity; - irda_tim_tx.buffer[buf_num].data[0] = 0; // 1 pulse - irda_tim_tx.buffer[buf_num].polarity[0] = IRDA_TX_CCMR_LOW; - irda_tim_tx.buffer[buf_num].data[1] = 0; // 1 pulse - irda_tim_tx.buffer[buf_num].polarity[1] = IRDA_TX_CCMR_LOW; - irda_tim_tx.buffer[buf_num].size = 2; - irda_tim_tx.buffer[buf_num].last_packet_end = true; - irda_tim_tx.buffer[buf_num].packet_end = true; + infrared_tim_tx.buffer[buf_num].data[0] = 0; // 1 pulse + infrared_tim_tx.buffer[buf_num].polarity[0] = INFRARED_TX_CCMR_LOW; + infrared_tim_tx.buffer[buf_num].data[1] = 0; // 1 pulse + infrared_tim_tx.buffer[buf_num].polarity[1] = INFRARED_TX_CCMR_LOW; + infrared_tim_tx.buffer[buf_num].size = 2; + infrared_tim_tx.buffer[buf_num].last_packet_end = true; + infrared_tim_tx.buffer[buf_num].packet_end = true; } -static void furi_hal_irda_tx_fill_buffer(uint8_t buf_num, uint8_t polarity_shift) { +static void furi_hal_infrared_tx_fill_buffer(uint8_t buf_num, uint8_t polarity_shift) { furi_assert(buf_num < 2); - furi_assert(furi_hal_irda_state != IrdaStateAsyncRx); - furi_assert(furi_hal_irda_state < IrdaStateMAX); - furi_assert(irda_tim_tx.data_callback); - IrdaTxBuf* buffer = &irda_tim_tx.buffer[buf_num]; + furi_assert(furi_hal_infrared_state != InfraredStateAsyncRx); + furi_assert(furi_hal_infrared_state < InfraredStateMAX); + furi_assert(infrared_tim_tx.data_callback); + InfraredTxBuf* buffer = &infrared_tim_tx.buffer[buf_num]; furi_assert(buffer->data != NULL); furi_assert(buffer->polarity != NULL); - FuriHalIrdaTxGetDataState status = FuriHalIrdaTxGetDataStateOk; + FuriHalInfraredTxGetDataState status = FuriHalInfraredTxGetDataStateOk; uint32_t duration = 0; bool level = 0; size_t* size = &buffer->size; size_t polarity_counter = 0; while(polarity_shift--) { - buffer->polarity[polarity_counter++] = IRDA_TX_CCMR_LOW; + buffer->polarity[polarity_counter++] = INFRARED_TX_CCMR_LOW; } - for(*size = 0; - (*size < IRDA_TIM_TX_DMA_BUFFER_SIZE) && (status == FuriHalIrdaTxGetDataStateOk);) { - if(irda_tim_tx.tx_timing_rest_duration > 0) { - if(irda_tim_tx.tx_timing_rest_duration > 0xFFFF) { + for(*size = 0; (*size < INFRARED_TIM_TX_DMA_BUFFER_SIZE) && + (status == FuriHalInfraredTxGetDataStateOk);) { + if(infrared_tim_tx.tx_timing_rest_duration > 0) { + if(infrared_tim_tx.tx_timing_rest_duration > 0xFFFF) { buffer->data[*size] = 0xFFFF; - status = FuriHalIrdaTxGetDataStateOk; + status = FuriHalInfraredTxGetDataStateOk; } else { - buffer->data[*size] = irda_tim_tx.tx_timing_rest_duration; - status = irda_tim_tx.tx_timing_rest_status; + buffer->data[*size] = infrared_tim_tx.tx_timing_rest_duration; + status = infrared_tim_tx.tx_timing_rest_status; } - irda_tim_tx.tx_timing_rest_duration -= buffer->data[*size]; - buffer->polarity[polarity_counter] = - irda_tim_tx.tx_timing_rest_level ? IRDA_TX_CCMR_HIGH : IRDA_TX_CCMR_LOW; + infrared_tim_tx.tx_timing_rest_duration -= buffer->data[*size]; + buffer->polarity[polarity_counter] = infrared_tim_tx.tx_timing_rest_level ? + INFRARED_TX_CCMR_HIGH : + INFRARED_TX_CCMR_LOW; ++(*size); ++polarity_counter; continue; } - status = irda_tim_tx.data_callback(irda_tim_tx.data_context, &duration, &level); + status = infrared_tim_tx.data_callback(infrared_tim_tx.data_context, &duration, &level); - uint32_t num_of_impulses = roundf(duration / irda_tim_tx.cycle_duration); + uint32_t num_of_impulses = roundf(duration / infrared_tim_tx.cycle_duration); if(num_of_impulses == 0) { - if((*size == 0) && (status == FuriHalIrdaTxGetDataStateDone)) { + if((*size == 0) && (status == FuriHalInfraredTxGetDataStateDone)) { /* if this is one sample in current buffer, but we * have more to send - continue */ - status = FuriHalIrdaTxGetDataStateOk; + status = FuriHalInfraredTxGetDataStateOk; } } else if((num_of_impulses - 1) > 0xFFFF) { - irda_tim_tx.tx_timing_rest_duration = num_of_impulses - 1; - irda_tim_tx.tx_timing_rest_status = status; - irda_tim_tx.tx_timing_rest_level = level; - status = FuriHalIrdaTxGetDataStateOk; + infrared_tim_tx.tx_timing_rest_duration = num_of_impulses - 1; + infrared_tim_tx.tx_timing_rest_status = status; + infrared_tim_tx.tx_timing_rest_level = level; + status = FuriHalInfraredTxGetDataStateOk; } else { - buffer->polarity[polarity_counter] = level ? IRDA_TX_CCMR_HIGH : IRDA_TX_CCMR_LOW; + buffer->polarity[polarity_counter] = level ? INFRARED_TX_CCMR_HIGH : + INFRARED_TX_CCMR_LOW; buffer->data[*size] = num_of_impulses - 1; ++(*size); ++polarity_counter; } } - buffer->last_packet_end = (status == FuriHalIrdaTxGetDataStateLastDone); - buffer->packet_end = buffer->last_packet_end || (status == FuriHalIrdaTxGetDataStateDone); + buffer->last_packet_end = (status == FuriHalInfraredTxGetDataStateLastDone); + buffer->packet_end = buffer->last_packet_end || (status == FuriHalInfraredTxGetDataStateDone); if(*size == 0) { buffer->data[0] = 0; // 1 pulse - buffer->polarity[0] = IRDA_TX_CCMR_LOW; + buffer->polarity[0] = INFRARED_TX_CCMR_LOW; buffer->size = 1; } } -static void furi_hal_irda_tx_dma_set_polarity(uint8_t buf_num, uint8_t polarity_shift) { +static void furi_hal_infrared_tx_dma_set_polarity(uint8_t buf_num, uint8_t polarity_shift) { furi_assert(buf_num < 2); - furi_assert(furi_hal_irda_state < IrdaStateMAX); - IrdaTxBuf* buffer = &irda_tim_tx.buffer[buf_num]; + furi_assert(furi_hal_infrared_state < InfraredStateMAX); + InfraredTxBuf* buffer = &infrared_tim_tx.buffer[buf_num]; furi_assert(buffer->polarity != NULL); FURI_CRITICAL_ENTER(); @@ -529,10 +533,10 @@ static void furi_hal_irda_tx_dma_set_polarity(uint8_t buf_num, uint8_t polarity_ FURI_CRITICAL_EXIT(); } -static void furi_hal_irda_tx_dma_set_buffer(uint8_t buf_num) { +static void furi_hal_infrared_tx_dma_set_buffer(uint8_t buf_num) { furi_assert(buf_num < 2); - furi_assert(furi_hal_irda_state < IrdaStateMAX); - IrdaTxBuf* buffer = &irda_tim_tx.buffer[buf_num]; + furi_assert(furi_hal_infrared_state < InfraredStateMAX); + InfraredTxBuf* buffer = &infrared_tim_tx.buffer[buf_num]; furi_assert(buffer->data != NULL); /* non-circular mode requires disabled channel before setup */ @@ -549,66 +553,66 @@ static void furi_hal_irda_tx_dma_set_buffer(uint8_t buf_num) { FURI_CRITICAL_EXIT(); } -static void furi_hal_irda_async_tx_free_resources(void) { +static void furi_hal_infrared_async_tx_free_resources(void) { furi_assert( - (furi_hal_irda_state == IrdaStateIdle) || - (furi_hal_irda_state == IrdaStateAsyncTxStopped)); + (furi_hal_infrared_state == InfraredStateIdle) || + (furi_hal_infrared_state == InfraredStateAsyncTxStopped)); osStatus_t status; - hal_gpio_init(&gpio_irda_tx, GpioModeOutputOpenDrain, GpioPullDown, GpioSpeedLow); + hal_gpio_init(&gpio_infrared_tx, GpioModeOutputOpenDrain, GpioPullDown, GpioSpeedLow); furi_hal_interrupt_set_dma_channel_isr(DMA1, LL_DMA_CHANNEL_1, NULL); furi_hal_interrupt_set_dma_channel_isr(DMA1, LL_DMA_CHANNEL_2, NULL); LL_TIM_DeInit(TIM1); LL_APB2_GRP1_DisableClock(LL_APB2_GRP1_PERIPH_TIM1); LL_C2_AHB1_GRP1_DisableClock(LL_C2_AHB1_GRP1_PERIPH_DMA1); - status = osSemaphoreDelete(irda_tim_tx.stop_semaphore); + status = osSemaphoreDelete(infrared_tim_tx.stop_semaphore); furi_check(status == osOK); - free(irda_tim_tx.buffer[0].data); - free(irda_tim_tx.buffer[1].data); - free(irda_tim_tx.buffer[0].polarity); - free(irda_tim_tx.buffer[1].polarity); + free(infrared_tim_tx.buffer[0].data); + free(infrared_tim_tx.buffer[1].data); + free(infrared_tim_tx.buffer[0].polarity); + free(infrared_tim_tx.buffer[1].polarity); - irda_tim_tx.buffer[0].data = NULL; - irda_tim_tx.buffer[1].data = NULL; - irda_tim_tx.buffer[0].polarity = NULL; - irda_tim_tx.buffer[1].polarity = NULL; + infrared_tim_tx.buffer[0].data = NULL; + infrared_tim_tx.buffer[1].data = NULL; + infrared_tim_tx.buffer[0].polarity = NULL; + infrared_tim_tx.buffer[1].polarity = NULL; } -void furi_hal_irda_async_tx_start(uint32_t freq, float duty_cycle) { - if((duty_cycle > 1) || (duty_cycle <= 0) || (freq > IRDA_MAX_FREQUENCY) || - (freq < IRDA_MIN_FREQUENCY) || (irda_tim_tx.data_callback == NULL)) { +void furi_hal_infrared_async_tx_start(uint32_t freq, float duty_cycle) { + if((duty_cycle > 1) || (duty_cycle <= 0) || (freq > INFRARED_MAX_FREQUENCY) || + (freq < INFRARED_MIN_FREQUENCY) || (infrared_tim_tx.data_callback == NULL)) { furi_crash(NULL); } - furi_assert(furi_hal_irda_state == IrdaStateIdle); - furi_assert(irda_tim_tx.buffer[0].data == NULL); - furi_assert(irda_tim_tx.buffer[1].data == NULL); - furi_assert(irda_tim_tx.buffer[0].polarity == NULL); - furi_assert(irda_tim_tx.buffer[1].polarity == NULL); + furi_assert(furi_hal_infrared_state == InfraredStateIdle); + furi_assert(infrared_tim_tx.buffer[0].data == NULL); + furi_assert(infrared_tim_tx.buffer[1].data == NULL); + furi_assert(infrared_tim_tx.buffer[0].polarity == NULL); + furi_assert(infrared_tim_tx.buffer[1].polarity == NULL); - size_t alloc_size_data = IRDA_TIM_TX_DMA_BUFFER_SIZE * sizeof(uint16_t); - irda_tim_tx.buffer[0].data = malloc(alloc_size_data); - irda_tim_tx.buffer[1].data = malloc(alloc_size_data); + size_t alloc_size_data = INFRARED_TIM_TX_DMA_BUFFER_SIZE * sizeof(uint16_t); + infrared_tim_tx.buffer[0].data = malloc(alloc_size_data); + infrared_tim_tx.buffer[1].data = malloc(alloc_size_data); size_t alloc_size_polarity = - (IRDA_TIM_TX_DMA_BUFFER_SIZE + IRDA_POLARITY_SHIFT) * sizeof(uint8_t); - irda_tim_tx.buffer[0].polarity = malloc(alloc_size_polarity); - irda_tim_tx.buffer[1].polarity = malloc(alloc_size_polarity); + (INFRARED_TIM_TX_DMA_BUFFER_SIZE + INFRARED_POLARITY_SHIFT) * sizeof(uint8_t); + infrared_tim_tx.buffer[0].polarity = malloc(alloc_size_polarity); + infrared_tim_tx.buffer[1].polarity = malloc(alloc_size_polarity); - irda_tim_tx.stop_semaphore = osSemaphoreNew(1, 0, NULL); - irda_tim_tx.cycle_duration = 1000000.0 / freq; - irda_tim_tx.tx_timing_rest_duration = 0; + infrared_tim_tx.stop_semaphore = osSemaphoreNew(1, 0, NULL); + infrared_tim_tx.cycle_duration = 1000000.0 / freq; + infrared_tim_tx.tx_timing_rest_duration = 0; - furi_hal_irda_tx_fill_buffer(0, IRDA_POLARITY_SHIFT); + furi_hal_infrared_tx_fill_buffer(0, INFRARED_POLARITY_SHIFT); - furi_hal_irda_configure_tim_pwm_tx(freq, duty_cycle); - furi_hal_irda_configure_tim_cmgr2_dma_tx(); - furi_hal_irda_configure_tim_rcr_dma_tx(); - furi_hal_irda_tx_dma_set_polarity(0, IRDA_POLARITY_SHIFT); - furi_hal_irda_tx_dma_set_buffer(0); + furi_hal_infrared_configure_tim_pwm_tx(freq, duty_cycle); + furi_hal_infrared_configure_tim_cmgr2_dma_tx(); + furi_hal_infrared_configure_tim_rcr_dma_tx(); + furi_hal_infrared_tx_dma_set_polarity(0, INFRARED_POLARITY_SHIFT); + furi_hal_infrared_tx_dma_set_buffer(0); - furi_hal_irda_state = IrdaStateAsyncTx; + furi_hal_infrared_state = InfraredStateAsyncTx; LL_TIM_ClearFlag_UPDATE(TIM1); LL_DMA_EnableChannel(DMA1, LL_DMA_CHANNEL_1); @@ -617,9 +621,9 @@ void furi_hal_irda_async_tx_start(uint32_t freq, float duty_cycle) { LL_TIM_GenerateEvent_UPDATE(TIM1); /* DMA -> TIMx_RCR */ delay_us(5); LL_GPIO_ResetOutputPin( - gpio_irda_tx.port, gpio_irda_tx.pin); /* when disable it prevents false pulse */ + gpio_infrared_tx.port, gpio_infrared_tx.pin); /* when disable it prevents false pulse */ hal_gpio_init_ex( - &gpio_irda_tx, GpioModeAltFunctionPushPull, GpioPullUp, GpioSpeedHigh, GpioAltFn1TIM1); + &gpio_infrared_tx, GpioModeAltFunctionPushPull, GpioPullUp, GpioSpeedHigh, GpioAltFn1TIM1); FURI_CRITICAL_ENTER(); LL_TIM_GenerateEvent_UPDATE(TIM1); /* TIMx_RCR -> Repetition counter */ @@ -627,39 +631,40 @@ void furi_hal_irda_async_tx_start(uint32_t freq, float duty_cycle) { FURI_CRITICAL_EXIT(); } -void furi_hal_irda_async_tx_wait_termination(void) { - furi_assert(furi_hal_irda_state >= IrdaStateAsyncTx); - furi_assert(furi_hal_irda_state < IrdaStateMAX); +void furi_hal_infrared_async_tx_wait_termination(void) { + furi_assert(furi_hal_infrared_state >= InfraredStateAsyncTx); + furi_assert(furi_hal_infrared_state < InfraredStateMAX); osStatus_t status; - status = osSemaphoreAcquire(irda_tim_tx.stop_semaphore, osWaitForever); + status = osSemaphoreAcquire(infrared_tim_tx.stop_semaphore, osWaitForever); furi_check(status == osOK); - furi_hal_irda_async_tx_free_resources(); - furi_hal_irda_state = IrdaStateIdle; + furi_hal_infrared_async_tx_free_resources(); + furi_hal_infrared_state = InfraredStateIdle; } -void furi_hal_irda_async_tx_stop(void) { - furi_assert(furi_hal_irda_state >= IrdaStateAsyncTx); - furi_assert(furi_hal_irda_state < IrdaStateMAX); +void furi_hal_infrared_async_tx_stop(void) { + furi_assert(furi_hal_infrared_state >= InfraredStateAsyncTx); + furi_assert(furi_hal_infrared_state < InfraredStateMAX); FURI_CRITICAL_ENTER(); - if(furi_hal_irda_state == IrdaStateAsyncTx) furi_hal_irda_state = IrdaStateAsyncTxStopReq; + if(furi_hal_infrared_state == InfraredStateAsyncTx) + furi_hal_infrared_state = InfraredStateAsyncTxStopReq; FURI_CRITICAL_EXIT(); - furi_hal_irda_async_tx_wait_termination(); + furi_hal_infrared_async_tx_wait_termination(); } -void furi_hal_irda_async_tx_set_data_isr_callback( - FuriHalIrdaTxGetDataISRCallback callback, +void furi_hal_infrared_async_tx_set_data_isr_callback( + FuriHalInfraredTxGetDataISRCallback callback, void* context) { - furi_assert(furi_hal_irda_state == IrdaStateIdle); - irda_tim_tx.data_callback = callback; - irda_tim_tx.data_context = context; + furi_assert(furi_hal_infrared_state == InfraredStateIdle); + infrared_tim_tx.data_callback = callback; + infrared_tim_tx.data_context = context; } -void furi_hal_irda_async_tx_set_signal_sent_isr_callback( - FuriHalIrdaTxSignalSentISRCallback callback, +void furi_hal_infrared_async_tx_set_signal_sent_isr_callback( + FuriHalInfraredTxSignalSentISRCallback callback, void* context) { - irda_tim_tx.signal_sent_callback = callback; - irda_tim_tx.signal_sent_context = context; + infrared_tim_tx.signal_sent_callback = callback; + infrared_tim_tx.signal_sent_context = context; } diff --git a/firmware/targets/f7/furi_hal/furi_hal_resources.c b/firmware/targets/f7/furi_hal/furi_hal_resources.c index d8955096..a5e2907f 100644 --- a/firmware/targets/f7/furi_hal/furi_hal_resources.c +++ b/firmware/targets/f7/furi_hal/furi_hal_resources.c @@ -71,8 +71,8 @@ const GpioPin gpio_rfid_carrier_out = {.port = RFID_OUT_GPIO_Port, .pin = RFID_O const GpioPin gpio_rfid_data_in = {.port = RFID_RF_IN_GPIO_Port, .pin = RFID_RF_IN_Pin}; const GpioPin gpio_rfid_carrier = {.port = RFID_CARRIER_GPIO_Port, .pin = RFID_CARRIER_Pin}; -const GpioPin gpio_irda_rx = {.port = IR_RX_GPIO_Port, .pin = IR_RX_Pin}; -const GpioPin gpio_irda_tx = {.port = IR_TX_GPIO_Port, .pin = IR_TX_Pin}; +const GpioPin gpio_infrared_rx = {.port = IR_RX_GPIO_Port, .pin = IR_RX_Pin}; +const GpioPin gpio_infrared_tx = {.port = IR_TX_GPIO_Port, .pin = IR_TX_Pin}; const GpioPin gpio_usart_tx = {.port = USART1_TX_Port, .pin = USART1_TX_Pin}; const GpioPin gpio_usart_rx = {.port = USART1_RX_Port, .pin = USART1_RX_Pin}; diff --git a/firmware/targets/f7/furi_hal/furi_hal_resources.h b/firmware/targets/f7/furi_hal/furi_hal_resources.h index 0851f1b1..d4bb89e5 100644 --- a/firmware/targets/f7/furi_hal/furi_hal_resources.h +++ b/firmware/targets/f7/furi_hal/furi_hal_resources.h @@ -76,8 +76,8 @@ extern const GpioPin gpio_rfid_carrier_out; extern const GpioPin gpio_rfid_data_in; extern const GpioPin gpio_rfid_carrier; -extern const GpioPin gpio_irda_rx; -extern const GpioPin gpio_irda_tx; +extern const GpioPin gpio_infrared_rx; +extern const GpioPin gpio_infrared_tx; extern const GpioPin gpio_usart_tx; extern const GpioPin gpio_usart_rx; diff --git a/firmware/targets/furi_hal_include/furi_hal_infrared.h b/firmware/targets/furi_hal_include/furi_hal_infrared.h new file mode 100644 index 00000000..5fcea066 --- /dev/null +++ b/firmware/targets/furi_hal_include/furi_hal_infrared.h @@ -0,0 +1,148 @@ +/** + * @file furi_hal_infrared.h + * INFRARED HAL API + */ + +#pragma once + +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#define INFRARED_MAX_FREQUENCY 56000 +#define INFRARED_MIN_FREQUENCY 10000 + +typedef enum { + FuriHalInfraredTxGetDataStateOk, /**< New data obtained */ + FuriHalInfraredTxGetDataStateDone, /**< New data obtained, and this is end of package */ + FuriHalInfraredTxGetDataStateLastDone, /**< New data obtained, and this is end of package and no more data available */ +} FuriHalInfraredTxGetDataState; + +/** Callback type for providing data to INFRARED DMA TX system. It is called every tim */ +typedef FuriHalInfraredTxGetDataState ( + *FuriHalInfraredTxGetDataISRCallback)(void* context, uint32_t* duration, bool* level); + +/** Callback type called every time signal is sent by DMA to Timer. + * + * Actually, it means there are 2 timings left to send for this signal, which is + * almost end. Don't use this callback to stop transmission, as far as there are + * next signal is charged for transmission by DMA. + */ +typedef void (*FuriHalInfraredTxSignalSentISRCallback)(void* context); + +/** Signature of callback function for receiving continuous INFRARED rx signal. + * + * @param ctx[in] context to pass to callback + * @param level[in] level of input INFRARED rx signal + * @param duration[in] duration of continuous rx signal level in us + */ +typedef void (*FuriHalInfraredRxCaptureCallback)(void* ctx, bool level, uint32_t duration); + +/** Signature of callback function for reaching silence timeout on INFRARED port. + * + * @param ctx[in] context to pass to callback + */ +typedef void (*FuriHalInfraredRxTimeoutCallback)(void* ctx); + +/** Initialize INFRARED RX timer to receive interrupts. + * + * It provides interrupts for every RX-signal edge changing with its duration. + */ +void furi_hal_infrared_async_rx_start(void); + +/** Deinitialize INFRARED RX interrupt. + */ +void furi_hal_infrared_async_rx_stop(void); + +/** Setup hal for receiving silence timeout. + * + * Should be used with 'furi_hal_infrared_timeout_irq_set_callback()'. + * + * @param[in] timeout_us time to wait for silence on INFRARED port before + * generating IRQ. + */ +void furi_hal_infrared_async_rx_set_timeout(uint32_t timeout_us); + +/** Setup callback for previously initialized INFRARED RX interrupt. + * + * @param[in] callback callback to call when RX signal edge changing occurs + * @param[in] ctx context for callback + */ +void furi_hal_infrared_async_rx_set_capture_isr_callback( + FuriHalInfraredRxCaptureCallback callback, + void* ctx); + +/** Setup callback for reaching silence timeout on INFRARED port. + * + * Should setup hal with 'furi_hal_infrared_setup_rx_timeout_irq()' first. + * + * @param[in] callback callback for silence timeout + * @param[in] ctx context to pass to callback + */ +void furi_hal_infrared_async_rx_set_timeout_isr_callback( + FuriHalInfraredRxTimeoutCallback callback, + void* ctx); + +/** Check if INFRARED is in use now. + * + * @return true if INFRARED is busy, false otherwise. + */ +bool furi_hal_infrared_is_busy(void); + +/** Set callback providing new data. + * + * This function has to be called before furi_hal_infrared_async_tx_start(). + * + * @param[in] callback function to provide new data + * @param[in] context context for callback + */ +void furi_hal_infrared_async_tx_set_data_isr_callback( + FuriHalInfraredTxGetDataISRCallback callback, + void* context); + +/** Start IR asynchronous transmission. + * + * It can be stopped by 2 reasons: + * 1. implicit call for furi_hal_infrared_async_tx_stop() + * 2. callback can provide FuriHalInfraredTxGetDataStateLastDone response which + * means no more data available for transmission. + * + * Any func (furi_hal_infrared_async_tx_stop() or + * furi_hal_infrared_async_tx_wait_termination()) has to be called to wait end of + * transmission and free resources. + * + * @param[in] freq frequency for PWM + * @param[in] duty_cycle duty cycle for PWM + */ +void furi_hal_infrared_async_tx_start(uint32_t freq, float duty_cycle); + +/** Stop IR asynchronous transmission and free resources. + * + * Transmission will stop as soon as transmission reaches end of package + * (FuriHalInfraredTxGetDataStateDone or FuriHalInfraredTxGetDataStateLastDone). + */ +void furi_hal_infrared_async_tx_stop(void); + +/** Wait for end of IR asynchronous transmission and free resources. + * + * Transmission will stop as soon as transmission reaches end of transmission + * (FuriHalInfraredTxGetDataStateLastDone). + */ +void furi_hal_infrared_async_tx_wait_termination(void); + +/** Set callback for end of signal transmission + * + * @param[in] callback function to call when signal is sent + * @param[in] context context for callback + */ +void furi_hal_infrared_async_tx_set_signal_sent_isr_callback( + FuriHalInfraredTxSignalSentISRCallback callback, + void* context); + +#ifdef __cplusplus +} +#endif diff --git a/firmware/targets/furi_hal_include/furi_hal_irda.h b/firmware/targets/furi_hal_include/furi_hal_irda.h deleted file mode 100644 index 551210b2..00000000 --- a/firmware/targets/furi_hal_include/furi_hal_irda.h +++ /dev/null @@ -1,148 +0,0 @@ -/** - * @file furi_hal_irda.h - * IRDA HAL API - */ - -#pragma once - -#include -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -#define IRDA_MAX_FREQUENCY 56000 -#define IRDA_MIN_FREQUENCY 10000 - -typedef enum { - FuriHalIrdaTxGetDataStateOk, /**< New data obtained */ - FuriHalIrdaTxGetDataStateDone, /**< New data obtained, and this is end of package */ - FuriHalIrdaTxGetDataStateLastDone, /**< New data obtained, and this is end of package and no more data available */ -} FuriHalIrdaTxGetDataState; - -/** Callback type for providing data to IRDA DMA TX system. It is called every tim */ -typedef FuriHalIrdaTxGetDataState ( - *FuriHalIrdaTxGetDataISRCallback)(void* context, uint32_t* duration, bool* level); - -/** Callback type called every time signal is sent by DMA to Timer. - * - * Actually, it means there are 2 timings left to send for this signal, which is - * almost end. Don't use this callback to stop transmission, as far as there are - * next signal is charged for transmission by DMA. - */ -typedef void (*FuriHalIrdaTxSignalSentISRCallback)(void* context); - -/** Signature of callback function for receiving continuous IRDA rx signal. - * - * @param ctx[in] context to pass to callback - * @param level[in] level of input IRDA rx signal - * @param duration[in] duration of continuous rx signal level in us - */ -typedef void (*FuriHalIrdaRxCaptureCallback)(void* ctx, bool level, uint32_t duration); - -/** Signature of callback function for reaching silence timeout on IRDA port. - * - * @param ctx[in] context to pass to callback - */ -typedef void (*FuriHalIrdaRxTimeoutCallback)(void* ctx); - -/** Initialize IRDA RX timer to receive interrupts. - * - * It provides interrupts for every RX-signal edge changing with its duration. - */ -void furi_hal_irda_async_rx_start(void); - -/** Deinitialize IRDA RX interrupt. - */ -void furi_hal_irda_async_rx_stop(void); - -/** Setup hal for receiving silence timeout. - * - * Should be used with 'furi_hal_irda_timeout_irq_set_callback()'. - * - * @param[in] timeout_us time to wait for silence on IRDA port before - * generating IRQ. - */ -void furi_hal_irda_async_rx_set_timeout(uint32_t timeout_us); - -/** Setup callback for previously initialized IRDA RX interrupt. - * - * @param[in] callback callback to call when RX signal edge changing occurs - * @param[in] ctx context for callback - */ -void furi_hal_irda_async_rx_set_capture_isr_callback( - FuriHalIrdaRxCaptureCallback callback, - void* ctx); - -/** Setup callback for reaching silence timeout on IRDA port. - * - * Should setup hal with 'furi_hal_irda_setup_rx_timeout_irq()' first. - * - * @param[in] callback callback for silence timeout - * @param[in] ctx context to pass to callback - */ -void furi_hal_irda_async_rx_set_timeout_isr_callback( - FuriHalIrdaRxTimeoutCallback callback, - void* ctx); - -/** Check if IRDA is in use now. - * - * @return true if IRDA is busy, false otherwise. - */ -bool furi_hal_irda_is_busy(void); - -/** Set callback providing new data. - * - * This function has to be called before furi_hal_irda_async_tx_start(). - * - * @param[in] callback function to provide new data - * @param[in] context context for callback - */ -void furi_hal_irda_async_tx_set_data_isr_callback( - FuriHalIrdaTxGetDataISRCallback callback, - void* context); - -/** Start IR asynchronous transmission. - * - * It can be stopped by 2 reasons: - * 1. implicit call for furi_hal_irda_async_tx_stop() - * 2. callback can provide FuriHalIrdaTxGetDataStateLastDone response which - * means no more data available for transmission. - * - * Any func (furi_hal_irda_async_tx_stop() or - * furi_hal_irda_async_tx_wait_termination()) has to be called to wait end of - * transmission and free resources. - * - * @param[in] freq frequency for PWM - * @param[in] duty_cycle duty cycle for PWM - */ -void furi_hal_irda_async_tx_start(uint32_t freq, float duty_cycle); - -/** Stop IR asynchronous transmission and free resources. - * - * Transmission will stop as soon as transmission reaches end of package - * (FuriHalIrdaTxGetDataStateDone or FuriHalIrdaTxGetDataStateLastDone). - */ -void furi_hal_irda_async_tx_stop(void); - -/** Wait for end of IR asynchronous transmission and free resources. - * - * Transmission will stop as soon as transmission reaches end of transmission - * (FuriHalIrdaTxGetDataStateLastDone). - */ -void furi_hal_irda_async_tx_wait_termination(void); - -/** Set callback for end of signal transmission - * - * @param[in] callback function to call when signal is sent - * @param[in] context context for callback - */ -void furi_hal_irda_async_tx_set_signal_sent_isr_callback( - FuriHalIrdaTxSignalSentISRCallback callback, - void* context); - -#ifdef __cplusplus -} -#endif diff --git a/lib/ReadMe.md b/lib/ReadMe.md index ec36350a..f29f028b 100644 --- a/lib/ReadMe.md +++ b/lib/ReadMe.md @@ -9,7 +9,7 @@ - `fatfs` - External storage file system - `flipper_file` - Flipper File Format library - `fnv1a-hash` - Fnv1a hash library -- `irda` - Irda library +- `infrared` - Infrared library - `libusb_stm32` - STM32 USB library - `littlefs` - Internal storage file system - `micro-ecc` - Elyptic Curve Crpytography library diff --git a/lib/irda/encoder_decoder/common/irda_common_decoder.c b/lib/infrared/encoder_decoder/common/infrared_common_decoder.c similarity index 70% rename from lib/irda/encoder_decoder/common/irda_common_decoder.c rename to lib/infrared/encoder_decoder/common/infrared_common_decoder.c index 9e597925..c39de09e 100644 --- a/lib/irda/encoder_decoder/common/irda_common_decoder.c +++ b/lib/infrared/encoder_decoder/common/infrared_common_decoder.c @@ -1,13 +1,13 @@ #include "furi/check.h" #include "furi/common_defines.h" -#include "irda.h" -#include "irda_common_i.h" +#include "infrared.h" +#include "infrared_common_i.h" #include #include -#include "irda_i.h" +#include "infrared_i.h" #include -static void irda_common_decoder_reset_state(IrdaCommonDecoder* decoder); +static void infrared_common_decoder_reset_state(InfraredCommonDecoder* decoder); static inline size_t consume_samples(uint32_t* array, size_t len, size_t shift) { furi_assert(len >= shift); @@ -17,7 +17,7 @@ static inline size_t consume_samples(uint32_t* array, size_t len, size_t shift) return len; } -static inline void accumulate_lsb(IrdaCommonDecoder* decoder, bool bit) { +static inline void accumulate_lsb(InfraredCommonDecoder* decoder, bool bit) { uint16_t index = decoder->databit_cnt / 8; uint8_t shift = decoder->databit_cnt % 8; // LSB first @@ -32,7 +32,7 @@ static inline void accumulate_lsb(IrdaCommonDecoder* decoder, bool bit) { ++decoder->databit_cnt; } -static bool irda_check_preamble(IrdaCommonDecoder* decoder) { +static bool infrared_check_preamble(InfraredCommonDecoder* decoder) { furi_assert(decoder); bool result = false; @@ -70,13 +70,13 @@ static bool irda_check_preamble(IrdaCommonDecoder* decoder) { * decoder->protocol->databit_len[1...] contains lesser values, but which can be decoded * for some protocol modifications. */ -static IrdaStatus irda_common_decode_bits(IrdaCommonDecoder* decoder) { +static InfraredStatus infrared_common_decode_bits(InfraredCommonDecoder* decoder) { furi_assert(decoder); - IrdaStatus status = IrdaStatusOk; - const IrdaTimings* timings = &decoder->protocol->timings; + InfraredStatus status = InfraredStatusOk; + const InfraredTimings* timings = &decoder->protocol->timings; - while(decoder->timings_cnt && (status == IrdaStatusOk)) { + while(decoder->timings_cnt && (status == InfraredStatusOk)) { bool level = (decoder->level + decoder->timings_cnt + 1) % 2; uint32_t timing = decoder->timings[0]; @@ -87,19 +87,19 @@ static IrdaStatus irda_common_decode_bits(IrdaCommonDecoder* decoder) { (i < COUNT_OF(decoder->protocol->databit_len)); ++i) { if(decoder->protocol->databit_len[i] == decoder->databit_cnt) { - return IrdaStatusReady; + return InfraredStatusReady; } } } else if(decoder->protocol->databit_len[0] == decoder->databit_cnt) { /* short low timing for longest protocol - this is signal is longer than we expected */ - return IrdaStatusError; + return InfraredStatusError; } } status = decoder->protocol->decode(decoder, level, timing); furi_check(decoder->databit_cnt <= decoder->protocol->databit_len[0]); - furi_assert(status == IrdaStatusError || status == IrdaStatusOk); - if(status == IrdaStatusError) { + furi_assert(status == InfraredStatusError || status == InfraredStatusOk); + if(status == InfraredStatusError) { break; } decoder->timings_cnt = consume_samples(decoder->timings, decoder->timings_cnt, 1); @@ -107,7 +107,7 @@ static IrdaStatus irda_common_decode_bits(IrdaCommonDecoder* decoder) { /* check if largest protocol version can be decoded */ if(level && (decoder->protocol->databit_len[0] == decoder->databit_cnt) && !timings->min_split_time) { - status = IrdaStatusReady; + status = InfraredStatusReady; break; } } @@ -116,10 +116,11 @@ static IrdaStatus irda_common_decode_bits(IrdaCommonDecoder* decoder) { } /* Pulse Distance-Width Modulation */ -IrdaStatus irda_common_decode_pdwm(IrdaCommonDecoder* decoder, bool level, uint32_t timing) { +InfraredStatus + infrared_common_decode_pdwm(InfraredCommonDecoder* decoder, bool level, uint32_t timing) { furi_assert(decoder); - IrdaStatus status = IrdaStatusOk; + InfraredStatus status = InfraredStatusOk; uint32_t bit_tolerance = decoder->protocol->timings.bit_tolerance; uint16_t bit1_mark = decoder->protocol->timings.bit1_mark; uint16_t bit1_space = decoder->protocol->timings.bit1_space; @@ -137,11 +138,11 @@ IrdaStatus irda_common_decode_pdwm(IrdaCommonDecoder* decoder, bool level, uint3 } else if(MATCH_TIMING(timing, bit0, bit_tolerance)) { accumulate_lsb(decoder, 0); } else { - status = IrdaStatusError; + status = InfraredStatusError; } } else { if(!MATCH_TIMING(timing, no_info_timing, bit_tolerance)) { - status = IrdaStatusError; + status = InfraredStatusError; } } @@ -149,7 +150,8 @@ IrdaStatus irda_common_decode_pdwm(IrdaCommonDecoder* decoder, bool level, uint3 } /* level switch detection goes in middle of time-quant */ -IrdaStatus irda_common_decode_manchester(IrdaCommonDecoder* decoder, bool level, uint32_t timing) { +InfraredStatus + infrared_common_decode_manchester(InfraredCommonDecoder* decoder, bool level, uint32_t timing) { furi_assert(decoder); uint16_t bit = decoder->protocol->timings.bit1_mark; uint16_t tolerance = decoder->protocol->timings.bit_tolerance; @@ -161,7 +163,7 @@ IrdaStatus irda_common_decode_manchester(IrdaCommonDecoder* decoder, bool level, bool double_timing = MATCH_TIMING(timing, 2 * bit, tolerance); if(!single_timing && !double_timing) { - return IrdaStatusError; + return InfraredStatusError; } if(decoder->protocol->manchester_start_from_space && (decoder->databit_cnt == 0)) { @@ -171,7 +173,7 @@ IrdaStatus irda_common_decode_manchester(IrdaCommonDecoder* decoder, bool level, if(*switch_detect == 0) { if(double_timing) { - return IrdaStatusError; + return InfraredStatusError; } /* only single timing - level switch required in the middle of time-quant */ *switch_detect = 1; @@ -182,16 +184,16 @@ IrdaStatus irda_common_decode_manchester(IrdaCommonDecoder* decoder, bool level, if(*switch_detect) { if(decoder->protocol->databit_len[0] == decoder->databit_cnt) { - return IrdaStatusError; + return InfraredStatusError; } accumulate_lsb(decoder, level); } - return IrdaStatusOk; + return InfraredStatusOk; } -IrdaMessage* irda_common_decoder_check_ready(IrdaCommonDecoder* decoder) { - IrdaMessage* message = NULL; +InfraredMessage* infrared_common_decoder_check_ready(InfraredCommonDecoder* decoder) { + InfraredMessage* message = NULL; bool found_length = false; for(int i = 0; @@ -207,23 +209,24 @@ IrdaMessage* irda_common_decoder_check_ready(IrdaCommonDecoder* decoder) { decoder->databit_cnt = 0; message = &decoder->message; if(decoder->protocol->decode_repeat) { - decoder->state = IrdaCommonDecoderStateProcessRepeat; + decoder->state = InfraredCommonDecoderStateProcessRepeat; } else { - decoder->state = IrdaCommonDecoderStateWaitPreamble; + decoder->state = InfraredCommonDecoderStateWaitPreamble; } } return message; } -IrdaMessage* irda_common_decode(IrdaCommonDecoder* decoder, bool level, uint32_t duration) { +InfraredMessage* + infrared_common_decode(InfraredCommonDecoder* decoder, bool level, uint32_t duration) { furi_assert(decoder); - IrdaMessage* message = 0; - IrdaStatus status = IrdaStatusError; + InfraredMessage* message = 0; + InfraredStatus status = InfraredStatusError; if(decoder->level == level) { - irda_common_decoder_reset(decoder); + infrared_common_decoder_reset(decoder); } decoder->level = level; // start with low level (Space timing) @@ -233,35 +236,35 @@ IrdaMessage* irda_common_decode(IrdaCommonDecoder* decoder, bool level, uint32_t while(1) { switch(decoder->state) { - case IrdaCommonDecoderStateWaitPreamble: - if(irda_check_preamble(decoder)) { - decoder->state = IrdaCommonDecoderStateDecode; + case InfraredCommonDecoderStateWaitPreamble: + if(infrared_check_preamble(decoder)) { + decoder->state = InfraredCommonDecoderStateDecode; decoder->databit_cnt = 0; decoder->switch_detect = false; continue; } break; - case IrdaCommonDecoderStateDecode: - status = irda_common_decode_bits(decoder); - if(status == IrdaStatusReady) { - message = irda_common_decoder_check_ready(decoder); + case InfraredCommonDecoderStateDecode: + status = infrared_common_decode_bits(decoder); + if(status == InfraredStatusReady) { + message = infrared_common_decoder_check_ready(decoder); if(message) { continue; } else if(decoder->protocol->databit_len[0] == decoder->databit_cnt) { /* error: can't decode largest protocol - begin decoding from start */ - decoder->state = IrdaCommonDecoderStateWaitPreamble; + decoder->state = InfraredCommonDecoderStateWaitPreamble; } - } else if(status == IrdaStatusError) { - irda_common_decoder_reset_state(decoder); + } else if(status == InfraredStatusError) { + infrared_common_decoder_reset_state(decoder); continue; } break; - case IrdaCommonDecoderStateProcessRepeat: + case InfraredCommonDecoderStateProcessRepeat: status = decoder->protocol->decode_repeat(decoder); - if(status == IrdaStatusError) { - irda_common_decoder_reset_state(decoder); + if(status == InfraredStatusError) { + infrared_common_decoder_reset_state(decoder); continue; - } else if(status == IrdaStatusReady) { + } else if(status == InfraredStatusReady) { decoder->message.repeat = true; message = &decoder->message; } @@ -273,7 +276,7 @@ IrdaMessage* irda_common_decode(IrdaCommonDecoder* decoder, bool level, uint32_t return message; } -void* irda_common_decoder_alloc(const IrdaCommonProtocolSpec* protocol) { +void* infrared_common_decoder_alloc(const InfraredCommonProtocolSpec* protocol) { furi_assert(protocol); /* protocol->databit_len[0] has to contain biggest value of bits that can be decoded */ @@ -281,24 +284,24 @@ void* irda_common_decoder_alloc(const IrdaCommonProtocolSpec* protocol) { furi_assert(protocol->databit_len[i] <= protocol->databit_len[0]); } - uint32_t alloc_size = sizeof(IrdaCommonDecoder) + protocol->databit_len[0] / 8 + + uint32_t alloc_size = sizeof(InfraredCommonDecoder) + protocol->databit_len[0] / 8 + !!(protocol->databit_len[0] % 8); - IrdaCommonDecoder* decoder = malloc(alloc_size); + InfraredCommonDecoder* decoder = malloc(alloc_size); decoder->protocol = protocol; decoder->level = true; return decoder; } -void irda_common_decoder_free(IrdaCommonDecoder* decoder) { +void infrared_common_decoder_free(InfraredCommonDecoder* decoder) { furi_assert(decoder); free(decoder); } -void irda_common_decoder_reset_state(IrdaCommonDecoder* decoder) { - decoder->state = IrdaCommonDecoderStateWaitPreamble; +void infrared_common_decoder_reset_state(InfraredCommonDecoder* decoder) { + decoder->state = InfraredCommonDecoderStateWaitPreamble; decoder->databit_cnt = 0; decoder->switch_detect = false; - decoder->message.protocol = IrdaProtocolUnknown; + decoder->message.protocol = InfraredProtocolUnknown; if(decoder->protocol->timings.preamble_mark == 0) { if(decoder->timings_cnt > 0) { decoder->timings_cnt = consume_samples(decoder->timings, decoder->timings_cnt, 1); @@ -306,9 +309,9 @@ void irda_common_decoder_reset_state(IrdaCommonDecoder* decoder) { } } -void irda_common_decoder_reset(IrdaCommonDecoder* decoder) { +void infrared_common_decoder_reset(InfraredCommonDecoder* decoder) { furi_assert(decoder); - irda_common_decoder_reset_state(decoder); + infrared_common_decoder_reset_state(decoder); decoder->timings_cnt = 0; } diff --git a/lib/irda/encoder_decoder/common/irda_common_encoder.c b/lib/infrared/encoder_decoder/common/infrared_common_encoder.c similarity index 64% rename from lib/irda/encoder_decoder/common/irda_common_encoder.c rename to lib/infrared/encoder_decoder/common/infrared_common_encoder.c index 81067650..563c1e64 100644 --- a/lib/irda/encoder_decoder/common/irda_common_encoder.c +++ b/lib/infrared/encoder_decoder/common/infrared_common_encoder.c @@ -1,19 +1,19 @@ #include "furi/check.h" -#include "irda.h" -#include "irda_common_i.h" +#include "infrared.h" +#include "infrared_common_i.h" #include #include -#include "irda_i.h" +#include "infrared_i.h" #include -static IrdaStatus - irda_common_encode_bits(IrdaCommonEncoder* encoder, uint32_t* duration, bool* level) { - IrdaStatus status = encoder->protocol->encode(encoder, duration, level); - furi_assert(status == IrdaStatusOk); +static InfraredStatus + infrared_common_encode_bits(InfraredCommonEncoder* encoder, uint32_t* duration, bool* level) { + InfraredStatus status = encoder->protocol->encode(encoder, duration, level); + furi_assert(status == InfraredStatusOk); ++encoder->timings_encoded; encoder->timings_sum += *duration; if((encoder->bits_encoded == encoder->bits_to_encode) && *level) { - status = IrdaStatusDone; + status = InfraredStatusDone; } return status; @@ -33,13 +33,15 @@ static IrdaStatus * 0 1 2 | 3 4 | * _____-------_____---___ */ -IrdaStatus - irda_common_encode_manchester(IrdaCommonEncoder* encoder, uint32_t* duration, bool* level) { +InfraredStatus infrared_common_encode_manchester( + InfraredCommonEncoder* encoder, + uint32_t* duration, + bool* level) { furi_assert(encoder); furi_assert(duration); furi_assert(level); - const IrdaTimings* timings = &encoder->protocol->timings; + const InfraredTimings* timings = &encoder->protocol->timings; uint8_t index = encoder->bits_encoded / 8; uint8_t shift = encoder->bits_encoded % 8; // LSB first bool logic_value = !!(encoder->data[index] & (0x01 << shift)); @@ -52,15 +54,16 @@ IrdaStatus else if(*level && (encoder->bits_encoded + 1 == encoder->bits_to_encode)) ++encoder->bits_encoded; /* don't encode last space */ - return IrdaStatusOk; + return InfraredStatusOk; } -IrdaStatus irda_common_encode_pdwm(IrdaCommonEncoder* encoder, uint32_t* duration, bool* level) { +InfraredStatus + infrared_common_encode_pdwm(InfraredCommonEncoder* encoder, uint32_t* duration, bool* level) { furi_assert(encoder); furi_assert(duration); furi_assert(level); - const IrdaTimings* timings = &encoder->protocol->timings; + const InfraredTimings* timings = &encoder->protocol->timings; uint8_t index = encoder->bits_encoded / 8; uint8_t shift = encoder->bits_encoded % 8; // LSB first bool logic_value = !!(encoder->data[index] & (0x01 << shift)); @@ -76,26 +79,27 @@ IrdaStatus irda_common_encode_pdwm(IrdaCommonEncoder* encoder, uint32_t* duratio if(!pwm) ++encoder->bits_encoded; } - return IrdaStatusOk; + return InfraredStatusOk; } -IrdaStatus irda_common_encode(IrdaCommonEncoder* encoder, uint32_t* duration, bool* level) { +InfraredStatus + infrared_common_encode(InfraredCommonEncoder* encoder, uint32_t* duration, bool* level) { furi_assert(encoder); furi_assert(duration); furi_assert(level); - IrdaStatus status = IrdaStatusOk; - const IrdaTimings* timings = &encoder->protocol->timings; + InfraredStatus status = InfraredStatusOk; + const InfraredTimings* timings = &encoder->protocol->timings; switch(encoder->state) { - case IrdaCommonEncoderStateSilence: + case InfraredCommonEncoderStateSilence: *duration = encoder->protocol->timings.silence_time; *level = false; - status = IrdaStatusOk; - encoder->state = IrdaCommonEncoderStatePreamble; + status = InfraredStatusOk; + encoder->state = InfraredCommonEncoderStatePreamble; ++encoder->timings_encoded; encoder->timings_sum = 0; break; - case IrdaCommonEncoderStatePreamble: + case InfraredCommonEncoderStatePreamble: if(timings->preamble_mark) { if(encoder->timings_encoded == 1) { *duration = timings->preamble_mark; @@ -103,39 +107,39 @@ IrdaStatus irda_common_encode(IrdaCommonEncoder* encoder, uint32_t* duration, bo } else { *duration = timings->preamble_space; *level = false; - encoder->state = IrdaCommonEncoderStateEncode; + encoder->state = InfraredCommonEncoderStateEncode; } ++encoder->timings_encoded; encoder->timings_sum += *duration; break; } else { - encoder->state = IrdaCommonEncoderStateEncode; + encoder->state = InfraredCommonEncoderStateEncode; } /* FALLTHROUGH */ - case IrdaCommonEncoderStateEncode: - status = irda_common_encode_bits(encoder, duration, level); - if(status == IrdaStatusDone) { + case InfraredCommonEncoderStateEncode: + status = infrared_common_encode_bits(encoder, duration, level); + if(status == InfraredStatusDone) { if(encoder->protocol->encode_repeat) { - encoder->state = IrdaCommonEncoderStateEncodeRepeat; + encoder->state = InfraredCommonEncoderStateEncodeRepeat; } else { encoder->timings_encoded = 0; encoder->timings_sum = 0; encoder->bits_encoded = 0; encoder->switch_detect = 0; - encoder->state = IrdaCommonEncoderStateSilence; + encoder->state = InfraredCommonEncoderStateSilence; } } break; - case IrdaCommonEncoderStateEncodeRepeat: + case InfraredCommonEncoderStateEncodeRepeat: status = encoder->protocol->encode_repeat(encoder, duration, level); break; } return status; } -void* irda_common_encoder_alloc(const IrdaCommonProtocolSpec* protocol) { +void* infrared_common_encoder_alloc(const InfraredCommonProtocolSpec* protocol) { furi_assert(protocol); - if(protocol->decode == irda_common_decode_pdwm) { + if(protocol->decode == infrared_common_decode_pdwm) { furi_assert( (protocol->timings.bit1_mark == protocol->timings.bit0_mark) ^ (protocol->timings.bit1_space == protocol->timings.bit0_space)); @@ -146,26 +150,26 @@ void* irda_common_encoder_alloc(const IrdaCommonProtocolSpec* protocol) { furi_assert(protocol->databit_len[i] <= protocol->databit_len[0]); } - uint32_t alloc_size = sizeof(IrdaCommonDecoder) + protocol->databit_len[0] / 8 + + uint32_t alloc_size = sizeof(InfraredCommonDecoder) + protocol->databit_len[0] / 8 + !!(protocol->databit_len[0] % 8); - IrdaCommonEncoder* encoder = malloc(alloc_size); + InfraredCommonEncoder* encoder = malloc(alloc_size); memset(encoder, 0, alloc_size); encoder->protocol = protocol; return encoder; } -void irda_common_encoder_free(IrdaCommonEncoder* encoder) { +void infrared_common_encoder_free(InfraredCommonEncoder* encoder) { furi_assert(encoder); free(encoder); } -void irda_common_encoder_reset(IrdaCommonEncoder* encoder) { +void infrared_common_encoder_reset(InfraredCommonEncoder* encoder) { furi_assert(encoder); encoder->timings_encoded = 0; encoder->timings_sum = 0; encoder->bits_encoded = 0; - encoder->state = IrdaCommonEncoderStateSilence; + encoder->state = InfraredCommonEncoderStateSilence; encoder->switch_detect = 0; uint8_t max_databit_len = 0; diff --git a/lib/infrared/encoder_decoder/common/infrared_common_i.h b/lib/infrared/encoder_decoder/common/infrared_common_i.h new file mode 100644 index 00000000..20dbeb79 --- /dev/null +++ b/lib/infrared/encoder_decoder/common/infrared_common_i.h @@ -0,0 +1,89 @@ +#pragma once + +#include +#include "infrared.h" +#include "infrared_i.h" + +#define MATCH_TIMING(x, v, delta) (((x) < (v + delta)) && ((x) > (v - delta))) + +typedef struct InfraredCommonDecoder InfraredCommonDecoder; +typedef struct InfraredCommonEncoder InfraredCommonEncoder; + +typedef InfraredStatus (*InfraredCommonDecode)(InfraredCommonDecoder*, bool, uint32_t); +typedef InfraredStatus (*InfraredCommonDecodeRepeat)(InfraredCommonDecoder*); +typedef bool (*InfraredCommonInterpret)(InfraredCommonDecoder*); +typedef InfraredStatus ( + *InfraredCommonEncode)(InfraredCommonEncoder* encoder, uint32_t* out, bool* polarity); + +typedef struct { + InfraredTimings timings; + bool manchester_start_from_space; + bool no_stop_bit; + uint8_t databit_len[4]; + InfraredCommonDecode decode; + InfraredCommonDecodeRepeat decode_repeat; + InfraredCommonInterpret interpret; + InfraredCommonEncode encode; + InfraredCommonEncode encode_repeat; +} InfraredCommonProtocolSpec; + +typedef enum { + InfraredCommonDecoderStateWaitPreamble, + InfraredCommonDecoderStateDecode, + InfraredCommonDecoderStateProcessRepeat, +} InfraredCommonStateDecoder; + +typedef enum { + InfraredCommonEncoderStateSilence, + InfraredCommonEncoderStatePreamble, + InfraredCommonEncoderStateEncode, + InfraredCommonEncoderStateEncodeRepeat, +} InfraredCommonStateEncoder; + +struct InfraredCommonDecoder { + const InfraredCommonProtocolSpec* protocol; + void* context; + uint32_t timings[6]; + InfraredMessage message; + InfraredCommonStateDecoder state; + uint8_t timings_cnt; + bool switch_detect; + bool level; + uint16_t databit_cnt; + uint8_t data[]; +}; + +struct InfraredCommonEncoder { + const InfraredCommonProtocolSpec* protocol; + InfraredCommonStateEncoder state; + bool switch_detect; + uint8_t bits_to_encode; + uint8_t bits_encoded; + uint32_t timings_sum; + uint32_t timings_encoded; + void* context; + uint8_t data[]; +}; + +InfraredMessage* + infrared_common_decode(InfraredCommonDecoder* decoder, bool level, uint32_t duration); +InfraredStatus + infrared_common_decode_pdwm(InfraredCommonDecoder* decoder, bool level, uint32_t timing); +InfraredStatus + infrared_common_decode_manchester(InfraredCommonDecoder* decoder, bool level, uint32_t timing); +void* infrared_common_decoder_alloc(const InfraredCommonProtocolSpec* protocol); +void infrared_common_decoder_free(InfraredCommonDecoder* decoder); +void infrared_common_decoder_reset(InfraredCommonDecoder* decoder); +InfraredMessage* infrared_common_decoder_check_ready(InfraredCommonDecoder* decoder); + +InfraredStatus + infrared_common_encode(InfraredCommonEncoder* encoder, uint32_t* duration, bool* polarity); +InfraredStatus + infrared_common_encode_pdwm(InfraredCommonEncoder* encoder, uint32_t* duration, bool* polarity); +InfraredStatus infrared_common_encode_manchester( + InfraredCommonEncoder* encoder, + uint32_t* duration, + bool* polarity); +void* infrared_common_encoder_alloc(const InfraredCommonProtocolSpec* protocol); +void infrared_common_encoder_free(InfraredCommonEncoder* encoder); +void infrared_common_encoder_reset(InfraredCommonEncoder* encoder); diff --git a/lib/infrared/encoder_decoder/common/infrared_common_protocol_defs.c b/lib/infrared/encoder_decoder/common/infrared_common_protocol_defs.c new file mode 100644 index 00000000..e8f7664a --- /dev/null +++ b/lib/infrared/encoder_decoder/common/infrared_common_protocol_defs.c @@ -0,0 +1,117 @@ +#include "infrared_common_i.h" +#include "infrared_protocol_defs_i.h" + +const InfraredCommonProtocolSpec protocol_nec = { + .timings = + { + .preamble_mark = INFRARED_NEC_PREAMBLE_MARK, + .preamble_space = INFRARED_NEC_PREAMBLE_SPACE, + .bit1_mark = INFRARED_NEC_BIT1_MARK, + .bit1_space = INFRARED_NEC_BIT1_SPACE, + .bit0_mark = INFRARED_NEC_BIT0_MARK, + .bit0_space = INFRARED_NEC_BIT0_SPACE, + .preamble_tolerance = INFRARED_NEC_PREAMBLE_TOLERANCE, + .bit_tolerance = INFRARED_NEC_BIT_TOLERANCE, + .silence_time = INFRARED_NEC_SILENCE, + .min_split_time = INFRARED_NEC_MIN_SPLIT_TIME, + }, + .databit_len[0] = 42, + .databit_len[1] = 32, + .no_stop_bit = false, + .decode = infrared_common_decode_pdwm, + .encode = infrared_common_encode_pdwm, + .interpret = infrared_decoder_nec_interpret, + .decode_repeat = infrared_decoder_nec_decode_repeat, + .encode_repeat = infrared_encoder_nec_encode_repeat, +}; + +const InfraredCommonProtocolSpec protocol_samsung32 = { + .timings = + { + .preamble_mark = INFRARED_SAMSUNG_PREAMBLE_MARK, + .preamble_space = INFRARED_SAMSUNG_PREAMBLE_SPACE, + .bit1_mark = INFRARED_SAMSUNG_BIT1_MARK, + .bit1_space = INFRARED_SAMSUNG_BIT1_SPACE, + .bit0_mark = INFRARED_SAMSUNG_BIT0_MARK, + .bit0_space = INFRARED_SAMSUNG_BIT0_SPACE, + .preamble_tolerance = INFRARED_SAMSUNG_PREAMBLE_TOLERANCE, + .bit_tolerance = INFRARED_SAMSUNG_BIT_TOLERANCE, + .silence_time = INFRARED_SAMSUNG_SILENCE, + .min_split_time = INFRARED_SAMSUNG_MIN_SPLIT_TIME, + }, + .databit_len[0] = 32, + .no_stop_bit = false, + .decode = infrared_common_decode_pdwm, + .encode = infrared_common_encode_pdwm, + .interpret = infrared_decoder_samsung32_interpret, + .decode_repeat = infrared_decoder_samsung32_decode_repeat, + .encode_repeat = infrared_encoder_samsung32_encode_repeat, +}; + +const InfraredCommonProtocolSpec protocol_rc6 = { + .timings = + { + .preamble_mark = INFRARED_RC6_PREAMBLE_MARK, + .preamble_space = INFRARED_RC6_PREAMBLE_SPACE, + .bit1_mark = INFRARED_RC6_BIT, + .preamble_tolerance = INFRARED_RC6_PREAMBLE_TOLERANCE, + .bit_tolerance = INFRARED_RC6_BIT_TOLERANCE, + .silence_time = INFRARED_RC6_SILENCE, + .min_split_time = INFRARED_RC6_MIN_SPLIT_TIME, + }, + .databit_len[0] = + 1 + 3 + 1 + 8 + + 8, // start_bit + 3 mode bits, + 1 toggle bit (x2 timing) + 8 address + 8 command + .manchester_start_from_space = false, + .decode = infrared_decoder_rc6_decode_manchester, + .encode = infrared_encoder_rc6_encode_manchester, + .interpret = infrared_decoder_rc6_interpret, + .decode_repeat = NULL, + .encode_repeat = NULL, +}; + +const InfraredCommonProtocolSpec protocol_rc5 = { + .timings = + { + .preamble_mark = 0, + .preamble_space = 0, + .bit1_mark = INFRARED_RC5_BIT, + .preamble_tolerance = 0, + .bit_tolerance = INFRARED_RC5_BIT_TOLERANCE, + .silence_time = INFRARED_RC5_SILENCE, + .min_split_time = INFRARED_RC5_MIN_SPLIT_TIME, + }, + .databit_len[0] = 1 + 1 + 1 + 5 + + 6, // start_bit + start_bit/command_bit + toggle_bit + 5 address + 6 command + .manchester_start_from_space = true, + .decode = infrared_common_decode_manchester, + .encode = infrared_common_encode_manchester, + .interpret = infrared_decoder_rc5_interpret, + .decode_repeat = NULL, + .encode_repeat = NULL, +}; + +const InfraredCommonProtocolSpec protocol_sirc = { + .timings = + { + .preamble_mark = INFRARED_SIRC_PREAMBLE_MARK, + .preamble_space = INFRARED_SIRC_PREAMBLE_SPACE, + .bit1_mark = INFRARED_SIRC_BIT1_MARK, + .bit1_space = INFRARED_SIRC_BIT1_SPACE, + .bit0_mark = INFRARED_SIRC_BIT0_MARK, + .bit0_space = INFRARED_SIRC_BIT0_SPACE, + .preamble_tolerance = INFRARED_SIRC_PREAMBLE_TOLERANCE, + .bit_tolerance = INFRARED_SIRC_BIT_TOLERANCE, + .silence_time = INFRARED_SIRC_SILENCE, + .min_split_time = INFRARED_SIRC_MIN_SPLIT_TIME, + }, + .databit_len[0] = 20, + .databit_len[1] = 15, + .databit_len[2] = 12, + .no_stop_bit = true, + .decode = infrared_common_decode_pdwm, + .encode = infrared_common_encode_pdwm, + .interpret = infrared_decoder_sirc_interpret, + .decode_repeat = NULL, + .encode_repeat = infrared_encoder_sirc_encode_repeat, +}; diff --git a/lib/infrared/encoder_decoder/infrared.c b/lib/infrared/encoder_decoder/infrared.c new file mode 100644 index 00000000..5dfa9281 --- /dev/null +++ b/lib/infrared/encoder_decoder/infrared.c @@ -0,0 +1,301 @@ +#include "infrared.h" +#include "furi/check.h" +#include "common/infrared_common_i.h" +#include "infrared_protocol_defs_i.h" +#include +#include +#include +#include +#include "infrared_i.h" +#include + +typedef struct { + InfraredAlloc alloc; + InfraredDecode decode; + InfraredDecoderReset reset; + InfraredFree free; + InfraredDecoderCheckReady check_ready; +} InfraredDecoders; + +typedef struct { + InfraredAlloc alloc; + InfraredEncode encode; + InfraredEncoderReset reset; + InfraredFree free; +} InfraredEncoders; + +struct InfraredDecoderHandler { + void** ctx; +}; + +struct InfraredEncoderHandler { + void* handler; + const InfraredEncoders* encoder; +}; + +typedef struct { + InfraredEncoders encoder; + InfraredDecoders decoder; + InfraredGetProtocolSpec get_protocol_spec; +} InfraredEncoderDecoder; + +static const InfraredEncoderDecoder infrared_encoder_decoder[] = { + { + .decoder = + {.alloc = infrared_decoder_nec_alloc, + .decode = infrared_decoder_nec_decode, + .reset = infrared_decoder_nec_reset, + .check_ready = infrared_decoder_nec_check_ready, + .free = infrared_decoder_nec_free}, + .encoder = + {.alloc = infrared_encoder_nec_alloc, + .encode = infrared_encoder_nec_encode, + .reset = infrared_encoder_nec_reset, + .free = infrared_encoder_nec_free}, + .get_protocol_spec = infrared_nec_get_spec, + }, + { + .decoder = + {.alloc = infrared_decoder_samsung32_alloc, + .decode = infrared_decoder_samsung32_decode, + .reset = infrared_decoder_samsung32_reset, + .check_ready = infrared_decoder_samsung32_check_ready, + .free = infrared_decoder_samsung32_free}, + .encoder = + {.alloc = infrared_encoder_samsung32_alloc, + .encode = infrared_encoder_samsung32_encode, + .reset = infrared_encoder_samsung32_reset, + .free = infrared_encoder_samsung32_free}, + .get_protocol_spec = infrared_samsung32_get_spec, + }, + { + .decoder = + {.alloc = infrared_decoder_rc5_alloc, + .decode = infrared_decoder_rc5_decode, + .reset = infrared_decoder_rc5_reset, + .check_ready = infrared_decoder_rc5_check_ready, + .free = infrared_decoder_rc5_free}, + .encoder = + {.alloc = infrared_encoder_rc5_alloc, + .encode = infrared_encoder_rc5_encode, + .reset = infrared_encoder_rc5_reset, + .free = infrared_encoder_rc5_free}, + .get_protocol_spec = infrared_rc5_get_spec, + }, + { + .decoder = + {.alloc = infrared_decoder_rc6_alloc, + .decode = infrared_decoder_rc6_decode, + .reset = infrared_decoder_rc6_reset, + .check_ready = infrared_decoder_rc6_check_ready, + .free = infrared_decoder_rc6_free}, + .encoder = + {.alloc = infrared_encoder_rc6_alloc, + .encode = infrared_encoder_rc6_encode, + .reset = infrared_encoder_rc6_reset, + .free = infrared_encoder_rc6_free}, + .get_protocol_spec = infrared_rc6_get_spec, + }, + { + .decoder = + {.alloc = infrared_decoder_sirc_alloc, + .decode = infrared_decoder_sirc_decode, + .reset = infrared_decoder_sirc_reset, + .check_ready = infrared_decoder_sirc_check_ready, + .free = infrared_decoder_sirc_free}, + .encoder = + {.alloc = infrared_encoder_sirc_alloc, + .encode = infrared_encoder_sirc_encode, + .reset = infrared_encoder_sirc_reset, + .free = infrared_encoder_sirc_free}, + .get_protocol_spec = infrared_sirc_get_spec, + }, +}; + +static int infrared_find_index_by_protocol(InfraredProtocol protocol); +static const InfraredProtocolSpecification* + infrared_get_spec_by_protocol(InfraredProtocol protocol); + +const InfraredMessage* + infrared_decode(InfraredDecoderHandler* handler, bool level, uint32_t duration) { + furi_assert(handler); + + InfraredMessage* message = NULL; + InfraredMessage* result = NULL; + + for(int i = 0; i < COUNT_OF(infrared_encoder_decoder); ++i) { + if(infrared_encoder_decoder[i].decoder.decode) { + message = infrared_encoder_decoder[i].decoder.decode(handler->ctx[i], level, duration); + if(!result && message) { + result = message; + } + } + } + + return result; +} + +InfraredDecoderHandler* infrared_alloc_decoder(void) { + InfraredDecoderHandler* handler = malloc(sizeof(InfraredDecoderHandler)); + handler->ctx = malloc(sizeof(void*) * COUNT_OF(infrared_encoder_decoder)); + + for(int i = 0; i < COUNT_OF(infrared_encoder_decoder); ++i) { + handler->ctx[i] = 0; + if(infrared_encoder_decoder[i].decoder.alloc) + handler->ctx[i] = infrared_encoder_decoder[i].decoder.alloc(); + } + + infrared_reset_decoder(handler); + return handler; +} + +void infrared_free_decoder(InfraredDecoderHandler* handler) { + furi_assert(handler); + furi_assert(handler->ctx); + + for(int i = 0; i < COUNT_OF(infrared_encoder_decoder); ++i) { + if(infrared_encoder_decoder[i].decoder.free) + infrared_encoder_decoder[i].decoder.free(handler->ctx[i]); + } + + free(handler->ctx); + free(handler); +} + +void infrared_reset_decoder(InfraredDecoderHandler* handler) { + for(int i = 0; i < COUNT_OF(infrared_encoder_decoder); ++i) { + if(infrared_encoder_decoder[i].decoder.reset) + infrared_encoder_decoder[i].decoder.reset(handler->ctx[i]); + } +} + +const InfraredMessage* infrared_check_decoder_ready(InfraredDecoderHandler* handler) { + furi_assert(handler); + + InfraredMessage* message = NULL; + InfraredMessage* result = NULL; + + for(int i = 0; i < COUNT_OF(infrared_encoder_decoder); ++i) { + if(infrared_encoder_decoder[i].decoder.check_ready) { + message = infrared_encoder_decoder[i].decoder.check_ready(handler->ctx[i]); + if(!result && message) { + result = message; + } + } + } + + return result; +} + +InfraredEncoderHandler* infrared_alloc_encoder(void) { + InfraredEncoderHandler* handler = malloc(sizeof(InfraredEncoderHandler)); + handler->handler = NULL; + handler->encoder = NULL; + return handler; +} + +void infrared_free_encoder(InfraredEncoderHandler* handler) { + furi_assert(handler); + const InfraredEncoders* encoder = handler->encoder; + + if(encoder || handler->handler) { + furi_assert(encoder); + furi_assert(handler->handler); + furi_assert(encoder->free); + encoder->free(handler->handler); + } + + free(handler); +} + +static int infrared_find_index_by_protocol(InfraredProtocol protocol) { + for(int i = 0; i < COUNT_OF(infrared_encoder_decoder); ++i) { + if(infrared_encoder_decoder[i].get_protocol_spec(protocol)) { + return i; + } + } + + return -1; +} + +void infrared_reset_encoder(InfraredEncoderHandler* handler, const InfraredMessage* message) { + furi_assert(handler); + furi_assert(message); + int index = infrared_find_index_by_protocol(message->protocol); + furi_check(index >= 0); + + const InfraredEncoders* required_encoder = &infrared_encoder_decoder[index].encoder; + furi_assert(required_encoder); + furi_assert(required_encoder->reset); + furi_assert(required_encoder->alloc); + + /* Realloc encoder if different protocol set */ + if(required_encoder != handler->encoder) { + if(handler->handler != NULL) { + furi_assert(handler->encoder->free); + handler->encoder->free(handler->handler); + } + handler->encoder = required_encoder; + handler->handler = handler->encoder->alloc(); + } + + handler->encoder->reset(handler->handler, message); +} + +InfraredStatus infrared_encode(InfraredEncoderHandler* handler, uint32_t* duration, bool* level) { + furi_assert(handler); + furi_assert(duration); + furi_assert(level); + const InfraredEncoders* encoder = handler->encoder; + furi_assert(encoder); + furi_assert(encoder->encode); + + InfraredStatus status = encoder->encode(handler->handler, duration, level); + furi_assert(status != InfraredStatusError); + + return status; +} + +bool infrared_is_protocol_valid(InfraredProtocol protocol) { + return infrared_find_index_by_protocol(protocol) >= 0; +} + +InfraredProtocol infrared_get_protocol_by_name(const char* protocol_name) { + for(InfraredProtocol protocol = 0; protocol < InfraredProtocolMAX; ++protocol) { + const char* name = infrared_get_protocol_name(protocol); + if(!strcmp(name, protocol_name)) return protocol; + } + return InfraredProtocolUnknown; +} + +static const InfraredProtocolSpecification* + infrared_get_spec_by_protocol(InfraredProtocol protocol) { + int index = infrared_find_index_by_protocol(protocol); + const InfraredProtocolSpecification* spec = NULL; + if(index >= 0) { + spec = infrared_encoder_decoder[index].get_protocol_spec(protocol); + } + + furi_assert(spec); + return spec; +} + +const char* infrared_get_protocol_name(InfraredProtocol protocol) { + return infrared_get_spec_by_protocol(protocol)->name; +} + +uint8_t infrared_get_protocol_address_length(InfraredProtocol protocol) { + return infrared_get_spec_by_protocol(protocol)->address_length; +} + +uint8_t infrared_get_protocol_command_length(InfraredProtocol protocol) { + return infrared_get_spec_by_protocol(protocol)->command_length; +} + +uint32_t infrared_get_protocol_frequency(InfraredProtocol protocol) { + return infrared_get_spec_by_protocol(protocol)->frequency; +} + +float infrared_get_protocol_duty_cycle(InfraredProtocol protocol) { + return infrared_get_spec_by_protocol(protocol)->duty_cycle; +} diff --git a/lib/infrared/encoder_decoder/infrared.h b/lib/infrared/encoder_decoder/infrared.h new file mode 100644 index 00000000..94591300 --- /dev/null +++ b/lib/infrared/encoder_decoder/infrared.h @@ -0,0 +1,205 @@ +#pragma once + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#define INFRARED_COMMON_CARRIER_FREQUENCY ((uint32_t)38000) +#define INFRARED_COMMON_DUTY_CYCLE ((float)0.33) + +/* if we want to see splitted raw signals during brutforce, + * we have to have RX raw timing delay less than TX */ +#define INFRARED_RAW_RX_TIMING_DELAY_US 150000 +#define INFRARED_RAW_TX_TIMING_DELAY_US 180000 + +typedef struct InfraredDecoderHandler InfraredDecoderHandler; +typedef struct InfraredEncoderHandler InfraredEncoderHandler; + +typedef enum { + InfraredProtocolUnknown = -1, + InfraredProtocolNEC = 0, + InfraredProtocolNECext, + InfraredProtocolNEC42, + InfraredProtocolNEC42ext, + InfraredProtocolSamsung32, + InfraredProtocolRC6, + InfraredProtocolRC5, + InfraredProtocolRC5X, + InfraredProtocolSIRC, + InfraredProtocolSIRC15, + InfraredProtocolSIRC20, + InfraredProtocolMAX, +} InfraredProtocol; + +typedef struct { + InfraredProtocol protocol; + uint32_t address; + uint32_t command; + bool repeat; +} InfraredMessage; + +typedef enum { + InfraredStatusError, + InfraredStatusOk, + InfraredStatusDone, + InfraredStatusReady, +} InfraredStatus; + +/** + * Initialize decoder. + * + * \return returns pointer to INFRARED decoder handler if success, otherwise - error. + */ +InfraredDecoderHandler* infrared_alloc_decoder(void); + +/** + * Provide to decoder next timing. + * + * \param[in] handler - handler to INFRARED decoders. Should be acquired with \c infrared_alloc_decoder(). + * \param[in] level - high(true) or low(false) level of input signal to analyze. + * it should alternate every call, otherwise it is an error case, + * and decoder resets its state and start decoding from the start. + * \param[in] duration - duration of steady high/low input signal. + * \return if message is ready, returns pointer to decoded message, returns NULL. + * Note: ownership of returned ptr belongs to handler. So pointer is valid + * up to next infrared_free_decoder(), infrared_reset_decoder(), + * infrared_decode(), infrared_check_decoder_ready() calls. + */ +const InfraredMessage* + infrared_decode(InfraredDecoderHandler* handler, bool level, uint32_t duration); + +/** + * Check whether decoder is ready. + * Functionality is quite similar to infrared_decode(), but with no timing providing. + * Some protocols (e.g. Sony SIRC) has variable payload length, which means we + * can't recognize end of message right after receiving last bit. That's why + * application should call to infrared_check_decoder_ready() after some timeout to + * retrieve decoded message, if so. + * + * \param[in] handler - handler to INFRARED decoders. Should be acquired with \c infrared_alloc_decoder(). + * \return if message is ready, returns pointer to decoded message, returns NULL. + * Note: ownership of returned ptr belongs to handler. So pointer is valid + * up to next infrared_free_decoder(), infrared_reset_decoder(), + * infrared_decode(), infrared_check_decoder_ready() calls. + */ +const InfraredMessage* infrared_check_decoder_ready(InfraredDecoderHandler* handler); + +/** + * Deinitialize decoder and free allocated memory. + * + * \param[in] handler - handler to INFRARED decoders. Should be acquired with \c infrared_alloc_decoder(). + */ +void infrared_free_decoder(InfraredDecoderHandler* handler); + +/** + * Reset INFRARED decoder. + * + * \param[in] handler - handler to INFRARED decoders. Should be acquired with \c infrared_alloc_decoder(). + */ +void infrared_reset_decoder(InfraredDecoderHandler* handler); + +/** + * Get protocol name by protocol enum. + * + * \param[in] protocol - protocol identifier. + * \return string to protocol name. + */ +const char* infrared_get_protocol_name(InfraredProtocol protocol); + +/** + * Get protocol enum by protocol name. + * + * \param[in] protocol_name - string to protocol name. + * \return protocol identifier. + */ +InfraredProtocol infrared_get_protocol_by_name(const char* protocol_name); + +/** + * Get address length by protocol enum. + * + * \param[in] protocol - protocol identifier. + * \return length of address in bits. + */ +uint8_t infrared_get_protocol_address_length(InfraredProtocol protocol); + +/** + * Get command length by protocol enum. + * + * \param[in] protocol - protocol identifier. + * \return length of command in bits. + */ +uint8_t infrared_get_protocol_command_length(InfraredProtocol protocol); + +/** + * Checks whether protocol valid. + * + * \param[in] protocol - protocol identifier. + * \return true if protocol is valid, false otherwise. + */ +bool infrared_is_protocol_valid(InfraredProtocol protocol); + +/** + * Allocate INFRARED encoder. + * + * \return encoder handler. + */ +InfraredEncoderHandler* infrared_alloc_encoder(void); + +/** + * Free encoder handler previously allocated with \c infrared_alloc_encoder(). + * + * \param[in] handler - handler to INFRARED encoder. Should be acquired with \c infrared_alloc_encoder(). + */ +void infrared_free_encoder(InfraredEncoderHandler* handler); + +/** + * Encode previously set INFRARED message. + * Usage: + * 1) alloc with \c infrared_alloc_encoder() + * 2) set message to encode with \c infrared_reset_encoder() + * 3) call for \c infrared_encode() to continuously get one at a time timings. + * 4) when \c infrared_encode() returns InfraredStatusDone, it means new message is fully encoded. + * 5) to encode additional timings, just continue calling \c infrared_encode(). + * + * \param[in] handler - handler to INFRARED encoder. Should be acquired with \c infrared_alloc_encoder(). + * \param[out] duration - encoded timing. + * \param[out] level - encoded level. + * + * \return status of encode operation. + */ +InfraredStatus infrared_encode(InfraredEncoderHandler* handler, uint32_t* duration, bool* level); + +/** + * Reset INFRARED encoder and set new message to encode. If it's not called after receiveing + * InfraredStatusDone in \c infrared_encode(), encoder will encode repeat messages + * till the end of time. + * + * \param[in] handler - handler to INFRARED encoder. Should be acquired with \c infrared_alloc_encoder(). + * \param[in] message - message to encode. + */ +void infrared_reset_encoder(InfraredEncoderHandler* handler, const InfraredMessage* message); + +/** + * Get PWM frequency value for selected protocol + * + * \param[in] protocol - protocol to get from PWM frequency + * + * \return frequency + */ +uint32_t infrared_get_protocol_frequency(InfraredProtocol protocol); + +/** + * Get PWM duty cycle value for selected protocol + * + * \param[in] protocol - protocol to get from PWM duty cycle + * + * \return duty cycle + */ +float infrared_get_protocol_duty_cycle(InfraredProtocol protocol); + +#ifdef __cplusplus +} +#endif diff --git a/lib/irda/encoder_decoder/irda_i.h b/lib/infrared/encoder_decoder/infrared_i.h similarity index 53% rename from lib/irda/encoder_decoder/irda_i.h rename to lib/infrared/encoder_decoder/infrared_i.h index 3ff980d5..3a645ced 100644 --- a/lib/irda/encoder_decoder/irda_i.h +++ b/lib/infrared/encoder_decoder/infrared_i.h @@ -1,5 +1,5 @@ #pragma once -#include "irda.h" +#include "infrared.h" #include #include @@ -14,7 +14,7 @@ typedef struct { uint16_t bit0_space; uint32_t preamble_tolerance; uint32_t bit_tolerance; -} IrdaTimings; +} InfraredTimings; typedef struct { const char* name; @@ -22,19 +22,19 @@ typedef struct { uint8_t command_length; uint32_t frequency; float duty_cycle; -} IrdaProtocolSpecification; +} InfraredProtocolSpecification; -typedef const IrdaProtocolSpecification* (*IrdaGetProtocolSpec)(IrdaProtocol protocol); +typedef const InfraredProtocolSpecification* (*InfraredGetProtocolSpec)(InfraredProtocol protocol); -typedef void* (*IrdaAlloc)(void); -typedef void (*IrdaFree)(void*); +typedef void* (*InfraredAlloc)(void); +typedef void (*InfraredFree)(void*); -typedef void (*IrdaDecoderReset)(void*); -typedef IrdaMessage* (*IrdaDecode)(void* ctx, bool level, uint32_t duration); -typedef IrdaMessage* (*IrdaDecoderCheckReady)(void*); +typedef void (*InfraredDecoderReset)(void*); +typedef InfraredMessage* (*InfraredDecode)(void* ctx, bool level, uint32_t duration); +typedef InfraredMessage* (*InfraredDecoderCheckReady)(void*); -typedef void (*IrdaEncoderReset)(void* encoder, const IrdaMessage* message); -typedef IrdaStatus (*IrdaEncode)(void* encoder, uint32_t* out, bool* polarity); +typedef void (*InfraredEncoderReset)(void* encoder, const InfraredMessage* message); +typedef InfraredStatus (*InfraredEncode)(void* encoder, uint32_t* out, bool* polarity); static inline uint8_t reverse(uint8_t value) { uint8_t reverse_value = 0; diff --git a/lib/infrared/encoder_decoder/infrared_protocol_defs_i.h b/lib/infrared/encoder_decoder/infrared_protocol_defs_i.h new file mode 100644 index 00000000..575961f1 --- /dev/null +++ b/lib/infrared/encoder_decoder/infrared_protocol_defs_i.h @@ -0,0 +1,269 @@ +#pragma once + +#include +#include +#include +#include "infrared.h" +#include "common/infrared_common_i.h" + +/*************************************************************************************************** +* NEC protocol description +* https://radioparty.ru/manuals/encyclopedia/213-ircontrol?start=1 +**************************************************************************************************** +* Preamble Preamble Pulse Distance/Width Pause Preamble Preamble Stop +* mark space Modulation up to period repeat repeat bit +* mark space +* +* 9000 4500 32 bit + stop bit ...110000 9000 2250 +* __________ _ _ _ _ _ _ _ _ _ _ _ _ _ ___________ _ +* ____ __________ _ _ _ __ __ __ _ _ __ __ _ _ ________________ ____________ ___ +* +***************************************************************************************************/ + +#define INFRARED_NEC_PREAMBLE_MARK 9000 +#define INFRARED_NEC_PREAMBLE_SPACE 4500 +#define INFRARED_NEC_BIT1_MARK 560 +#define INFRARED_NEC_BIT1_SPACE 1690 +#define INFRARED_NEC_BIT0_MARK 560 +#define INFRARED_NEC_BIT0_SPACE 560 +#define INFRARED_NEC_REPEAT_PERIOD 110000 +#define INFRARED_NEC_SILENCE INFRARED_NEC_REPEAT_PERIOD +#define INFRARED_NEC_MIN_SPLIT_TIME INFRARED_NEC_REPEAT_PAUSE_MIN +#define INFRARED_NEC_REPEAT_PAUSE_MIN 4000 +#define INFRARED_NEC_REPEAT_PAUSE_MAX 150000 +#define INFRARED_NEC_REPEAT_MARK 9000 +#define INFRARED_NEC_REPEAT_SPACE 2250 +#define INFRARED_NEC_PREAMBLE_TOLERANCE 200 // us +#define INFRARED_NEC_BIT_TOLERANCE 120 // us + +void* infrared_decoder_nec_alloc(void); +void infrared_decoder_nec_reset(void* decoder); +void infrared_decoder_nec_free(void* decoder); +InfraredMessage* infrared_decoder_nec_check_ready(void* decoder); +InfraredMessage* infrared_decoder_nec_decode(void* decoder, bool level, uint32_t duration); +void* infrared_encoder_nec_alloc(void); +InfraredStatus infrared_encoder_nec_encode(void* encoder_ptr, uint32_t* duration, bool* level); +void infrared_encoder_nec_reset(void* encoder_ptr, const InfraredMessage* message); +void infrared_encoder_nec_free(void* encoder_ptr); +bool infrared_decoder_nec_interpret(InfraredCommonDecoder* decoder); +InfraredStatus infrared_decoder_nec_decode_repeat(InfraredCommonDecoder* decoder); +InfraredStatus infrared_encoder_nec_encode_repeat( + InfraredCommonEncoder* encoder, + uint32_t* duration, + bool* level); +const InfraredProtocolSpecification* infrared_nec_get_spec(InfraredProtocol protocol); + +extern const InfraredCommonProtocolSpec protocol_nec; + +/*************************************************************************************************** +* SAMSUNG32 protocol description +* https://www.mikrocontroller.net/articles/IRMP_-_english#SAMSUNG +**************************************************************************************************** +* Preamble Preamble Pulse Distance/Width Pause Preamble Preamble Bit1 Stop +* mark space Modulation repeat repeat bit +* mark space +* +* 4500 4500 32 bit + stop bit 40000/100000 4500 4500 +* __________ _ _ _ _ _ _ _ _ _ _ _ ___________ _ _ +* _ __________ __ _ __ __ __ _ _ __ __ _ ________________ ____________ ____ ___ +* +***************************************************************************************************/ + +#define INFRARED_SAMSUNG_PREAMBLE_MARK 4500 +#define INFRARED_SAMSUNG_PREAMBLE_SPACE 4500 +#define INFRARED_SAMSUNG_BIT1_MARK 550 +#define INFRARED_SAMSUNG_BIT1_SPACE 1650 +#define INFRARED_SAMSUNG_BIT0_MARK 550 +#define INFRARED_SAMSUNG_BIT0_SPACE 550 +#define INFRARED_SAMSUNG_REPEAT_PAUSE_MIN 30000 +#define INFRARED_SAMSUNG_REPEAT_PAUSE1 46000 +#define INFRARED_SAMSUNG_REPEAT_PAUSE2 97000 +/* Samsung silence have to be greater than REPEAT MAX + * otherwise there can be problems during unit tests parsing + * of some data. Real tolerances we don't know, but in real life + * silence time should be greater than max repeat time. This is + * because of similar preambule timings for repeat and first messages. */ +#define INFRARED_SAMSUNG_MIN_SPLIT_TIME 5000 +#define INFRARED_SAMSUNG_SILENCE 145000 +#define INFRARED_SAMSUNG_REPEAT_PAUSE_MAX 140000 +#define INFRARED_SAMSUNG_REPEAT_MARK 4500 +#define INFRARED_SAMSUNG_REPEAT_SPACE 4500 +#define INFRARED_SAMSUNG_PREAMBLE_TOLERANCE 200 // us +#define INFRARED_SAMSUNG_BIT_TOLERANCE 120 // us + +void* infrared_decoder_samsung32_alloc(void); +void infrared_decoder_samsung32_reset(void* decoder); +void infrared_decoder_samsung32_free(void* decoder); +InfraredMessage* infrared_decoder_samsung32_check_ready(void* ctx); +InfraredMessage* infrared_decoder_samsung32_decode(void* decoder, bool level, uint32_t duration); +InfraredStatus + infrared_encoder_samsung32_encode(void* encoder_ptr, uint32_t* duration, bool* level); +void infrared_encoder_samsung32_reset(void* encoder_ptr, const InfraredMessage* message); +void* infrared_encoder_samsung32_alloc(void); +void infrared_encoder_samsung32_free(void* encoder_ptr); +bool infrared_decoder_samsung32_interpret(InfraredCommonDecoder* decoder); +InfraredStatus infrared_decoder_samsung32_decode_repeat(InfraredCommonDecoder* decoder); +InfraredStatus infrared_encoder_samsung32_encode_repeat( + InfraredCommonEncoder* encoder, + uint32_t* duration, + bool* level); +const InfraredProtocolSpecification* infrared_samsung32_get_spec(InfraredProtocol protocol); + +extern const InfraredCommonProtocolSpec protocol_samsung32; + +/*************************************************************************************************** +* RC6 protocol description +* https://www.mikrocontroller.net/articles/IRMP_-_english#RC6_.2B_RC6A +**************************************************************************************************** +* Preamble Manchester/biphase Silence +* mark/space Modulation +* +* 2666 889 444/888 - bit (x2 for toggle bit) 2666 +* +* ________ __ __ __ __ ____ __ __ __ __ __ __ __ __ +* _ _________ ____ __ __ ____ __ __ __ __ __ __ __ __ _______________ +* | 1 | 0 | 0 | 0 | 0 | ... | ... | | +* s m2 m1 m0 T address (MSB) command (MSB) +* +* s - start bit (always 1) +* m0-2 - mode (000 for RC6) +* T - toggle bit, twice longer +* address - 8 bit +* command - 8 bit +***************************************************************************************************/ + +#define INFRARED_RC6_CARRIER_FREQUENCY 36000 +#define INFRARED_RC6_DUTY_CYCLE 0.33 + +#define INFRARED_RC6_PREAMBLE_MARK 2666 +#define INFRARED_RC6_PREAMBLE_SPACE 889 +#define INFRARED_RC6_BIT 444 // half of time-quant for 1 bit +#define INFRARED_RC6_PREAMBLE_TOLERANCE 200 // us +#define INFRARED_RC6_BIT_TOLERANCE 120 // us +/* protocol allows 2700 silence, but it is hard to send 1 message without repeat */ +#define INFRARED_RC6_SILENCE (2700 * 10) +#define INFRARED_RC6_MIN_SPLIT_TIME 2700 + +void* infrared_decoder_rc6_alloc(void); +void infrared_decoder_rc6_reset(void* decoder); +void infrared_decoder_rc6_free(void* decoder); +InfraredMessage* infrared_decoder_rc6_check_ready(void* ctx); +InfraredMessage* infrared_decoder_rc6_decode(void* decoder, bool level, uint32_t duration); +void* infrared_encoder_rc6_alloc(void); +void infrared_encoder_rc6_reset(void* encoder_ptr, const InfraredMessage* message); +void infrared_encoder_rc6_free(void* decoder); +InfraredStatus infrared_encoder_rc6_encode(void* encoder_ptr, uint32_t* duration, bool* polarity); +bool infrared_decoder_rc6_interpret(InfraredCommonDecoder* decoder); +InfraredStatus infrared_decoder_rc6_decode_manchester( + InfraredCommonDecoder* decoder, + bool level, + uint32_t timing); +InfraredStatus infrared_encoder_rc6_encode_manchester( + InfraredCommonEncoder* encoder_ptr, + uint32_t* duration, + bool* polarity); +const InfraredProtocolSpecification* infrared_rc6_get_spec(InfraredProtocol protocol); + +extern const InfraredCommonProtocolSpec protocol_rc6; + +/*************************************************************************************************** +* RC5 protocol description +* https://www.mikrocontroller.net/articles/IRMP_-_english#RC5_.2B_RC5X +**************************************************************************************************** +* Manchester/biphase +* Modulation +* +* 888/1776 - bit (x2 for toggle bit) +* +* __ ____ __ __ __ __ __ __ __ __ +* __ __ ____ __ __ __ __ __ __ __ _ +* | 1 | 1 | 0 | ... | ... | +* s si T address (MSB) command (MSB) +* +* Note: manchester starts from space timing, so it have to be handled properly +* s - start bit (always 1) +* si - RC5: start bit (always 1), RC5X - 7-th bit of address (in our case always 0) +* T - toggle bit, change it's value every button press +* address - 5 bit +* command - 6/7 bit +***************************************************************************************************/ + +#define INFRARED_RC5_CARRIER_FREQUENCY 36000 +#define INFRARED_RC5_DUTY_CYCLE 0.33 + +#define INFRARED_RC5_PREAMBLE_MARK 0 +#define INFRARED_RC5_PREAMBLE_SPACE 0 +#define INFRARED_RC5_BIT 888 // half of time-quant for 1 bit +#define INFRARED_RC5_PREAMBLE_TOLERANCE 200 // us +#define INFRARED_RC5_BIT_TOLERANCE 120 // us +/* protocol allows 2700 silence, but it is hard to send 1 message without repeat */ +#define INFRARED_RC5_SILENCE (2700 * 10) +#define INFRARED_RC5_MIN_SPLIT_TIME 2700 + +void* infrared_decoder_rc5_alloc(void); +void infrared_decoder_rc5_reset(void* decoder); +void infrared_decoder_rc5_free(void* decoder); +InfraredMessage* infrared_decoder_rc5_check_ready(void* ctx); +InfraredMessage* infrared_decoder_rc5_decode(void* decoder, bool level, uint32_t duration); +void* infrared_encoder_rc5_alloc(void); +void infrared_encoder_rc5_reset(void* encoder_ptr, const InfraredMessage* message); +void infrared_encoder_rc5_free(void* decoder); +InfraredStatus infrared_encoder_rc5_encode(void* encoder_ptr, uint32_t* duration, bool* polarity); +bool infrared_decoder_rc5_interpret(InfraredCommonDecoder* decoder); +const InfraredProtocolSpecification* infrared_rc5_get_spec(InfraredProtocol protocol); + +extern const InfraredCommonProtocolSpec protocol_rc5; + +/*************************************************************************************************** +* Sony SIRC protocol description +* https://www.sbprojects.net/knowledge/ir/sirc.php +* http://picprojects.org.uk/ +**************************************************************************************************** +* Preamble Preamble Pulse Width Modulation Pause Entirely repeat +* mark space up to period message.. +* +* 2400 600 12/15/20 bits (600,1200) ...45000 2400 600 +* __________ _ _ _ _ _ _ _ _ _ _ _ _ _ __________ _ _ +* ____ __________ _ _ _ __ __ __ _ _ __ __ _ _ ____________________ __________ _ +* | command | address | +* SIRC | 7b LSB | 5b LSB | +* SIRC15 | 7b LSB | 8b LSB | +* SIRC20 | 7b LSB | 13b LSB | +* +* No way to determine either next message is repeat or not, +* so recognize only fact message received. Sony remotes always send at least 3 messages. +* Assume 8 last extended bits for SIRC20 are address bits. +***************************************************************************************************/ + +#define INFRARED_SIRC_CARRIER_FREQUENCY 40000 +#define INFRARED_SIRC_DUTY_CYCLE 0.33 +#define INFRARED_SIRC_PREAMBLE_MARK 2400 +#define INFRARED_SIRC_PREAMBLE_SPACE 600 +#define INFRARED_SIRC_BIT1_MARK 1200 +#define INFRARED_SIRC_BIT1_SPACE 600 +#define INFRARED_SIRC_BIT0_MARK 600 +#define INFRARED_SIRC_BIT0_SPACE 600 +#define INFRARED_SIRC_PREAMBLE_TOLERANCE 200 // us +#define INFRARED_SIRC_BIT_TOLERANCE 120 // us +#define INFRARED_SIRC_SILENCE 10000 +#define INFRARED_SIRC_MIN_SPLIT_TIME (INFRARED_SIRC_SILENCE - 1000) +#define INFRARED_SIRC_REPEAT_PERIOD 45000 + +void* infrared_decoder_sirc_alloc(void); +void infrared_decoder_sirc_reset(void* decoder); +InfraredMessage* infrared_decoder_sirc_check_ready(void* decoder); +uint32_t infrared_decoder_sirc_get_timeout(void* decoder); +void infrared_decoder_sirc_free(void* decoder); +InfraredMessage* infrared_decoder_sirc_decode(void* decoder, bool level, uint32_t duration); +void* infrared_encoder_sirc_alloc(void); +void infrared_encoder_sirc_reset(void* encoder_ptr, const InfraredMessage* message); +void infrared_encoder_sirc_free(void* decoder); +InfraredStatus infrared_encoder_sirc_encode(void* encoder_ptr, uint32_t* duration, bool* polarity); +bool infrared_decoder_sirc_interpret(InfraredCommonDecoder* decoder); +const InfraredProtocolSpecification* infrared_sirc_get_spec(InfraredProtocol protocol); +InfraredStatus infrared_encoder_sirc_encode_repeat( + InfraredCommonEncoder* encoder, + uint32_t* duration, + bool* level); + +extern const InfraredCommonProtocolSpec protocol_sirc; diff --git a/lib/irda/encoder_decoder/nec/irda_decoder_nec.c b/lib/infrared/encoder_decoder/nec/infrared_decoder_nec.c similarity index 58% rename from lib/irda/encoder_decoder/nec/irda_decoder_nec.c rename to lib/infrared/encoder_decoder/nec/infrared_decoder_nec.c index f5418535..10ff56da 100644 --- a/lib/irda/encoder_decoder/nec/irda_decoder_nec.c +++ b/lib/infrared/encoder_decoder/nec/infrared_decoder_nec.c @@ -1,16 +1,16 @@ -#include "common/irda_common_i.h" -#include "irda.h" -#include "irda_protocol_defs_i.h" +#include "common/infrared_common_i.h" +#include "infrared.h" +#include "infrared_protocol_defs_i.h" #include #include #include -#include "../irda_i.h" +#include "../infrared_i.h" -IrdaMessage* irda_decoder_nec_check_ready(void* ctx) { - return irda_common_decoder_check_ready(ctx); +InfraredMessage* infrared_decoder_nec_check_ready(void* ctx) { + return infrared_common_decoder_check_ready(ctx); } -bool irda_decoder_nec_interpret(IrdaCommonDecoder* decoder) { +bool infrared_decoder_nec_interpret(InfraredCommonDecoder* decoder) { furi_assert(decoder); bool result = false; @@ -21,13 +21,13 @@ bool irda_decoder_nec_interpret(IrdaCommonDecoder* decoder) { uint8_t command = decoder->data[2]; uint8_t command_inverse = decoder->data[3]; if((command == (uint8_t)~command_inverse) && (address == (uint8_t)~address_inverse)) { - decoder->message.protocol = IrdaProtocolNEC; + decoder->message.protocol = InfraredProtocolNEC; decoder->message.address = address; decoder->message.command = command; decoder->message.repeat = false; result = true; } else { - decoder->message.protocol = IrdaProtocolNECext; + decoder->message.protocol = InfraredProtocolNECext; decoder->message.address = decoder->data[0] | (decoder->data[1] << 8); decoder->message.command = decoder->data[2] | (decoder->data[3] << 8); decoder->message.repeat = false; @@ -42,13 +42,13 @@ bool irda_decoder_nec_interpret(IrdaCommonDecoder* decoder) { uint16_t command_inverse = (*data2 >> 2) & 0xFF; if((address == (~address_inverse & 0x1FFF)) && (command == (~command_inverse & 0xFF))) { - decoder->message.protocol = IrdaProtocolNEC42; + decoder->message.protocol = InfraredProtocolNEC42; decoder->message.address = address; decoder->message.command = command; decoder->message.repeat = false; result = true; } else { - decoder->message.protocol = IrdaProtocolNEC42ext; + decoder->message.protocol = InfraredProtocolNEC42ext; decoder->message.address = address | (address_inverse << 13); decoder->message.command = command | (command_inverse << 8); decoder->message.repeat = false; @@ -60,41 +60,41 @@ bool irda_decoder_nec_interpret(IrdaCommonDecoder* decoder) { } // timings start from Space (delay between message and repeat) -IrdaStatus irda_decoder_nec_decode_repeat(IrdaCommonDecoder* decoder) { +InfraredStatus infrared_decoder_nec_decode_repeat(InfraredCommonDecoder* decoder) { furi_assert(decoder); float preamble_tolerance = decoder->protocol->timings.preamble_tolerance; uint32_t bit_tolerance = decoder->protocol->timings.bit_tolerance; - IrdaStatus status = IrdaStatusError; + InfraredStatus status = InfraredStatusError; - if(decoder->timings_cnt < 4) return IrdaStatusOk; + if(decoder->timings_cnt < 4) return InfraredStatusOk; - if((decoder->timings[0] > IRDA_NEC_REPEAT_PAUSE_MIN) && - (decoder->timings[0] < IRDA_NEC_REPEAT_PAUSE_MAX) && - MATCH_TIMING(decoder->timings[1], IRDA_NEC_REPEAT_MARK, preamble_tolerance) && - MATCH_TIMING(decoder->timings[2], IRDA_NEC_REPEAT_SPACE, preamble_tolerance) && + if((decoder->timings[0] > INFRARED_NEC_REPEAT_PAUSE_MIN) && + (decoder->timings[0] < INFRARED_NEC_REPEAT_PAUSE_MAX) && + MATCH_TIMING(decoder->timings[1], INFRARED_NEC_REPEAT_MARK, preamble_tolerance) && + MATCH_TIMING(decoder->timings[2], INFRARED_NEC_REPEAT_SPACE, preamble_tolerance) && MATCH_TIMING(decoder->timings[3], decoder->protocol->timings.bit1_mark, bit_tolerance)) { - status = IrdaStatusReady; + status = InfraredStatusReady; decoder->timings_cnt = 0; } else { - status = IrdaStatusError; + status = InfraredStatusError; } return status; } -void* irda_decoder_nec_alloc(void) { - return irda_common_decoder_alloc(&protocol_nec); +void* infrared_decoder_nec_alloc(void) { + return infrared_common_decoder_alloc(&protocol_nec); } -IrdaMessage* irda_decoder_nec_decode(void* decoder, bool level, uint32_t duration) { - return irda_common_decode(decoder, level, duration); +InfraredMessage* infrared_decoder_nec_decode(void* decoder, bool level, uint32_t duration) { + return infrared_common_decode(decoder, level, duration); } -void irda_decoder_nec_free(void* decoder) { - irda_common_decoder_free(decoder); +void infrared_decoder_nec_free(void* decoder) { + infrared_common_decoder_free(decoder); } -void irda_decoder_nec_reset(void* decoder) { - irda_common_decoder_reset(decoder); +void infrared_decoder_nec_reset(void* decoder) { + infrared_common_decoder_reset(decoder); } diff --git a/lib/irda/encoder_decoder/nec/irda_encoder_nec.c b/lib/infrared/encoder_decoder/nec/infrared_encoder_nec.c similarity index 58% rename from lib/irda/encoder_decoder/nec/irda_encoder_nec.c rename to lib/infrared/encoder_decoder/nec/infrared_encoder_nec.c index e818f128..e1afae7b 100644 --- a/lib/irda/encoder_decoder/nec/irda_encoder_nec.c +++ b/lib/infrared/encoder_decoder/nec/infrared_encoder_nec.c @@ -1,28 +1,29 @@ #include "furi/check.h" -#include "irda.h" -#include "common/irda_common_i.h" +#include "infrared.h" +#include "common/infrared_common_i.h" #include -#include "../irda_i.h" -#include "irda_protocol_defs_i.h" +#include "../infrared_i.h" +#include "infrared_protocol_defs_i.h" #include static const uint32_t repeat_timings[] = { - IRDA_NEC_REPEAT_PERIOD - IRDA_NEC_REPEAT_MARK - IRDA_NEC_REPEAT_SPACE - IRDA_NEC_BIT1_MARK, - IRDA_NEC_REPEAT_MARK, - IRDA_NEC_REPEAT_SPACE, - IRDA_NEC_BIT1_MARK, + INFRARED_NEC_REPEAT_PERIOD - INFRARED_NEC_REPEAT_MARK - INFRARED_NEC_REPEAT_SPACE - + INFRARED_NEC_BIT1_MARK, + INFRARED_NEC_REPEAT_MARK, + INFRARED_NEC_REPEAT_SPACE, + INFRARED_NEC_BIT1_MARK, }; -void irda_encoder_nec_reset(void* encoder_ptr, const IrdaMessage* message) { +void infrared_encoder_nec_reset(void* encoder_ptr, const InfraredMessage* message) { furi_assert(encoder_ptr); furi_assert(message); - IrdaCommonEncoder* encoder = encoder_ptr; - irda_common_encoder_reset(encoder); + InfraredCommonEncoder* encoder = encoder_ptr; + infrared_common_encoder_reset(encoder); uint32_t* data1 = (void*)encoder->data; uint32_t* data2 = data1 + 1; - if(message->protocol == IrdaProtocolNEC) { + if(message->protocol == InfraredProtocolNEC) { uint8_t address = message->address; uint8_t address_inverse = ~address; uint8_t command = message->command; @@ -32,11 +33,11 @@ void irda_encoder_nec_reset(void* encoder_ptr, const IrdaMessage* message) { *data1 |= command << 16; *data1 |= command_inverse << 24; encoder->bits_to_encode = 32; - } else if(message->protocol == IrdaProtocolNECext) { + } else if(message->protocol == InfraredProtocolNECext) { *data1 = (uint16_t)message->address; *data1 |= (message->command & 0xFFFF) << 16; encoder->bits_to_encode = 32; - } else if(message->protocol == IrdaProtocolNEC42) { + } else if(message->protocol == InfraredProtocolNEC42) { /* 13 address + 13 inverse address + 8 command + 8 inv command */ *data1 = message->address & 0x1FFFUL; *data1 |= (~message->address & 0x1FFFUL) << 13; @@ -44,7 +45,7 @@ void irda_encoder_nec_reset(void* encoder_ptr, const IrdaMessage* message) { *data2 = (message->command & 0xC0UL) >> 6; *data2 |= (~message->command & 0xFFUL) << 2; encoder->bits_to_encode = 42; - } else if(message->protocol == IrdaProtocolNEC42ext) { + } else if(message->protocol == InfraredProtocolNEC42ext) { *data1 = message->address & 0x3FFFFFF; *data1 |= ((message->command & 0x3F) << 26); *data2 = (message->command & 0xFFC0) >> 6; @@ -54,8 +55,10 @@ void irda_encoder_nec_reset(void* encoder_ptr, const IrdaMessage* message) { } } -IrdaStatus - irda_encoder_nec_encode_repeat(IrdaCommonEncoder* encoder, uint32_t* duration, bool* level) { +InfraredStatus infrared_encoder_nec_encode_repeat( + InfraredCommonEncoder* encoder, + uint32_t* duration, + bool* level) { furi_assert(encoder); /* space + 2 timings preambule + payload + stop bit */ @@ -67,24 +70,24 @@ IrdaStatus if(repeat_cnt > 0) { *duration = repeat_timings[repeat_cnt % COUNT_OF(repeat_timings)]; } else { - *duration = IRDA_NEC_REPEAT_PERIOD - encoder->timings_sum; + *duration = INFRARED_NEC_REPEAT_PERIOD - encoder->timings_sum; } *level = repeat_cnt % 2; ++encoder->timings_encoded; bool done = (!((repeat_cnt + 1) % COUNT_OF(repeat_timings))); - return done ? IrdaStatusDone : IrdaStatusOk; + return done ? InfraredStatusDone : InfraredStatusOk; } -void* irda_encoder_nec_alloc(void) { - return irda_common_encoder_alloc(&protocol_nec); +void* infrared_encoder_nec_alloc(void) { + return infrared_common_encoder_alloc(&protocol_nec); } -void irda_encoder_nec_free(void* encoder_ptr) { - irda_common_encoder_free(encoder_ptr); +void infrared_encoder_nec_free(void* encoder_ptr) { + infrared_common_encoder_free(encoder_ptr); } -IrdaStatus irda_encoder_nec_encode(void* encoder_ptr, uint32_t* duration, bool* level) { - return irda_common_encode(encoder_ptr, duration, level); +InfraredStatus infrared_encoder_nec_encode(void* encoder_ptr, uint32_t* duration, bool* level) { + return infrared_common_encode(encoder_ptr, duration, level); } diff --git a/lib/infrared/encoder_decoder/nec/infrared_nec_spec.c b/lib/infrared/encoder_decoder/nec/infrared_nec_spec.c new file mode 100644 index 00000000..16cab8b5 --- /dev/null +++ b/lib/infrared/encoder_decoder/nec/infrared_nec_spec.c @@ -0,0 +1,47 @@ +#include "../infrared_i.h" +#include "infrared_protocol_defs_i.h" + +static const InfraredProtocolSpecification infrared_nec_protocol_specification = { + .name = "NEC", + .address_length = 8, + .command_length = 8, + .frequency = INFRARED_COMMON_CARRIER_FREQUENCY, + .duty_cycle = INFRARED_COMMON_DUTY_CYCLE, +}; + +static const InfraredProtocolSpecification infrared_necext_protocol_specification = { + .name = "NECext", + .address_length = 16, + .command_length = 16, + .frequency = INFRARED_COMMON_CARRIER_FREQUENCY, + .duty_cycle = INFRARED_COMMON_DUTY_CYCLE, +}; + +static const InfraredProtocolSpecification infrared_nec42_protocol_specification = { + .name = "NEC42", + .address_length = 13, + .command_length = 8, + .frequency = INFRARED_COMMON_CARRIER_FREQUENCY, + .duty_cycle = INFRARED_COMMON_DUTY_CYCLE, +}; + +static const InfraredProtocolSpecification infrared_nec42ext_protocol_specification = { + .name = "NEC42ext", + .address_length = 26, + .command_length = 16, + .frequency = INFRARED_COMMON_CARRIER_FREQUENCY, + .duty_cycle = INFRARED_COMMON_DUTY_CYCLE, +}; + +const InfraredProtocolSpecification* infrared_nec_get_spec(InfraredProtocol protocol) { + if(protocol == InfraredProtocolNEC) + return &infrared_nec_protocol_specification; + else if(protocol == InfraredProtocolNECext) + return &infrared_necext_protocol_specification; + else if(protocol == InfraredProtocolNEC42) + return &infrared_nec42_protocol_specification; + else if(protocol == InfraredProtocolNEC42ext) + return &infrared_nec42ext_protocol_specification; + else + return NULL; +} diff --git a/lib/infrared/encoder_decoder/rc5/infrared_decoder_rc5.c b/lib/infrared/encoder_decoder/rc5/infrared_decoder_rc5.c new file mode 100644 index 00000000..6b4a7c2e --- /dev/null +++ b/lib/infrared/encoder_decoder/rc5/infrared_decoder_rc5.c @@ -0,0 +1,82 @@ +#include "infrared.h" +#include +#include +#include +#include +#include "../infrared_i.h" +#include "../infrared_protocol_defs_i.h" + +typedef struct { + InfraredCommonDecoder* common_decoder; + bool toggle; +} InfraredRc5Decoder; + +InfraredMessage* infrared_decoder_rc5_check_ready(void* ctx) { + InfraredRc5Decoder* decoder = ctx; + return infrared_common_decoder_check_ready(decoder->common_decoder); +} + +bool infrared_decoder_rc5_interpret(InfraredCommonDecoder* decoder) { + furi_assert(decoder); + + bool result = false; + uint32_t* data = (void*)&decoder->data[0]; + /* Manchester (inverse): + * 0->1 : 1 + * 1->0 : 0 + */ + decoder->data[0] = ~decoder->data[0]; + decoder->data[1] = ~decoder->data[1]; + + // MSB first + uint8_t address = reverse((uint8_t)decoder->data[0]) & 0x1F; + uint8_t command = (reverse((uint8_t)decoder->data[1]) >> 2) & 0x3F; + bool start_bit1 = *data & 0x01; + bool start_bit2 = *data & 0x02; + bool toggle = !!(*data & 0x04); + + if(start_bit1 == 1) { + InfraredProtocol protocol = start_bit2 ? InfraredProtocolRC5 : InfraredProtocolRC5X; + InfraredMessage* message = &decoder->message; + InfraredRc5Decoder* rc5_decoder = decoder->context; + bool* prev_toggle = &rc5_decoder->toggle; + if((message->address == address) && (message->command == command) && + (message->protocol == protocol)) { + message->repeat = (toggle == *prev_toggle); + } else { + message->repeat = false; + } + *prev_toggle = toggle; + message->command = command; + message->address = address; + message->protocol = protocol; + + result = true; + } + + return result; +} + +void* infrared_decoder_rc5_alloc(void) { + InfraredRc5Decoder* decoder = malloc(sizeof(InfraredRc5Decoder)); + decoder->toggle = false; + decoder->common_decoder = infrared_common_decoder_alloc(&protocol_rc5); + decoder->common_decoder->context = decoder; + return decoder; +} + +InfraredMessage* infrared_decoder_rc5_decode(void* decoder, bool level, uint32_t duration) { + InfraredRc5Decoder* decoder_rc5 = decoder; + return infrared_common_decode(decoder_rc5->common_decoder, level, duration); +} + +void infrared_decoder_rc5_free(void* decoder) { + InfraredRc5Decoder* decoder_rc5 = decoder; + infrared_common_decoder_free(decoder_rc5->common_decoder); + free(decoder_rc5); +} + +void infrared_decoder_rc5_reset(void* decoder) { + InfraredRc5Decoder* decoder_rc5 = decoder; + infrared_common_decoder_reset(decoder_rc5->common_decoder); +} diff --git a/lib/infrared/encoder_decoder/rc5/infrared_encoder_rc5.c b/lib/infrared/encoder_decoder/rc5/infrared_encoder_rc5.c new file mode 100644 index 00000000..f063f7e5 --- /dev/null +++ b/lib/infrared/encoder_decoder/rc5/infrared_encoder_rc5.c @@ -0,0 +1,55 @@ +#include "furi/memmgr.h" +#include "infrared.h" +#include "common/infrared_common_i.h" +#include "infrared_protocol_defs_i.h" +#include +#include "../infrared_i.h" + +typedef struct InfraredEncoderRC5 { + InfraredCommonEncoder* common_encoder; + bool toggle_bit; +} InfraredEncoderRC5; + +void infrared_encoder_rc5_reset(void* encoder_ptr, const InfraredMessage* message) { + furi_assert(encoder_ptr); + + InfraredEncoderRC5* encoder = encoder_ptr; + InfraredCommonEncoder* common_encoder = encoder->common_encoder; + infrared_common_encoder_reset(common_encoder); + + uint32_t* data = (void*)common_encoder->data; + /* RC5 */ + *data |= 0x01; // start bit + if(message->protocol == InfraredProtocolRC5) { + *data |= 0x02; // start bit + } + *data |= encoder->toggle_bit ? 0x04 : 0; + *data |= (reverse(message->address) >> 3) << 3; /* address 5 bit */ + *data |= (reverse(message->command) >> 2) << 8; /* command 6 bit */ + + common_encoder->data[0] = ~common_encoder->data[0]; + common_encoder->data[1] = ~common_encoder->data[1]; + + common_encoder->bits_to_encode = common_encoder->protocol->databit_len[0]; + encoder->toggle_bit ^= 1; +} + +InfraredStatus infrared_encoder_rc5_encode(void* encoder_ptr, uint32_t* duration, bool* level) { + InfraredEncoderRC5* encoder = encoder_ptr; + return infrared_common_encode(encoder->common_encoder, duration, level); +} + +void* infrared_encoder_rc5_alloc(void) { + InfraredEncoderRC5* encoder = malloc(sizeof(InfraredEncoderRC5)); + encoder->common_encoder = infrared_common_encoder_alloc(&protocol_rc5); + encoder->toggle_bit = false; + return encoder; +} + +void infrared_encoder_rc5_free(void* encoder_ptr) { + furi_assert(encoder_ptr); + + InfraredEncoderRC5* encoder = encoder_ptr; + free(encoder->common_encoder); + free(encoder); +} diff --git a/lib/infrared/encoder_decoder/rc5/infrared_rc5_spec.c b/lib/infrared/encoder_decoder/rc5/infrared_rc5_spec.c new file mode 100644 index 00000000..25ea230e --- /dev/null +++ b/lib/infrared/encoder_decoder/rc5/infrared_rc5_spec.c @@ -0,0 +1,27 @@ +#include "../infrared_i.h" +#include "infrared_protocol_defs_i.h" + +static const InfraredProtocolSpecification infrared_rc5_protocol_specification = { + .name = "RC5", + .address_length = 5, + .command_length = 6, + .frequency = INFRARED_RC5_CARRIER_FREQUENCY, + .duty_cycle = INFRARED_RC5_DUTY_CYCLE, +}; + +static const InfraredProtocolSpecification infrared_rc5x_protocol_specification = { + .name = "RC5X", + .address_length = 5, + .command_length = 7, + .frequency = INFRARED_RC5_CARRIER_FREQUENCY, + .duty_cycle = INFRARED_RC5_DUTY_CYCLE, +}; + +const InfraredProtocolSpecification* infrared_rc5_get_spec(InfraredProtocol protocol) { + if(protocol == InfraredProtocolRC5) + return &infrared_rc5_protocol_specification; + else if(protocol == InfraredProtocolRC5X) + return &infrared_rc5x_protocol_specification; + else + return NULL; +} diff --git a/lib/irda/encoder_decoder/rc6/irda_decoder_rc6.c b/lib/infrared/encoder_decoder/rc6/infrared_decoder_rc6.c similarity index 56% rename from lib/irda/encoder_decoder/rc6/irda_decoder_rc6.c rename to lib/infrared/encoder_decoder/rc6/infrared_decoder_rc6.c index a38d2c77..9101cac1 100644 --- a/lib/irda/encoder_decoder/rc6/irda_decoder_rc6.c +++ b/lib/infrared/encoder_decoder/rc6/infrared_decoder_rc6.c @@ -1,22 +1,22 @@ -#include "irda.h" +#include "infrared.h" #include #include #include #include -#include "../irda_i.h" -#include "../irda_protocol_defs_i.h" +#include "../infrared_i.h" +#include "../infrared_protocol_defs_i.h" typedef struct { - IrdaCommonDecoder* common_decoder; + InfraredCommonDecoder* common_decoder; bool toggle; -} IrdaRc6Decoder; +} InfraredRc6Decoder; -IrdaMessage* irda_decoder_rc6_check_ready(void* ctx) { - IrdaRc6Decoder* decoder_rc6 = ctx; - return irda_common_decoder_check_ready(decoder_rc6->common_decoder); +InfraredMessage* infrared_decoder_rc6_check_ready(void* ctx) { + InfraredRc6Decoder* decoder_rc6 = ctx; + return infrared_common_decoder_check_ready(decoder_rc6->common_decoder); } -bool irda_decoder_rc6_interpret(IrdaCommonDecoder* decoder) { +bool infrared_decoder_rc6_interpret(InfraredCommonDecoder* decoder) { furi_assert(decoder); bool result = false; @@ -29,11 +29,11 @@ bool irda_decoder_rc6_interpret(IrdaCommonDecoder* decoder) { uint8_t mode = (*data >> 1) & 0x7; if((start_bit == 1) && (mode == 0)) { - IrdaMessage* message = &decoder->message; - IrdaRc6Decoder* rc6_decoder = decoder->context; + InfraredMessage* message = &decoder->message; + InfraredRc6Decoder* rc6_decoder = decoder->context; bool* prev_toggle = &rc6_decoder->toggle; if((message->address == address) && (message->command == command) && - (message->protocol == IrdaProtocolRC6)) { + (message->protocol == InfraredProtocolRC6)) { message->repeat = (toggle == *prev_toggle); } else { message->repeat = false; @@ -41,7 +41,7 @@ bool irda_decoder_rc6_interpret(IrdaCommonDecoder* decoder) { *prev_toggle = toggle; message->command = command; message->address = address; - message->protocol = IrdaProtocolRC6; + message->protocol = InfraredProtocolRC6; result = true; } @@ -54,10 +54,12 @@ bool irda_decoder_rc6_interpret(IrdaCommonDecoder* decoder) { * it separately and than pass decoding for other bits to * common manchester decode function. */ -IrdaStatus - irda_decoder_rc6_decode_manchester(IrdaCommonDecoder* decoder, bool level, uint32_t timing) { +InfraredStatus infrared_decoder_rc6_decode_manchester( + InfraredCommonDecoder* decoder, + bool level, + uint32_t timing) { // 4th bit lasts 2x times more - IrdaStatus status = IrdaStatusError; + InfraredStatus status = InfraredStatusError; uint16_t bit = decoder->protocol->timings.bit1_mark; uint16_t tolerance = decoder->protocol->timings.bit_tolerance; @@ -71,43 +73,43 @@ IrdaStatus if(single_timing ^ triple_timing) { ++decoder->databit_cnt; decoder->data[0] |= (single_timing ? !level : level) << 4; - status = IrdaStatusOk; + status = InfraredStatusOk; } } else if(decoder->databit_cnt == 5) { if(single_timing || triple_timing) { if(triple_timing) timing = bit; decoder->switch_detect = false; - status = irda_common_decode_manchester(decoder, level, timing); + status = infrared_common_decode_manchester(decoder, level, timing); } else if(double_timing) { - status = IrdaStatusOk; + status = InfraredStatusOk; } } else { - status = irda_common_decode_manchester(decoder, level, timing); + status = infrared_common_decode_manchester(decoder, level, timing); } return status; } -void* irda_decoder_rc6_alloc(void) { - IrdaRc6Decoder* decoder = malloc(sizeof(IrdaRc6Decoder)); +void* infrared_decoder_rc6_alloc(void) { + InfraredRc6Decoder* decoder = malloc(sizeof(InfraredRc6Decoder)); decoder->toggle = false; - decoder->common_decoder = irda_common_decoder_alloc(&protocol_rc6); + decoder->common_decoder = infrared_common_decoder_alloc(&protocol_rc6); decoder->common_decoder->context = decoder; return decoder; } -IrdaMessage* irda_decoder_rc6_decode(void* decoder, bool level, uint32_t duration) { - IrdaRc6Decoder* decoder_rc6 = decoder; - return irda_common_decode(decoder_rc6->common_decoder, level, duration); +InfraredMessage* infrared_decoder_rc6_decode(void* decoder, bool level, uint32_t duration) { + InfraredRc6Decoder* decoder_rc6 = decoder; + return infrared_common_decode(decoder_rc6->common_decoder, level, duration); } -void irda_decoder_rc6_free(void* decoder) { - IrdaRc6Decoder* decoder_rc6 = decoder; - irda_common_decoder_free(decoder_rc6->common_decoder); +void infrared_decoder_rc6_free(void* decoder) { + InfraredRc6Decoder* decoder_rc6 = decoder; + infrared_common_decoder_free(decoder_rc6->common_decoder); free(decoder_rc6); } -void irda_decoder_rc6_reset(void* decoder) { - IrdaRc6Decoder* decoder_rc6 = decoder; - irda_common_decoder_reset(decoder_rc6->common_decoder); +void infrared_decoder_rc6_reset(void* decoder) { + InfraredRc6Decoder* decoder_rc6 = decoder; + infrared_common_decoder_reset(decoder_rc6->common_decoder); } diff --git a/lib/infrared/encoder_decoder/rc6/infrared_encoder_rc6.c b/lib/infrared/encoder_decoder/rc6/infrared_encoder_rc6.c new file mode 100644 index 00000000..7d8ff975 --- /dev/null +++ b/lib/infrared/encoder_decoder/rc6/infrared_encoder_rc6.c @@ -0,0 +1,61 @@ +#include "furi/memmgr.h" +#include "infrared.h" +#include "common/infrared_common_i.h" +#include "infrared_protocol_defs_i.h" +#include +#include "../infrared_i.h" + +typedef struct InfraredEncoderRC6 { + InfraredCommonEncoder* common_encoder; + bool toggle_bit; +} InfraredEncoderRC6; + +void infrared_encoder_rc6_reset(void* encoder_ptr, const InfraredMessage* message) { + furi_assert(encoder_ptr); + + InfraredEncoderRC6* encoder = encoder_ptr; + InfraredCommonEncoder* common_encoder = encoder->common_encoder; + infrared_common_encoder_reset(common_encoder); + + uint32_t* data = (void*)common_encoder->data; + *data |= 0x01; // start bit + (void)*data; // 3 bits for mode == 0 + *data |= encoder->toggle_bit ? 0x10 : 0; + *data |= reverse(message->address) << 5; + *data |= reverse(message->command) << 13; + + common_encoder->bits_to_encode = common_encoder->protocol->databit_len[0]; + encoder->toggle_bit ^= 1; +} + +InfraredStatus infrared_encoder_rc6_encode(void* encoder_ptr, uint32_t* duration, bool* level) { + InfraredEncoderRC6* encoder = encoder_ptr; + return infrared_common_encode(encoder->common_encoder, duration, level); +} + +void* infrared_encoder_rc6_alloc(void) { + InfraredEncoderRC6* encoder = malloc(sizeof(InfraredEncoderRC6)); + encoder->common_encoder = infrared_common_encoder_alloc(&protocol_rc6); + encoder->toggle_bit = false; + return encoder; +} + +void infrared_encoder_rc6_free(void* encoder_ptr) { + furi_assert(encoder_ptr); + + InfraredEncoderRC6* encoder = encoder_ptr; + free(encoder->common_encoder); + free(encoder); +} + +InfraredStatus infrared_encoder_rc6_encode_manchester( + InfraredCommonEncoder* common_encoder, + uint32_t* duration, + bool* polarity) { + InfraredStatus status = InfraredStatusError; + + bool toggle_bit = (common_encoder->bits_encoded == 4); + status = infrared_common_encode_manchester(common_encoder, duration, polarity); + if(toggle_bit) *duration *= 2; + return status; +} diff --git a/lib/infrared/encoder_decoder/rc6/infrared_rc6_spec.c b/lib/infrared/encoder_decoder/rc6/infrared_rc6_spec.c new file mode 100644 index 00000000..9e0ba746 --- /dev/null +++ b/lib/infrared/encoder_decoder/rc6/infrared_rc6_spec.c @@ -0,0 +1,17 @@ +#include "../infrared_i.h" +#include "infrared_protocol_defs_i.h" + +static const InfraredProtocolSpecification infrared_rc6_protocol_specification = { + .name = "RC6", + .address_length = 8, + .command_length = 8, + .frequency = INFRARED_RC6_CARRIER_FREQUENCY, + .duty_cycle = INFRARED_RC6_DUTY_CYCLE, +}; + +const InfraredProtocolSpecification* infrared_rc6_get_spec(InfraredProtocol protocol) { + if(protocol == InfraredProtocolRC6) + return &infrared_rc6_protocol_specification; + else + return NULL; +} diff --git a/lib/infrared/encoder_decoder/samsung/infrared_decoder_samsung.c b/lib/infrared/encoder_decoder/samsung/infrared_decoder_samsung.c new file mode 100644 index 00000000..4450ffd1 --- /dev/null +++ b/lib/infrared/encoder_decoder/samsung/infrared_decoder_samsung.c @@ -0,0 +1,72 @@ +#include "infrared.h" +#include "infrared_protocol_defs_i.h" +#include +#include +#include +#include "../infrared_i.h" + +InfraredMessage* infrared_decoder_samsung32_check_ready(void* ctx) { + return infrared_common_decoder_check_ready(ctx); +} + +bool infrared_decoder_samsung32_interpret(InfraredCommonDecoder* decoder) { + furi_assert(decoder); + + bool result = false; + uint8_t address1 = decoder->data[0]; + uint8_t address2 = decoder->data[1]; + uint8_t command = decoder->data[2]; + uint8_t command_inverse = decoder->data[3]; + + if((address1 == address2) && (command == (uint8_t)~command_inverse)) { + decoder->message.command = command; + decoder->message.address = address1; + decoder->message.protocol = InfraredProtocolSamsung32; + decoder->message.repeat = false; + result = true; + } + + return result; +} + +// timings start from Space (delay between message and repeat) +InfraredStatus infrared_decoder_samsung32_decode_repeat(InfraredCommonDecoder* decoder) { + furi_assert(decoder); + + float preamble_tolerance = decoder->protocol->timings.preamble_tolerance; + uint32_t bit_tolerance = decoder->protocol->timings.bit_tolerance; + InfraredStatus status = InfraredStatusError; + + if(decoder->timings_cnt < 6) return InfraredStatusOk; + + if((decoder->timings[0] > INFRARED_SAMSUNG_REPEAT_PAUSE_MIN) && + (decoder->timings[0] < INFRARED_SAMSUNG_REPEAT_PAUSE_MAX) && + MATCH_TIMING(decoder->timings[1], INFRARED_SAMSUNG_REPEAT_MARK, preamble_tolerance) && + MATCH_TIMING(decoder->timings[2], INFRARED_SAMSUNG_REPEAT_SPACE, preamble_tolerance) && + MATCH_TIMING(decoder->timings[3], decoder->protocol->timings.bit1_mark, bit_tolerance) && + MATCH_TIMING(decoder->timings[4], decoder->protocol->timings.bit1_space, bit_tolerance) && + MATCH_TIMING(decoder->timings[5], decoder->protocol->timings.bit1_mark, bit_tolerance)) { + status = InfraredStatusReady; + decoder->timings_cnt = 0; + } else { + status = InfraredStatusError; + } + + return status; +} + +void* infrared_decoder_samsung32_alloc(void) { + return infrared_common_decoder_alloc(&protocol_samsung32); +} + +InfraredMessage* infrared_decoder_samsung32_decode(void* decoder, bool level, uint32_t duration) { + return infrared_common_decode(decoder, level, duration); +} + +void infrared_decoder_samsung32_free(void* decoder) { + infrared_common_decoder_free(decoder); +} + +void infrared_decoder_samsung32_reset(void* decoder) { + infrared_common_decoder_reset(decoder); +} diff --git a/lib/irda/encoder_decoder/samsung/irda_encoder_samsung.c b/lib/infrared/encoder_decoder/samsung/infrared_encoder_samsung.c similarity index 50% rename from lib/irda/encoder_decoder/samsung/irda_encoder_samsung.c rename to lib/infrared/encoder_decoder/samsung/infrared_encoder_samsung.c index 522db8a2..88745ff5 100644 --- a/lib/irda/encoder_decoder/samsung/irda_encoder_samsung.c +++ b/lib/infrared/encoder_decoder/samsung/infrared_encoder_samsung.c @@ -1,24 +1,24 @@ #include "furi/check.h" -#include "common/irda_common_i.h" +#include "common/infrared_common_i.h" #include -#include "../irda_i.h" -#include "irda_protocol_defs_i.h" +#include "../infrared_i.h" +#include "infrared_protocol_defs_i.h" #include static const uint32_t repeat_timings[] = { - IRDA_SAMSUNG_REPEAT_PAUSE2, - IRDA_SAMSUNG_REPEAT_MARK, - IRDA_SAMSUNG_REPEAT_SPACE, - IRDA_SAMSUNG_BIT1_MARK, - IRDA_SAMSUNG_BIT1_SPACE, - IRDA_SAMSUNG_BIT1_MARK, + INFRARED_SAMSUNG_REPEAT_PAUSE2, + INFRARED_SAMSUNG_REPEAT_MARK, + INFRARED_SAMSUNG_REPEAT_SPACE, + INFRARED_SAMSUNG_BIT1_MARK, + INFRARED_SAMSUNG_BIT1_SPACE, + INFRARED_SAMSUNG_BIT1_MARK, }; -void irda_encoder_samsung32_reset(void* encoder_ptr, const IrdaMessage* message) { +void infrared_encoder_samsung32_reset(void* encoder_ptr, const InfraredMessage* message) { furi_assert(encoder_ptr); - IrdaCommonEncoder* encoder = encoder_ptr; - irda_common_encoder_reset(encoder); + InfraredCommonEncoder* encoder = encoder_ptr; + infrared_common_encoder_reset(encoder); uint8_t address = message->address; uint8_t command = message->command; @@ -33,8 +33,8 @@ void irda_encoder_samsung32_reset(void* encoder_ptr, const IrdaMessage* message) encoder->bits_to_encode = encoder->protocol->databit_len[0]; } -IrdaStatus irda_encoder_samsung32_encode_repeat( - IrdaCommonEncoder* encoder, +InfraredStatus infrared_encoder_samsung32_encode_repeat( + InfraredCommonEncoder* encoder, uint32_t* duration, bool* level) { furi_assert(encoder); @@ -48,23 +48,24 @@ IrdaStatus irda_encoder_samsung32_encode_repeat( if(repeat_cnt > 0) *duration = repeat_timings[repeat_cnt % COUNT_OF(repeat_timings)]; else - *duration = IRDA_SAMSUNG_REPEAT_PAUSE1; + *duration = INFRARED_SAMSUNG_REPEAT_PAUSE1; *level = repeat_cnt % 2; ++encoder->timings_encoded; bool done = (!((repeat_cnt + 1) % COUNT_OF(repeat_timings))); - return done ? IrdaStatusDone : IrdaStatusOk; + return done ? InfraredStatusDone : InfraredStatusOk; } -void* irda_encoder_samsung32_alloc(void) { - return irda_common_encoder_alloc(&protocol_samsung32); +void* infrared_encoder_samsung32_alloc(void) { + return infrared_common_encoder_alloc(&protocol_samsung32); } -void irda_encoder_samsung32_free(void* encoder_ptr) { - irda_common_encoder_free(encoder_ptr); +void infrared_encoder_samsung32_free(void* encoder_ptr) { + infrared_common_encoder_free(encoder_ptr); } -IrdaStatus irda_encoder_samsung32_encode(void* encoder_ptr, uint32_t* duration, bool* level) { - return irda_common_encode(encoder_ptr, duration, level); +InfraredStatus + infrared_encoder_samsung32_encode(void* encoder_ptr, uint32_t* duration, bool* level) { + return infrared_common_encode(encoder_ptr, duration, level); } diff --git a/lib/infrared/encoder_decoder/samsung/infrared_samsung_spec.c b/lib/infrared/encoder_decoder/samsung/infrared_samsung_spec.c new file mode 100644 index 00000000..f4cbf699 --- /dev/null +++ b/lib/infrared/encoder_decoder/samsung/infrared_samsung_spec.c @@ -0,0 +1,17 @@ +#include "../infrared_i.h" +#include "infrared_protocol_defs_i.h" + +static const InfraredProtocolSpecification infrared_samsung32_protocol_specification = { + .name = "Samsung32", + .address_length = 8, + .command_length = 8, + .frequency = INFRARED_COMMON_CARRIER_FREQUENCY, + .duty_cycle = INFRARED_COMMON_DUTY_CYCLE, +}; + +const InfraredProtocolSpecification* infrared_samsung32_get_spec(InfraredProtocol protocol) { + if(protocol == InfraredProtocolSamsung32) + return &infrared_samsung32_protocol_specification; + else + return NULL; +} diff --git a/lib/infrared/encoder_decoder/sirc/infrared_decoder_sirc.c b/lib/infrared/encoder_decoder/sirc/infrared_decoder_sirc.c new file mode 100644 index 00000000..45f06c94 --- /dev/null +++ b/lib/infrared/encoder_decoder/sirc/infrared_decoder_sirc.c @@ -0,0 +1,60 @@ +#include "common/infrared_common_i.h" +#include "infrared.h" +#include "infrared_protocol_defs_i.h" +#include +#include +#include +#include "../infrared_i.h" + +InfraredMessage* infrared_decoder_sirc_check_ready(void* ctx) { + return infrared_common_decoder_check_ready(ctx); +} + +bool infrared_decoder_sirc_interpret(InfraredCommonDecoder* decoder) { + furi_assert(decoder); + + uint32_t* data = (void*)&decoder->data[0]; + uint16_t address = 0; + uint8_t command = 0; + InfraredProtocol protocol = InfraredProtocolUnknown; + + if(decoder->databit_cnt == 12) { + address = (*data >> 7) & 0x1F; + command = *data & 0x7F; + protocol = InfraredProtocolSIRC; + } else if(decoder->databit_cnt == 15) { + address = (*data >> 7) & 0xFF; + command = *data & 0x7F; + protocol = InfraredProtocolSIRC15; + } else if(decoder->databit_cnt == 20) { + address = (*data >> 7) & 0x1FFF; + command = *data & 0x7F; + protocol = InfraredProtocolSIRC20; + } else { + return false; + } + + decoder->message.protocol = protocol; + decoder->message.address = address; + decoder->message.command = command; + /* SIRC doesn't specify repeat detection */ + decoder->message.repeat = false; + + return true; +} + +void* infrared_decoder_sirc_alloc(void) { + return infrared_common_decoder_alloc(&protocol_sirc); +} + +InfraredMessage* infrared_decoder_sirc_decode(void* decoder, bool level, uint32_t duration) { + return infrared_common_decode(decoder, level, duration); +} + +void infrared_decoder_sirc_free(void* decoder) { + infrared_common_decoder_free(decoder); +} + +void infrared_decoder_sirc_reset(void* decoder) { + infrared_common_decoder_reset(decoder); +} diff --git a/lib/infrared/encoder_decoder/sirc/infrared_encoder_sirc.c b/lib/infrared/encoder_decoder/sirc/infrared_encoder_sirc.c new file mode 100644 index 00000000..a6918cee --- /dev/null +++ b/lib/infrared/encoder_decoder/sirc/infrared_encoder_sirc.c @@ -0,0 +1,73 @@ +#include "furi/check.h" +#include "infrared.h" +#include "common/infrared_common_i.h" +#include +#include "../infrared_i.h" +#include "infrared_protocol_defs_i.h" +#include + +void infrared_encoder_sirc_reset(void* encoder_ptr, const InfraredMessage* message) { + furi_assert(encoder_ptr); + furi_assert(message); + + InfraredCommonEncoder* encoder = encoder_ptr; + infrared_common_encoder_reset(encoder); + + uint32_t* data = (void*)encoder->data; + + if(message->protocol == InfraredProtocolSIRC) { + *data = (message->command & 0x7F); + *data |= (message->address & 0x1F) << 7; + encoder->bits_to_encode = 12; + } else if(message->protocol == InfraredProtocolSIRC15) { + *data = (message->command & 0x7F); + *data |= (message->address & 0xFF) << 7; + encoder->bits_to_encode = 15; + } else if(message->protocol == InfraredProtocolSIRC20) { + *data = (message->command & 0x7F); + *data |= (message->address & 0x1FFF) << 7; + encoder->bits_to_encode = 20; + } else { + furi_assert(0); + } +} + +InfraredStatus infrared_encoder_sirc_encode_repeat( + InfraredCommonEncoder* encoder, + uint32_t* duration, + bool* level) { + furi_assert(encoder); + + furi_assert(encoder->timings_encoded == (1 + 2 + encoder->bits_to_encode * 2 - 1)); + + furi_assert(encoder->timings_sum < INFRARED_SIRC_REPEAT_PERIOD); + *duration = INFRARED_SIRC_REPEAT_PERIOD - encoder->timings_sum; + *level = false; + + encoder->timings_sum = 0; + encoder->timings_encoded = 1; + encoder->bits_encoded = 0; + encoder->state = InfraredCommonEncoderStatePreamble; + + return InfraredStatusOk; +} + +void* infrared_encoder_sirc_alloc(void) { + return infrared_common_encoder_alloc(&protocol_sirc); +} + +void infrared_encoder_sirc_free(void* encoder_ptr) { + infrared_common_encoder_free(encoder_ptr); +} + +InfraredStatus infrared_encoder_sirc_encode(void* encoder_ptr, uint32_t* duration, bool* level) { + InfraredCommonEncoder* encoder = encoder_ptr; + + InfraredStatus status = infrared_common_encode(encoder, duration, level); + if((status == InfraredStatusOk) && (encoder->bits_encoded == encoder->bits_to_encode)) { + furi_assert(!*level); + status = InfraredStatusDone; + encoder->state = InfraredCommonEncoderStateEncodeRepeat; + } + return status; +} diff --git a/lib/infrared/encoder_decoder/sirc/infrared_sirc_spec.c b/lib/infrared/encoder_decoder/sirc/infrared_sirc_spec.c new file mode 100644 index 00000000..9bf35908 --- /dev/null +++ b/lib/infrared/encoder_decoder/sirc/infrared_sirc_spec.c @@ -0,0 +1,37 @@ +#include "../infrared_i.h" +#include "infrared_protocol_defs_i.h" + +static const InfraredProtocolSpecification infrared_sirc_protocol_specification = { + .name = "SIRC", + .address_length = 5, + .command_length = 7, + .frequency = INFRARED_SIRC_CARRIER_FREQUENCY, + .duty_cycle = INFRARED_SIRC_DUTY_CYCLE, +}; + +static const InfraredProtocolSpecification infrared_sirc15_protocol_specification = { + .name = "SIRC15", + .address_length = 8, + .command_length = 7, + .frequency = INFRARED_SIRC_CARRIER_FREQUENCY, + .duty_cycle = INFRARED_SIRC_DUTY_CYCLE, +}; + +static const InfraredProtocolSpecification infrared_sirc20_protocol_specification = { + .name = "SIRC20", + .address_length = 13, + .command_length = 7, + .frequency = INFRARED_SIRC_CARRIER_FREQUENCY, + .duty_cycle = INFRARED_SIRC_DUTY_CYCLE, +}; + +const InfraredProtocolSpecification* infrared_sirc_get_spec(InfraredProtocol protocol) { + if(protocol == InfraredProtocolSIRC) + return &infrared_sirc_protocol_specification; + else if(protocol == InfraredProtocolSIRC15) + return &infrared_sirc15_protocol_specification; + else if(protocol == InfraredProtocolSIRC20) + return &infrared_sirc20_protocol_specification; + else + return NULL; +} diff --git a/lib/infrared/worker/infrared_transmit.c b/lib/infrared/worker/infrared_transmit.c new file mode 100644 index 00000000..d4c87ce5 --- /dev/null +++ b/lib/infrared/worker/infrared_transmit.c @@ -0,0 +1,116 @@ +#include "infrared.h" +#include +#include +#include +#include +#include +#include + +static uint32_t infrared_tx_number_of_transmissions = 0; +static uint32_t infrared_tx_raw_timings_index = 0; +static uint32_t infrared_tx_raw_timings_number = 0; +static uint32_t infrared_tx_raw_start_from_mark = 0; +static bool infrared_tx_raw_add_silence = false; + +FuriHalInfraredTxGetDataState + infrared_get_raw_data_callback(void* context, uint32_t* duration, bool* level) { + furi_assert(duration); + furi_assert(level); + furi_assert(context); + + FuriHalInfraredTxGetDataState state = FuriHalInfraredTxGetDataStateOk; + const uint32_t* timings = context; + + if(infrared_tx_raw_add_silence && (infrared_tx_raw_timings_index == 0)) { + infrared_tx_raw_add_silence = false; + *level = false; + *duration = INFRARED_RAW_TX_TIMING_DELAY_US; + } else { + *level = infrared_tx_raw_start_from_mark ^ (infrared_tx_raw_timings_index % 2); + *duration = timings[infrared_tx_raw_timings_index++]; + } + + if(infrared_tx_raw_timings_number == infrared_tx_raw_timings_index) { + state = FuriHalInfraredTxGetDataStateLastDone; + } + + return state; +} + +void infrared_send_raw_ext( + const uint32_t timings[], + uint32_t timings_cnt, + bool start_from_mark, + uint32_t frequency, + float duty_cycle) { + furi_assert(timings); + + infrared_tx_raw_start_from_mark = start_from_mark; + infrared_tx_raw_timings_index = 0; + infrared_tx_raw_timings_number = timings_cnt; + infrared_tx_raw_add_silence = start_from_mark; + furi_hal_infrared_async_tx_set_data_isr_callback( + infrared_get_raw_data_callback, (void*)timings); + furi_hal_infrared_async_tx_start(frequency, duty_cycle); + furi_hal_infrared_async_tx_wait_termination(); + + furi_assert(!furi_hal_infrared_is_busy()); +} + +void infrared_send_raw(const uint32_t timings[], uint32_t timings_cnt, bool start_from_mark) { + infrared_send_raw_ext( + timings, + timings_cnt, + start_from_mark, + INFRARED_COMMON_CARRIER_FREQUENCY, + INFRARED_COMMON_DUTY_CYCLE); +} + +FuriHalInfraredTxGetDataState + infrared_get_data_callback(void* context, uint32_t* duration, bool* level) { + FuriHalInfraredTxGetDataState state = FuriHalInfraredTxGetDataStateLastDone; + InfraredEncoderHandler* handler = context; + InfraredStatus status = InfraredStatusError; + + if(infrared_tx_number_of_transmissions > 0) { + status = infrared_encode(handler, duration, level); + } + + if(status == InfraredStatusError) { + state = FuriHalInfraredTxGetDataStateLastDone; + *duration = 0; + *level = 0; + } else if(status == InfraredStatusOk) { + state = FuriHalInfraredTxGetDataStateOk; + } else if(status == InfraredStatusDone) { + state = FuriHalInfraredTxGetDataStateDone; + if(--infrared_tx_number_of_transmissions == 0) { + state = FuriHalInfraredTxGetDataStateLastDone; + } + } else { + furi_crash(NULL); + } + + return state; +} + +void infrared_send(const InfraredMessage* message, int times) { + furi_assert(message); + furi_assert(times); + furi_assert(infrared_is_protocol_valid(message->protocol)); + + InfraredEncoderHandler* handler = infrared_alloc_encoder(); + infrared_reset_encoder(handler, message); + infrared_tx_number_of_transmissions = times; + + uint32_t frequency = infrared_get_protocol_frequency(message->protocol); + float duty_cycle = infrared_get_protocol_duty_cycle(message->protocol); + + furi_hal_infrared_async_tx_set_data_isr_callback(infrared_get_data_callback, handler); + furi_hal_infrared_async_tx_start(frequency, duty_cycle); + furi_hal_infrared_async_tx_wait_termination(); + + infrared_free_encoder(handler); + + furi_assert(!furi_hal_infrared_is_busy()); +} diff --git a/lib/irda/worker/irda_transmit.h b/lib/infrared/worker/infrared_transmit.h similarity index 78% rename from lib/irda/worker/irda_transmit.h rename to lib/infrared/worker/infrared_transmit.h index 6eaa0d0c..27e6a7df 100644 --- a/lib/irda/worker/irda_transmit.h +++ b/lib/infrared/worker/infrared_transmit.h @@ -1,5 +1,5 @@ -#include -#include +#include +#include #include #ifdef __cplusplus @@ -7,12 +7,12 @@ extern "C" { #endif /** - * Send message over IRDA. + * Send message over INFRARED. * * \param[in] message - message to send. * \param[in] times - number of times message should be sent. */ -void irda_send(const IrdaMessage* message, int times); +void infrared_send(const InfraredMessage* message, int times); /** * Send raw data through infrared port. @@ -22,7 +22,7 @@ void irda_send(const IrdaMessage* message, int times); * \param[in] start_from_mark - true if timings starts from mark, * otherwise from space */ -void irda_send_raw(const uint32_t timings[], uint32_t timings_cnt, bool start_from_mark); +void infrared_send_raw(const uint32_t timings[], uint32_t timings_cnt, bool start_from_mark); /** * Send raw data through infrared port, with additional settings. @@ -34,7 +34,7 @@ void irda_send_raw(const uint32_t timings[], uint32_t timings_cnt, bool start_fr * \param[in] duty_cycle - duty cycle to generate on PWM * \param[in] frequency - frequency to generate on PWM */ -void irda_send_raw_ext( +void infrared_send_raw_ext( const uint32_t timings[], uint32_t timings_cnt, bool start_from_mark, diff --git a/lib/infrared/worker/infrared_worker.c b/lib/infrared/worker/infrared_worker.c new file mode 100644 index 00000000..86a88367 --- /dev/null +++ b/lib/infrared/worker/infrared_worker.c @@ -0,0 +1,608 @@ +#include "furi/check.h" +#include "furi/common_defines.h" +#include "sys/_stdint.h" +#include "infrared_worker.h" +#include +#include +#include +#include +#include + +#include +#include + +#define INFRARED_WORKER_RX_TIMEOUT INFRARED_RAW_RX_TIMING_DELAY_US + +#define INFRARED_WORKER_RX_RECEIVED 0x01 +#define INFRARED_WORKER_RX_TIMEOUT_RECEIVED 0x02 +#define INFRARED_WORKER_OVERRUN 0x04 +#define INFRARED_WORKER_EXIT 0x08 +#define INFRARED_WORKER_TX_FILL_BUFFER 0x10 +#define INFRARED_WORKER_TX_MESSAGE_SENT 0x20 + +#define INFRARED_WORKER_ALL_RX_EVENTS \ + (INFRARED_WORKER_RX_RECEIVED | INFRARED_WORKER_RX_TIMEOUT_RECEIVED | \ + INFRARED_WORKER_OVERRUN | INFRARED_WORKER_EXIT) + +#define INFRARED_WORKER_ALL_TX_EVENTS \ + (INFRARED_WORKER_TX_FILL_BUFFER | INFRARED_WORKER_TX_MESSAGE_SENT | INFRARED_WORKER_EXIT) + +#define INFRARED_WORKER_ALL_EVENTS (INFRARED_WORKER_ALL_RX_EVENTS | INFRARED_WORKER_ALL_TX_EVENTS) + +typedef enum { + InfraredWorkerStateIdle, + InfraredWorkerStateRunRx, + InfraredWorkerStateRunTx, + InfraredWorkerStateWaitTxEnd, + InfraredWorkerStateStopTx, + InfraredWorkerStateStartTx, +} InfraredWorkerState; + +struct InfraredWorkerSignal { + bool decoded; + size_t timings_cnt; + union { + InfraredMessage message; + /* +1 is for pause we add at the beginning */ + uint32_t timings[MAX_TIMINGS_AMOUNT + 1]; + }; +}; + +struct InfraredWorker { + FuriThread* thread; + StreamBufferHandle_t stream; + osEventFlagsId_t events; + + InfraredWorkerSignal signal; + InfraredWorkerState state; + InfraredEncoderHandler* infrared_encoder; + InfraredDecoderHandler* infrared_decoder; + NotificationApp* notification; + bool blink_enable; + + union { + struct { + InfraredWorkerGetSignalCallback get_signal_callback; + InfraredWorkerMessageSentCallback message_sent_callback; + void* get_signal_context; + void* message_sent_context; + uint32_t frequency; + float duty_cycle; + uint32_t tx_raw_cnt; + bool need_reinitialization; + bool steady_signal_sent; + } tx; + struct { + InfraredWorkerReceivedSignalCallback received_signal_callback; + void* received_signal_context; + bool overrun; + } rx; + }; +}; + +typedef struct { + uint32_t duration; + bool level; + FuriHalInfraredTxGetDataState state; +} InfraredWorkerTiming; + +static int32_t infrared_worker_tx_thread(void* context); +static FuriHalInfraredTxGetDataState + infrared_worker_furi_hal_data_isr_callback(void* context, uint32_t* duration, bool* level); +static void infrared_worker_furi_hal_message_sent_isr_callback(void* context); + +static void infrared_worker_rx_timeout_callback(void* context) { + InfraredWorker* instance = context; + uint32_t flags_set = osEventFlagsSet(instance->events, INFRARED_WORKER_RX_TIMEOUT_RECEIVED); + furi_check(flags_set & INFRARED_WORKER_RX_TIMEOUT_RECEIVED); +} + +static void infrared_worker_rx_callback(void* context, bool level, uint32_t duration) { + InfraredWorker* instance = context; + + BaseType_t xHigherPriorityTaskWoken = pdFALSE; + furi_assert(duration != 0); + LevelDuration level_duration = level_duration_make(level, duration); + + size_t ret = xStreamBufferSendFromISR( + instance->stream, &level_duration, sizeof(LevelDuration), &xHigherPriorityTaskWoken); + uint32_t events = (ret == sizeof(LevelDuration)) ? INFRARED_WORKER_RX_RECEIVED : + INFRARED_WORKER_OVERRUN; + portYIELD_FROM_ISR(xHigherPriorityTaskWoken); + + uint32_t flags_set = osEventFlagsSet(instance->events, events); + furi_check(flags_set & events); +} + +static void infrared_worker_process_timeout(InfraredWorker* instance) { + if(instance->signal.timings_cnt < 2) return; + + const InfraredMessage* message_decoded = + infrared_check_decoder_ready(instance->infrared_decoder); + if(message_decoded) { + instance->signal.message = *message_decoded; + instance->signal.timings_cnt = 0; + instance->signal.decoded = true; + } else { + instance->signal.decoded = false; + } + if(instance->rx.received_signal_callback) + instance->rx.received_signal_callback( + instance->rx.received_signal_context, &instance->signal); +} + +static void + infrared_worker_process_timings(InfraredWorker* instance, uint32_t duration, bool level) { + const InfraredMessage* message_decoded = + infrared_decode(instance->infrared_decoder, level, duration); + if(message_decoded) { + instance->signal.message = *message_decoded; + instance->signal.timings_cnt = 0; + instance->signal.decoded = true; + if(instance->rx.received_signal_callback) + instance->rx.received_signal_callback( + instance->rx.received_signal_context, &instance->signal); + } else { + /* Skip first timing if it starts from Space */ + if((instance->signal.timings_cnt == 0) && !level) { + return; + } + + if(instance->signal.timings_cnt < MAX_TIMINGS_AMOUNT) { + instance->signal.timings[instance->signal.timings_cnt] = duration; + ++instance->signal.timings_cnt; + } else { + uint32_t flags_set = osEventFlagsSet(instance->events, INFRARED_WORKER_OVERRUN); + furi_check(flags_set & INFRARED_WORKER_OVERRUN); + instance->rx.overrun = true; + } + } +} + +static int32_t infrared_worker_rx_thread(void* thread_context) { + InfraredWorker* instance = thread_context; + uint32_t events = 0; + LevelDuration level_duration; + TickType_t last_blink_time = 0; + + while(1) { + events = + osEventFlagsWait(instance->events, INFRARED_WORKER_ALL_RX_EVENTS, 0, osWaitForever); + furi_check(events & INFRARED_WORKER_ALL_RX_EVENTS); /* at least one caught */ + + if(events & INFRARED_WORKER_RX_RECEIVED) { + if(!instance->rx.overrun && instance->blink_enable && + ((xTaskGetTickCount() - last_blink_time) > 80)) { + last_blink_time = xTaskGetTickCount(); + notification_message(instance->notification, &sequence_blink_blue_10); + } + if(instance->signal.timings_cnt == 0) + notification_message(instance->notification, &sequence_display_on); + while(sizeof(LevelDuration) == + xStreamBufferReceive( + instance->stream, &level_duration, sizeof(LevelDuration), 0)) { + if(!instance->rx.overrun) { + bool level = level_duration_get_level(level_duration); + uint32_t duration = level_duration_get_duration(level_duration); + infrared_worker_process_timings(instance, duration, level); + } + } + } + if(events & INFRARED_WORKER_OVERRUN) { + printf("#"); + infrared_reset_decoder(instance->infrared_decoder); + instance->signal.timings_cnt = 0; + if(instance->blink_enable) + notification_message(instance->notification, &sequence_set_red_255); + } + if(events & INFRARED_WORKER_RX_TIMEOUT_RECEIVED) { + if(instance->rx.overrun) { + printf("\nOVERRUN, max samples: %d\n", MAX_TIMINGS_AMOUNT); + instance->rx.overrun = false; + if(instance->blink_enable) + notification_message(instance->notification, &sequence_reset_red); + } else { + infrared_worker_process_timeout(instance); + } + instance->signal.timings_cnt = 0; + } + if(events & INFRARED_WORKER_EXIT) break; + } + + return 0; +} + +void infrared_worker_rx_set_received_signal_callback( + InfraredWorker* instance, + InfraredWorkerReceivedSignalCallback callback, + void* context) { + furi_assert(instance); + instance->rx.received_signal_callback = callback; + instance->rx.received_signal_context = context; +} + +InfraredWorker* infrared_worker_alloc() { + InfraredWorker* instance = malloc(sizeof(InfraredWorker)); + + instance->thread = furi_thread_alloc(); + furi_thread_set_name(instance->thread, "InfraredWorker"); + furi_thread_set_stack_size(instance->thread, 2048); + furi_thread_set_context(instance->thread, instance); + + size_t buffer_size = + MAX(sizeof(InfraredWorkerTiming) * (MAX_TIMINGS_AMOUNT + 1), + sizeof(LevelDuration) * MAX_TIMINGS_AMOUNT); + instance->stream = xStreamBufferCreate(buffer_size, sizeof(InfraredWorkerTiming)); + instance->infrared_decoder = infrared_alloc_decoder(); + instance->infrared_encoder = infrared_alloc_encoder(); + instance->blink_enable = false; + instance->notification = furi_record_open("notification"); + instance->state = InfraredWorkerStateIdle; + instance->events = osEventFlagsNew(NULL); + + return instance; +} + +void infrared_worker_free(InfraredWorker* instance) { + furi_assert(instance); + furi_assert(instance->state == InfraredWorkerStateIdle); + + furi_record_close("notification"); + infrared_free_decoder(instance->infrared_decoder); + infrared_free_encoder(instance->infrared_encoder); + vStreamBufferDelete(instance->stream); + furi_thread_free(instance->thread); + osEventFlagsDelete(instance->events); + + free(instance); +} + +void infrared_worker_rx_start(InfraredWorker* instance) { + furi_assert(instance); + furi_assert(instance->state == InfraredWorkerStateIdle); + + xStreamBufferSetTriggerLevel(instance->stream, sizeof(LevelDuration)); + + osEventFlagsClear(instance->events, INFRARED_WORKER_ALL_EVENTS); + furi_thread_set_callback(instance->thread, infrared_worker_rx_thread); + furi_thread_start(instance->thread); + + furi_hal_infrared_async_rx_set_capture_isr_callback(infrared_worker_rx_callback, instance); + furi_hal_infrared_async_rx_set_timeout_isr_callback( + infrared_worker_rx_timeout_callback, instance); + furi_hal_infrared_async_rx_start(); + furi_hal_infrared_async_rx_set_timeout(INFRARED_WORKER_RX_TIMEOUT); + + instance->rx.overrun = false; + instance->state = InfraredWorkerStateRunRx; +} + +void infrared_worker_rx_stop(InfraredWorker* instance) { + furi_assert(instance); + furi_assert(instance->state == InfraredWorkerStateRunRx); + + furi_hal_infrared_async_rx_set_timeout_isr_callback(NULL, NULL); + furi_hal_infrared_async_rx_set_capture_isr_callback(NULL, NULL); + furi_hal_infrared_async_rx_stop(); + + osEventFlagsSet(instance->events, INFRARED_WORKER_EXIT); + furi_thread_join(instance->thread); + + BaseType_t xReturn = xStreamBufferReset(instance->stream); + furi_assert(xReturn == pdPASS); + (void)xReturn; + + instance->state = InfraredWorkerStateIdle; +} + +bool infrared_worker_signal_is_decoded(const InfraredWorkerSignal* signal) { + furi_assert(signal); + return signal->decoded; +} + +void infrared_worker_get_raw_signal( + const InfraredWorkerSignal* signal, + const uint32_t** timings, + size_t* timings_cnt) { + furi_assert(signal); + furi_assert(timings); + furi_assert(timings_cnt); + + *timings = signal->timings; + *timings_cnt = signal->timings_cnt; +} + +const InfraredMessage* infrared_worker_get_decoded_signal(const InfraredWorkerSignal* signal) { + furi_assert(signal); + return &signal->message; +} + +void infrared_worker_rx_enable_blink_on_receiving(InfraredWorker* instance, bool enable) { + furi_assert(instance); + instance->blink_enable = enable; +} + +void infrared_worker_tx_start(InfraredWorker* instance) { + furi_assert(instance); + furi_assert(instance->state == InfraredWorkerStateIdle); + furi_assert(instance->tx.get_signal_callback); + + // size have to be greater than api hal infrared async tx buffer size + xStreamBufferSetTriggerLevel(instance->stream, sizeof(InfraredWorkerTiming)); + + osEventFlagsClear(instance->events, INFRARED_WORKER_ALL_EVENTS); + furi_thread_set_callback(instance->thread, infrared_worker_tx_thread); + + instance->tx.steady_signal_sent = false; + instance->tx.need_reinitialization = false; + furi_hal_infrared_async_tx_set_data_isr_callback( + infrared_worker_furi_hal_data_isr_callback, instance); + furi_hal_infrared_async_tx_set_signal_sent_isr_callback( + infrared_worker_furi_hal_message_sent_isr_callback, instance); + + instance->state = InfraredWorkerStateStartTx; + furi_thread_start(instance->thread); +} + +static void infrared_worker_furi_hal_message_sent_isr_callback(void* context) { + InfraredWorker* instance = context; + uint32_t flags_set = osEventFlagsSet(instance->events, INFRARED_WORKER_TX_MESSAGE_SENT); + furi_check(flags_set & INFRARED_WORKER_TX_MESSAGE_SENT); +} + +static FuriHalInfraredTxGetDataState + infrared_worker_furi_hal_data_isr_callback(void* context, uint32_t* duration, bool* level) { + furi_assert(context); + furi_assert(duration); + furi_assert(level); + + InfraredWorker* instance = context; + InfraredWorkerTiming timing; + FuriHalInfraredTxGetDataState state; + + if(sizeof(InfraredWorkerTiming) == + xStreamBufferReceiveFromISR(instance->stream, &timing, sizeof(InfraredWorkerTiming), 0)) { + *level = timing.level; + *duration = timing.duration; + state = timing.state; + } else { + furi_assert(0); + *level = 0; + *duration = 100; + state = FuriHalInfraredTxGetDataStateDone; + } + + uint32_t flags_set = osEventFlagsSet(instance->events, INFRARED_WORKER_TX_FILL_BUFFER); + furi_check(flags_set & INFRARED_WORKER_TX_FILL_BUFFER); + + return state; +} + +static bool infrared_get_new_signal(InfraredWorker* instance) { + bool new_signal_obtained = false; + + InfraredWorkerGetSignalResponse response = + instance->tx.get_signal_callback(instance->tx.get_signal_context, instance); + if(response == InfraredWorkerGetSignalResponseNew) { + uint32_t new_tx_frequency = 0; + float new_tx_duty_cycle = 0; + if(instance->signal.decoded) { + new_tx_frequency = infrared_get_protocol_frequency(instance->signal.message.protocol); + new_tx_duty_cycle = + infrared_get_protocol_duty_cycle(instance->signal.message.protocol); + } else { + furi_assert(instance->signal.timings_cnt > 1); + new_tx_frequency = INFRARED_COMMON_CARRIER_FREQUENCY; + new_tx_duty_cycle = INFRARED_COMMON_DUTY_CYCLE; + } + + instance->tx.tx_raw_cnt = 0; + instance->tx.need_reinitialization = (new_tx_frequency != instance->tx.frequency) || + (new_tx_duty_cycle != instance->tx.duty_cycle); + instance->tx.frequency = new_tx_frequency; + instance->tx.duty_cycle = new_tx_duty_cycle; + if(instance->signal.decoded) { + infrared_reset_encoder(instance->infrared_encoder, &instance->signal.message); + } + new_signal_obtained = true; + } else if(response == InfraredWorkerGetSignalResponseSame) { + new_signal_obtained = true; + /* no need to reinit */ + } else if(response == InfraredWorkerGetSignalResponseStop) { + new_signal_obtained = false; + } else { + furi_assert(0); + } + + return new_signal_obtained; +} + +static bool infrared_worker_tx_fill_buffer(InfraredWorker* instance) { + bool new_data_available = true; + InfraredWorkerTiming timing; + InfraredStatus status = InfraredStatusError; + + while(!xStreamBufferIsFull(instance->stream) && !instance->tx.need_reinitialization && + new_data_available) { + if(instance->signal.decoded) { + status = infrared_encode(instance->infrared_encoder, &timing.duration, &timing.level); + } else { + timing.duration = instance->signal.timings[instance->tx.tx_raw_cnt]; + /* raw always starts from Mark, but we fill it with space delay at start */ + timing.level = (instance->tx.tx_raw_cnt % 2); + ++instance->tx.tx_raw_cnt; + if(instance->tx.tx_raw_cnt >= instance->signal.timings_cnt) { + instance->tx.tx_raw_cnt = 0; + status = InfraredStatusDone; + } else { + status = InfraredStatusOk; + } + } + + if(status == InfraredStatusError) { + furi_assert(0); + new_data_available = false; + break; + } else if(status == InfraredStatusOk) { + timing.state = FuriHalInfraredTxGetDataStateOk; + } else if(status == InfraredStatusDone) { + timing.state = FuriHalInfraredTxGetDataStateDone; + + new_data_available = infrared_get_new_signal(instance); + if(instance->tx.need_reinitialization || !new_data_available) { + timing.state = FuriHalInfraredTxGetDataStateLastDone; + } + } else { + furi_assert(0); + } + uint32_t written_size = + xStreamBufferSend(instance->stream, &timing, sizeof(InfraredWorkerTiming), 0); + furi_assert(sizeof(InfraredWorkerTiming) == written_size); + (void)written_size; + } + + return new_data_available; +} + +static int32_t infrared_worker_tx_thread(void* thread_context) { + InfraredWorker* instance = thread_context; + furi_assert(instance->state == InfraredWorkerStateStartTx); + furi_assert(thread_context); + + uint32_t events = 0; + bool new_data_available = true; + bool exit = false; + + exit = !infrared_get_new_signal(instance); + furi_assert(!exit); + + while(!exit) { + switch(instance->state) { + case InfraredWorkerStateStartTx: + instance->tx.need_reinitialization = false; + new_data_available = infrared_worker_tx_fill_buffer(instance); + furi_hal_infrared_async_tx_start(instance->tx.frequency, instance->tx.duty_cycle); + + if(!new_data_available) { + instance->state = InfraredWorkerStateStopTx; + } else if(instance->tx.need_reinitialization) { + instance->state = InfraredWorkerStateWaitTxEnd; + } else { + instance->state = InfraredWorkerStateRunTx; + } + + break; + case InfraredWorkerStateStopTx: + furi_hal_infrared_async_tx_stop(); + exit = true; + break; + case InfraredWorkerStateWaitTxEnd: + furi_hal_infrared_async_tx_wait_termination(); + instance->state = InfraredWorkerStateStartTx; + + events = osEventFlagsGet(instance->events); + if(events & INFRARED_WORKER_EXIT) { + exit = true; + break; + } + + break; + case InfraredWorkerStateRunTx: + events = osEventFlagsWait( + instance->events, INFRARED_WORKER_ALL_TX_EVENTS, 0, osWaitForever); + furi_check(events & INFRARED_WORKER_ALL_TX_EVENTS); /* at least one caught */ + + if(events & INFRARED_WORKER_EXIT) { + instance->state = InfraredWorkerStateStopTx; + break; + } + + if(events & INFRARED_WORKER_TX_FILL_BUFFER) { + infrared_worker_tx_fill_buffer(instance); + + if(instance->tx.need_reinitialization) { + instance->state = InfraredWorkerStateWaitTxEnd; + } + } + + if(events & INFRARED_WORKER_TX_MESSAGE_SENT) { + if(instance->tx.message_sent_callback) + instance->tx.message_sent_callback(instance->tx.message_sent_context); + } + break; + default: + furi_assert(0); + break; + } + } + + return 0; +} + +void infrared_worker_tx_set_get_signal_callback( + InfraredWorker* instance, + InfraredWorkerGetSignalCallback callback, + void* context) { + furi_assert(instance); + instance->tx.get_signal_callback = callback; + instance->tx.get_signal_context = context; +} + +void infrared_worker_tx_set_signal_sent_callback( + InfraredWorker* instance, + InfraredWorkerMessageSentCallback callback, + void* context) { + furi_assert(instance); + instance->tx.message_sent_callback = callback; + instance->tx.message_sent_context = context; +} + +void infrared_worker_tx_stop(InfraredWorker* instance) { + furi_assert(instance); + furi_assert(instance->state != InfraredWorkerStateRunRx); + + osEventFlagsSet(instance->events, INFRARED_WORKER_EXIT); + furi_thread_join(instance->thread); + furi_hal_infrared_async_tx_set_data_isr_callback(NULL, NULL); + furi_hal_infrared_async_tx_set_signal_sent_isr_callback(NULL, NULL); + + instance->signal.timings_cnt = 0; + BaseType_t xReturn = pdFAIL; + xReturn = xStreamBufferReset(instance->stream); + furi_assert(xReturn == pdPASS); + (void)xReturn; + instance->state = InfraredWorkerStateIdle; +} + +void infrared_worker_set_decoded_signal(InfraredWorker* instance, const InfraredMessage* message) { + furi_assert(instance); + furi_assert(message); + + instance->signal.decoded = true; + instance->signal.message = *message; +} + +void infrared_worker_set_raw_signal( + InfraredWorker* instance, + const uint32_t* timings, + size_t timings_cnt) { + furi_assert(instance); + furi_assert(timings); + furi_assert(timings_cnt > 0); + size_t max_copy_num = COUNT_OF(instance->signal.timings) - 1; + furi_check(timings_cnt <= max_copy_num); + + instance->signal.timings[0] = INFRARED_RAW_TX_TIMING_DELAY_US; + memcpy(&instance->signal.timings[1], timings, timings_cnt * sizeof(uint32_t)); + instance->signal.decoded = false; + instance->signal.timings_cnt = timings_cnt + 1; +} + +InfraredWorkerGetSignalResponse + infrared_worker_tx_get_signal_steady_callback(void* context, InfraredWorker* instance) { + InfraredWorkerGetSignalResponse response = instance->tx.steady_signal_sent ? + InfraredWorkerGetSignalResponseSame : + InfraredWorkerGetSignalResponseNew; + instance->tx.steady_signal_sent = true; + return response; +} diff --git a/lib/infrared/worker/infrared_worker.h b/lib/infrared/worker/infrared_worker.h new file mode 100644 index 00000000..f54b3e01 --- /dev/null +++ b/lib/infrared/worker/infrared_worker.h @@ -0,0 +1,175 @@ +#pragma once + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#define MAX_TIMINGS_AMOUNT 512 + +/** Interface struct of infrared worker */ +typedef struct InfraredWorker InfraredWorker; +/** Interface struct of received signal */ +typedef struct InfraredWorkerSignal InfraredWorkerSignal; + +typedef enum { + InfraredWorkerGetSignalResponseNew, /** Signal, provided by callback is new and encoder should be reseted */ + InfraredWorkerGetSignalResponseSame, /** Signal, provided by callback is same. No encoder resetting. */ + InfraredWorkerGetSignalResponseStop, /** No more signals available. */ +} InfraredWorkerGetSignalResponse; + +/** Callback type for providing next signal to send. Should be used with + * infrared_worker_make_decoded_signal() or infrared_worker_make_raw_signal() + */ +typedef InfraredWorkerGetSignalResponse ( + *InfraredWorkerGetSignalCallback)(void* context, InfraredWorker* instance); + +/** Callback type for 'message is sent' event */ +typedef void (*InfraredWorkerMessageSentCallback)(void* context); + +/** Callback type to call by InfraredWorker thread when new signal is received */ +typedef void ( + *InfraredWorkerReceivedSignalCallback)(void* context, InfraredWorkerSignal* received_signal); + +/** Allocate InfraredWorker + * + * @return just created instance of InfraredWorker + */ +InfraredWorker* infrared_worker_alloc(); + +/** Free InfraredWorker + * + * @param[in] instance - InfraredWorker instance + */ +void infrared_worker_free(InfraredWorker* instance); + +/** Start InfraredWorker thread, initialise furi_hal, prepare all work. + * + * @param[in] instance - InfraredWorker instance + */ +void infrared_worker_rx_start(InfraredWorker* instance); + +/** Stop InfraredWorker thread, deinitialize furi_hal. + * + * @param[in] instance - InfraredWorker instance + */ +void infrared_worker_rx_stop(InfraredWorker* instance); + +/** Set received data callback InfraredWorker + * + * @param[in] instance - InfraredWorker instance + * @param[in] context - context to pass to callbacks + * @param[in] callback - InfraredWorkerReceivedSignalCallback callback + */ +void infrared_worker_rx_set_received_signal_callback( + InfraredWorker* instance, + InfraredWorkerReceivedSignalCallback callback, + void* context); + +/** Enable blinking on receiving any signal on IR port. + * + * @param[in] instance - instance of InfraredWorker + * @param[in] enable - true if you want to enable blinking + * false otherwise + */ +void infrared_worker_rx_enable_blink_on_receiving(InfraredWorker* instance, bool enable); + +/** Clarify is received signal either decoded or raw + * + * @param[in] signal - received signal + * @return true if signal is decoded, false if signal is raw + */ +bool infrared_worker_signal_is_decoded(const InfraredWorkerSignal* signal); + +/** Start transmitting signal. Callback InfraredWorkerGetSignalCallback should be + * set before this function is called, as it calls for it to fill buffer before + * starting transmission. + * + * @param[in] instance - InfraredWorker instance + */ +void infrared_worker_tx_start(InfraredWorker* instance); + +/** Stop transmitting signal. Waits for end of current signal and stops transmission. + * + * @param[in] instance - InfraredWorker instance + */ +void infrared_worker_tx_stop(InfraredWorker* instance); + +/** Set callback for providing next signal to send + * + * @param[in] instance - InfraredWorker instance + * @param[in] context - context to pass to callbacks + * @param[in] callback - InfraredWorkerGetSignalCallback callback + */ +void infrared_worker_tx_set_get_signal_callback( + InfraredWorker* instance, + InfraredWorkerGetSignalCallback callback, + void* context); + +/** Set callback for end of signal transmitting + * + * @param[in] instance - InfraredWorker instance + * @param[in] context - context to pass to callbacks + * @param[in] callback - InfraredWorkerMessageSentCallback callback + */ +void infrared_worker_tx_set_signal_sent_callback( + InfraredWorker* instance, + InfraredWorkerMessageSentCallback callback, + void* context); + +/** Callback to pass to infrared_worker_tx_set_get_signal_callback() if signal + * is steady and will not be changed between infrared_worker start and stop. + * Before starting transmission, desired steady signal must be set with + * infrared_worker_make_decoded_signal() or infrared_worker_make_raw_signal(). + * + * This function should not be implicitly called. + * + * @param[in] context - context + * @param[out] instance - InfraredWorker instance + */ +InfraredWorkerGetSignalResponse + infrared_worker_tx_get_signal_steady_callback(void* context, InfraredWorker* instance); + +/** Acquire raw signal from interface struct 'InfraredWorkerSignal'. + * First, you have to ensure that signal is raw. + * + * @param[in] signal - received signal + * @param[out] timings - pointer to array of timings + * @param[out] timings_cnt - pointer to amount of timings + */ +void infrared_worker_get_raw_signal( + const InfraredWorkerSignal* signal, + const uint32_t** timings, + size_t* timings_cnt); + +/** Acquire decoded message from interface struct 'InfraredWorkerSignal'. + * First, you have to ensure that signal is decoded. + * + * @param[in] signal - received signal + * @return decoded INFRARED message + */ +const InfraredMessage* infrared_worker_get_decoded_signal(const InfraredWorkerSignal* signal); + +/** Set current decoded signal for InfraredWorker instance + * + * @param[out] instance - InfraredWorker instance + * @param[in] message - decoded signal + */ +void infrared_worker_set_decoded_signal(InfraredWorker* instance, const InfraredMessage* message); + +/** Set current raw signal for InfraredWorker instance + * + * @param[out] instance - InfraredWorker instance + * @param[in] timings - array of raw timings + * @param[in] timings_cnt - size of array of raw timings + */ +void infrared_worker_set_raw_signal( + InfraredWorker* instance, + const uint32_t* timings, + size_t timings_cnt); + +#ifdef __cplusplus +} +#endif diff --git a/lib/irda/encoder_decoder/common/irda_common_i.h b/lib/irda/encoder_decoder/common/irda_common_i.h deleted file mode 100644 index aab32e1c..00000000 --- a/lib/irda/encoder_decoder/common/irda_common_i.h +++ /dev/null @@ -1,81 +0,0 @@ -#pragma once - -#include -#include "irda.h" -#include "irda_i.h" - -#define MATCH_TIMING(x, v, delta) (((x) < (v + delta)) && ((x) > (v - delta))) - -typedef struct IrdaCommonDecoder IrdaCommonDecoder; -typedef struct IrdaCommonEncoder IrdaCommonEncoder; - -typedef IrdaStatus (*IrdaCommonDecode)(IrdaCommonDecoder*, bool, uint32_t); -typedef IrdaStatus (*IrdaCommonDecodeRepeat)(IrdaCommonDecoder*); -typedef bool (*IrdaCommonInterpret)(IrdaCommonDecoder*); -typedef IrdaStatus (*IrdaCommonEncode)(IrdaCommonEncoder* encoder, uint32_t* out, bool* polarity); - -typedef struct { - IrdaTimings timings; - bool manchester_start_from_space; - bool no_stop_bit; - uint8_t databit_len[4]; - IrdaCommonDecode decode; - IrdaCommonDecodeRepeat decode_repeat; - IrdaCommonInterpret interpret; - IrdaCommonEncode encode; - IrdaCommonEncode encode_repeat; -} IrdaCommonProtocolSpec; - -typedef enum { - IrdaCommonDecoderStateWaitPreamble, - IrdaCommonDecoderStateDecode, - IrdaCommonDecoderStateProcessRepeat, -} IrdaCommonStateDecoder; - -typedef enum { - IrdaCommonEncoderStateSilence, - IrdaCommonEncoderStatePreamble, - IrdaCommonEncoderStateEncode, - IrdaCommonEncoderStateEncodeRepeat, -} IrdaCommonStateEncoder; - -struct IrdaCommonDecoder { - const IrdaCommonProtocolSpec* protocol; - void* context; - uint32_t timings[6]; - IrdaMessage message; - IrdaCommonStateDecoder state; - uint8_t timings_cnt; - bool switch_detect; - bool level; - uint16_t databit_cnt; - uint8_t data[]; -}; - -struct IrdaCommonEncoder { - const IrdaCommonProtocolSpec* protocol; - IrdaCommonStateEncoder state; - bool switch_detect; - uint8_t bits_to_encode; - uint8_t bits_encoded; - uint32_t timings_sum; - uint32_t timings_encoded; - void* context; - uint8_t data[]; -}; - -IrdaMessage* irda_common_decode(IrdaCommonDecoder* decoder, bool level, uint32_t duration); -IrdaStatus irda_common_decode_pdwm(IrdaCommonDecoder* decoder, bool level, uint32_t timing); -IrdaStatus irda_common_decode_manchester(IrdaCommonDecoder* decoder, bool level, uint32_t timing); -void* irda_common_decoder_alloc(const IrdaCommonProtocolSpec* protocol); -void irda_common_decoder_free(IrdaCommonDecoder* decoder); -void irda_common_decoder_reset(IrdaCommonDecoder* decoder); -IrdaMessage* irda_common_decoder_check_ready(IrdaCommonDecoder* decoder); - -IrdaStatus irda_common_encode(IrdaCommonEncoder* encoder, uint32_t* duration, bool* polarity); -IrdaStatus irda_common_encode_pdwm(IrdaCommonEncoder* encoder, uint32_t* duration, bool* polarity); -IrdaStatus - irda_common_encode_manchester(IrdaCommonEncoder* encoder, uint32_t* duration, bool* polarity); -void* irda_common_encoder_alloc(const IrdaCommonProtocolSpec* protocol); -void irda_common_encoder_free(IrdaCommonEncoder* encoder); -void irda_common_encoder_reset(IrdaCommonEncoder* encoder); diff --git a/lib/irda/encoder_decoder/common/irda_common_protocol_defs.c b/lib/irda/encoder_decoder/common/irda_common_protocol_defs.c deleted file mode 100644 index 7edc0974..00000000 --- a/lib/irda/encoder_decoder/common/irda_common_protocol_defs.c +++ /dev/null @@ -1,117 +0,0 @@ -#include "irda_common_i.h" -#include "irda_protocol_defs_i.h" - -const IrdaCommonProtocolSpec protocol_nec = { - .timings = - { - .preamble_mark = IRDA_NEC_PREAMBLE_MARK, - .preamble_space = IRDA_NEC_PREAMBLE_SPACE, - .bit1_mark = IRDA_NEC_BIT1_MARK, - .bit1_space = IRDA_NEC_BIT1_SPACE, - .bit0_mark = IRDA_NEC_BIT0_MARK, - .bit0_space = IRDA_NEC_BIT0_SPACE, - .preamble_tolerance = IRDA_NEC_PREAMBLE_TOLERANCE, - .bit_tolerance = IRDA_NEC_BIT_TOLERANCE, - .silence_time = IRDA_NEC_SILENCE, - .min_split_time = IRDA_NEC_MIN_SPLIT_TIME, - }, - .databit_len[0] = 42, - .databit_len[1] = 32, - .no_stop_bit = false, - .decode = irda_common_decode_pdwm, - .encode = irda_common_encode_pdwm, - .interpret = irda_decoder_nec_interpret, - .decode_repeat = irda_decoder_nec_decode_repeat, - .encode_repeat = irda_encoder_nec_encode_repeat, -}; - -const IrdaCommonProtocolSpec protocol_samsung32 = { - .timings = - { - .preamble_mark = IRDA_SAMSUNG_PREAMBLE_MARK, - .preamble_space = IRDA_SAMSUNG_PREAMBLE_SPACE, - .bit1_mark = IRDA_SAMSUNG_BIT1_MARK, - .bit1_space = IRDA_SAMSUNG_BIT1_SPACE, - .bit0_mark = IRDA_SAMSUNG_BIT0_MARK, - .bit0_space = IRDA_SAMSUNG_BIT0_SPACE, - .preamble_tolerance = IRDA_SAMSUNG_PREAMBLE_TOLERANCE, - .bit_tolerance = IRDA_SAMSUNG_BIT_TOLERANCE, - .silence_time = IRDA_SAMSUNG_SILENCE, - .min_split_time = IRDA_SAMSUNG_MIN_SPLIT_TIME, - }, - .databit_len[0] = 32, - .no_stop_bit = false, - .decode = irda_common_decode_pdwm, - .encode = irda_common_encode_pdwm, - .interpret = irda_decoder_samsung32_interpret, - .decode_repeat = irda_decoder_samsung32_decode_repeat, - .encode_repeat = irda_encoder_samsung32_encode_repeat, -}; - -const IrdaCommonProtocolSpec protocol_rc6 = { - .timings = - { - .preamble_mark = IRDA_RC6_PREAMBLE_MARK, - .preamble_space = IRDA_RC6_PREAMBLE_SPACE, - .bit1_mark = IRDA_RC6_BIT, - .preamble_tolerance = IRDA_RC6_PREAMBLE_TOLERANCE, - .bit_tolerance = IRDA_RC6_BIT_TOLERANCE, - .silence_time = IRDA_RC6_SILENCE, - .min_split_time = IRDA_RC6_MIN_SPLIT_TIME, - }, - .databit_len[0] = - 1 + 3 + 1 + 8 + - 8, // start_bit + 3 mode bits, + 1 toggle bit (x2 timing) + 8 address + 8 command - .manchester_start_from_space = false, - .decode = irda_decoder_rc6_decode_manchester, - .encode = irda_encoder_rc6_encode_manchester, - .interpret = irda_decoder_rc6_interpret, - .decode_repeat = NULL, - .encode_repeat = NULL, -}; - -const IrdaCommonProtocolSpec protocol_rc5 = { - .timings = - { - .preamble_mark = 0, - .preamble_space = 0, - .bit1_mark = IRDA_RC5_BIT, - .preamble_tolerance = 0, - .bit_tolerance = IRDA_RC5_BIT_TOLERANCE, - .silence_time = IRDA_RC5_SILENCE, - .min_split_time = IRDA_RC5_MIN_SPLIT_TIME, - }, - .databit_len[0] = 1 + 1 + 1 + 5 + - 6, // start_bit + start_bit/command_bit + toggle_bit + 5 address + 6 command - .manchester_start_from_space = true, - .decode = irda_common_decode_manchester, - .encode = irda_common_encode_manchester, - .interpret = irda_decoder_rc5_interpret, - .decode_repeat = NULL, - .encode_repeat = NULL, -}; - -const IrdaCommonProtocolSpec protocol_sirc = { - .timings = - { - .preamble_mark = IRDA_SIRC_PREAMBLE_MARK, - .preamble_space = IRDA_SIRC_PREAMBLE_SPACE, - .bit1_mark = IRDA_SIRC_BIT1_MARK, - .bit1_space = IRDA_SIRC_BIT1_SPACE, - .bit0_mark = IRDA_SIRC_BIT0_MARK, - .bit0_space = IRDA_SIRC_BIT0_SPACE, - .preamble_tolerance = IRDA_SIRC_PREAMBLE_TOLERANCE, - .bit_tolerance = IRDA_SIRC_BIT_TOLERANCE, - .silence_time = IRDA_SIRC_SILENCE, - .min_split_time = IRDA_SIRC_MIN_SPLIT_TIME, - }, - .databit_len[0] = 20, - .databit_len[1] = 15, - .databit_len[2] = 12, - .no_stop_bit = true, - .decode = irda_common_decode_pdwm, - .encode = irda_common_encode_pdwm, - .interpret = irda_decoder_sirc_interpret, - .decode_repeat = NULL, - .encode_repeat = irda_encoder_sirc_encode_repeat, -}; diff --git a/lib/irda/encoder_decoder/irda.c b/lib/irda/encoder_decoder/irda.c deleted file mode 100644 index f6fbb6af..00000000 --- a/lib/irda/encoder_decoder/irda.c +++ /dev/null @@ -1,298 +0,0 @@ -#include "irda.h" -#include "furi/check.h" -#include "common/irda_common_i.h" -#include "irda_protocol_defs_i.h" -#include -#include -#include -#include -#include "irda_i.h" -#include - -typedef struct { - IrdaAlloc alloc; - IrdaDecode decode; - IrdaDecoderReset reset; - IrdaFree free; - IrdaDecoderCheckReady check_ready; -} IrdaDecoders; - -typedef struct { - IrdaAlloc alloc; - IrdaEncode encode; - IrdaEncoderReset reset; - IrdaFree free; -} IrdaEncoders; - -struct IrdaDecoderHandler { - void** ctx; -}; - -struct IrdaEncoderHandler { - void* handler; - const IrdaEncoders* encoder; -}; - -typedef struct { - IrdaEncoders encoder; - IrdaDecoders decoder; - IrdaGetProtocolSpec get_protocol_spec; -} IrdaEncoderDecoder; - -static const IrdaEncoderDecoder irda_encoder_decoder[] = { - { - .decoder = - {.alloc = irda_decoder_nec_alloc, - .decode = irda_decoder_nec_decode, - .reset = irda_decoder_nec_reset, - .check_ready = irda_decoder_nec_check_ready, - .free = irda_decoder_nec_free}, - .encoder = - {.alloc = irda_encoder_nec_alloc, - .encode = irda_encoder_nec_encode, - .reset = irda_encoder_nec_reset, - .free = irda_encoder_nec_free}, - .get_protocol_spec = irda_nec_get_spec, - }, - { - .decoder = - {.alloc = irda_decoder_samsung32_alloc, - .decode = irda_decoder_samsung32_decode, - .reset = irda_decoder_samsung32_reset, - .check_ready = irda_decoder_samsung32_check_ready, - .free = irda_decoder_samsung32_free}, - .encoder = - {.alloc = irda_encoder_samsung32_alloc, - .encode = irda_encoder_samsung32_encode, - .reset = irda_encoder_samsung32_reset, - .free = irda_encoder_samsung32_free}, - .get_protocol_spec = irda_samsung32_get_spec, - }, - { - .decoder = - {.alloc = irda_decoder_rc5_alloc, - .decode = irda_decoder_rc5_decode, - .reset = irda_decoder_rc5_reset, - .check_ready = irda_decoder_rc5_check_ready, - .free = irda_decoder_rc5_free}, - .encoder = - {.alloc = irda_encoder_rc5_alloc, - .encode = irda_encoder_rc5_encode, - .reset = irda_encoder_rc5_reset, - .free = irda_encoder_rc5_free}, - .get_protocol_spec = irda_rc5_get_spec, - }, - { - .decoder = - {.alloc = irda_decoder_rc6_alloc, - .decode = irda_decoder_rc6_decode, - .reset = irda_decoder_rc6_reset, - .check_ready = irda_decoder_rc6_check_ready, - .free = irda_decoder_rc6_free}, - .encoder = - {.alloc = irda_encoder_rc6_alloc, - .encode = irda_encoder_rc6_encode, - .reset = irda_encoder_rc6_reset, - .free = irda_encoder_rc6_free}, - .get_protocol_spec = irda_rc6_get_spec, - }, - { - .decoder = - {.alloc = irda_decoder_sirc_alloc, - .decode = irda_decoder_sirc_decode, - .reset = irda_decoder_sirc_reset, - .check_ready = irda_decoder_sirc_check_ready, - .free = irda_decoder_sirc_free}, - .encoder = - {.alloc = irda_encoder_sirc_alloc, - .encode = irda_encoder_sirc_encode, - .reset = irda_encoder_sirc_reset, - .free = irda_encoder_sirc_free}, - .get_protocol_spec = irda_sirc_get_spec, - }, -}; - -static int irda_find_index_by_protocol(IrdaProtocol protocol); -static const IrdaProtocolSpecification* irda_get_spec_by_protocol(IrdaProtocol protocol); - -const IrdaMessage* irda_decode(IrdaDecoderHandler* handler, bool level, uint32_t duration) { - furi_assert(handler); - - IrdaMessage* message = NULL; - IrdaMessage* result = NULL; - - for(int i = 0; i < COUNT_OF(irda_encoder_decoder); ++i) { - if(irda_encoder_decoder[i].decoder.decode) { - message = irda_encoder_decoder[i].decoder.decode(handler->ctx[i], level, duration); - if(!result && message) { - result = message; - } - } - } - - return result; -} - -IrdaDecoderHandler* irda_alloc_decoder(void) { - IrdaDecoderHandler* handler = malloc(sizeof(IrdaDecoderHandler)); - handler->ctx = malloc(sizeof(void*) * COUNT_OF(irda_encoder_decoder)); - - for(int i = 0; i < COUNT_OF(irda_encoder_decoder); ++i) { - handler->ctx[i] = 0; - if(irda_encoder_decoder[i].decoder.alloc) - handler->ctx[i] = irda_encoder_decoder[i].decoder.alloc(); - } - - irda_reset_decoder(handler); - return handler; -} - -void irda_free_decoder(IrdaDecoderHandler* handler) { - furi_assert(handler); - furi_assert(handler->ctx); - - for(int i = 0; i < COUNT_OF(irda_encoder_decoder); ++i) { - if(irda_encoder_decoder[i].decoder.free) - irda_encoder_decoder[i].decoder.free(handler->ctx[i]); - } - - free(handler->ctx); - free(handler); -} - -void irda_reset_decoder(IrdaDecoderHandler* handler) { - for(int i = 0; i < COUNT_OF(irda_encoder_decoder); ++i) { - if(irda_encoder_decoder[i].decoder.reset) - irda_encoder_decoder[i].decoder.reset(handler->ctx[i]); - } -} - -const IrdaMessage* irda_check_decoder_ready(IrdaDecoderHandler* handler) { - furi_assert(handler); - - IrdaMessage* message = NULL; - IrdaMessage* result = NULL; - - for(int i = 0; i < COUNT_OF(irda_encoder_decoder); ++i) { - if(irda_encoder_decoder[i].decoder.check_ready) { - message = irda_encoder_decoder[i].decoder.check_ready(handler->ctx[i]); - if(!result && message) { - result = message; - } - } - } - - return result; -} - -IrdaEncoderHandler* irda_alloc_encoder(void) { - IrdaEncoderHandler* handler = malloc(sizeof(IrdaEncoderHandler)); - handler->handler = NULL; - handler->encoder = NULL; - return handler; -} - -void irda_free_encoder(IrdaEncoderHandler* handler) { - furi_assert(handler); - const IrdaEncoders* encoder = handler->encoder; - - if(encoder || handler->handler) { - furi_assert(encoder); - furi_assert(handler->handler); - furi_assert(encoder->free); - encoder->free(handler->handler); - } - - free(handler); -} - -static int irda_find_index_by_protocol(IrdaProtocol protocol) { - for(int i = 0; i < COUNT_OF(irda_encoder_decoder); ++i) { - if(irda_encoder_decoder[i].get_protocol_spec(protocol)) { - return i; - } - } - - return -1; -} - -void irda_reset_encoder(IrdaEncoderHandler* handler, const IrdaMessage* message) { - furi_assert(handler); - furi_assert(message); - int index = irda_find_index_by_protocol(message->protocol); - furi_check(index >= 0); - - const IrdaEncoders* required_encoder = &irda_encoder_decoder[index].encoder; - furi_assert(required_encoder); - furi_assert(required_encoder->reset); - furi_assert(required_encoder->alloc); - - /* Realloc encoder if different protocol set */ - if(required_encoder != handler->encoder) { - if(handler->handler != NULL) { - furi_assert(handler->encoder->free); - handler->encoder->free(handler->handler); - } - handler->encoder = required_encoder; - handler->handler = handler->encoder->alloc(); - } - - handler->encoder->reset(handler->handler, message); -} - -IrdaStatus irda_encode(IrdaEncoderHandler* handler, uint32_t* duration, bool* level) { - furi_assert(handler); - furi_assert(duration); - furi_assert(level); - const IrdaEncoders* encoder = handler->encoder; - furi_assert(encoder); - furi_assert(encoder->encode); - - IrdaStatus status = encoder->encode(handler->handler, duration, level); - furi_assert(status != IrdaStatusError); - - return status; -} - -bool irda_is_protocol_valid(IrdaProtocol protocol) { - return irda_find_index_by_protocol(protocol) >= 0; -} - -IrdaProtocol irda_get_protocol_by_name(const char* protocol_name) { - for(IrdaProtocol protocol = 0; protocol < IrdaProtocolMAX; ++protocol) { - const char* name = irda_get_protocol_name(protocol); - if(!strcmp(name, protocol_name)) return protocol; - } - return IrdaProtocolUnknown; -} - -static const IrdaProtocolSpecification* irda_get_spec_by_protocol(IrdaProtocol protocol) { - int index = irda_find_index_by_protocol(protocol); - const IrdaProtocolSpecification* spec = NULL; - if(index >= 0) { - spec = irda_encoder_decoder[index].get_protocol_spec(protocol); - } - - furi_assert(spec); - return spec; -} - -const char* irda_get_protocol_name(IrdaProtocol protocol) { - return irda_get_spec_by_protocol(protocol)->name; -} - -uint8_t irda_get_protocol_address_length(IrdaProtocol protocol) { - return irda_get_spec_by_protocol(protocol)->address_length; -} - -uint8_t irda_get_protocol_command_length(IrdaProtocol protocol) { - return irda_get_spec_by_protocol(protocol)->command_length; -} - -uint32_t irda_get_protocol_frequency(IrdaProtocol protocol) { - return irda_get_spec_by_protocol(protocol)->frequency; -} - -float irda_get_protocol_duty_cycle(IrdaProtocol protocol) { - return irda_get_spec_by_protocol(protocol)->duty_cycle; -} diff --git a/lib/irda/encoder_decoder/irda.h b/lib/irda/encoder_decoder/irda.h deleted file mode 100644 index ac7c6026..00000000 --- a/lib/irda/encoder_decoder/irda.h +++ /dev/null @@ -1,204 +0,0 @@ -#pragma once - -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -#define IRDA_COMMON_CARRIER_FREQUENCY ((uint32_t)38000) -#define IRDA_COMMON_DUTY_CYCLE ((float)0.33) - -/* if we want to see splitted raw signals during brutforce, - * we have to have RX raw timing delay less than TX */ -#define IRDA_RAW_RX_TIMING_DELAY_US 150000 -#define IRDA_RAW_TX_TIMING_DELAY_US 180000 - -typedef struct IrdaDecoderHandler IrdaDecoderHandler; -typedef struct IrdaEncoderHandler IrdaEncoderHandler; - -typedef enum { - IrdaProtocolUnknown = -1, - IrdaProtocolNEC = 0, - IrdaProtocolNECext, - IrdaProtocolNEC42, - IrdaProtocolNEC42ext, - IrdaProtocolSamsung32, - IrdaProtocolRC6, - IrdaProtocolRC5, - IrdaProtocolRC5X, - IrdaProtocolSIRC, - IrdaProtocolSIRC15, - IrdaProtocolSIRC20, - IrdaProtocolMAX, -} IrdaProtocol; - -typedef struct { - IrdaProtocol protocol; - uint32_t address; - uint32_t command; - bool repeat; -} IrdaMessage; - -typedef enum { - IrdaStatusError, - IrdaStatusOk, - IrdaStatusDone, - IrdaStatusReady, -} IrdaStatus; - -/** - * Initialize decoder. - * - * \return returns pointer to IRDA decoder handler if success, otherwise - error. - */ -IrdaDecoderHandler* irda_alloc_decoder(void); - -/** - * Provide to decoder next timing. - * - * \param[in] handler - handler to IRDA decoders. Should be acquired with \c irda_alloc_decoder(). - * \param[in] level - high(true) or low(false) level of input signal to analyze. - * it should alternate every call, otherwise it is an error case, - * and decoder resets its state and start decoding from the start. - * \param[in] duration - duration of steady high/low input signal. - * \return if message is ready, returns pointer to decoded message, returns NULL. - * Note: ownership of returned ptr belongs to handler. So pointer is valid - * up to next irda_free_decoder(), irda_reset_decoder(), - * irda_decode(), irda_check_decoder_ready() calls. - */ -const IrdaMessage* irda_decode(IrdaDecoderHandler* handler, bool level, uint32_t duration); - -/** - * Check whether decoder is ready. - * Functionality is quite similar to irda_decode(), but with no timing providing. - * Some protocols (e.g. Sony SIRC) has variable payload length, which means we - * can't recognize end of message right after receiving last bit. That's why - * application should call to irda_check_decoder_ready() after some timeout to - * retrieve decoded message, if so. - * - * \param[in] handler - handler to IRDA decoders. Should be acquired with \c irda_alloc_decoder(). - * \return if message is ready, returns pointer to decoded message, returns NULL. - * Note: ownership of returned ptr belongs to handler. So pointer is valid - * up to next irda_free_decoder(), irda_reset_decoder(), - * irda_decode(), irda_check_decoder_ready() calls. - */ -const IrdaMessage* irda_check_decoder_ready(IrdaDecoderHandler* handler); - -/** - * Deinitialize decoder and free allocated memory. - * - * \param[in] handler - handler to IRDA decoders. Should be acquired with \c irda_alloc_decoder(). - */ -void irda_free_decoder(IrdaDecoderHandler* handler); - -/** - * Reset IRDA decoder. - * - * \param[in] handler - handler to IRDA decoders. Should be acquired with \c irda_alloc_decoder(). - */ -void irda_reset_decoder(IrdaDecoderHandler* handler); - -/** - * Get protocol name by protocol enum. - * - * \param[in] protocol - protocol identifier. - * \return string to protocol name. - */ -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. - * - * \param[in] protocol - protocol identifier. - * \return length of address in bits. - */ -uint8_t irda_get_protocol_address_length(IrdaProtocol protocol); - -/** - * Get command length by protocol enum. - * - * \param[in] protocol - protocol identifier. - * \return length of command in bits. - */ -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); - -/** - * Allocate IRDA encoder. - * - * \return encoder handler. - */ -IrdaEncoderHandler* irda_alloc_encoder(void); - -/** - * Free encoder handler previously allocated with \c irda_alloc_encoder(). - * - * \param[in] handler - handler to IRDA encoder. Should be acquired with \c irda_alloc_encoder(). - */ -void irda_free_encoder(IrdaEncoderHandler* handler); - -/** - * Encode previously set IRDA message. - * Usage: - * 1) alloc with \c irda_alloc_encoder() - * 2) set message to encode with \c irda_reset_encoder() - * 3) call for \c irda_encode() to continuously get one at a time timings. - * 4) when \c irda_encode() returns IrdaStatusDone, it means new message is fully encoded. - * 5) to encode additional timings, just continue calling \c irda_encode(). - * - * \param[in] handler - handler to IRDA encoder. Should be acquired with \c irda_alloc_encoder(). - * \param[out] duration - encoded timing. - * \param[out] level - encoded level. - * - * \return status of encode operation. - */ -IrdaStatus irda_encode(IrdaEncoderHandler* handler, uint32_t* duration, bool* level); - -/** - * Reset IRDA encoder and set new message to encode. If it's not called after receiveing - * IrdaStatusDone in \c irda_encode(), encoder will encode repeat messages - * till the end of time. - * - * \param[in] handler - handler to IRDA encoder. Should be acquired with \c irda_alloc_encoder(). - * \param[in] message - message to encode. - */ -void irda_reset_encoder(IrdaEncoderHandler* handler, const IrdaMessage* message); - -/** - * Get PWM frequency value for selected protocol - * - * \param[in] protocol - protocol to get from PWM frequency - * - * \return frequency - */ -uint32_t irda_get_protocol_frequency(IrdaProtocol protocol); - -/** - * Get PWM duty cycle value for selected protocol - * - * \param[in] protocol - protocol to get from PWM duty cycle - * - * \return duty cycle - */ -float irda_get_protocol_duty_cycle(IrdaProtocol protocol); - -#ifdef __cplusplus -} -#endif diff --git a/lib/irda/encoder_decoder/irda_protocol_defs_i.h b/lib/irda/encoder_decoder/irda_protocol_defs_i.h deleted file mode 100644 index 87c4d906..00000000 --- a/lib/irda/encoder_decoder/irda_protocol_defs_i.h +++ /dev/null @@ -1,262 +0,0 @@ -#pragma once - -#include -#include -#include -#include "irda.h" -#include "common/irda_common_i.h" - -/*************************************************************************************************** -* NEC protocol description -* https://radioparty.ru/manuals/encyclopedia/213-ircontrol?start=1 -**************************************************************************************************** -* Preamble Preamble Pulse Distance/Width Pause Preamble Preamble Stop -* mark space Modulation up to period repeat repeat bit -* mark space -* -* 9000 4500 32 bit + stop bit ...110000 9000 2250 -* __________ _ _ _ _ _ _ _ _ _ _ _ _ _ ___________ _ -* ____ __________ _ _ _ __ __ __ _ _ __ __ _ _ ________________ ____________ ___ -* -***************************************************************************************************/ - -#define IRDA_NEC_PREAMBLE_MARK 9000 -#define IRDA_NEC_PREAMBLE_SPACE 4500 -#define IRDA_NEC_BIT1_MARK 560 -#define IRDA_NEC_BIT1_SPACE 1690 -#define IRDA_NEC_BIT0_MARK 560 -#define IRDA_NEC_BIT0_SPACE 560 -#define IRDA_NEC_REPEAT_PERIOD 110000 -#define IRDA_NEC_SILENCE IRDA_NEC_REPEAT_PERIOD -#define IRDA_NEC_MIN_SPLIT_TIME IRDA_NEC_REPEAT_PAUSE_MIN -#define IRDA_NEC_REPEAT_PAUSE_MIN 4000 -#define IRDA_NEC_REPEAT_PAUSE_MAX 150000 -#define IRDA_NEC_REPEAT_MARK 9000 -#define IRDA_NEC_REPEAT_SPACE 2250 -#define IRDA_NEC_PREAMBLE_TOLERANCE 200 // us -#define IRDA_NEC_BIT_TOLERANCE 120 // us - -void* irda_decoder_nec_alloc(void); -void irda_decoder_nec_reset(void* decoder); -void irda_decoder_nec_free(void* decoder); -IrdaMessage* irda_decoder_nec_check_ready(void* decoder); -IrdaMessage* irda_decoder_nec_decode(void* decoder, bool level, uint32_t duration); -void* irda_encoder_nec_alloc(void); -IrdaStatus irda_encoder_nec_encode(void* encoder_ptr, uint32_t* duration, bool* level); -void irda_encoder_nec_reset(void* encoder_ptr, const IrdaMessage* message); -void irda_encoder_nec_free(void* encoder_ptr); -bool irda_decoder_nec_interpret(IrdaCommonDecoder* decoder); -IrdaStatus irda_decoder_nec_decode_repeat(IrdaCommonDecoder* decoder); -IrdaStatus - irda_encoder_nec_encode_repeat(IrdaCommonEncoder* encoder, uint32_t* duration, bool* level); -const IrdaProtocolSpecification* irda_nec_get_spec(IrdaProtocol protocol); - -extern const IrdaCommonProtocolSpec protocol_nec; - -/*************************************************************************************************** -* SAMSUNG32 protocol description -* https://www.mikrocontroller.net/articles/IRMP_-_english#SAMSUNG -**************************************************************************************************** -* Preamble Preamble Pulse Distance/Width Pause Preamble Preamble Bit1 Stop -* mark space Modulation repeat repeat bit -* mark space -* -* 4500 4500 32 bit + stop bit 40000/100000 4500 4500 -* __________ _ _ _ _ _ _ _ _ _ _ _ ___________ _ _ -* _ __________ __ _ __ __ __ _ _ __ __ _ ________________ ____________ ____ ___ -* -***************************************************************************************************/ - -#define IRDA_SAMSUNG_PREAMBLE_MARK 4500 -#define IRDA_SAMSUNG_PREAMBLE_SPACE 4500 -#define IRDA_SAMSUNG_BIT1_MARK 550 -#define IRDA_SAMSUNG_BIT1_SPACE 1650 -#define IRDA_SAMSUNG_BIT0_MARK 550 -#define IRDA_SAMSUNG_BIT0_SPACE 550 -#define IRDA_SAMSUNG_REPEAT_PAUSE_MIN 30000 -#define IRDA_SAMSUNG_REPEAT_PAUSE1 46000 -#define IRDA_SAMSUNG_REPEAT_PAUSE2 97000 -/* Samsung silence have to be greater than REPEAT MAX - * otherwise there can be problems during unit tests parsing - * of some data. Real tolerances we don't know, but in real life - * silence time should be greater than max repeat time. This is - * because of similar preambule timings for repeat and first messages. */ -#define IRDA_SAMSUNG_MIN_SPLIT_TIME 5000 -#define IRDA_SAMSUNG_SILENCE 145000 -#define IRDA_SAMSUNG_REPEAT_PAUSE_MAX 140000 -#define IRDA_SAMSUNG_REPEAT_MARK 4500 -#define IRDA_SAMSUNG_REPEAT_SPACE 4500 -#define IRDA_SAMSUNG_PREAMBLE_TOLERANCE 200 // us -#define IRDA_SAMSUNG_BIT_TOLERANCE 120 // us - -void* irda_decoder_samsung32_alloc(void); -void irda_decoder_samsung32_reset(void* decoder); -void irda_decoder_samsung32_free(void* decoder); -IrdaMessage* irda_decoder_samsung32_check_ready(void* ctx); -IrdaMessage* irda_decoder_samsung32_decode(void* decoder, bool level, uint32_t duration); -IrdaStatus irda_encoder_samsung32_encode(void* encoder_ptr, uint32_t* duration, bool* level); -void irda_encoder_samsung32_reset(void* encoder_ptr, const IrdaMessage* message); -void* irda_encoder_samsung32_alloc(void); -void irda_encoder_samsung32_free(void* encoder_ptr); -bool irda_decoder_samsung32_interpret(IrdaCommonDecoder* decoder); -IrdaStatus irda_decoder_samsung32_decode_repeat(IrdaCommonDecoder* decoder); -IrdaStatus irda_encoder_samsung32_encode_repeat( - IrdaCommonEncoder* encoder, - uint32_t* duration, - bool* level); -const IrdaProtocolSpecification* irda_samsung32_get_spec(IrdaProtocol protocol); - -extern const IrdaCommonProtocolSpec protocol_samsung32; - -/*************************************************************************************************** -* RC6 protocol description -* https://www.mikrocontroller.net/articles/IRMP_-_english#RC6_.2B_RC6A -**************************************************************************************************** -* Preamble Manchester/biphase Silence -* mark/space Modulation -* -* 2666 889 444/888 - bit (x2 for toggle bit) 2666 -* -* ________ __ __ __ __ ____ __ __ __ __ __ __ __ __ -* _ _________ ____ __ __ ____ __ __ __ __ __ __ __ __ _______________ -* | 1 | 0 | 0 | 0 | 0 | ... | ... | | -* s m2 m1 m0 T address (MSB) command (MSB) -* -* s - start bit (always 1) -* m0-2 - mode (000 for RC6) -* T - toggle bit, twice longer -* address - 8 bit -* command - 8 bit -***************************************************************************************************/ - -#define IRDA_RC6_CARRIER_FREQUENCY 36000 -#define IRDA_RC6_DUTY_CYCLE 0.33 - -#define IRDA_RC6_PREAMBLE_MARK 2666 -#define IRDA_RC6_PREAMBLE_SPACE 889 -#define IRDA_RC6_BIT 444 // half of time-quant for 1 bit -#define IRDA_RC6_PREAMBLE_TOLERANCE 200 // us -#define IRDA_RC6_BIT_TOLERANCE 120 // us -/* protocol allows 2700 silence, but it is hard to send 1 message without repeat */ -#define IRDA_RC6_SILENCE (2700 * 10) -#define IRDA_RC6_MIN_SPLIT_TIME 2700 - -void* irda_decoder_rc6_alloc(void); -void irda_decoder_rc6_reset(void* decoder); -void irda_decoder_rc6_free(void* decoder); -IrdaMessage* irda_decoder_rc6_check_ready(void* ctx); -IrdaMessage* irda_decoder_rc6_decode(void* decoder, bool level, uint32_t duration); -void* irda_encoder_rc6_alloc(void); -void irda_encoder_rc6_reset(void* encoder_ptr, const IrdaMessage* message); -void irda_encoder_rc6_free(void* decoder); -IrdaStatus irda_encoder_rc6_encode(void* encoder_ptr, uint32_t* duration, bool* polarity); -bool irda_decoder_rc6_interpret(IrdaCommonDecoder* decoder); -IrdaStatus - irda_decoder_rc6_decode_manchester(IrdaCommonDecoder* decoder, bool level, uint32_t timing); -IrdaStatus irda_encoder_rc6_encode_manchester( - IrdaCommonEncoder* encoder_ptr, - uint32_t* duration, - bool* polarity); -const IrdaProtocolSpecification* irda_rc6_get_spec(IrdaProtocol protocol); - -extern const IrdaCommonProtocolSpec protocol_rc6; - -/*************************************************************************************************** -* RC5 protocol description -* https://www.mikrocontroller.net/articles/IRMP_-_english#RC5_.2B_RC5X -**************************************************************************************************** -* Manchester/biphase -* Modulation -* -* 888/1776 - bit (x2 for toggle bit) -* -* __ ____ __ __ __ __ __ __ __ __ -* __ __ ____ __ __ __ __ __ __ __ _ -* | 1 | 1 | 0 | ... | ... | -* s si T address (MSB) command (MSB) -* -* Note: manchester starts from space timing, so it have to be handled properly -* s - start bit (always 1) -* si - RC5: start bit (always 1), RC5X - 7-th bit of address (in our case always 0) -* T - toggle bit, change it's value every button press -* address - 5 bit -* command - 6/7 bit -***************************************************************************************************/ - -#define IRDA_RC5_CARRIER_FREQUENCY 36000 -#define IRDA_RC5_DUTY_CYCLE 0.33 - -#define IRDA_RC5_PREAMBLE_MARK 0 -#define IRDA_RC5_PREAMBLE_SPACE 0 -#define IRDA_RC5_BIT 888 // half of time-quant for 1 bit -#define IRDA_RC5_PREAMBLE_TOLERANCE 200 // us -#define IRDA_RC5_BIT_TOLERANCE 120 // us -/* protocol allows 2700 silence, but it is hard to send 1 message without repeat */ -#define IRDA_RC5_SILENCE (2700 * 10) -#define IRDA_RC5_MIN_SPLIT_TIME 2700 - -void* irda_decoder_rc5_alloc(void); -void irda_decoder_rc5_reset(void* decoder); -void irda_decoder_rc5_free(void* decoder); -IrdaMessage* irda_decoder_rc5_check_ready(void* ctx); -IrdaMessage* irda_decoder_rc5_decode(void* decoder, bool level, uint32_t duration); -void* irda_encoder_rc5_alloc(void); -void irda_encoder_rc5_reset(void* encoder_ptr, const IrdaMessage* message); -void irda_encoder_rc5_free(void* decoder); -IrdaStatus irda_encoder_rc5_encode(void* encoder_ptr, uint32_t* duration, bool* polarity); -bool irda_decoder_rc5_interpret(IrdaCommonDecoder* decoder); -const IrdaProtocolSpecification* irda_rc5_get_spec(IrdaProtocol protocol); - -extern const IrdaCommonProtocolSpec protocol_rc5; - -/*************************************************************************************************** -* Sony SIRC protocol description -* https://www.sbprojects.net/knowledge/ir/sirc.php -* http://picprojects.org.uk/ -**************************************************************************************************** -* Preamble Preamble Pulse Width Modulation Pause Entirely repeat -* mark space up to period message.. -* -* 2400 600 12/15/20 bits (600,1200) ...45000 2400 600 -* __________ _ _ _ _ _ _ _ _ _ _ _ _ _ __________ _ _ -* ____ __________ _ _ _ __ __ __ _ _ __ __ _ _ ____________________ __________ _ -* | command | address | -* SIRC | 7b LSB | 5b LSB | -* SIRC15 | 7b LSB | 8b LSB | -* SIRC20 | 7b LSB | 13b LSB | -* -* No way to determine either next message is repeat or not, -* so recognize only fact message received. Sony remotes always send at least 3 messages. -* Assume 8 last extended bits for SIRC20 are address bits. -***************************************************************************************************/ - -#define IRDA_SIRC_CARRIER_FREQUENCY 40000 -#define IRDA_SIRC_DUTY_CYCLE 0.33 -#define IRDA_SIRC_PREAMBLE_MARK 2400 -#define IRDA_SIRC_PREAMBLE_SPACE 600 -#define IRDA_SIRC_BIT1_MARK 1200 -#define IRDA_SIRC_BIT1_SPACE 600 -#define IRDA_SIRC_BIT0_MARK 600 -#define IRDA_SIRC_BIT0_SPACE 600 -#define IRDA_SIRC_PREAMBLE_TOLERANCE 200 // us -#define IRDA_SIRC_BIT_TOLERANCE 120 // us -#define IRDA_SIRC_SILENCE 10000 -#define IRDA_SIRC_MIN_SPLIT_TIME (IRDA_SIRC_SILENCE - 1000) -#define IRDA_SIRC_REPEAT_PERIOD 45000 - -void* irda_decoder_sirc_alloc(void); -void irda_decoder_sirc_reset(void* decoder); -IrdaMessage* irda_decoder_sirc_check_ready(void* decoder); -uint32_t irda_decoder_sirc_get_timeout(void* decoder); -void irda_decoder_sirc_free(void* decoder); -IrdaMessage* irda_decoder_sirc_decode(void* decoder, bool level, uint32_t duration); -void* irda_encoder_sirc_alloc(void); -void irda_encoder_sirc_reset(void* encoder_ptr, const IrdaMessage* message); -void irda_encoder_sirc_free(void* decoder); -IrdaStatus irda_encoder_sirc_encode(void* encoder_ptr, uint32_t* duration, bool* polarity); -bool irda_decoder_sirc_interpret(IrdaCommonDecoder* decoder); -const IrdaProtocolSpecification* irda_sirc_get_spec(IrdaProtocol protocol); -IrdaStatus - irda_encoder_sirc_encode_repeat(IrdaCommonEncoder* encoder, uint32_t* duration, bool* level); - -extern const IrdaCommonProtocolSpec protocol_sirc; diff --git a/lib/irda/encoder_decoder/nec/irda_nec_spec.c b/lib/irda/encoder_decoder/nec/irda_nec_spec.c deleted file mode 100644 index b193b6b4..00000000 --- a/lib/irda/encoder_decoder/nec/irda_nec_spec.c +++ /dev/null @@ -1,47 +0,0 @@ -#include "../irda_i.h" -#include "irda_protocol_defs_i.h" - -static const IrdaProtocolSpecification irda_nec_protocol_specification = { - .name = "NEC", - .address_length = 8, - .command_length = 8, - .frequency = IRDA_COMMON_CARRIER_FREQUENCY, - .duty_cycle = IRDA_COMMON_DUTY_CYCLE, -}; - -static const IrdaProtocolSpecification irda_necext_protocol_specification = { - .name = "NECext", - .address_length = 16, - .command_length = 16, - .frequency = IRDA_COMMON_CARRIER_FREQUENCY, - .duty_cycle = IRDA_COMMON_DUTY_CYCLE, -}; - -static const IrdaProtocolSpecification irda_nec42_protocol_specification = { - .name = "NEC42", - .address_length = 13, - .command_length = 8, - .frequency = IRDA_COMMON_CARRIER_FREQUENCY, - .duty_cycle = IRDA_COMMON_DUTY_CYCLE, -}; - -static const IrdaProtocolSpecification irda_nec42ext_protocol_specification = { - .name = "NEC42ext", - .address_length = 26, - .command_length = 16, - .frequency = IRDA_COMMON_CARRIER_FREQUENCY, - .duty_cycle = IRDA_COMMON_DUTY_CYCLE, -}; - -const IrdaProtocolSpecification* irda_nec_get_spec(IrdaProtocol protocol) { - if(protocol == IrdaProtocolNEC) - return &irda_nec_protocol_specification; - else if(protocol == IrdaProtocolNECext) - return &irda_necext_protocol_specification; - else if(protocol == IrdaProtocolNEC42) - return &irda_nec42_protocol_specification; - else if(protocol == IrdaProtocolNEC42ext) - return &irda_nec42ext_protocol_specification; - else - return NULL; -} diff --git a/lib/irda/encoder_decoder/rc5/irda_decoder_rc5.c b/lib/irda/encoder_decoder/rc5/irda_decoder_rc5.c deleted file mode 100644 index a9c72e65..00000000 --- a/lib/irda/encoder_decoder/rc5/irda_decoder_rc5.c +++ /dev/null @@ -1,82 +0,0 @@ -#include "irda.h" -#include -#include -#include -#include -#include "../irda_i.h" -#include "../irda_protocol_defs_i.h" - -typedef struct { - IrdaCommonDecoder* common_decoder; - bool toggle; -} IrdaRc5Decoder; - -IrdaMessage* irda_decoder_rc5_check_ready(void* ctx) { - IrdaRc5Decoder* decoder = ctx; - return irda_common_decoder_check_ready(decoder->common_decoder); -} - -bool irda_decoder_rc5_interpret(IrdaCommonDecoder* decoder) { - furi_assert(decoder); - - bool result = false; - uint32_t* data = (void*)&decoder->data[0]; - /* Manchester (inverse): - * 0->1 : 1 - * 1->0 : 0 - */ - decoder->data[0] = ~decoder->data[0]; - decoder->data[1] = ~decoder->data[1]; - - // MSB first - uint8_t address = reverse((uint8_t)decoder->data[0]) & 0x1F; - uint8_t command = (reverse((uint8_t)decoder->data[1]) >> 2) & 0x3F; - bool start_bit1 = *data & 0x01; - bool start_bit2 = *data & 0x02; - bool toggle = !!(*data & 0x04); - - if(start_bit1 == 1) { - IrdaProtocol protocol = start_bit2 ? IrdaProtocolRC5 : IrdaProtocolRC5X; - IrdaMessage* message = &decoder->message; - IrdaRc5Decoder* rc5_decoder = decoder->context; - bool* prev_toggle = &rc5_decoder->toggle; - if((message->address == address) && (message->command == command) && - (message->protocol == protocol)) { - message->repeat = (toggle == *prev_toggle); - } else { - message->repeat = false; - } - *prev_toggle = toggle; - message->command = command; - message->address = address; - message->protocol = protocol; - - result = true; - } - - return result; -} - -void* irda_decoder_rc5_alloc(void) { - IrdaRc5Decoder* decoder = malloc(sizeof(IrdaRc5Decoder)); - decoder->toggle = false; - decoder->common_decoder = irda_common_decoder_alloc(&protocol_rc5); - decoder->common_decoder->context = decoder; - return decoder; -} - -IrdaMessage* irda_decoder_rc5_decode(void* decoder, bool level, uint32_t duration) { - IrdaRc5Decoder* decoder_rc5 = decoder; - return irda_common_decode(decoder_rc5->common_decoder, level, duration); -} - -void irda_decoder_rc5_free(void* decoder) { - IrdaRc5Decoder* decoder_rc5 = decoder; - irda_common_decoder_free(decoder_rc5->common_decoder); - free(decoder_rc5); -} - -void irda_decoder_rc5_reset(void* decoder) { - IrdaRc5Decoder* decoder_rc5 = decoder; - irda_common_decoder_reset(decoder_rc5->common_decoder); -} diff --git a/lib/irda/encoder_decoder/rc5/irda_encoder_rc5.c b/lib/irda/encoder_decoder/rc5/irda_encoder_rc5.c deleted file mode 100644 index 36e742cd..00000000 --- a/lib/irda/encoder_decoder/rc5/irda_encoder_rc5.c +++ /dev/null @@ -1,55 +0,0 @@ -#include "furi/memmgr.h" -#include "irda.h" -#include "common/irda_common_i.h" -#include "irda_protocol_defs_i.h" -#include -#include "../irda_i.h" - -typedef struct IrdaEncoderRC5 { - IrdaCommonEncoder* common_encoder; - bool toggle_bit; -} IrdaEncoderRC5; - -void irda_encoder_rc5_reset(void* encoder_ptr, const IrdaMessage* message) { - furi_assert(encoder_ptr); - - IrdaEncoderRC5* encoder = encoder_ptr; - IrdaCommonEncoder* common_encoder = encoder->common_encoder; - irda_common_encoder_reset(common_encoder); - - uint32_t* data = (void*)common_encoder->data; - /* RC5 */ - *data |= 0x01; // start bit - if(message->protocol == IrdaProtocolRC5) { - *data |= 0x02; // start bit - } - *data |= encoder->toggle_bit ? 0x04 : 0; - *data |= (reverse(message->address) >> 3) << 3; /* address 5 bit */ - *data |= (reverse(message->command) >> 2) << 8; /* command 6 bit */ - - common_encoder->data[0] = ~common_encoder->data[0]; - common_encoder->data[1] = ~common_encoder->data[1]; - - common_encoder->bits_to_encode = common_encoder->protocol->databit_len[0]; - encoder->toggle_bit ^= 1; -} - -IrdaStatus irda_encoder_rc5_encode(void* encoder_ptr, uint32_t* duration, bool* level) { - IrdaEncoderRC5* encoder = encoder_ptr; - return irda_common_encode(encoder->common_encoder, duration, level); -} - -void* irda_encoder_rc5_alloc(void) { - IrdaEncoderRC5* encoder = malloc(sizeof(IrdaEncoderRC5)); - encoder->common_encoder = irda_common_encoder_alloc(&protocol_rc5); - encoder->toggle_bit = false; - return encoder; -} - -void irda_encoder_rc5_free(void* encoder_ptr) { - furi_assert(encoder_ptr); - - IrdaEncoderRC5* encoder = encoder_ptr; - free(encoder->common_encoder); - free(encoder); -} diff --git a/lib/irda/encoder_decoder/rc5/irda_rc5_spec.c b/lib/irda/encoder_decoder/rc5/irda_rc5_spec.c deleted file mode 100644 index 89d597f2..00000000 --- a/lib/irda/encoder_decoder/rc5/irda_rc5_spec.c +++ /dev/null @@ -1,27 +0,0 @@ -#include "../irda_i.h" -#include "irda_protocol_defs_i.h" - -static const IrdaProtocolSpecification irda_rc5_protocol_specification = { - .name = "RC5", - .address_length = 5, - .command_length = 6, - .frequency = IRDA_RC5_CARRIER_FREQUENCY, - .duty_cycle = IRDA_RC5_DUTY_CYCLE, -}; - -static const IrdaProtocolSpecification irda_rc5x_protocol_specification = { - .name = "RC5X", - .address_length = 5, - .command_length = 7, - .frequency = IRDA_RC5_CARRIER_FREQUENCY, - .duty_cycle = IRDA_RC5_DUTY_CYCLE, -}; - -const IrdaProtocolSpecification* irda_rc5_get_spec(IrdaProtocol protocol) { - if(protocol == IrdaProtocolRC5) - return &irda_rc5_protocol_specification; - else if(protocol == IrdaProtocolRC5X) - return &irda_rc5x_protocol_specification; - else - return NULL; -} diff --git a/lib/irda/encoder_decoder/rc6/irda_encoder_rc6.c b/lib/irda/encoder_decoder/rc6/irda_encoder_rc6.c deleted file mode 100644 index 41a397cf..00000000 --- a/lib/irda/encoder_decoder/rc6/irda_encoder_rc6.c +++ /dev/null @@ -1,61 +0,0 @@ -#include "furi/memmgr.h" -#include "irda.h" -#include "common/irda_common_i.h" -#include "irda_protocol_defs_i.h" -#include -#include "../irda_i.h" - -typedef struct IrdaEncoderRC6 { - IrdaCommonEncoder* common_encoder; - bool toggle_bit; -} IrdaEncoderRC6; - -void irda_encoder_rc6_reset(void* encoder_ptr, const IrdaMessage* message) { - furi_assert(encoder_ptr); - - IrdaEncoderRC6* encoder = encoder_ptr; - IrdaCommonEncoder* common_encoder = encoder->common_encoder; - irda_common_encoder_reset(common_encoder); - - uint32_t* data = (void*)common_encoder->data; - *data |= 0x01; // start bit - (void)*data; // 3 bits for mode == 0 - *data |= encoder->toggle_bit ? 0x10 : 0; - *data |= reverse(message->address) << 5; - *data |= reverse(message->command) << 13; - - common_encoder->bits_to_encode = common_encoder->protocol->databit_len[0]; - encoder->toggle_bit ^= 1; -} - -IrdaStatus irda_encoder_rc6_encode(void* encoder_ptr, uint32_t* duration, bool* level) { - IrdaEncoderRC6* encoder = encoder_ptr; - return irda_common_encode(encoder->common_encoder, duration, level); -} - -void* irda_encoder_rc6_alloc(void) { - IrdaEncoderRC6* encoder = malloc(sizeof(IrdaEncoderRC6)); - encoder->common_encoder = irda_common_encoder_alloc(&protocol_rc6); - encoder->toggle_bit = false; - return encoder; -} - -void irda_encoder_rc6_free(void* encoder_ptr) { - furi_assert(encoder_ptr); - - IrdaEncoderRC6* encoder = encoder_ptr; - free(encoder->common_encoder); - free(encoder); -} - -IrdaStatus irda_encoder_rc6_encode_manchester( - IrdaCommonEncoder* common_encoder, - uint32_t* duration, - bool* polarity) { - IrdaStatus status = IrdaStatusError; - - bool toggle_bit = (common_encoder->bits_encoded == 4); - status = irda_common_encode_manchester(common_encoder, duration, polarity); - if(toggle_bit) *duration *= 2; - return status; -} diff --git a/lib/irda/encoder_decoder/rc6/irda_rc6_spec.c b/lib/irda/encoder_decoder/rc6/irda_rc6_spec.c deleted file mode 100644 index 5f333bb0..00000000 --- a/lib/irda/encoder_decoder/rc6/irda_rc6_spec.c +++ /dev/null @@ -1,17 +0,0 @@ -#include "../irda_i.h" -#include "irda_protocol_defs_i.h" - -static const IrdaProtocolSpecification irda_rc6_protocol_specification = { - .name = "RC6", - .address_length = 8, - .command_length = 8, - .frequency = IRDA_RC6_CARRIER_FREQUENCY, - .duty_cycle = IRDA_RC6_DUTY_CYCLE, -}; - -const IrdaProtocolSpecification* irda_rc6_get_spec(IrdaProtocol protocol) { - if(protocol == IrdaProtocolRC6) - return &irda_rc6_protocol_specification; - else - return NULL; -} diff --git a/lib/irda/encoder_decoder/samsung/irda_decoder_samsung.c b/lib/irda/encoder_decoder/samsung/irda_decoder_samsung.c deleted file mode 100644 index 68fa41dd..00000000 --- a/lib/irda/encoder_decoder/samsung/irda_decoder_samsung.c +++ /dev/null @@ -1,72 +0,0 @@ -#include "irda.h" -#include "irda_protocol_defs_i.h" -#include -#include -#include -#include "../irda_i.h" - -IrdaMessage* irda_decoder_samsung32_check_ready(void* ctx) { - return irda_common_decoder_check_ready(ctx); -} - -bool irda_decoder_samsung32_interpret(IrdaCommonDecoder* decoder) { - furi_assert(decoder); - - bool result = false; - uint8_t address1 = decoder->data[0]; - uint8_t address2 = decoder->data[1]; - uint8_t command = decoder->data[2]; - uint8_t command_inverse = decoder->data[3]; - - if((address1 == address2) && (command == (uint8_t)~command_inverse)) { - decoder->message.command = command; - decoder->message.address = address1; - decoder->message.protocol = IrdaProtocolSamsung32; - decoder->message.repeat = false; - result = true; - } - - return result; -} - -// timings start from Space (delay between message and repeat) -IrdaStatus irda_decoder_samsung32_decode_repeat(IrdaCommonDecoder* decoder) { - furi_assert(decoder); - - float preamble_tolerance = decoder->protocol->timings.preamble_tolerance; - uint32_t bit_tolerance = decoder->protocol->timings.bit_tolerance; - IrdaStatus status = IrdaStatusError; - - if(decoder->timings_cnt < 6) return IrdaStatusOk; - - if((decoder->timings[0] > IRDA_SAMSUNG_REPEAT_PAUSE_MIN) && - (decoder->timings[0] < IRDA_SAMSUNG_REPEAT_PAUSE_MAX) && - MATCH_TIMING(decoder->timings[1], IRDA_SAMSUNG_REPEAT_MARK, preamble_tolerance) && - MATCH_TIMING(decoder->timings[2], IRDA_SAMSUNG_REPEAT_SPACE, preamble_tolerance) && - MATCH_TIMING(decoder->timings[3], decoder->protocol->timings.bit1_mark, bit_tolerance) && - MATCH_TIMING(decoder->timings[4], decoder->protocol->timings.bit1_space, bit_tolerance) && - MATCH_TIMING(decoder->timings[5], decoder->protocol->timings.bit1_mark, bit_tolerance)) { - status = IrdaStatusReady; - decoder->timings_cnt = 0; - } else { - status = IrdaStatusError; - } - - return status; -} - -void* irda_decoder_samsung32_alloc(void) { - return irda_common_decoder_alloc(&protocol_samsung32); -} - -IrdaMessage* irda_decoder_samsung32_decode(void* decoder, bool level, uint32_t duration) { - return irda_common_decode(decoder, level, duration); -} - -void irda_decoder_samsung32_free(void* decoder) { - irda_common_decoder_free(decoder); -} - -void irda_decoder_samsung32_reset(void* decoder) { - irda_common_decoder_reset(decoder); -} diff --git a/lib/irda/encoder_decoder/samsung/irda_samsung_spec.c b/lib/irda/encoder_decoder/samsung/irda_samsung_spec.c deleted file mode 100644 index dcc532ca..00000000 --- a/lib/irda/encoder_decoder/samsung/irda_samsung_spec.c +++ /dev/null @@ -1,17 +0,0 @@ -#include "../irda_i.h" -#include "irda_protocol_defs_i.h" - -static const IrdaProtocolSpecification irda_samsung32_protocol_specification = { - .name = "Samsung32", - .address_length = 8, - .command_length = 8, - .frequency = IRDA_COMMON_CARRIER_FREQUENCY, - .duty_cycle = IRDA_COMMON_DUTY_CYCLE, -}; - -const IrdaProtocolSpecification* irda_samsung32_get_spec(IrdaProtocol protocol) { - if(protocol == IrdaProtocolSamsung32) - return &irda_samsung32_protocol_specification; - else - return NULL; -} diff --git a/lib/irda/encoder_decoder/sirc/irda_decoder_sirc.c b/lib/irda/encoder_decoder/sirc/irda_decoder_sirc.c deleted file mode 100644 index 9bcb6801..00000000 --- a/lib/irda/encoder_decoder/sirc/irda_decoder_sirc.c +++ /dev/null @@ -1,60 +0,0 @@ -#include "common/irda_common_i.h" -#include "irda.h" -#include "irda_protocol_defs_i.h" -#include -#include -#include -#include "../irda_i.h" - -IrdaMessage* irda_decoder_sirc_check_ready(void* ctx) { - return irda_common_decoder_check_ready(ctx); -} - -bool irda_decoder_sirc_interpret(IrdaCommonDecoder* decoder) { - furi_assert(decoder); - - uint32_t* data = (void*)&decoder->data[0]; - uint16_t address = 0; - uint8_t command = 0; - IrdaProtocol protocol = IrdaProtocolUnknown; - - if(decoder->databit_cnt == 12) { - address = (*data >> 7) & 0x1F; - command = *data & 0x7F; - protocol = IrdaProtocolSIRC; - } else if(decoder->databit_cnt == 15) { - address = (*data >> 7) & 0xFF; - command = *data & 0x7F; - protocol = IrdaProtocolSIRC15; - } else if(decoder->databit_cnt == 20) { - address = (*data >> 7) & 0x1FFF; - command = *data & 0x7F; - protocol = IrdaProtocolSIRC20; - } else { - return false; - } - - decoder->message.protocol = protocol; - decoder->message.address = address; - decoder->message.command = command; - /* SIRC doesn't specify repeat detection */ - decoder->message.repeat = false; - - return true; -} - -void* irda_decoder_sirc_alloc(void) { - return irda_common_decoder_alloc(&protocol_sirc); -} - -IrdaMessage* irda_decoder_sirc_decode(void* decoder, bool level, uint32_t duration) { - return irda_common_decode(decoder, level, duration); -} - -void irda_decoder_sirc_free(void* decoder) { - irda_common_decoder_free(decoder); -} - -void irda_decoder_sirc_reset(void* decoder) { - irda_common_decoder_reset(decoder); -} diff --git a/lib/irda/encoder_decoder/sirc/irda_encoder_sirc.c b/lib/irda/encoder_decoder/sirc/irda_encoder_sirc.c deleted file mode 100644 index 73c4f622..00000000 --- a/lib/irda/encoder_decoder/sirc/irda_encoder_sirc.c +++ /dev/null @@ -1,71 +0,0 @@ -#include "furi/check.h" -#include "irda.h" -#include "common/irda_common_i.h" -#include -#include "../irda_i.h" -#include "irda_protocol_defs_i.h" -#include - -void irda_encoder_sirc_reset(void* encoder_ptr, const IrdaMessage* message) { - furi_assert(encoder_ptr); - furi_assert(message); - - IrdaCommonEncoder* encoder = encoder_ptr; - irda_common_encoder_reset(encoder); - - uint32_t* data = (void*)encoder->data; - - if(message->protocol == IrdaProtocolSIRC) { - *data = (message->command & 0x7F); - *data |= (message->address & 0x1F) << 7; - encoder->bits_to_encode = 12; - } else if(message->protocol == IrdaProtocolSIRC15) { - *data = (message->command & 0x7F); - *data |= (message->address & 0xFF) << 7; - encoder->bits_to_encode = 15; - } else if(message->protocol == IrdaProtocolSIRC20) { - *data = (message->command & 0x7F); - *data |= (message->address & 0x1FFF) << 7; - encoder->bits_to_encode = 20; - } else { - furi_assert(0); - } -} - -IrdaStatus - irda_encoder_sirc_encode_repeat(IrdaCommonEncoder* encoder, uint32_t* duration, bool* level) { - furi_assert(encoder); - - furi_assert(encoder->timings_encoded == (1 + 2 + encoder->bits_to_encode * 2 - 1)); - - furi_assert(encoder->timings_sum < IRDA_SIRC_REPEAT_PERIOD); - *duration = IRDA_SIRC_REPEAT_PERIOD - encoder->timings_sum; - *level = false; - - encoder->timings_sum = 0; - encoder->timings_encoded = 1; - encoder->bits_encoded = 0; - encoder->state = IrdaCommonEncoderStatePreamble; - - return IrdaStatusOk; -} - -void* irda_encoder_sirc_alloc(void) { - return irda_common_encoder_alloc(&protocol_sirc); -} - -void irda_encoder_sirc_free(void* encoder_ptr) { - irda_common_encoder_free(encoder_ptr); -} - -IrdaStatus irda_encoder_sirc_encode(void* encoder_ptr, uint32_t* duration, bool* level) { - IrdaCommonEncoder* encoder = encoder_ptr; - - IrdaStatus status = irda_common_encode(encoder, duration, level); - if((status == IrdaStatusOk) && (encoder->bits_encoded == encoder->bits_to_encode)) { - furi_assert(!*level); - status = IrdaStatusDone; - encoder->state = IrdaCommonEncoderStateEncodeRepeat; - } - return status; -} diff --git a/lib/irda/encoder_decoder/sirc/irda_sirc_spec.c b/lib/irda/encoder_decoder/sirc/irda_sirc_spec.c deleted file mode 100644 index fc06d594..00000000 --- a/lib/irda/encoder_decoder/sirc/irda_sirc_spec.c +++ /dev/null @@ -1,37 +0,0 @@ -#include "../irda_i.h" -#include "irda_protocol_defs_i.h" - -static const IrdaProtocolSpecification irda_sirc_protocol_specification = { - .name = "SIRC", - .address_length = 5, - .command_length = 7, - .frequency = IRDA_SIRC_CARRIER_FREQUENCY, - .duty_cycle = IRDA_SIRC_DUTY_CYCLE, -}; - -static const IrdaProtocolSpecification irda_sirc15_protocol_specification = { - .name = "SIRC15", - .address_length = 8, - .command_length = 7, - .frequency = IRDA_SIRC_CARRIER_FREQUENCY, - .duty_cycle = IRDA_SIRC_DUTY_CYCLE, -}; - -static const IrdaProtocolSpecification irda_sirc20_protocol_specification = { - .name = "SIRC20", - .address_length = 13, - .command_length = 7, - .frequency = IRDA_SIRC_CARRIER_FREQUENCY, - .duty_cycle = IRDA_SIRC_DUTY_CYCLE, -}; - -const IrdaProtocolSpecification* irda_sirc_get_spec(IrdaProtocol protocol) { - if(protocol == IrdaProtocolSIRC) - return &irda_sirc_protocol_specification; - else if(protocol == IrdaProtocolSIRC15) - return &irda_sirc15_protocol_specification; - else if(protocol == IrdaProtocolSIRC20) - return &irda_sirc20_protocol_specification; - else - return NULL; -} diff --git a/lib/irda/worker/irda_transmit.c b/lib/irda/worker/irda_transmit.c deleted file mode 100644 index d66e1e38..00000000 --- a/lib/irda/worker/irda_transmit.c +++ /dev/null @@ -1,114 +0,0 @@ -#include "irda.h" -#include -#include -#include -#include -#include -#include - -static uint32_t irda_tx_number_of_transmissions = 0; -static uint32_t irda_tx_raw_timings_index = 0; -static uint32_t irda_tx_raw_timings_number = 0; -static uint32_t irda_tx_raw_start_from_mark = 0; -static bool irda_tx_raw_add_silence = false; - -FuriHalIrdaTxGetDataState - irda_get_raw_data_callback(void* context, uint32_t* duration, bool* level) { - furi_assert(duration); - furi_assert(level); - furi_assert(context); - - FuriHalIrdaTxGetDataState state = FuriHalIrdaTxGetDataStateOk; - const uint32_t* timings = context; - - if(irda_tx_raw_add_silence && (irda_tx_raw_timings_index == 0)) { - irda_tx_raw_add_silence = false; - *level = false; - *duration = IRDA_RAW_TX_TIMING_DELAY_US; - } else { - *level = irda_tx_raw_start_from_mark ^ (irda_tx_raw_timings_index % 2); - *duration = timings[irda_tx_raw_timings_index++]; - } - - if(irda_tx_raw_timings_number == irda_tx_raw_timings_index) { - state = FuriHalIrdaTxGetDataStateLastDone; - } - - return state; -} - -void irda_send_raw_ext( - const uint32_t timings[], - uint32_t timings_cnt, - bool start_from_mark, - uint32_t frequency, - float duty_cycle) { - furi_assert(timings); - - irda_tx_raw_start_from_mark = start_from_mark; - irda_tx_raw_timings_index = 0; - irda_tx_raw_timings_number = timings_cnt; - irda_tx_raw_add_silence = start_from_mark; - furi_hal_irda_async_tx_set_data_isr_callback(irda_get_raw_data_callback, (void*)timings); - furi_hal_irda_async_tx_start(frequency, duty_cycle); - furi_hal_irda_async_tx_wait_termination(); - - furi_assert(!furi_hal_irda_is_busy()); -} - -void irda_send_raw(const uint32_t timings[], uint32_t timings_cnt, bool start_from_mark) { - irda_send_raw_ext( - timings, - timings_cnt, - start_from_mark, - IRDA_COMMON_CARRIER_FREQUENCY, - IRDA_COMMON_DUTY_CYCLE); -} - -FuriHalIrdaTxGetDataState irda_get_data_callback(void* context, uint32_t* duration, bool* level) { - FuriHalIrdaTxGetDataState state = FuriHalIrdaTxGetDataStateLastDone; - IrdaEncoderHandler* handler = context; - IrdaStatus status = IrdaStatusError; - - if(irda_tx_number_of_transmissions > 0) { - status = irda_encode(handler, duration, level); - } - - if(status == IrdaStatusError) { - state = FuriHalIrdaTxGetDataStateLastDone; - *duration = 0; - *level = 0; - } else if(status == IrdaStatusOk) { - state = FuriHalIrdaTxGetDataStateOk; - } else if(status == IrdaStatusDone) { - state = FuriHalIrdaTxGetDataStateDone; - if(--irda_tx_number_of_transmissions == 0) { - state = FuriHalIrdaTxGetDataStateLastDone; - } - } else { - furi_crash(NULL); - } - - return state; -} - -void irda_send(const IrdaMessage* message, int times) { - furi_assert(message); - furi_assert(times); - furi_assert(irda_is_protocol_valid(message->protocol)); - - IrdaEncoderHandler* handler = irda_alloc_encoder(); - irda_reset_encoder(handler, message); - irda_tx_number_of_transmissions = times; - - uint32_t frequency = irda_get_protocol_frequency(message->protocol); - float duty_cycle = irda_get_protocol_duty_cycle(message->protocol); - - furi_hal_irda_async_tx_set_data_isr_callback(irda_get_data_callback, handler); - furi_hal_irda_async_tx_start(frequency, duty_cycle); - furi_hal_irda_async_tx_wait_termination(); - - irda_free_encoder(handler); - - furi_assert(!furi_hal_irda_is_busy()); -} diff --git a/lib/irda/worker/irda_worker.c b/lib/irda/worker/irda_worker.c deleted file mode 100644 index 40636dfd..00000000 --- a/lib/irda/worker/irda_worker.c +++ /dev/null @@ -1,598 +0,0 @@ -#include "furi/check.h" -#include "furi/common_defines.h" -#include "sys/_stdint.h" -#include "irda_worker.h" -#include -#include -#include -#include -#include - -#include -#include - -#define IRDA_WORKER_RX_TIMEOUT IRDA_RAW_RX_TIMING_DELAY_US - -#define IRDA_WORKER_RX_RECEIVED 0x01 -#define IRDA_WORKER_RX_TIMEOUT_RECEIVED 0x02 -#define IRDA_WORKER_OVERRUN 0x04 -#define IRDA_WORKER_EXIT 0x08 -#define IRDA_WORKER_TX_FILL_BUFFER 0x10 -#define IRDA_WORKER_TX_MESSAGE_SENT 0x20 - -#define IRDA_WORKER_ALL_RX_EVENTS \ - (IRDA_WORKER_RX_RECEIVED | IRDA_WORKER_RX_TIMEOUT_RECEIVED | IRDA_WORKER_OVERRUN | \ - IRDA_WORKER_EXIT) - -#define IRDA_WORKER_ALL_TX_EVENTS \ - (IRDA_WORKER_TX_FILL_BUFFER | IRDA_WORKER_TX_MESSAGE_SENT | IRDA_WORKER_EXIT) - -#define IRDA_WORKER_ALL_EVENTS (IRDA_WORKER_ALL_RX_EVENTS | IRDA_WORKER_ALL_TX_EVENTS) - -typedef enum { - IrdaWorkerStateIdle, - IrdaWorkerStateRunRx, - IrdaWorkerStateRunTx, - IrdaWorkerStateWaitTxEnd, - IrdaWorkerStateStopTx, - IrdaWorkerStateStartTx, -} IrdaWorkerState; - -struct IrdaWorkerSignal { - bool decoded; - size_t timings_cnt; - union { - IrdaMessage message; - /* +1 is for pause we add at the beginning */ - uint32_t timings[MAX_TIMINGS_AMOUNT + 1]; - }; -}; - -struct IrdaWorker { - FuriThread* thread; - StreamBufferHandle_t stream; - osEventFlagsId_t events; - - IrdaWorkerSignal signal; - IrdaWorkerState state; - IrdaEncoderHandler* irda_encoder; - IrdaDecoderHandler* irda_decoder; - NotificationApp* notification; - bool blink_enable; - - union { - struct { - IrdaWorkerGetSignalCallback get_signal_callback; - IrdaWorkerMessageSentCallback message_sent_callback; - void* get_signal_context; - void* message_sent_context; - uint32_t frequency; - float duty_cycle; - uint32_t tx_raw_cnt; - bool need_reinitialization; - bool steady_signal_sent; - } tx; - struct { - IrdaWorkerReceivedSignalCallback received_signal_callback; - void* received_signal_context; - bool overrun; - } rx; - }; -}; - -typedef struct { - uint32_t duration; - bool level; - FuriHalIrdaTxGetDataState state; -} IrdaWorkerTiming; - -static int32_t irda_worker_tx_thread(void* context); -static FuriHalIrdaTxGetDataState - irda_worker_furi_hal_data_isr_callback(void* context, uint32_t* duration, bool* level); -static void irda_worker_furi_hal_message_sent_isr_callback(void* context); - -static void irda_worker_rx_timeout_callback(void* context) { - IrdaWorker* instance = context; - uint32_t flags_set = osEventFlagsSet(instance->events, IRDA_WORKER_RX_TIMEOUT_RECEIVED); - furi_check(flags_set & IRDA_WORKER_RX_TIMEOUT_RECEIVED); -} - -static void irda_worker_rx_callback(void* context, bool level, uint32_t duration) { - IrdaWorker* instance = context; - - BaseType_t xHigherPriorityTaskWoken = pdFALSE; - furi_assert(duration != 0); - LevelDuration level_duration = level_duration_make(level, duration); - - size_t ret = xStreamBufferSendFromISR( - instance->stream, &level_duration, sizeof(LevelDuration), &xHigherPriorityTaskWoken); - uint32_t events = (ret == sizeof(LevelDuration)) ? IRDA_WORKER_RX_RECEIVED : - IRDA_WORKER_OVERRUN; - portYIELD_FROM_ISR(xHigherPriorityTaskWoken); - - uint32_t flags_set = osEventFlagsSet(instance->events, events); - furi_check(flags_set & events); -} - -static void irda_worker_process_timeout(IrdaWorker* instance) { - if(instance->signal.timings_cnt < 2) return; - - const IrdaMessage* message_decoded = irda_check_decoder_ready(instance->irda_decoder); - if(message_decoded) { - instance->signal.message = *message_decoded; - instance->signal.timings_cnt = 0; - instance->signal.decoded = true; - } else { - instance->signal.decoded = false; - } - if(instance->rx.received_signal_callback) - instance->rx.received_signal_callback( - instance->rx.received_signal_context, &instance->signal); -} - -static void irda_worker_process_timings(IrdaWorker* instance, uint32_t duration, bool level) { - const IrdaMessage* message_decoded = irda_decode(instance->irda_decoder, level, duration); - if(message_decoded) { - instance->signal.message = *message_decoded; - instance->signal.timings_cnt = 0; - instance->signal.decoded = true; - if(instance->rx.received_signal_callback) - instance->rx.received_signal_callback( - instance->rx.received_signal_context, &instance->signal); - } else { - /* Skip first timing if it starts from Space */ - if((instance->signal.timings_cnt == 0) && !level) { - return; - } - - if(instance->signal.timings_cnt < MAX_TIMINGS_AMOUNT) { - instance->signal.timings[instance->signal.timings_cnt] = duration; - ++instance->signal.timings_cnt; - } else { - uint32_t flags_set = osEventFlagsSet(instance->events, IRDA_WORKER_OVERRUN); - furi_check(flags_set & IRDA_WORKER_OVERRUN); - instance->rx.overrun = true; - } - } -} - -static int32_t irda_worker_rx_thread(void* thread_context) { - IrdaWorker* instance = thread_context; - uint32_t events = 0; - LevelDuration level_duration; - TickType_t last_blink_time = 0; - - while(1) { - events = osEventFlagsWait(instance->events, IRDA_WORKER_ALL_RX_EVENTS, 0, osWaitForever); - furi_check(events & IRDA_WORKER_ALL_RX_EVENTS); /* at least one caught */ - - if(events & IRDA_WORKER_RX_RECEIVED) { - if(!instance->rx.overrun && instance->blink_enable && - ((xTaskGetTickCount() - last_blink_time) > 80)) { - last_blink_time = xTaskGetTickCount(); - notification_message(instance->notification, &sequence_blink_blue_10); - } - if(instance->signal.timings_cnt == 0) - notification_message(instance->notification, &sequence_display_on); - while(sizeof(LevelDuration) == - xStreamBufferReceive( - instance->stream, &level_duration, sizeof(LevelDuration), 0)) { - if(!instance->rx.overrun) { - bool level = level_duration_get_level(level_duration); - uint32_t duration = level_duration_get_duration(level_duration); - irda_worker_process_timings(instance, duration, level); - } - } - } - if(events & IRDA_WORKER_OVERRUN) { - printf("#"); - irda_reset_decoder(instance->irda_decoder); - instance->signal.timings_cnt = 0; - if(instance->blink_enable) - notification_message(instance->notification, &sequence_set_red_255); - } - if(events & IRDA_WORKER_RX_TIMEOUT_RECEIVED) { - if(instance->rx.overrun) { - printf("\nOVERRUN, max samples: %d\n", MAX_TIMINGS_AMOUNT); - instance->rx.overrun = false; - if(instance->blink_enable) - notification_message(instance->notification, &sequence_reset_red); - } else { - irda_worker_process_timeout(instance); - } - instance->signal.timings_cnt = 0; - } - if(events & IRDA_WORKER_EXIT) break; - } - - return 0; -} - -void irda_worker_rx_set_received_signal_callback( - IrdaWorker* instance, - IrdaWorkerReceivedSignalCallback callback, - void* context) { - furi_assert(instance); - instance->rx.received_signal_callback = callback; - instance->rx.received_signal_context = context; -} - -IrdaWorker* irda_worker_alloc() { - IrdaWorker* instance = malloc(sizeof(IrdaWorker)); - - instance->thread = furi_thread_alloc(); - furi_thread_set_name(instance->thread, "IrdaWorker"); - furi_thread_set_stack_size(instance->thread, 2048); - furi_thread_set_context(instance->thread, instance); - - size_t buffer_size = - MAX(sizeof(IrdaWorkerTiming) * (MAX_TIMINGS_AMOUNT + 1), - sizeof(LevelDuration) * MAX_TIMINGS_AMOUNT); - instance->stream = xStreamBufferCreate(buffer_size, sizeof(IrdaWorkerTiming)); - instance->irda_decoder = irda_alloc_decoder(); - instance->irda_encoder = irda_alloc_encoder(); - instance->blink_enable = false; - instance->notification = furi_record_open("notification"); - instance->state = IrdaWorkerStateIdle; - instance->events = osEventFlagsNew(NULL); - - return instance; -} - -void irda_worker_free(IrdaWorker* instance) { - furi_assert(instance); - furi_assert(instance->state == IrdaWorkerStateIdle); - - furi_record_close("notification"); - irda_free_decoder(instance->irda_decoder); - irda_free_encoder(instance->irda_encoder); - vStreamBufferDelete(instance->stream); - furi_thread_free(instance->thread); - osEventFlagsDelete(instance->events); - - free(instance); -} - -void irda_worker_rx_start(IrdaWorker* instance) { - furi_assert(instance); - furi_assert(instance->state == IrdaWorkerStateIdle); - - xStreamBufferSetTriggerLevel(instance->stream, sizeof(LevelDuration)); - - osEventFlagsClear(instance->events, IRDA_WORKER_ALL_EVENTS); - furi_thread_set_callback(instance->thread, irda_worker_rx_thread); - furi_thread_start(instance->thread); - - furi_hal_irda_async_rx_set_capture_isr_callback(irda_worker_rx_callback, instance); - furi_hal_irda_async_rx_set_timeout_isr_callback(irda_worker_rx_timeout_callback, instance); - furi_hal_irda_async_rx_start(); - furi_hal_irda_async_rx_set_timeout(IRDA_WORKER_RX_TIMEOUT); - - instance->rx.overrun = false; - instance->state = IrdaWorkerStateRunRx; -} - -void irda_worker_rx_stop(IrdaWorker* instance) { - furi_assert(instance); - furi_assert(instance->state == IrdaWorkerStateRunRx); - - furi_hal_irda_async_rx_set_timeout_isr_callback(NULL, NULL); - furi_hal_irda_async_rx_set_capture_isr_callback(NULL, NULL); - furi_hal_irda_async_rx_stop(); - - osEventFlagsSet(instance->events, IRDA_WORKER_EXIT); - furi_thread_join(instance->thread); - - BaseType_t xReturn = xStreamBufferReset(instance->stream); - furi_assert(xReturn == pdPASS); - (void)xReturn; - - instance->state = IrdaWorkerStateIdle; -} - -bool irda_worker_signal_is_decoded(const IrdaWorkerSignal* signal) { - furi_assert(signal); - return signal->decoded; -} - -void irda_worker_get_raw_signal( - const IrdaWorkerSignal* signal, - const uint32_t** timings, - size_t* timings_cnt) { - furi_assert(signal); - furi_assert(timings); - furi_assert(timings_cnt); - - *timings = signal->timings; - *timings_cnt = signal->timings_cnt; -} - -const IrdaMessage* irda_worker_get_decoded_signal(const IrdaWorkerSignal* signal) { - furi_assert(signal); - return &signal->message; -} - -void irda_worker_rx_enable_blink_on_receiving(IrdaWorker* instance, bool enable) { - furi_assert(instance); - instance->blink_enable = enable; -} - -void irda_worker_tx_start(IrdaWorker* instance) { - furi_assert(instance); - furi_assert(instance->state == IrdaWorkerStateIdle); - furi_assert(instance->tx.get_signal_callback); - - // size have to be greater than api hal irda async tx buffer size - xStreamBufferSetTriggerLevel(instance->stream, sizeof(IrdaWorkerTiming)); - - osEventFlagsClear(instance->events, IRDA_WORKER_ALL_EVENTS); - furi_thread_set_callback(instance->thread, irda_worker_tx_thread); - - instance->tx.steady_signal_sent = false; - instance->tx.need_reinitialization = false; - furi_hal_irda_async_tx_set_data_isr_callback(irda_worker_furi_hal_data_isr_callback, instance); - furi_hal_irda_async_tx_set_signal_sent_isr_callback( - irda_worker_furi_hal_message_sent_isr_callback, instance); - - instance->state = IrdaWorkerStateStartTx; - furi_thread_start(instance->thread); -} - -static void irda_worker_furi_hal_message_sent_isr_callback(void* context) { - IrdaWorker* instance = context; - uint32_t flags_set = osEventFlagsSet(instance->events, IRDA_WORKER_TX_MESSAGE_SENT); - furi_check(flags_set & IRDA_WORKER_TX_MESSAGE_SENT); -} - -static FuriHalIrdaTxGetDataState - irda_worker_furi_hal_data_isr_callback(void* context, uint32_t* duration, bool* level) { - furi_assert(context); - furi_assert(duration); - furi_assert(level); - - IrdaWorker* instance = context; - IrdaWorkerTiming timing; - FuriHalIrdaTxGetDataState state; - - if(sizeof(IrdaWorkerTiming) == - xStreamBufferReceiveFromISR(instance->stream, &timing, sizeof(IrdaWorkerTiming), 0)) { - *level = timing.level; - *duration = timing.duration; - state = timing.state; - } else { - furi_assert(0); - *level = 0; - *duration = 100; - state = FuriHalIrdaTxGetDataStateDone; - } - - uint32_t flags_set = osEventFlagsSet(instance->events, IRDA_WORKER_TX_FILL_BUFFER); - furi_check(flags_set & IRDA_WORKER_TX_FILL_BUFFER); - - return state; -} - -static bool irda_get_new_signal(IrdaWorker* instance) { - bool new_signal_obtained = false; - - IrdaWorkerGetSignalResponse response = - instance->tx.get_signal_callback(instance->tx.get_signal_context, instance); - if(response == IrdaWorkerGetSignalResponseNew) { - uint32_t new_tx_frequency = 0; - float new_tx_duty_cycle = 0; - if(instance->signal.decoded) { - new_tx_frequency = irda_get_protocol_frequency(instance->signal.message.protocol); - new_tx_duty_cycle = irda_get_protocol_duty_cycle(instance->signal.message.protocol); - } else { - furi_assert(instance->signal.timings_cnt > 1); - new_tx_frequency = IRDA_COMMON_CARRIER_FREQUENCY; - new_tx_duty_cycle = IRDA_COMMON_DUTY_CYCLE; - } - - instance->tx.tx_raw_cnt = 0; - instance->tx.need_reinitialization = (new_tx_frequency != instance->tx.frequency) || - (new_tx_duty_cycle != instance->tx.duty_cycle); - instance->tx.frequency = new_tx_frequency; - instance->tx.duty_cycle = new_tx_duty_cycle; - if(instance->signal.decoded) { - irda_reset_encoder(instance->irda_encoder, &instance->signal.message); - } - new_signal_obtained = true; - } else if(response == IrdaWorkerGetSignalResponseSame) { - new_signal_obtained = true; - /* no need to reinit */ - } else if(response == IrdaWorkerGetSignalResponseStop) { - new_signal_obtained = false; - } else { - furi_assert(0); - } - - return new_signal_obtained; -} - -static bool irda_worker_tx_fill_buffer(IrdaWorker* instance) { - bool new_data_available = true; - IrdaWorkerTiming timing; - IrdaStatus status = IrdaStatusError; - - while(!xStreamBufferIsFull(instance->stream) && !instance->tx.need_reinitialization && - new_data_available) { - if(instance->signal.decoded) { - status = irda_encode(instance->irda_encoder, &timing.duration, &timing.level); - } else { - timing.duration = instance->signal.timings[instance->tx.tx_raw_cnt]; - /* raw always starts from Mark, but we fill it with space delay at start */ - timing.level = (instance->tx.tx_raw_cnt % 2); - ++instance->tx.tx_raw_cnt; - if(instance->tx.tx_raw_cnt >= instance->signal.timings_cnt) { - instance->tx.tx_raw_cnt = 0; - status = IrdaStatusDone; - } else { - status = IrdaStatusOk; - } - } - - if(status == IrdaStatusError) { - furi_assert(0); - new_data_available = false; - break; - } else if(status == IrdaStatusOk) { - timing.state = FuriHalIrdaTxGetDataStateOk; - } else if(status == IrdaStatusDone) { - timing.state = FuriHalIrdaTxGetDataStateDone; - - new_data_available = irda_get_new_signal(instance); - if(instance->tx.need_reinitialization || !new_data_available) { - timing.state = FuriHalIrdaTxGetDataStateLastDone; - } - } else { - furi_assert(0); - } - uint32_t written_size = - xStreamBufferSend(instance->stream, &timing, sizeof(IrdaWorkerTiming), 0); - furi_assert(sizeof(IrdaWorkerTiming) == written_size); - (void)written_size; - } - - return new_data_available; -} - -static int32_t irda_worker_tx_thread(void* thread_context) { - IrdaWorker* instance = thread_context; - furi_assert(instance->state == IrdaWorkerStateStartTx); - furi_assert(thread_context); - - uint32_t events = 0; - bool new_data_available = true; - bool exit = false; - - exit = !irda_get_new_signal(instance); - furi_assert(!exit); - - while(!exit) { - switch(instance->state) { - case IrdaWorkerStateStartTx: - instance->tx.need_reinitialization = false; - new_data_available = irda_worker_tx_fill_buffer(instance); - furi_hal_irda_async_tx_start(instance->tx.frequency, instance->tx.duty_cycle); - - if(!new_data_available) { - instance->state = IrdaWorkerStateStopTx; - } else if(instance->tx.need_reinitialization) { - instance->state = IrdaWorkerStateWaitTxEnd; - } else { - instance->state = IrdaWorkerStateRunTx; - } - - break; - case IrdaWorkerStateStopTx: - furi_hal_irda_async_tx_stop(); - exit = true; - break; - case IrdaWorkerStateWaitTxEnd: - furi_hal_irda_async_tx_wait_termination(); - instance->state = IrdaWorkerStateStartTx; - - events = osEventFlagsGet(instance->events); - if(events & IRDA_WORKER_EXIT) { - exit = true; - break; - } - - break; - case IrdaWorkerStateRunTx: - events = - osEventFlagsWait(instance->events, IRDA_WORKER_ALL_TX_EVENTS, 0, osWaitForever); - furi_check(events & IRDA_WORKER_ALL_TX_EVENTS); /* at least one caught */ - - if(events & IRDA_WORKER_EXIT) { - instance->state = IrdaWorkerStateStopTx; - break; - } - - if(events & IRDA_WORKER_TX_FILL_BUFFER) { - irda_worker_tx_fill_buffer(instance); - - if(instance->tx.need_reinitialization) { - instance->state = IrdaWorkerStateWaitTxEnd; - } - } - - if(events & IRDA_WORKER_TX_MESSAGE_SENT) { - if(instance->tx.message_sent_callback) - instance->tx.message_sent_callback(instance->tx.message_sent_context); - } - break; - default: - furi_assert(0); - break; - } - } - - return 0; -} - -void irda_worker_tx_set_get_signal_callback( - IrdaWorker* instance, - IrdaWorkerGetSignalCallback callback, - void* context) { - furi_assert(instance); - instance->tx.get_signal_callback = callback; - instance->tx.get_signal_context = context; -} - -void irda_worker_tx_set_signal_sent_callback( - IrdaWorker* instance, - IrdaWorkerMessageSentCallback callback, - void* context) { - furi_assert(instance); - instance->tx.message_sent_callback = callback; - instance->tx.message_sent_context = context; -} - -void irda_worker_tx_stop(IrdaWorker* instance) { - furi_assert(instance); - furi_assert(instance->state != IrdaWorkerStateRunRx); - - osEventFlagsSet(instance->events, IRDA_WORKER_EXIT); - furi_thread_join(instance->thread); - furi_hal_irda_async_tx_set_data_isr_callback(NULL, NULL); - furi_hal_irda_async_tx_set_signal_sent_isr_callback(NULL, NULL); - - instance->signal.timings_cnt = 0; - BaseType_t xReturn = pdFAIL; - xReturn = xStreamBufferReset(instance->stream); - furi_assert(xReturn == pdPASS); - (void)xReturn; - instance->state = IrdaWorkerStateIdle; -} - -void irda_worker_set_decoded_signal(IrdaWorker* instance, const IrdaMessage* message) { - furi_assert(instance); - furi_assert(message); - - instance->signal.decoded = true; - instance->signal.message = *message; -} - -void irda_worker_set_raw_signal(IrdaWorker* instance, const uint32_t* timings, size_t timings_cnt) { - furi_assert(instance); - furi_assert(timings); - furi_assert(timings_cnt > 0); - size_t max_copy_num = COUNT_OF(instance->signal.timings) - 1; - furi_check(timings_cnt <= max_copy_num); - - instance->signal.timings[0] = IRDA_RAW_TX_TIMING_DELAY_US; - memcpy(&instance->signal.timings[1], timings, timings_cnt * sizeof(uint32_t)); - instance->signal.decoded = false; - instance->signal.timings_cnt = timings_cnt + 1; -} - -IrdaWorkerGetSignalResponse - irda_worker_tx_get_signal_steady_callback(void* context, IrdaWorker* instance) { - IrdaWorkerGetSignalResponse response = instance->tx.steady_signal_sent ? - IrdaWorkerGetSignalResponseSame : - IrdaWorkerGetSignalResponseNew; - instance->tx.steady_signal_sent = true; - return response; -} diff --git a/lib/irda/worker/irda_worker.h b/lib/irda/worker/irda_worker.h deleted file mode 100644 index bd204040..00000000 --- a/lib/irda/worker/irda_worker.h +++ /dev/null @@ -1,171 +0,0 @@ -#pragma once - -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -#define MAX_TIMINGS_AMOUNT 512 - -/** Interface struct of irda worker */ -typedef struct IrdaWorker IrdaWorker; -/** Interface struct of received signal */ -typedef struct IrdaWorkerSignal IrdaWorkerSignal; - -typedef enum { - IrdaWorkerGetSignalResponseNew, /** Signal, provided by callback is new and encoder should be reseted */ - IrdaWorkerGetSignalResponseSame, /** Signal, provided by callback is same. No encoder resetting. */ - IrdaWorkerGetSignalResponseStop, /** No more signals available. */ -} IrdaWorkerGetSignalResponse; - -/** Callback type for providing next signal to send. Should be used with - * irda_worker_make_decoded_signal() or irda_worker_make_raw_signal() - */ -typedef IrdaWorkerGetSignalResponse ( - *IrdaWorkerGetSignalCallback)(void* context, IrdaWorker* instance); - -/** Callback type for 'message is sent' event */ -typedef void (*IrdaWorkerMessageSentCallback)(void* context); - -/** Callback type to call by IrdaWorker thread when new signal is received */ -typedef void (*IrdaWorkerReceivedSignalCallback)(void* context, IrdaWorkerSignal* received_signal); - -/** Allocate IrdaWorker - * - * @return just created instance of IrdaWorker - */ -IrdaWorker* irda_worker_alloc(); - -/** Free IrdaWorker - * - * @param[in] instance - IrdaWorker instance - */ -void irda_worker_free(IrdaWorker* instance); - -/** Start IrdaWorker thread, initialise furi_hal, prepare all work. - * - * @param[in] instance - IrdaWorker instance - */ -void irda_worker_rx_start(IrdaWorker* instance); - -/** Stop IrdaWorker thread, deinitialize furi_hal. - * - * @param[in] instance - IrdaWorker instance - */ -void irda_worker_rx_stop(IrdaWorker* instance); - -/** Set received data callback IrdaWorker - * - * @param[in] instance - IrdaWorker instance - * @param[in] context - context to pass to callbacks - * @param[in] callback - IrdaWorkerReceivedSignalCallback callback - */ -void irda_worker_rx_set_received_signal_callback( - IrdaWorker* instance, - IrdaWorkerReceivedSignalCallback callback, - void* context); - -/** Enable blinking on receiving any signal on IR port. - * - * @param[in] instance - instance of IrdaWorker - * @param[in] enable - true if you want to enable blinking - * false otherwise - */ -void irda_worker_rx_enable_blink_on_receiving(IrdaWorker* instance, bool enable); - -/** Clarify is received signal either decoded or raw - * - * @param[in] signal - received signal - * @return true if signal is decoded, false if signal is raw - */ -bool irda_worker_signal_is_decoded(const IrdaWorkerSignal* signal); - -/** Start transmitting signal. Callback IrdaWorkerGetSignalCallback should be - * set before this function is called, as it calls for it to fill buffer before - * starting transmission. - * - * @param[in] instance - IrdaWorker instance - */ -void irda_worker_tx_start(IrdaWorker* instance); - -/** Stop transmitting signal. Waits for end of current signal and stops transmission. - * - * @param[in] instance - IrdaWorker instance - */ -void irda_worker_tx_stop(IrdaWorker* instance); - -/** Set callback for providing next signal to send - * - * @param[in] instance - IrdaWorker instance - * @param[in] context - context to pass to callbacks - * @param[in] callback - IrdaWorkerGetSignalCallback callback - */ -void irda_worker_tx_set_get_signal_callback( - IrdaWorker* instance, - IrdaWorkerGetSignalCallback callback, - void* context); - -/** Set callback for end of signal transmitting - * - * @param[in] instance - IrdaWorker instance - * @param[in] context - context to pass to callbacks - * @param[in] callback - IrdaWorkerMessageSentCallback callback - */ -void irda_worker_tx_set_signal_sent_callback( - IrdaWorker* instance, - IrdaWorkerMessageSentCallback callback, - void* context); - -/** Callback to pass to irda_worker_tx_set_get_signal_callback() if signal - * is steady and will not be changed between irda_worker start and stop. - * Before starting transmission, desired steady signal must be set with - * irda_worker_make_decoded_signal() or irda_worker_make_raw_signal(). - * - * This function should not be implicitly called. - * - * @param[in] context - context - * @param[out] instance - IrdaWorker instance - */ -IrdaWorkerGetSignalResponse - irda_worker_tx_get_signal_steady_callback(void* context, IrdaWorker* instance); - -/** Acquire raw signal from interface struct 'IrdaWorkerSignal'. - * First, you have to ensure that signal is raw. - * - * @param[in] signal - received signal - * @param[out] timings - pointer to array of timings - * @param[out] timings_cnt - pointer to amount of timings - */ -void irda_worker_get_raw_signal( - const IrdaWorkerSignal* signal, - const uint32_t** timings, - size_t* timings_cnt); - -/** Acquire decoded message from interface struct 'IrdaWorkerSignal'. - * First, you have to ensure that signal is decoded. - * - * @param[in] signal - received signal - * @return decoded IRDA message - */ -const IrdaMessage* irda_worker_get_decoded_signal(const IrdaWorkerSignal* signal); - -/** Set current decoded signal for IrdaWorker instance - * - * @param[out] instance - IrdaWorker instance - * @param[in] message - decoded signal - */ -void irda_worker_set_decoded_signal(IrdaWorker* instance, const IrdaMessage* message); - -/** Set current raw signal for IrdaWorker instance - * - * @param[out] instance - IrdaWorker instance - * @param[in] timings - array of raw timings - * @param[in] timings_cnt - size of array of raw timings - */ -void irda_worker_set_raw_signal(IrdaWorker* instance, const uint32_t* timings, size_t timings_cnt); - -#ifdef __cplusplus -} -#endif diff --git a/lib/lib.mk b/lib/lib.mk index 09f929f1..5216b0ad 100644 --- a/lib/lib.mk +++ b/lib/lib.mk @@ -83,11 +83,11 @@ CFLAGS += -I$(LIB_DIR)/drivers C_SOURCES += $(wildcard $(LIB_DIR)/drivers/*.c) # IR lib -CFLAGS += -I$(LIB_DIR)/irda/encoder_decoder -CFLAGS += -I$(LIB_DIR)/irda/worker -C_SOURCES += $(wildcard $(LIB_DIR)/irda/encoder_decoder/*.c) -C_SOURCES += $(wildcard $(LIB_DIR)/irda/encoder_decoder/*/*.c) -C_SOURCES += $(wildcard $(LIB_DIR)/irda/worker/*.c) +CFLAGS += -I$(LIB_DIR)/infrared/encoder_decoder +CFLAGS += -I$(LIB_DIR)/infrared/worker +C_SOURCES += $(wildcard $(LIB_DIR)/infrared/encoder_decoder/*.c) +C_SOURCES += $(wildcard $(LIB_DIR)/infrared/encoder_decoder/*/*.c) +C_SOURCES += $(wildcard $(LIB_DIR)/infrared/worker/*.c) # SubGhz C_SOURCES += $(wildcard $(LIB_DIR)/subghz/*.c)