Skip to content

Commit

Permalink
Finished alternative names, fixed case-insensitivity
Browse files Browse the repository at this point in the history
  • Loading branch information
kala13x committed Mar 17, 2024
1 parent 8b2c1c6 commit bdc7afe
Show file tree
Hide file tree
Showing 12 changed files with 78 additions and 21 deletions.
Binary file modified .flipcorg/gallery/screen7.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 13 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
<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">
<img src="https://github.com/kala13x/flipper-xremote/blob/main/.flipcorg/banner.png" alt="XRemote">
</p>
Expand Down Expand Up @@ -58,16 +63,17 @@ Button name | Description
`Play` | Play
`Stop` | Stop


## 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
```

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
Expand Down Expand Up @@ -113,8 +119,10 @@ Play_pa: playpause,play,pause
- Use deploy script from this repository to build and run the application on the device:

```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.
## Progress
Expand Down
34 changes: 31 additions & 3 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,37 @@ Stop | Stop

## 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

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
3 changes: 2 additions & 1 deletion docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
Alternative names

- Implemented alternative names functionality
- Implemented case-insensitive button search
- Added Eject button support
- Fixed bugs
- Fixed bugs and refactored code

## v1.2

Expand Down
8 changes: 4 additions & 4 deletions infrared/infrared_remote.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
for(size_t i = 0; i < InfraredButtonArray_size(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;
return true;
}
Expand All @@ -105,8 +105,8 @@ InfraredRemoteButton*
infrared_remote_get_button_by_name(InfraredRemote* remote, const char* name) {
for(size_t i = 0; i < InfraredButtonArray_size(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;
}
Expand Down
Binary file modified screens/settings_menu.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 21 additions & 4 deletions views/xremote_common_view.c
Original file line number Diff line number Diff line change
Expand Up @@ -133,15 +133,17 @@ View* xremote_view_get_view(XRemoteView* rview) {
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);
FlipperFormat* ff = flipper_format_buffered_file_alloc(storage);
FuriString* header = furi_string_alloc();

FURI_LOG_I(XREMOTE_APP_TAG, "loading alt_names file: \'%s\'", XREMOTE_ALT_NAMES);

InfraredRemoteButton* button = NULL;
char key[XREMOTE_NAME_MAX] = {0};
bool key_found = false;
uint32_t version = 0;

do {
Expand All @@ -151,7 +153,20 @@ InfraredRemoteButton*
if(!furi_string_equal(header, "XRemote Alt-Names") || (version != 1)) break;

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 posit = furi_string_search_str(value, ",", start);
Expand Down Expand Up @@ -190,6 +205,8 @@ InfraredRemoteButton*
furi_string_free(header);
flipper_format_free(ff);

if(!key_found && try_low) return infrared_remote_get_button_by_alt_name(remote, key, false);

return button;
}

Expand All @@ -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);

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;
}
Expand Down
2 changes: 1 addition & 1 deletion views/xremote_common_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#include "../infrared/infrared_remote.h"

#define XREMOTE_BUTTON_COUNT 27
#define XREMOTE_NAME_MAX 16
#define XREMOTE_NAME_MAX 32

#define XREMOTE_COMMAND_POWER "Power"
#define XREMOTE_COMMAND_EJECT "Eject"
Expand Down
1 change: 0 additions & 1 deletion xremote.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ int32_t xremote_main(void* p) {
/* Allocate context and main application */
XRemoteAppContext* context = xremote_app_context_alloc(p);
XRemoteApp* app = xremote_app_alloc(context);
xremote_app_alt_names_check_and_store();

/* Allocate and build the menu */
xremote_app_submenu_alloc(app, XRemoteViewSubmenu, xremote_exit_callback);
Expand Down
5 changes: 4 additions & 1 deletion xremote_app.c
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ bool xremote_app_extension_store(XRemoteAppButtons* buttons, FuriString* path) {
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);
FlipperFormat* ff = flipper_format_file_alloc(storage);
bool success = false;
Expand Down Expand Up @@ -353,6 +353,9 @@ XRemoteAppContext* xremote_app_context_alloc(void* arg) {
ctx->app_settings = xremote_app_settings_alloc();
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 */
ctx->view_dispatcher = view_dispatcher_alloc();
view_dispatcher_enable_queue(ctx->view_dispatcher);
Expand Down
2 changes: 1 addition & 1 deletion xremote_app.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_load(XRemoteAppButtons* buttons, FuriString* path);
bool xremote_app_alt_names_check_and_store();
bool xremote_app_alt_names_check_and_init();

//////////////////////////////////////////////////////////////////////////////
// XRemote application factory
Expand Down
1 change: 1 addition & 0 deletions xremote_settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ static void infrared_settings_alt_names_changed(VariableItem* 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);

if(settings->alt_names) xremote_app_alt_names_check_and_init();
variable_item_set_current_value_text(item, alt_names_str);
xremote_app_settings_store(settings);
}
Expand Down

0 comments on commit bdc7afe

Please sign in to comment.