From ff14fd7facbf9b9129202417aa150aa324824473 Mon Sep 17 00:00:00 2001 From: Tau Date: Mon, 21 Oct 2019 22:12:05 -0400 Subject: [PATCH] idzio: Restrict maximum wheel ADC abs. value --- idzio/config.c | 3 ++- idzio/config.h | 1 + idzio/dllmain.c | 18 +++++++++++++++--- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/idzio/config.c b/idzio/config.c index 2b18edee..2422d1a1 100644 --- a/idzio/config.c +++ b/idzio/config.c @@ -57,6 +57,7 @@ void idz_di_config_load(struct idz_di_config *cfg, const wchar_t *filename) swprintf_s(key, _countof(key), L"gear%i", i + 1); cfg->gear[i] = GetPrivateProfileIntW(L"dinput", key, i + 1, filename); } + } void idz_io_config_load(struct idz_io_config *cfg, const wchar_t *filename) @@ -67,6 +68,7 @@ void idz_io_config_load(struct idz_io_config *cfg, const wchar_t *filename) cfg->vk_test = GetPrivateProfileIntW(L"io3", L"test", '1', filename); cfg->vk_service = GetPrivateProfileIntW(L"io3", L"service", '2', filename); cfg->vk_coin = GetPrivateProfileIntW(L"io3", L"coin", '3', filename); + cfg->restrict_ = GetPrivateProfileIntW(L"io3", L"restrict", 196, filename); GetPrivateProfileStringW( L"io3", @@ -93,4 +95,3 @@ void idz_shifter_config_load( 0, filename); } - diff --git a/idzio/config.h b/idzio/config.h index d91b5f3d..0c2b9f3f 100644 --- a/idzio/config.h +++ b/idzio/config.h @@ -25,6 +25,7 @@ struct idz_io_config { uint8_t vk_service; uint8_t vk_coin; wchar_t mode[8]; + int restrict_; struct idz_shifter_config shifter; struct idz_di_config di; }; diff --git a/idzio/dllmain.c b/idzio/dllmain.c index 3ced7fe7..ee97ba06 100644 --- a/idzio/dllmain.c +++ b/idzio/dllmain.c @@ -73,12 +73,24 @@ void idz_io_jvs_read_shifter(uint8_t *gear) idz_io_backend->jvs_read_shifter(gear); } -void idz_io_jvs_read_analogs(struct idz_io_analog_state *state) +void idz_io_jvs_read_analogs(struct idz_io_analog_state *out) { - assert(state != NULL); + struct idz_io_analog_state tmp; + + assert(out != NULL); assert(idz_io_backend != NULL); - idz_io_backend->jvs_read_analogs(state); + idz_io_backend->jvs_read_analogs(&tmp); + + /* Apply steering wheel restriction. Real cabs only report about 77% of + the IO-3's max ADC output value when the wheel is turned to either of + its maximum positions. To match this behavior we set the default value + for the wheel restriction config parameter to 196 (out of 256). This + scaling factor is applied using fixed-point arithmetic below. */ + + out->wheel = (tmp.wheel * idz_io_cfg.restrict_) / 256; + out->accel = tmp.accel; + out->brake = tmp.brake; } void idz_io_jvs_read_coin_counter(uint16_t *out)