Skip to content

Commit

Permalink
use options.cfg to read if custom hotkeys active
Browse files Browse the repository at this point in the history
  • Loading branch information
Apaczer committed Jul 4, 2023
1 parent 74d8e2f commit 3d7db83
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 10 deletions.
12 changes: 7 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,16 @@ Remember: all hotkeys will work only in combination with RESET/HOME button (see
| Select | Force-close app |

## Config
**WARNING**: custom hotkeys defined here will only work when below file exist:
button config location
- custom hotkeys config location
`/mnt/.buttons.conf`
button config format
- hotkeys config format
`x:a:y:b:up:down:left:right:select:start:l2:r2:hold-x:hold-a:hold-y:hold-b:hold-up:hold-down:hold-left:hold-right:hold-select:hold-start:hold-l2:hold-r2`
button config file default values
- default hotkeys config values and format (the string must match exactly)
`0:0:0:0:3:4:2:1:22:13:0:0:0:0:0:0:0:0:0:0:0:0:0:0`
<u>NOTE</u>: When enabling custom hotkeys an existing ones will be disable&overwritten by above defaults or any passed by user. However that doesn't apply to hardcoded ones like emulating L1/R1 or other additional buttons.
**NOTE**:
- when enabling custom hotkeys an existing ones will be disabled&overwritten by above defaults or any passed by user. However that doesn't apply to hardcoded ones like emulating L1/R1 or other additional buttons.
- you can disable/enable custom hotkey bindings in `/mnt/options.cfg` with HOTKEY_CUSTOM=0 or 1 entry
- when there's no custom hotkeys config file and HOTKEY_CUSTOM=1 then above default hotkeys apply across device

## Actions
1 = backlight up
Expand Down
33 changes: 28 additions & 5 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
#define MIYOO_BUTTON_FILE "/mnt/.buttons.conf"
#define MIYOO_BATTERY "/sys/class/power_supply/miyoo-battery/voltage_now"
#define MIYOO_BATTERY_FILE "/mnt/.batterylow.conf"
#define MIYOO_OPTIONS_FILE "/mnt/options.cfg"

#define BUTTON_COUNT 12

Expand Down Expand Up @@ -245,8 +246,11 @@ int main(int argc, char** argv)
int fb0, kbd, snd, vir, fd;
int battery_low=3550;
FILE *battery_file;
FILE *options_file;
char wstr[100];
int battery_level;
char lstr[256];
int battery_level;
int hotkeys_enabled = -1;
setvbuf (stdout, NULL, _IONBF, 0);

create_daemon();
Expand Down Expand Up @@ -280,10 +284,29 @@ int main(int argc, char** argv)
// buttons
read_button_config(MIYOO_BUTTON_FILE,actionmap);
signal(SIGUSR1, my_handler);

//check if .buttons.conf file exist for custom hotkeys to overwrite kernel's bindings

options_file = fopen(MIYOO_OPTIONS_FILE, "r");
if (options_file != NULL) {
while (fgets(lstr, sizeof(lstr), options_file)) {
if (strcmp(lstr, "HOTKEY_CUSTOM=1") == 0) {
hotkeys_enabled = 1;
//printf("%s\n", lstr);
break;
} else if (strcmp(lstr, "HOTKEY_CUSTOM=0") == 0) {
hotkeys_enabled = 0;
//printf("%s\n", lstr);
break;
}
}
fclose(options_file);
} else {
// printf("Could not open the OPTIONS file.\n");
return 1;
}

//check if button file exist for custom hotkeys to apply or either entry in options file to accept default hotkeys.
fd = open(MIYOO_BUTTON_FILE, O_RDWR);
if(fd < 0){
if((fd >= 0 && hotkeys_enabled == 0) || (fd < 0 && hotkeys_enabled != 1)){
hotkey_custom = 0;
}
ioctl(kbd, MIYOO_KBD_SET_HOTKEY, hotkey_custom);
Expand Down Expand Up @@ -314,7 +337,7 @@ int main(int argc, char** argv)
if (battery_counter == 0){
battery_file = fopen(MIYOO_BATTERY, "r");
while ( (fgets(wstr,100,battery_file)) != NULL ) {
battery_level = atoi(wstr) ;
battery_level = atoi(wstr) ;
//printf("%s\n", wstr);
}
fclose(battery_file);
Expand Down

0 comments on commit 3d7db83

Please sign in to comment.