Skip to content

Commit

Permalink
Implemented alternative names functionality (#9)
Browse files Browse the repository at this point in the history
* Started implementation of alternative names

* Implemented alternative names functionality

* Update README.md

* Update README.md
  • Loading branch information
kala13x authored Mar 17, 2024
1 parent fc7ae69 commit 6c0de2d
Show file tree
Hide file tree
Showing 13 changed files with 284 additions and 40 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.
44 changes: 43 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,46 @@ Button name | Description
`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.

Alternate names are case insensitive and defined in the 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:

```
Filetype: XRemote Alt-Names
Version: 1
#
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
```

## Installation options

1. Install the latest stable version directly from the official [application catalog](https://lab.flipper.net/apps/flipper_xremote).
Expand All @@ -73,7 +113,7 @@ Button name | Description
- Use deploy script from this repository to build and run the application on the device:

```bash
./deploy.sh --fw=/path/to/the/firmware
./deploy.sh -b --fw=/path/to/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.
Expand All @@ -89,6 +129,7 @@ Button name | Description
- [x] Player buttons page
- [x] Custom buttons page
- [x] Edit custom layout
- [x] Alternative button names
- [ ] Add or remove button
- [ ] All buttons page
- [x] Application settings
Expand All @@ -98,6 +139,7 @@ Button name | Description
- [x] Vertical/horizontal views
- [x] IR command repeat count
- [x] Exit button behavior
- [x] Enable/disable alt names
## Screens
Expand Down
60 changes: 46 additions & 14 deletions deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,39 @@ XCLR_DIM="\x1B[2m"
XCLR_RED="\x1B[31m"
XCLR_RESET="\x1B[0m\n"

# Parse firmware path from arguments if present
FBT_CMD="./fbt"
FBT_DBG="DEBUG=0"
FBT_ARGS="COMPACT=1 launch"

BUILD_PROJECT=0
LINK_PROJECT=0
RUN_QFLIPPER=0
BUILD_DONE=0

for arg in "$@"; do
if [[ $arg == --firmware=* || $arg == --fw=* ]]; then
FLIPPER_FIRMWARE="${arg#*=}"
fi

if [[ $arg == "--build" || $arg == "-b" ]]; then
BUILD_PROJECT=1
fi

if [[ $arg == "--run" || $arg == "-r" ]]; then
RUN_PROJECT=1
fi

if [[ $arg == "--link" || $arg == "-l" ]]; then
LINK_PROJECT=1
fi

if [[ $arg == "--debug" || $arg == "-d" ]]; then
FBT_DBG="DEBUG=1"
fi

if [[ $arg == "--sudo" || $arg == "-s" ]]; then
FBT_CMD="sudo ./fbt"
fi
done

# Check if FLIPPER_FIRMWARE variable is set
Expand Down Expand Up @@ -41,21 +69,25 @@ XREMOTE_PROJ_NAME=$(basename "$XREMOTE_PROJ_PATH")
FLIPPER_APPSRC="applications_user/$XREMOTE_PROJ_NAME"
FLIPPER_USER_APP="$FLIPPER_FIRMWARE/$FLIPPER_APPSRC"

# Unlink existing user application first
[ -s $FLIPPER_USER_APP ] && rm -f $FLIPPER_USER_APP
ln -s $XREMOTE_PROJ_PATH $FLIPPER_FIRMWARE/applications_user
link_project() {
[ -s $FLIPPER_USER_APP ] && rm -f $FLIPPER_USER_APP
ln -s $XREMOTE_PROJ_PATH $FLIPPER_FIRMWARE/applications_user
}

# Build and deploy the project
cd $FLIPPER_FIRMWARE
DEPLOY_DONE=0
sudo ./fbt COMPACT=1 DEBUG=0 launch APPSRC=$FLIPPER_APPSRC && DEPLOY_DONE=1
build_project() {
cd $FLIPPER_FIRMWARE
$FBT_CMD $FBT_ARGS $FBT_DBG APPSRC=$FLIPPER_APPSRC && BUILD_DONE=1
}

# Run qflipper command if asked
for arg in "$@"; do
if [[ $arg == "--run" || $arg == "-r" ]]; then
[ $DEPLOY_DONE -eq 1 ] && sudo qflipper
run_project() {
if [[ $BUILD_PROJECT -eq 0 || $BUILD_DONE -eq 1 ]]; then
qFlipper
fi
done
}

[ $LINK_PROJECT -eq 1 ] && link_project
[ $BUILD_PROJECT -eq 1 ] && build_project
[ $RUN_PROJECT -eq 1 ] && run_project

# Return with success
exit 0
exit 0
11 changes: 7 additions & 4 deletions infrared/infrared_remote.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
#include <stddef.h>
#include <stdlib.h>
#include <m-array.h>
#include <string.h>
#include <ctype.h>
#include <toolbox/path.h>
#include <storage/storage.h>
#include <core/common_defines.h>
Expand Down Expand Up @@ -89,7 +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);
if(!strcmp(infrared_remote_button_get_name(button), name)) {
FuriString* firi_name = infrared_remote_button_get_furi_name(button);

if(button && !furi_string_cmpi_str(firi_name, name)) {
*index = i;
return true;
}
Expand All @@ -101,9 +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);
if(!strcmp(infrared_remote_button_get_name(button), name)) {
return button;
}
FuriString* firi_name = infrared_remote_button_get_furi_name(button);
if(button && !furi_string_cmpi_str(firi_name, name)) return button;
}
return NULL;
}
Expand Down
8 changes: 7 additions & 1 deletion infrared/infrared_remote_button.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
https://github.com/DarkFlippers/unleashed-firmware
The original project is licensed under the GNU GPLv3
No modifications were made to this file.
Modifications made:
- Added function infrared_remote_button_get_furi_name()
*/

