From c04d423f4b510f1e3d668283e8c6465ea1f04750 Mon Sep 17 00:00:00 2001 From: CTCaer Date: Wed, 23 Mar 2022 00:49:47 +0200 Subject: [PATCH] nyx: add option to use right joycon as mouse control `jcforceright=1` in nyx.ini enables that feature. Useful for users with broken touch screen and broken left joycon rail. --- README.md | 1 + nyx/nyx_gui/config.c | 4 +++ nyx/nyx_gui/config.h | 1 + nyx/nyx_gui/frontend/gui.c | 68 +++++++++++++++++++++++++++++--------- nyx/nyx_gui/nyx.c | 2 ++ 5 files changed, 61 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index d6c2ee6..481f279 100644 --- a/README.md +++ b/README.md @@ -172,6 +172,7 @@ If the main .ini is not found, it is created on the first hekate boot and only h | verification=1 | 0: Disable Backup/Restore verification, 1: Sparse (block based, fast and mostly reliable), 2: Full (sha256 based, slow and 100% reliable). | | umsemmcrw=0 | 1: eMMC/emuMMC UMS will be mounted as writable by default. | | jcdisable=0 | 1: Disables Joycon driver completely. | +| jcforceright=0 | 1: Forces right joycon to be used as main mouse control. | | bpmpclock=1 | 0: Auto, 1: Faster, 2: Fast. Use 2 if Nyx hangs or some functions like UMS/Backup Verification fail. | diff --git a/nyx/nyx_gui/config.c b/nyx/nyx_gui/config.c index ab62296..5f510c7 100644 --- a/nyx/nyx_gui/config.c +++ b/nyx/nyx_gui/config.c @@ -52,6 +52,7 @@ void set_nyx_default_configuration() n_cfg.verification = 1; n_cfg.ums_emmc_rw = 0; n_cfg.jc_disable = 0; + n_cfg.jc_force_right = 0; n_cfg.bpmp_clock = 0; } @@ -210,6 +211,9 @@ int create_nyx_config_entry(bool force_unmount) f_puts("\njcdisable=", &fp); itoa(n_cfg.jc_disable, lbuf, 10); f_puts(lbuf, &fp); + f_puts("\njcforceright=", &fp); + itoa(n_cfg.jc_force_right, lbuf, 10); + f_puts(lbuf, &fp); f_puts("\nbpmpclock=", &fp); itoa(n_cfg.bpmp_clock, lbuf, 10); f_puts(lbuf, &fp); diff --git a/nyx/nyx_gui/config.h b/nyx/nyx_gui/config.h index 04784c1..42e0ce0 100644 --- a/nyx/nyx_gui/config.h +++ b/nyx/nyx_gui/config.h @@ -48,6 +48,7 @@ typedef struct _nyx_config u32 verification; u32 ums_emmc_rw; u32 jc_disable; + u32 jc_force_right; u32 bpmp_clock; } nyx_config; diff --git a/nyx/nyx_gui/frontend/gui.c b/nyx/nyx_gui/frontend/gui.c index b4a58c1..7b9fb0e 100644 --- a/nyx/nyx_gui/frontend/gui.c +++ b/nyx/nyx_gui/frontend/gui.c @@ -394,9 +394,23 @@ static bool _jc_virt_mouse_read(lv_indev_data_t *data) // Calibrate left stick. if (!jc_drv_ctx.centering_done) { - if (jc_pad->conn_l - && jc_pad->lstick_x > 0x400 && jc_pad->lstick_y > 0x400 - && jc_pad->lstick_x < 0xC00 && jc_pad->lstick_y < 0xC00) + if (n_cfg.jc_force_right) + { + if (jc_pad->conn_r + && jc_pad->rstick_x > 0x400 && jc_pad->rstick_y > 0x400 + && jc_pad->rstick_x < 0xC00 && jc_pad->rstick_y < 0xC00) + { + jc_drv_ctx.cx_max = jc_pad->rstick_x + 0x96; + jc_drv_ctx.cx_min = jc_pad->rstick_x - 0x96; + jc_drv_ctx.cy_max = jc_pad->rstick_y + 0x96; + jc_drv_ctx.cy_min = jc_pad->rstick_y - 0x96; + jc_drv_ctx.centering_done = true; + jc_drv_ctx.cursor_timeout = 0; + } + } + else if (jc_pad->conn_l + && jc_pad->lstick_x > 0x400 && jc_pad->lstick_y > 0x400 + && jc_pad->lstick_x < 0xC00 && jc_pad->lstick_y < 0xC00) { jc_drv_ctx.cx_max = jc_pad->lstick_x + 0x96; jc_drv_ctx.cx_min = jc_pad->lstick_x - 0x96; @@ -413,7 +427,12 @@ static bool _jc_virt_mouse_read(lv_indev_data_t *data) } // Re-calibrate on disconnection. - if (!jc_pad->conn_l) + if (n_cfg.jc_force_right) + { + if (!jc_pad->conn_r) + jc_drv_ctx.centering_done = 0; + } + else if (!jc_pad->conn_l) jc_drv_ctx.centering_done = 0; // Set button presses. @@ -466,19 +485,38 @@ static bool _jc_virt_mouse_read(lv_indev_data_t *data) } // Calculate new cursor position. - if (jc_pad->lstick_x <= jc_drv_ctx.cx_max && jc_pad->lstick_x >= jc_drv_ctx.cx_min) - jc_drv_ctx.pos_x += 0; - else if (jc_pad->lstick_x > jc_drv_ctx.cx_max) - jc_drv_ctx.pos_x += ((jc_pad->lstick_x - jc_drv_ctx.cx_max) / 30); - else - jc_drv_ctx.pos_x -= ((jc_drv_ctx.cx_min - jc_pad->lstick_x) / 30); + if (!n_cfg.jc_force_right) + { + if (jc_pad->lstick_x <= jc_drv_ctx.cx_max && jc_pad->lstick_x >= jc_drv_ctx.cx_min) + jc_drv_ctx.pos_x += 0; + else if (jc_pad->lstick_x > jc_drv_ctx.cx_max) + jc_drv_ctx.pos_x += ((jc_pad->lstick_x - jc_drv_ctx.cx_max) / 30); + else + jc_drv_ctx.pos_x -= ((jc_drv_ctx.cx_min - jc_pad->lstick_x) / 30); - if (jc_pad->lstick_y <= jc_drv_ctx.cy_max && jc_pad->lstick_y >= jc_drv_ctx.cy_min) - jc_drv_ctx.pos_y += 0; - else if (jc_pad->lstick_y > jc_drv_ctx.cy_max) - jc_drv_ctx.pos_y -= ((jc_pad->lstick_y - jc_drv_ctx.cy_max) / 30); + if (jc_pad->lstick_y <= jc_drv_ctx.cy_max && jc_pad->lstick_y >= jc_drv_ctx.cy_min) + jc_drv_ctx.pos_y += 0; + else if (jc_pad->lstick_y > jc_drv_ctx.cy_max) + jc_drv_ctx.pos_y -= ((jc_pad->lstick_y - jc_drv_ctx.cy_max) / 30); + else + jc_drv_ctx.pos_y += ((jc_drv_ctx.cy_min - jc_pad->lstick_y) / 30); + } else - jc_drv_ctx.pos_y += ((jc_drv_ctx.cy_min - jc_pad->lstick_y) / 30); + { + if (jc_pad->rstick_x <= jc_drv_ctx.cx_max && jc_pad->rstick_x >= jc_drv_ctx.cx_min) + jc_drv_ctx.pos_x += 0; + else if (jc_pad->rstick_x > jc_drv_ctx.cx_max) + jc_drv_ctx.pos_x += ((jc_pad->rstick_x - jc_drv_ctx.cx_max) / 30); + else + jc_drv_ctx.pos_x -= ((jc_drv_ctx.cx_min - jc_pad->rstick_x) / 30); + + if (jc_pad->rstick_y <= jc_drv_ctx.cy_max && jc_pad->rstick_y >= jc_drv_ctx.cy_min) + jc_drv_ctx.pos_y += 0; + else if (jc_pad->rstick_y > jc_drv_ctx.cy_max) + jc_drv_ctx.pos_y -= ((jc_pad->rstick_y - jc_drv_ctx.cy_max) / 30); + else + jc_drv_ctx.pos_y += ((jc_drv_ctx.cy_min - jc_pad->rstick_y) / 30); + } // Ensure value inside screen limits. if (jc_drv_ctx.pos_x < 0) diff --git a/nyx/nyx_gui/nyx.c b/nyx/nyx_gui/nyx.c index 361af2c..eb7dbda 100644 --- a/nyx/nyx_gui/nyx.c +++ b/nyx/nyx_gui/nyx.c @@ -271,6 +271,8 @@ skip_main_cfg_parse: n_cfg.ums_emmc_rw = atoi(kv->val) == 1; else if (!strcmp("jcdisable", kv->key)) n_cfg.jc_disable = atoi(kv->val) == 1; + else if (!strcmp("jcforceright", kv->key)) + n_cfg.jc_force_right = atoi(kv->val) == 1; else if (!strcmp("bpmpclock", kv->key)) n_cfg.bpmp_clock = strtol(kv->val, NULL, 10); }