From 2e1a773a082d0dbe2f7172909d9af2afbb800164 Mon Sep 17 00:00:00 2001 From: CTCaer Date: Mon, 25 Dec 2023 02:36:27 +0200 Subject: [PATCH] nyx: relax joycon calibration init Wait a bit before actually doing stick calibration in order to avoid bad values. --- nyx/nyx_gui/frontend/gui.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/nyx/nyx_gui/frontend/gui.c b/nyx/nyx_gui/frontend/gui.c index 8d5ad93..b281d98 100644 --- a/nyx/nyx_gui/frontend/gui.c +++ b/nyx/nyx_gui/frontend/gui.c @@ -65,7 +65,9 @@ char *text_color; typedef struct _jc_lv_driver_t { lv_indev_t *indev; - bool centering_done; +// LV_INDEV_READ_PERIOD * JC_CAL_MAX_STEPS = 264 ms. +#define JC_CAL_MAX_STEPS 8 + u32 calibration_step; u16 cx_max; u16 cx_min; u16 cy_max; @@ -412,7 +414,7 @@ static bool _jc_virt_mouse_read(lv_indev_data_t *data) } // Calibrate left stick. - if (!jc_drv_ctx.centering_done) + if (jc_drv_ctx.calibration_step != JC_CAL_MAX_STEPS) { if (n_cfg.jc_force_right) { @@ -420,11 +422,11 @@ static bool _jc_virt_mouse_read(lv_indev_data_t *data) && jc_pad->rstick_x > 0x400 && jc_pad->rstick_y > 0x400 && jc_pad->rstick_x < 0xC00 && jc_pad->rstick_y < 0xC00) { + jc_drv_ctx.calibration_step++; 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; } } @@ -432,14 +434,15 @@ static bool _jc_virt_mouse_read(lv_indev_data_t *data) && jc_pad->lstick_x > 0x400 && jc_pad->lstick_y > 0x400 && jc_pad->lstick_x < 0xC00 && jc_pad->lstick_y < 0xC00) { + jc_drv_ctx.calibration_step++; jc_drv_ctx.cx_max = jc_pad->lstick_x + 0x96; jc_drv_ctx.cx_min = jc_pad->lstick_x - 0x96; jc_drv_ctx.cy_max = jc_pad->lstick_y + 0x96; jc_drv_ctx.cy_min = jc_pad->lstick_y - 0x96; - jc_drv_ctx.centering_done = true; jc_drv_ctx.cursor_timeout = 0; } - else + + if (jc_drv_ctx.calibration_step != JC_CAL_MAX_STEPS) { data->state = LV_INDEV_STATE_REL; return false; @@ -447,13 +450,10 @@ static bool _jc_virt_mouse_read(lv_indev_data_t *data) } // Re-calibrate on disconnection. - 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; + if (n_cfg.jc_force_right && !jc_pad->conn_r) + jc_drv_ctx.calibration_step = 0; + else if (!n_cfg.jc_force_right && !jc_pad->conn_l) + jc_drv_ctx.calibration_step = 0; // Set button presses. if (jc_pad->a || jc_pad->zl || jc_pad->zr)