Просмотр исходного кода

Finished alternative names, fixed case-insensitivity

Sandro Kalatozishvili 1 год назад
Родитель
Сommit
bdc7afe667

BIN
.flipcorg/gallery/screen7.png


+ 13 - 5
README.md

@@ -1,4 +1,9 @@
 <p align="center">Advanced IR Remote App for Flipper Device</p>
 <p align="center">Advanced IR Remote App for Flipper Device</p>
+
+<p align="center">
+  Version 1.3 - <a href="https://github.com/kala13x/flipper-xremote/blob/main/docs/changelog.md">Changelog</a>
+</p>
+
 <p align="center">
 <p align="center">
     <img src="https://github.com/kala13x/flipper-xremote/blob/main/.flipcorg/banner.png" alt="XRemote">
     <img src="https://github.com/kala13x/flipper-xremote/blob/main/.flipcorg/banner.png" alt="XRemote">
 </p>
 </p>
@@ -58,16 +63,17 @@ Button name | Description
 `Play`      | Play
 `Play`      | Play
 `Stop`      | Stop
 `Stop`      | Stop
 
 
-
 ## Alternative button names
 ## Alternative button names
-In addition to the predefined names, `XRemote` uses alternative button names to make it as easy as possible to interact with different types of IR dumps. This means that if a button is not found in the file with the appropriate name, the application will try to find the same button with alternative names. Ensure this feature is enabled in the application settings before you use it.
+In addition to the predefined names, `XRemote` uses alternative button names to make it as easy as possible to interact with different types of IR dumps. That means if a button with the appropriate name is not found in the file, the application will try to find the same button with alternative names. Ensure this feature is enabled in the application settings before you use it.
 
 
-Alternate names are case insensitive and defined in the file:
+The application stores and reads alternate names from the following file:
 ```
 ```
 SD Card/apps_data/flipper_xremote/alt_names.cfg
 SD Card/apps_data/flipper_xremote/alt_names.cfg
 ```
 ```
 
 
-If this file does not exist, it will be created automatically with default values when the application is launched. You are free to remove, edit or add any values you want to this file. Here is the alt_names.cfg file with default contents:
+If the `Alt-Names` option is enabled in the config and the file does not exist, it will be created automatically with default values during the application's startup. You can edit, add, or remove any button or alternate name values from this file. Button names must either have only the first uppercase or be entirely lowercase. As for alternate names, they are case-insensitive. The button can have one or several comma-separated alternate names.
+
+This is the default `alt_names.cfg` file:
 
 
 ```
 ```
 Filetype: XRemote Alt-Names
 Filetype: XRemote Alt-Names
@@ -113,8 +119,10 @@ Play_pa: playpause,play,pause
    - Use deploy script from this repository to build and run the application on the device:
    - Use deploy script from this repository to build and run the application on the device:
 
 
     ```bash
     ```bash
-    ./deploy.sh -b --fw=/path/to/the/firmware
+    ./deploy.sh --fw=/path/to/the/firmware -b -l
     ```
     ```
+
+    Do not use `-l` (link) option of you are building the project directly from the `applications_user` directory of the firmware.
 2. If you don't have the firmware or the Linux please refer to the [official documentation](https://github.com/flipperdevices/flipperzero-firmware/blob/dev/documentation/AppsOnSDCard.md) for build instructions.
 2. If you don't have the firmware or the Linux please refer to the [official documentation](https://github.com/flipperdevices/flipperzero-firmware/blob/dev/documentation/AppsOnSDCard.md) for build instructions.
 
 
 ## Progress
 ## Progress

+ 31 - 3
docs/README.md

@@ -51,9 +51,37 @@ Stop        | Stop
 
 
 ## Alternative button names
 ## Alternative button names
 
 
-In addition to the predefined names, XRemote uses alternative button names to make it as easy as possible to interact with different types of IR dumps. This means that if a button is not found in the file with the appropriate name, the application will try to find the same button with alternative names. Ensure this feature is enabled in the application settings before you use it.
+In addition to the predefined names, XRemote uses alternative button names to make it as easy as possible to interact with different types of IR dumps. That means if a button with the appropriate name is not found in the file, the application will try to find the same button with alternative names. Ensure this feature is enabled in the application settings before you use it.
 
 
-Alternate names are case insensitive and defined in the file:
+The application stores and reads alternate names from the following file:
 SD_Card/apps_data/flipper_xremote/alt_names.cfg
 SD_Card/apps_data/flipper_xremote/alt_names.cfg
 
 
