feat: implement initial cyborg multi-action button mappings
- Added support for Single, Long, and Double press actions in libazeron. - Mapped Cyborg surgical command IDs (0x20F6, 0x20F8, 0x204A). - Updated azeron-cli to support --long and --double mapping flags. - Updated protocol documentation with newly discovered Cyborg commands. - Added TODO.md for remaining joystick and timing tasks.
This commit is contained in:
@@ -285,10 +285,14 @@ int cmd_map_button(int argc, char *argv[])
|
||||
int device_index = 0;
|
||||
int button_id;
|
||||
const char *key_name;
|
||||
enum azeron_action_type action_type = AZERON_ACTION_SINGLE;
|
||||
|
||||
if (argc < 3) {
|
||||
fprintf(stderr, "Usage: %s map-button <button-id> <key> [options]\n", argv[0]);
|
||||
fprintf(stderr, "Example: %s map-button 1 KEY_W\n", argv[0]);
|
||||
fprintf(stderr, "Options:\n");
|
||||
fprintf(stderr, " --long Map to long press\n");
|
||||
fprintf(stderr, " --double Map to double press\n");
|
||||
fprintf(stderr, "Example: %s map-button 1 KEY_W --long\n", argv[0]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -303,6 +307,8 @@ int cmd_map_button(int argc, char *argv[])
|
||||
/* Parse options */
|
||||
static struct option long_options[] = {
|
||||
{"device", required_argument, 0, 'd'},
|
||||
{"long", no_argument, 0, 'l'},
|
||||
{"double", no_argument, 0, 'b'},
|
||||
{"help", no_argument, 0, 'h'},
|
||||
{0, 0, 0, 0}
|
||||
};
|
||||
@@ -310,11 +316,17 @@ int cmd_map_button(int argc, char *argv[])
|
||||
int opt;
|
||||
int option_index = 0;
|
||||
optind = 3; /* Skip command, button-id and key */
|
||||
while ((opt = getopt_long(argc, argv, "d:h", long_options, &option_index)) != -1) {
|
||||
while ((opt = getopt_long(argc, argv, "d:lbh", long_options, &option_index)) != -1) {
|
||||
switch (opt) {
|
||||
case 'd':
|
||||
device_index = atoi(optarg);
|
||||
break;
|
||||
case 'l':
|
||||
action_type = AZERON_ACTION_LONG;
|
||||
break;
|
||||
case 'b':
|
||||
action_type = AZERON_ACTION_DOUBLE;
|
||||
break;
|
||||
case 'h':
|
||||
printf("Usage: %s map-button <button-id> <key> [options]\n", argv[0]);
|
||||
return 0;
|
||||
@@ -339,6 +351,7 @@ int cmd_map_button(int argc, char *argv[])
|
||||
|
||||
/* Prepare mapping */
|
||||
mapping.button_id = (uint8_t)button_id;
|
||||
mapping.action = action_type;
|
||||
mapping.type = AZERON_BTN_KEYBOARD;
|
||||
|
||||
int keycode = azeron_keycode_from_string(key_name);
|
||||
@@ -356,7 +369,13 @@ int cmd_map_button(int argc, char *argv[])
|
||||
mapping.key_code = (uint16_t)keycode;
|
||||
}
|
||||
|
||||
printf("Mapping button %d to key 0x%02x (%s)...\n", button_id + 1, mapping.key_code, key_name);
|
||||
const char *action_str = "single";
|
||||
if (action_type == AZERON_ACTION_LONG) action_str = "long";
|
||||
else if (action_type == AZERON_ACTION_DOUBLE) action_str = "double";
|
||||
|
||||
printf("Mapping button %d (%s press) to key 0x%02x (%s)...\n",
|
||||
button_id + 1, action_str, mapping.key_code, key_name);
|
||||
|
||||
ret = azeron_device_set_button_mapping(device, &mapping);
|
||||
if (ret != AZERON_SUCCESS) {
|
||||
fprintf(stderr, "Failed to set button mapping: %s\n", azeron_error_string(ret));
|
||||
|
||||
Reference in New Issue
Block a user