Skip to content

Commit bdc7afe

Browse files
committed
Finished alternative names, fixed case-insensitivity
1 parent 8b2c1c6 commit bdc7afe

File tree

12 files changed

+78
-21
lines changed

12 files changed

+78
-21
lines changed

.flipcorg/gallery/screen7.png

226 Bytes
Loading

README.md

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
<p align="center">Advanced IR Remote App for Flipper Device</p>
2+
3+
<p align="center">
4+
Version 1.3 - <a href="https://github.com/kala13x/flipper-xremote/blob/main/docs/changelog.md">Changelog</a>
5+
</p>
6+
27
<p align="center">
38
<img src="https://github.com/kala13x/flipper-xremote/blob/main/.flipcorg/banner.png" alt="XRemote">
49
</p>
@@ -58,16 +63,17 @@ Button name | Description
5863
`Play` | Play
5964
`Stop` | Stop
6065

61-
6266
## Alternative button names
63-
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.
67+
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.
6468

65-
Alternate names are case insensitive and defined in the file:
69+
The application stores and reads alternate names from the following file:
6670
```
6771
SD Card/apps_data/flipper_xremote/alt_names.cfg
6872
```
6973

70-
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:
74+
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.
75+
76+
This is the default `alt_names.cfg` file:
7177

7278
```
7379
Filetype: XRemote Alt-Names
@@ -113,8 +119,10 @@ Play_pa: playpause,play,pause
113119
- Use deploy script from this repository to build and run the application on the device:
114120

115121
```bash
116-
./deploy.sh -b --fw=/path/to/the/firmware
122+
./deploy.sh --fw=/path/to/the/firmware -b -l
117123
```
124+
125+
Do not use `-l` (link) option of you are building the project directly from the `applications_user` directory of the firmware.
118126
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.
119127
120128
## Progress

docs/README.md

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,37 @@ Stop | Stop
5151

5252
## Alternative button names
5353

54-
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.
54+
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.
5555

56-
Alternate names are case insensitive and defined in the file:
56+
The application stores and reads alternate names from the following file:
5757
SD_Card/apps_data/flipper_xremote/alt_names.cfg
5858

59-
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.
59+
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.
60+
61+
## Default alternative names
62+
63+
Button name | Alternative names
64+
------------|-------------------
65+
Power | shutdown,off,on,standby
66+
Setup | settings,config,cfg
67+
Input | source,select
68+
Menu | osd,gui
69+
List | guide
70+
Info | display
71+
Mode | aspect,format
72+
Back | return,exit
73+
Ok | enter,select
74+
Up | uparrow
75+
Down | downarrow
76+
Left | leftarrow
77+
Right | rightarrow
78+
Mute | silence,silent,unmute
79+
Vol_up | vol+,volume+,volup,+
80+
Vol_dn | vol-,volume-,voldown,-
81+
Ch_next | ch+,channel+,chup
82+
Ch_prev | ch-,channel-,chdown
83+
Next | next,skip,ffwd
84+
Prev | prev,back,rewind,rew
85+
Fast_fo | fastfwd,fastforward,ff
86+
Fast_ba | fastback,fastrewind,fb
87+
Play_pa | playpause,play,pause

docs/changelog.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
Alternative names
44

55
- Implemented alternative names functionality
6+
- Implemented case-insensitive button search
67
- Added Eject button support
7-
- Fixed bugs
8+
- Fixed bugs and refactored code
89

910
## v1.2
1011

infrared/infrared_remote.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,9 @@ InfraredRemoteButton* infrared_remote_get_button(InfraredRemote* remote, size_t
9191
bool infrared_remote_find_button_by_name(InfraredRemote* remote, const char* name, size_t* index) {
9292
for(size_t i = 0; i < InfraredButtonArray_size(remote->buttons); i++) {
9393
InfraredRemoteButton* button = *InfraredButtonArray_get(remote->buttons, i);
94-
FuriString* firi_name = infrared_remote_button_get_furi_name(button);
94+
FuriString* furi_name = infrared_remote_button_get_furi_name(button);
9595

96-
if(button && !furi_string_cmpi_str(firi_name, name)) {
96+
if(button && !furi_string_cmpi_str(furi_name, name)) {
9797
*index = i;
9898
return true;
9999
}
@@ -105,8 +105,8 @@ InfraredRemoteButton*
105105
infrared_remote_get_button_by_name(InfraredRemote* remote, const char* name) {
106106
for(size_t i = 0; i < InfraredButtonArray_size(remote->buttons); i++) {
107107
InfraredRemoteButton* button = *InfraredButtonArray_get(remote->buttons, i);
108-
FuriString* firi_name = infrared_remote_button_get_furi_name(button);
109-
if(button && !furi_string_cmpi_str(firi_name, name)) return button;
108+
FuriString* furi_name = infrared_remote_button_get_furi_name(button);
109+
if(button && !furi_string_cmpi_str(furi_name, name)) return button;
110110
}
111111
return NULL;
112112
}

screens/settings_menu.png

230 Bytes
Loading

views/xremote_common_view.c

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,15 +133,17 @@ View* xremote_view_get_view(XRemoteView* rview) {
133133
return rview->view;
134134
}
135135

136-
InfraredRemoteButton*
137-
infrared_remote_get_button_by_alt_name(InfraredRemote* remote, const char* name) {
136+
static InfraredRemoteButton*
137+
infrared_remote_get_button_by_alt_name(InfraredRemote* remote, const char* name, bool try_low) {
138138
Storage* storage = furi_record_open(RECORD_STORAGE);
139139
FlipperFormat* ff = flipper_format_buffered_file_alloc(storage);
140140
FuriString* header = furi_string_alloc();
141141

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

144144
InfraredRemoteButton* button = NULL;
145+
char key[XREMOTE_NAME_MAX] = {0};
146+
bool key_found = false;
145147
uint32_t version = 0;
146148

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

153155
FuriString* value = furi_string_alloc();
154-
if(!flipper_format_read_string(ff, name, value)) break;
156+
key_found = flipper_format_read_string(ff, name, value);
157+
158+
if(!key_found) {
159+
if(!try_low) break;
160+
size_t i;
161+
162+
/* Convert name to lowercase and try again */
163+
for(i = 0; name[i] != '\0' && i < sizeof(key) - 1; i++) {
164+
key[i] = tolower(name[i]);
165+
}
166+
167+
key[i] = '\0';
168+
break;
169+
}
155170

156171
size_t start = 0;
157172
size_t posit = furi_string_search_str(value, ",", start);
@@ -190,6 +205,8 @@ InfraredRemoteButton*
190205
furi_string_free(header);
191206
flipper_format_free(ff);
192207

208+
if(!key_found && try_low) return infrared_remote_get_button_by_alt_name(remote, key, false);
209+
193210
return button;
194211
}
195212

@@ -202,7 +219,7 @@ InfraredRemoteButton* xremote_view_get_button_by_name(XRemoteView* rview, const
202219
InfraredRemoteButton* button = infrared_remote_get_button_by_name(buttons->remote, name);
203220

204221
if(button == NULL && settings->alt_names)
205-
button = infrared_remote_get_button_by_alt_name(buttons->remote, name);
222+
button = infrared_remote_get_button_by_alt_name(buttons->remote, name, true);
206223

207224
return button;
208225
}

views/xremote_common_view.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
#include "../infrared/infrared_remote.h"
2222

2323
#define XREMOTE_BUTTON_COUNT 27
24-
#define XREMOTE_NAME_MAX 16
24+
#define XREMOTE_NAME_MAX 32
2525

2626
#define XREMOTE_COMMAND_POWER "Power"
2727
#define XREMOTE_COMMAND_EJECT "Eject"

xremote.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ int32_t xremote_main(void* p) {
8181
/* Allocate context and main application */
8282
XRemoteAppContext* context = xremote_app_context_alloc(p);
8383
XRemoteApp* app = xremote_app_alloc(context);
84-
xremote_app_alt_names_check_and_store();
8584

8685
/* Allocate and build the menu */
8786
xremote_app_submenu_alloc(app, XRemoteViewSubmenu, xremote_exit_callback);

xremote_app.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ bool xremote_app_extension_store(XRemoteAppButtons* buttons, FuriString* path) {
148148
return success;
149149
}
150150

151-
bool xremote_app_alt_names_check_and_store() {
151+
bool xremote_app_alt_names_check_and_init() {
152152
Storage* storage = furi_record_open(RECORD_STORAGE);
153153
FlipperFormat* ff = flipper_format_file_alloc(storage);
154154
bool success = false;
@@ -353,6 +353,9 @@ XRemoteAppContext* xremote_app_context_alloc(void* arg) {
353353
ctx->app_settings = xremote_app_settings_alloc();
354354
xremote_app_settings_load(ctx->app_settings);
355355

356+
/* Initialize alternative names */
357+
if(ctx->app_settings->alt_names) xremote_app_alt_names_check_and_init();
358+
356359
/* Allocate and setup view dispatcher */
357360
ctx->view_dispatcher = view_dispatcher_alloc();
358361
view_dispatcher_enable_queue(ctx->view_dispatcher);

xremote_app.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ XRemoteAppButtons* xremote_app_buttons_load(XRemoteAppContext* app_ctx);
121121

122122
bool xremote_app_extension_store(XRemoteAppButtons* buttons, FuriString* path);
123123
bool xremote_app_extension_load(XRemoteAppButtons* buttons, FuriString* path);
124-
bool xremote_app_alt_names_check_and_store();
124+
bool xremote_app_alt_names_check_and_init();
125125

126126
//////////////////////////////////////////////////////////////////////////////
127127
// XRemote application factory

xremote_settings.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ static void infrared_settings_alt_names_changed(VariableItem* item) {
7373
settings->alt_names = variable_item_get_current_value_index(item);
7474
const char* alt_names_str = xremote_app_get_alt_names_str(settings->alt_names);
7575

76+
if(settings->alt_names) xremote_app_alt_names_check_and_init();
7677
variable_item_set_current_value_text(item, alt_names_str);
7778
xremote_app_settings_store(settings);
7879
}

0 commit comments

Comments
 (0)