-If this file does not exist, it will be created automatically with default values when the application is launched. You are free to remove, edit or add any values you want to this file.
+If the Alt-Names option is enabled in the config and the file does not exist, it will be created automatically with default values during the application's startup. You can edit, add, or remove any button or alternate name values from this file. Button names must either have only the first uppercase or be entirely lowercase. As for alternate names, they are case-insensitive. The button can have one or several comma-separated alternate names.
+
+## Default alternative names
+
+Button name | Alternative names
+------------|-------------------
+Power       | shutdown,off,on,standby
+Setup       | settings,config,cfg
+Input       | source,select
+Menu        | osd,gui
+List        | guide
+Info        | display
+Mode        | aspect,format
+Back        | return,exit
+Ok          | enter,select
+Up          | uparrow
+Down        | downarrow
+Left        | leftarrow
+Right       | rightarrow
+Mute        | silence,silent,unmute
+Vol_up      | vol+,volume+,volup,+
+Vol_dn      | vol-,volume-,voldown,-
+Ch_next     | ch+,channel+,chup
+Ch_prev     | ch-,channel-,chdown
+Next        | next,skip,ffwd
+Prev        | prev,back,rewind,rew
+Fast_fo     | fastfwd,fastforward,ff
+Fast_ba     | fastback,fastrewind,fb
+Play_pa     | playpause,play,pause

+ 2 - 1
docs/changelog.md

@@ -3,8 +3,9 @@
 Alternative names
 Alternative names
 
 
 - Implemented alternative names functionality
 - Implemented alternative names functionality
+- Implemented case-insensitive button search
 - Added Eject button support
 - Added Eject button support
-- Fixed bugs
+- Fixed bugs and refactored code
 
 
 ## v1.2
 ## v1.2
 
 

+ 4 - 4
infrared/infrared_remote.c

