diff --git a/allynone.c b/allynone.c index 8172706..987a55f 100644 --- a/allynone.c +++ b/allynone.c @@ -89,6 +89,7 @@ int main(int argc, char ** argv) { .enable_qam = true, .ff_gain = 0xFFFF, .rumble_on_mode_switch = true, + .m1m2_mode = 0, } }; diff --git a/config.cfg.default b/config.cfg.default index a932f9a..f6dd94b 100644 --- a/config.cfg.default +++ b/config.cfg.default @@ -4,4 +4,5 @@ nintendo_layout = false; default_gamepad = 1; rumble_on_mode_switch = true; gamepad_rumble_control = true; -gamepad_leds_control = true; \ No newline at end of file +gamepad_leds_control = true; +m1m2_mode = 0; \ No newline at end of file diff --git a/main.c b/main.c index 08999d3..62f4a24 100644 --- a/main.c +++ b/main.c @@ -55,6 +55,7 @@ int main(int argc, char ** argv) { .enable_qam = true, .ff_gain = 0xFFFF, .rumble_on_mode_switch = true, + .m1m2_mode = 0, } }; diff --git a/rog_ally.c b/rog_ally.c index 2671a72..b966a76 100644 --- a/rog_ally.c +++ b/rog_ally.c @@ -45,6 +45,8 @@ typedef struct rc71l_asus_kbd_user_data { struct rc71l_platform* parent; struct udev *udev; + + int m1, m2; } rc71l_asus_kbd_user_data_t; typedef struct rc71l_timer_user_data { @@ -67,7 +69,12 @@ typedef struct rc71l_platform { } rc71l_platform_t; -static rc71l_asus_kbd_user_data_t asus_userdata = {}; +static rc71l_asus_kbd_user_data_t asus_userdata = { + .parent = NULL, + .udev = NULL, + .m1 = 0, + .m2 = 0, +}; static rc71l_xbox360_user_data_t controller_user_data = { .accounted_mode_switches = 0, @@ -182,34 +189,80 @@ static int asus_kbd_ev_map( if (e->ev[i].code == KEY_F14) { // this is left back paddle, works as expected - const in_message_t current_message = { - .type = GAMEPAD_SET_ELEMENT, - .data = { - .gamepad_set = { - .element = GAMEPAD_BTN_L5, - .status = { - .btn = e->ev[1].value, + + if (e->ev[i].value == 0) { + asus_kbd_user_data->m1 -= (asus_kbd_user_data->m1 == 0) ? 0 : 1; + } else if (e->ev[i].value == 1) { + asus_kbd_user_data->m1 += 1; + } + + if (conf->m1m2_mode == 0) { + const in_message_t current_message = { + .type = GAMEPAD_SET_ELEMENT, + .data = { + .gamepad_set = { + .element = GAMEPAD_BTN_L5, + .status = { + .btn = e->ev[1].value, + } } } - } - }; + }; - messages[written_msg++] = current_message; + messages[written_msg++] = current_message; + } else if (conf->m1m2_mode == 1) { + const in_message_t current_message = { + .type = GAMEPAD_SET_ELEMENT, + .data = { + .gamepad_set = { + .element = GAMEPAD_BTN_TOUCHPAD, + .status = { + .btn = (asus_kbd_user_data->m1 + asus_kbd_user_data->m2) == 0 ? 0 : 1, + } + } + } + }; + + messages[written_msg++] = current_message; + } } else if (e->ev[i].code == KEY_F15) { // this is right back paddle, works as expected - const in_message_t current_message = { - .type = GAMEPAD_SET_ELEMENT, - .data = { - .gamepad_set = { - .element = GAMEPAD_BTN_R5, - .status = { - .btn = e->ev[1].value, + + if (e->ev[i].value == 0) { + asus_kbd_user_data->m2 -= (asus_kbd_user_data->m2 == 0) ? 0 : 1; + } else if (e->ev[i].value == 1) { + asus_kbd_user_data->m2 += 1; + } + + if (conf->m1m2_mode == 0) { + const in_message_t current_message = { + .type = GAMEPAD_SET_ELEMENT, + .data = { + .gamepad_set = { + .element = GAMEPAD_BTN_R5, + .status = { + .btn = e->ev[1].value, + } } } - } - }; + }; - messages[written_msg++] = current_message; + messages[written_msg++] = current_message; + } else if (conf->m1m2_mode == 1) { + const in_message_t current_message = { + .type = GAMEPAD_SET_ELEMENT, + .data = { + .gamepad_set = { + .element = GAMEPAD_BTN_TOUCHPAD, + .status = { + .btn = (asus_kbd_user_data->m1 + asus_kbd_user_data->m2) == 0 ? 0 : 1, + } + } + } + }; + + messages[written_msg++] = current_message; + } } else if ((e->ev[i].code == KEY_F16) && (e->ev[i].value != 0)) { // this is left screen button, on release both 0 and 1 events are emitted so just discard the 0 const in_message_t current_message = { diff --git a/settings.c b/settings.c index 6442215..6a2ef48 100644 --- a/settings.c +++ b/settings.c @@ -37,6 +37,17 @@ void load_in_config(dev_in_settings_t *const out_conf, const char* const filepat fprintf(stderr, "ff_gain (int) configuration not found. Default value will be used.\n"); } + int m1m2_mode; + if (config_lookup_int(&cfg, "m1m2_mode", &m1m2_mode) != CONFIG_FALSE) { + if (m1m2_mode <= 2) { + out_conf->m1m2_mode = m1m2_mode; + } else { + fprintf(stderr, "m1m2_mode (int) must be a number between 0 and 2"); + } + } else { + fprintf(stderr, "m1m2_mode (int) configuration not found. Default value will be used.\n"); + } + config_destroy(&cfg); load_in_config_err: diff --git a/settings.h b/settings.h index 3d32878..878ae1a 100644 --- a/settings.h +++ b/settings.h @@ -6,6 +6,7 @@ typedef struct dev_in_settings { bool enable_qam; bool rumble_on_mode_switch; uint16_t ff_gain; + uint8_t m1m2_mode; } dev_in_settings_t; void load_in_config(dev_in_settings_t *const out_conf, const char* const filepath);