change RESET command to CLEAR, add default fkgpiod.conf

Signed-off-by: Michel-FK <michel.stempin@funkey-project.com>
This commit is contained in:
Michel-FK 2021-04-05 19:31:02 +02:00
parent b482c729bd
commit 16b7a7b167
7 changed files with 43 additions and 14 deletions

View File

@ -28,6 +28,7 @@ $ echo "LOAD /etc/fkgpiod.conf" > /tmp/fkgpiod.fifo
## Available script commands (commands are not case sensitive):
```
CLEAR Clear the button mapping
DUMP Dump the button mapping
KEYDOWN <key_code> Send a key down event with the given keycode
KEYPRESS <key_code> Send key press event with the given keycode
@ -35,7 +36,6 @@ KEYUP <key_code> Send a key up event with the
LOAD <configuration_file> Load a configuration file
MAP <button_combination> TO KEY <key_code> Map a button combination to a keycode
MAP <button_combination> TO COMMAND <shell_command> Map a button combination to a Shell command
RESET Reset the button mapping
SLEEP <delays_ms> Sleep for the given delay in ms
TYPE <character_string> Type in a character string
UNMAP <button_combination> Unmap a button combination
@ -48,7 +48,9 @@ where:
- <configuration_file> is the full path to a configurtion file
- <delay_ms> is a delay in ms
- <character_string> is a character string
- <key_code> is among:
- <key_code> is taken from the Linux key and button codes
(https://github.com/torvalds/linux/blob/master/include/uapi/linux/input-event-codes.h),
which in turn is modeled after USB HUT 1.12 (see http://www.usb.org/developers/hidpage):
- KEY_0 to KEY_9, KEY_A to KEY_Z
- KEY_F1 to KEY_F24, KEY_KP0 to KEY_KP9, KEY_PROG1 to KEY_PROG4
- BTN_0 to BTN_9, BTN_A to BTN_C, BTN_X to BTN_Z, BTN_BASE2 to BTN_BASE6

25
fkgpiod.conf Normal file
View File

@ -0,0 +1,25 @@
CLEAR
MAP FN TO KEY KEY_K
MAP START TO KEY KEY_S
MAP UP TO KEY KEY_U
MAP LEFT TO KEY KEY_L
MAP FN+LEFT TO KEY KEY_J
MAP DOWN TO KEY KEY_D
MAP FN+DOWN TO KEY KEY_H
MAP RIGHT TO KEY KEY_R
MAP FN+RIGHT TO KEY KEY_I
MAP R TO KEY KEY_N
MAP FN+R TO KEY KEY_O
MAP L TO KEY KEY_M
MAP FN+L TO KEY KEY_V
MAP A TO KEY KEY_A
MAP B TO KEY KEY_B
MAP X TO KEY KEY_X
MAP Y TO KEY KEY_Y
MAP MENU TO KEY KEY_Q
MAP FN+UP TO COMMAND snap
MAP FN+A TO COMMAND quick_action_volume_up
MAP FN+Y TO COMMAND quick_action_volume_down
MAP FN+X TO COMMAND quick_action_bright_up
MAP FN+B TO COMMAND quick_action_bright_down
MAP FN+L+R TO COMMAND display_notif_system_stats

6
main.c
View File

@ -61,6 +61,7 @@ static void print_usage(void)
"\n"
"Available script commands (commands are not case sensitive):\n"
"-----------------------------------------------------------\n"
"CLEAR Clear the button mapping\n"
"DUMP Dump the button mapping\n"
"KEYDOWN <keycode> Send a key down event with the given keycode\n"
"KEYPRESS <keycode> Send key press event with the given keycode\n"
@ -68,7 +69,6 @@ static void print_usage(void)
"LOAD <configuration_file> Load a configuration file\n"
"MAP <button_combination> TO KEY <keycode> Map a button combination to a keycode\n"
"MAP <button_combination> TO COMMAND <shell_command> Map a button combination to a Shell command\n"
"RESET Reset the button mapping\n"
"SLEEP <delays_ms> Sleep for the given delay in ms\n"
"TYPE <string> Type in a string\n"
"UNMAP <button_combination> Unmap a button combination\n"
@ -80,7 +80,9 @@ static void print_usage(void)
" - <configuration_file> is the full path to a configurtion file\n"
" - <delay_ms> is a delay in ms\n"
" - <string> is a character string\n"
" - <keycode> is among:\n"
" - <keycode> is taken from the Linux key and button codes\n"
" (https://github.com/torvalds/linux/blob/master/include/uapi/linux/input-event-codes.h),\n"
" which in turn is modeled after USB HUT 1.12 (see http://www.usb.org/developers/hidpage):\n"
" - KEY_0 to KEY_9, KEY_A to KEY_Z\n"
" - KEY_F1 to KEY_F24, KEY_KP0 to KEY_KP9, KEY_PROG1 to KEY_PROG4\n"
" - BTN_0 to BTN_9, BTN_A to BTN_C, BTN_X to BTN_Z, BTN_BASE2 to BTN_BASE6\n"

View File

@ -119,8 +119,8 @@ void init_mapping_list(mapping_list_t *list)
list->prev = list;
}
/* Empty a mpping list */
void reset_mapping_list(mapping_list_t *list)
/* Clear a mapping list */
void clear_mapping_list(mapping_list_t *list)
{
struct mapping_list_t *p, *n;
mapping_t *tmp;

View File

@ -59,7 +59,7 @@ typedef struct mapping_t {
} mapping_t;
void init_mapping_list(mapping_list_t *list);
void reset_mapping_list(mapping_list_t *list);
void clear_mapping_list(mapping_list_t *list);
mapping_t *first_mapping(mapping_list_t *list);
mapping_t *next_mapping(mapping_t *mapping);
bool last_mapping(const mapping_list_t *list, const mapping_t *mapping);

View File

@ -72,7 +72,7 @@ static const char *gpio_names[] = {GPIOS};
static const keyword_t valid_commands[] = {
{"MAP", STATE_MAP},
{"UNMAP", STATE_UNMAP},
{"RESET", STATE_RESET},
{"CLEAR", STATE_CLEAR},
{"LOAD", STATE_LOAD},
{"SLEEP", STATE_SLEEP},
{"KEYUP", STATE_KEYUP},
@ -274,7 +274,7 @@ bool parse_config_line(char *line, mapping_list_t *list,
} while (token_end != NULL);
break;
case STATE_RESET:
case STATE_CLEAR:
case STATE_DUMP:
break;
@ -348,9 +348,9 @@ bool parse_config_line(char *line, mapping_list_t *list,
*monitored_gpio_mask &= ~gpio_mask;
break;
case STATE_RESET:
LOG_DEBUG("RESET\n");
reset_mapping_list(list);
case STATE_CLEAR:
LOG_DEBUG("CLEAR\n");
clear_mapping_list(list);
break;
case STATE_LOAD:

View File

@ -61,7 +61,7 @@ typedef enum {GPIOS} button_t;
X(STATE_INIT, "INIT") \
X(STATE_MAP, "MAP") \
X(STATE_UNMAP, "UNMAP") \
X(STATE_RESET, "RESET") \
X(STATE_CLEAR, "CLEAR") \
X(STATE_LOAD, "LOAD") \
X(STATE_SLEEP, "SLEEP") \
X(STATE_KEYUP, "KEYUP") \