@@ -91,9 +91,9 @@ InfraredRemoteButton* infrared_remote_get_button(InfraredRemote* remote, size_t
 bool infrared_remote_find_button_by_name(InfraredRemote* remote, const char* name, size_t* index) {
 bool infrared_remote_find_button_by_name(InfraredRemote* remote, const char* name, size_t* index) {
     for(size_t i = 0; i < InfraredButtonArray_size(remote->buttons); i++) {
     for(size_t i = 0; i < InfraredButtonArray_size(remote->buttons); i++) {
         InfraredRemoteButton* button = *InfraredButtonArray_get(remote->buttons, i);
         InfraredRemoteButton* button = *InfraredButtonArray_get(remote->buttons, i);
-        FuriString* firi_name = infrared_remote_button_get_furi_name(button);
+        FuriString* furi_name = infrared_remote_button_get_furi_name(button);
 
 
-        if(button && !furi_string_cmpi_str(firi_name, name)) {
+        if(button && !furi_string_cmpi_str(furi_name, name)) {
             *index = i;
             *index = i;
             return true;
             return true;
         }
         }
@@ -105,8 +105,8 @@ InfraredRemoteButton*
     infrared_remote_get_button_by_name(InfraredRemote* remote, const char* name) {
     infrared_remote_get_button_by_name(InfraredRemote* remote, const char* name) {
     for(size_t i = 0; i < InfraredButtonArray_size(remote->buttons); i++) {
     for(size_t i = 0; i < InfraredButtonArray_size(remote->buttons); i++) {
         InfraredRemoteButton* button = *InfraredButtonArray_get(remote->buttons, i);
         InfraredRemoteButton* button = *InfraredButtonArray_get(remote->buttons, i);
-        FuriString* firi_name = infrared_remote_button_get_furi_name(button);
-        if(button && !furi_string_cmpi_str(firi_name, name)) return button;
+        FuriString* furi_name = infrared_remote_button_get_furi_name(button);
+        if(button && !furi_string_cmpi_str(furi_name, name)) return button;
     }
     }
     return NULL;
     return NULL;
 }
 }

BIN
screens/settings_menu.png


+ 21 - 4
views/xremote_common_view.c

@@ -133,8 +133,8 @@ View* xremote_view_get_view(XRemoteView* rview) {
     return rview->view;
     return rview->view;
 }
 }
 
 
-InfraredRemoteButton*
-    infrared_remote_get_button_by_alt_name(InfraredRemote* remote, const char* name) {
+static InfraredRemoteButton*
+    infrared_remote_get_button_by_alt_name(InfraredRemote* remote, const char* name, bool try_low) {
     Storage* storage = furi_record_open(RECORD_STORAGE);
     Storage* storage = furi_record_open(RECORD_STORAGE);
     FlipperFormat* ff = flipper_format_buffered_file_alloc(storage);
     FlipperFormat* ff = flipper_format_buffered_file_alloc(storage);
     FuriString* header = furi_string_alloc();
     FuriString* header = furi_string_alloc();
@@ -142,6 +142,8 @@ InfraredRemoteButton*
     FURI_LOG_I(XREMOTE_APP_TAG, "loading alt_names file: \'%s\'", XREMOTE_ALT_NAMES);
     FURI_LOG_I(XREMOTE_APP_TAG, "loading alt_names file: \'%s\'", XREMOTE_ALT_NAMES);
 
 
     InfraredRemoteButton* button = NULL;
     InfraredRemoteButton* button = NULL;
+    char key[XREMOTE_NAME_MAX] = {0};
+    bool key_found = false;
     uint32_t version = 0;
     uint32_t version = 0;
 
 
     do {
     do {
@@ -151,7 +153,20 @@ InfraredRemoteButton*
         if(!furi_string_equal(header, "XRemote Alt-Names") || (version != 1)) break;
         if(!furi_string_equal(header, "XRemote Alt-Names") || (version != 1)) break;
 
 
         FuriString* value = furi_string_alloc();
         FuriString* value = furi_string_alloc();
-        if(!flipper_format_read_string(ff, name, value)) break;
+        key_found = flipper_format_read_string(ff, name, value);
+
+        if(!key_found) {
+            if(!try_low) break;
+            size_t i;
+
+            /* Convert name to lowercase and try again */
+            for(i = 0; name[i] != '\0' && i < sizeof(key) - 1; i++) {
+                key[i] = tolower(name[i]);
+            }
+
+            key[i] = '\0';
+            break;
+        }
 
 
         size_t start = 0;
         size_t start = 0;
         size_t posit = furi_string_search_str(value, ",", start);
         size_t posit = furi_string_search_str(value, ",", start);
@@ -190,6 +205,8 @@ InfraredRemoteButton*
     furi_string_free(header);
     furi_string_free(header);
     flipper_format_free(ff);
     flipper_format_free(ff);
 
 
+    if(!key_found && try_low) return infrared_remote_get_button_by_alt_name(remote, key, false);
+
     return button;
     return button;
 }
 }
 
 
@@ -202,7 +219,7 @@ InfraredRemoteButton* xremote_view_get_button_by_name(XRemoteView* rview, const
     InfraredRemoteButton* button = infrared_remote_get_button_by_name(buttons->remote, name);
     InfraredRemoteButton* button = infrared_remote_get_button_by_name(buttons->remote, name);
 
 
     if(button == NULL && settings->alt_names)
     if(button == NULL && settings->alt_names)
-        button = infrared_remote_get_button_by_alt_name(buttons->remote, name);
+        button = infrared_remote_get_button_by_alt_name(buttons->remote, name, true);
 
 
     return button;
     return button;
 }
 }

+ 1 - 1
views/xremote_common_view.h

@@ -21,7 +21,7 @@
 #include "../infrared/infrared_remote.h"
 #include "../infrared/infrared_remote.h"
 
 
 #define XREMOTE_BUTTON_COUNT 27
 #define XREMOTE_BUTTON_COUNT 27
-#define XREMOTE_NAME_MAX 16
+#define XREMOTE_NAME_MAX 32
 
 
 #define XREMOTE_COMMAND_POWER "Power"
 #define XREMOTE_COMMAND_POWER "Power"
 #define XREMOTE_COMMAND_EJECT "Eject"
 #define XREMOTE_COMMAND_EJECT "Eject"

+ 0 - 1
xremote.c

@@ -81,7 +81,6 @@ int32_t xremote_main(void* p) {
     /* Allocate context and main application */
     /* Allocate context and main application */
     XRemoteAppContext* context = xremote_app_context_alloc(p);
     XRemoteAppContext* context = xremote_app_context_alloc(p);
     XRemoteApp* app = xremote_app_alloc(context);
     XRemoteApp* app = xremote_app_alloc(context);
-    xremote_app_alt_names_check_and_store();
 
 
     /* Allocate and build the menu */
     /* Allocate and build the menu */
     xremote_app_submenu_alloc(app, XRemoteViewSubmenu, xremote_exit_callback);
     xremote_app_submenu_alloc(app, XRemoteViewSubmenu, xremote_exit_callback);

+ 4 - 1
xremote_app.c

@@ -148,7 +148,7 @@ bool xremote_app_extension_store(XRemoteAppButtons* buttons, FuriString* path) {
     return success;
     return success;
 }
 }
 
 
-bool xremote_app_alt_names_check_and_store() {
+bool xremote_app_alt_names_check_and_init() {
     Storage* storage = furi_record_open(RECORD_STORAGE);
     Storage* storage = furi_record_open(RECORD_STORAGE);
     FlipperFormat* ff = flipper_format_file_alloc(storage);
     FlipperFormat* ff = flipper_format_file_alloc(storage);
     bool success = false;
     bool success = false;
@@ -353,6 +353,9 @@ XRemoteAppContext* xremote_app_context_alloc(void* arg) {
     ctx->app_settings = xremote_app_settings_alloc();
     ctx->app_settings = xremote_app_settings_alloc();
     xremote_app_settings_load(ctx->app_settings);
     xremote_app_settings_load(ctx->app_settings);
 
 
+    /* Initialize alternative names */
+    if(ctx->app_settings->alt_names) xremote_app_alt_names_check_and_init();
+
     /* Allocate and setup view dispatcher */
     /* Allocate and setup view dispatcher */
     ctx->view_dispatcher = view_dispatcher_alloc();
     ctx->view_dispatcher = view_dispatcher_alloc();
     view_dispatcher_enable_queue(ctx->view_dispatcher);
     view_dispatcher_enable_queue(ctx->view_dispatcher);

+ 1 - 1
xremote_app.h

@@ -121,7 +121,7 @@ XRemoteAppButtons* xremote_app_buttons_load(XRemoteAppContext* app_ctx);
 
 
 bool xremote_app_extension_store(XRemoteAppButtons* buttons, FuriString* path);
 bool xremote_app_extension_store(XRemoteAppButtons* buttons, FuriString* path);
 bool xremote_app_extension_load(XRemoteAppButtons* buttons, FuriString* path);
 bool xremote_app_extension_load(XRemoteAppButtons* buttons, FuriString* path);
-bool xremote_app_alt_names_check_and_store();
+bool xremote_app_alt_names_check_and_init();
 
 
 //////////////////////////////////////////////////////////////////////////////
 //////////////////////////////////////////////////////////////////////////////
 // XRemote application factory
 // XRemote application factory

+ 1 - 0
xremote_settings.c

@@ -73,6 +73,7 @@ static void infrared_settings_alt_names_changed(VariableItem* item) {
     settings->alt_names = variable_item_get_current_value_index(item);
     settings->alt_names = variable_item_get_current_value_index(item);
     const char* alt_names_str = xremote_app_get_alt_names_str(settings->alt_names);
     const char* alt_names_str = xremote_app_get_alt_names_str(settings->alt_names);
 
 
+    if(settings->alt_names) xremote_app_alt_names_check_and_init();
     variable_item_set_current_value_text(item, alt_names_str);
     variable_item_set_current_value_text(item, alt_names_str);
     xremote_app_settings_store(settings);
     xremote_app_settings_store(settings);
 }
 }