#include "infrared_remote_button.h"
Expand Down Expand Up @@ -36,6 +38,10 @@ const char* infrared_remote_button_get_name(InfraredRemoteButton* button) {
return furi_string_get_cstr(button->name);
}

FuriString* infrared_remote_button_get_furi_name(InfraredRemoteButton* button) {
return button->name;
}

void infrared_remote_button_set_signal(InfraredRemoteButton* button, InfraredSignal* signal) {
infrared_signal_set_signal(button->signal, signal);
}
Expand Down
5 changes: 4 additions & 1 deletion infrared/infrared_remote_button.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
https://github.com/DarkFlippers/unleashed-firmware
The original project is licensed under the GNU GPLv3
No modifications were made to this file.
Modifications made:
- Added function infrared_remote_button_get_furi_name()
*/

#pragma once
Expand All @@ -17,6 +19,7 @@ void infrared_remote_button_free(InfraredRemoteButton* button);

void infrared_remote_button_set_name(InfraredRemoteButton* button, const char* name);
const char* infrared_remote_button_get_name(InfraredRemoteButton* button);
FuriString* infrared_remote_button_get_furi_name(InfraredRemoteButton* button);

void infrared_remote_button_set_signal(InfraredRemoteButton* button, InfraredSignal* signal);
InfraredSignal* infrared_remote_button_get_signal(InfraredRemoteButton* button);
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.
74 changes: 70 additions & 4 deletions views/xremote_common_view.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,7 @@ XRemoteView*

void xremote_view_clear_context(XRemoteView* rview) {
furi_assert(rview);

if(rview->context && rview->on_clear) rview->on_clear(rview->context);

rview->context = NULL;
}

Expand Down Expand Up @@ -134,16 +132,84 @@ View* xremote_view_get_view(XRemoteView* rview) {
return rview->view;
}

InfraredRemoteButton*
infrared_remote_get_button_by_alt_name(InfraredRemote* remote, const char* name) {
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;
uint32_t version = 0;

do {
/* Open file and read the header */
if(!flipper_format_buffered_file_open_existing(ff, XREMOTE_ALT_NAMES)) break;
if(!flipper_format_read_header(ff, header, &version)) break;
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;

size_t start = 0;
size_t posit = furi_string_search_str(value, ",", start);

if(posit == FURI_STRING_FAILURE) {
const char* alt_name_cstr = furi_string_get_cstr(value);
button = infrared_remote_get_button_by_name(remote, alt_name_cstr);
} else {
FuriString* alt_name = furi_string_alloc();

while(posit != FURI_STRING_FAILURE) {
furi_string_set_n(alt_name, value, start, posit - start);
const char* alt_name_cstr = furi_string_get_cstr(alt_name);
button = infrared_remote_get_button_by_name(remote, alt_name_cstr);

furi_string_reset(alt_name);
if(button != NULL) break;

start = posit + 1; // Move to the next position
posit = furi_string_search_str(value, ",", start);
}

if(posit == FURI_STRING_FAILURE && button == NULL) {
size_t str_len = furi_string_utf8_length(value);
furi_string_set_n(alt_name, value, start, str_len - start);
const char* alt_name_cstr = furi_string_get_cstr(alt_name);
button = infrared_remote_get_button_by_name(remote, alt_name_cstr);
}

furi_string_free(alt_name);
}

} while(false);

furi_record_close(RECORD_STORAGE);
furi_string_free(header);
flipper_format_free(ff);

return button;
}

InfraredRemoteButton* xremote_view_get_button_by_name(XRemoteView* rview, const char* name) {
xremote_app_assert(rview->context, NULL);
xremote_app_assert(rview->app_ctx, NULL);

XRemoteAppSettings* settings = rview->app_ctx->app_settings;
XRemoteAppButtons* buttons = (XRemoteAppButtons*)rview->context;
return 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)
button = infrared_remote_get_button_by_alt_name(buttons->remote, name);

return button;
}

bool xremote_view_press_button(XRemoteView* rview, InfraredRemoteButton* button) {
xremote_app_assert(button, false);
XRemoteAppSettings* settings = rview->app_ctx->app_settings;

XRemoteAppSettings* settings = rview->app_ctx->app_settings;
InfraredSignal* signal = infrared_remote_button_get_signal(button);
xremote_app_assert(signal, false);

Expand Down
1 change: 1 addition & 0 deletions xremote.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ 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
6 changes: 3 additions & 3 deletions xremote.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@

#include "xremote_app.h"

#define XREMOTE_VERSION_MAJ 1
#define XREMOTE_VERSION_MIN 2
#define XREMOTE_BUILD_NUMBER 0
#define XREMOTE_VERSION_MAJ 1
#define XREMOTE_VERSION_MIN 2
#define XREMOTE_BUILD_NUMBER 2

/* Returns FAP_VERSION + XREMOTE_BUILD_NUMBER */
void xremote_get_version(char* version, size_t length);
Loading

0 comments on commit 6c0de2d

Please sign in to comment.