refact(vigem-iidxio): Use new config api

Summary:

Test Plan:
This commit is contained in:
icex2
2024-08-17 12:51:00 +02:00
parent 4c9175c697
commit c03f5d3909
7 changed files with 82 additions and 281 deletions
+2 -2
View File
@@ -494,7 +494,7 @@ $(zipdir)/iidx-hwio-x86.zip: \
build/bin/indep-32/vigem-iidxio.exe \
dist/iidx/eamio-icca.xml \
dist/iidx/iidxio-bio2.xml \
dist/iidx/vigem-iidxio.conf \
dist/iidx/vigem-iidxio.xml \
| $(zipdir)/
$(V)echo ... $@
$(V)zip -j $@ $^
@@ -508,7 +508,7 @@ $(zipdir)/iidx-hwio-x64.zip: \
build/bin/indep-64/vigem-iidxio.exe \
dist/iidx/eamio-icca.xml \
dist/iidx/iidxio-bio2.xml \
dist/iidx/vigem-iidxio.conf \
dist/iidx/vigem-iidxio.xml \
| $(zipdir)/
$(V)echo ... $@
$(V)zip -j $@ $^
-26
View File
@@ -1,26 +0,0 @@
# Use relative mode analog mapping instead of absolute analog values
vigem.iidxio.tt.anlog.relative=false
# Sensitivity value for relative mode (1 to 32767). Tweak if you are having issues with jittering/misfiring/unresponsiveness
vigem.iidxio.tt.anlog.relative_sensitivity=1024
# Button turntable: "debounce" value (1 to 50, recommend 20). Tweak if you are having issues with TT button misfiring/unresponsiveness
vigem.iidxio.tt.button.debounce=20
# Button turntable: minimum ticks required within (debounce * 2) ms to register movement (1 to 4, recommend 2). Tweak if you button input is too (un-) responsive
vigem.iidxio.tt.button.threshold=2
# Print verbose debug output to the console for debugging turntable sensitivity issues
vigem.iidxio.tt.debug_output=false
# Enable input based key lighting
vigem.iidxio.cab_light.enable_keylight=true
# Different cabinet light modes: 0 = off, 1 = neons sequence, 2 = neons flash on TT spin
vigem.iidxio.cab_light.light_mode=0
# Display text on 16seg. If text exceeds 9 char display limit, it will scroll + cycle
vigem.iidxio.cab_light.text_16seg=
# Cycle time/scroll speed for text exceeding 16seg display length (9) to scroll from right
vigem.iidxio.cab_light.text_scroll_cycle_time_ms=500
+29
View File
@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="Shift-JIS"?>
<vigem-iidxio>
<tt>
<analog>
<!-- Use relative mode analog mapping instead of absolute analog values -->
<relative __type="bool">0</relative>
<!-- Sensitivity value for relative mode (1 to 32767). Tweak if you are having issues with jittering/misfiring/unresponsiveness -->
<relative_sensitivity __type="s32">1024</relative_sensitivity>
</analog>
<button>
<!-- Button turntable: "debounce" value (1 to 50, recommend 20). Tweak if you are having issues with TT button misfiring/unresponsiveness -->
<debounce __type="s32">20</debounce>
<!-- Button turntable: minimum ticks required within (debounce * 2) ms to register movement (1 to 4, recommend 2). Tweak if you button input is too (un-) responsive -->
<threshold __type="s32">2</threshold>
</button>
<!-- Print verbose debug output to the console for debugging turntable sensitivity issues -->
<debug_output __type="bool">0</debug_output>
</tt>
<cab_light>
<!-- Enable input based key lighting -->
<enable_keylight __type="bool">1</enable_keylight>
<!-- Different cabinet light modes: 0 = off, 1 = neons sequence, 2 = neons flash on TT spin -->
<light_mode __type="s32">0</light_mode>
<!-- Display text on 16seg. If text exceeds 9 char display limit, it will scroll + cycle -->
<text_16seg __type="str"></text_16seg>
<!-- Cycle time/scroll speed for text exceeding 16seg display length (9) to scroll from right -->
<text_scroll_cycle_time_ms __type="s32">500</text_scroll_cycle_time_ms>
</cab_light>
</vigem-iidxio>
+4 -3
View File
@@ -8,20 +8,21 @@ cppflags_vigem-iidxio := \
ldflags_vigem-iidxio := \
-lsetupapi \
-lws2_32 \
libs_vigem-iidxio := \
core \
cconfig \
util \
vigemstub \
module \
ezusb \
iface \
iface-io \
iface-core \
security \
util \
src_vigem-iidxio := \
cab-16seg-sequencer.c \
cab-light-sequencer.c \
main.c \
config.c \
main.c \
+12 -239
View File
@@ -1,243 +1,16 @@
#include "cconfig/cconfig-main.h"
#include "cconfig/cconfig-util.h"
#include "iface-core/log.h"
#include "core/config-ext.h"
#include "vigem-iidxio/config.h"
#define VIGEM_IIDXIO_CONFIG_TT_ANALOG_RELATIVE_KEY \
"vigem.iidxio.tt.anlog.relative"
#define VIGEM_IIDXIO_CONFIG_TT_ANALOG_RELATIVE_SENSITIVITY_KEY \
"vigem.iidxio.tt.anlog.relative_sensitivity"
#define VIGEM_IIDXIO_CONFIG_TT_BUTTON_DEBOUNCE_KEY \
"vigem.iidxio.tt.button.debounce"
#define VIGEM_IIDXIO_CONFIG_TT_BUTTON_THRESHOLD_KEY \
"vigem.iidxio.tt.button.threshold"
#define VIGEM_IIDXIO_CONFIG_TT_DEBUG_OUTPUT_KEY "vigem.iidxio.tt.debug_output"
#define VIGEM_IIDXIO_CONFIG_CAB_LIGHT_ENABLE_KEYLIGHT_KEY \
"vigem.iidxio.cab_light.enable_keylight"
#define VIGEM_IIDXIO_CONFIG_CAB_LIGHT_LIGHT_MODE_KEY \
"vigem.iidxio.cab_light.light_mode"
#define VIGEM_IIDXIO_CONFIG_CAB_LIGHT_TEXT_16SEG_KEY \
"vigem.iidxio.cab_light.text_16seg"
#define VIGEM_IIDXIO_CONFIG_CAB_LIGHT_TEXT_SCROLL_CYCLE_TIME_MS_KEY \
"vigem.iidxio.cab_light.text_scroll_cycle_time_ms"
#define VIGEM_IIDXIO_CONFIG_DEFAULT_TT_ANALOG_RELATIVE_VALUE false
#define VIGEM_IIDXIO_CONFIG_DEFAULT_TT_ANALOG_RELATIVE_SENSITIVITY_VALUE 1024
#define VIGEM_IIDXIO_CONFIG_DEFAULT_TT_BUTTON_DEBOUNCE_VALUE 20
#define VIGEM_IIDXIO_CONFIG_DEFAULT_TT_BUTTON_THRESHOLD_VALUE 2
#define VIGEM_IIDXIO_CONFIG_DEFAULT_TT_DEBUG_OUTPUT_VALUE false
#define VIGEM_IIDXIO_CONFIG_DEFAULT_CAB_LIGHT_ENABLE_KEYLIGHT_VALUE true
#define VIGEM_IIDXIO_CONFIG_DEFAULT_CAB_LIGHT_LIGHT_MODE_VALUE 0
#define VIGEM_IIDXIO_CONFIG_DEFAULT_CAB_LIGHT_TEXT_16SEG_VALUE ""
#define VIGEM_IIDXIO_CONFIG_DEFAULT_CAB_LIGHT_TEXT_SCROLL_CYCLE_TIME_MS_VALUE \
500
static void _vigem_iidxio_config_init(struct cconfig *config)
void vigem_iidxio_config_get(const bt_core_config_t *config, vigem_iidxio_config_t *config_out)
{
cconfig_util_set_bool(
config,
VIGEM_IIDXIO_CONFIG_TT_ANALOG_RELATIVE_KEY,
VIGEM_IIDXIO_CONFIG_DEFAULT_TT_ANALOG_RELATIVE_VALUE,
"Use relative mode analog mapping instead of absolute analog values");
cconfig_util_set_int(
config,
VIGEM_IIDXIO_CONFIG_TT_ANALOG_RELATIVE_SENSITIVITY_KEY,
VIGEM_IIDXIO_CONFIG_DEFAULT_TT_ANALOG_RELATIVE_SENSITIVITY_VALUE,
"Sensitivity value for relative mode (1 to 32767). Tweak if you are "
"having issues with "
"jittering/misfiring/unresponsiveness");
cconfig_util_set_int(
config,
VIGEM_IIDXIO_CONFIG_TT_BUTTON_DEBOUNCE_KEY,
VIGEM_IIDXIO_CONFIG_DEFAULT_TT_BUTTON_DEBOUNCE_VALUE,
"Button turntable: \"debounce\" value (1 to 50, recommend 20). Tweak "
"if you are having "
"issues with TT button misfiring/unresponsiveness");
cconfig_util_set_int(
config,
VIGEM_IIDXIO_CONFIG_TT_BUTTON_THRESHOLD_KEY,
VIGEM_IIDXIO_CONFIG_DEFAULT_TT_BUTTON_THRESHOLD_VALUE,
"Button turntable: minimum ticks required within (debounce * 2) ms to "
"register movement "
"(1 to 4, recommend 2). Tweak if you button input is too (un-) "
"responsive");
cconfig_util_set_bool(
config,
VIGEM_IIDXIO_CONFIG_TT_DEBUG_OUTPUT_KEY,
VIGEM_IIDXIO_CONFIG_DEFAULT_TT_DEBUG_OUTPUT_VALUE,
"Print verbose debug output to the console for debugging turntable "
"sensitivity issues");
cconfig_util_set_bool(
config,
VIGEM_IIDXIO_CONFIG_CAB_LIGHT_ENABLE_KEYLIGHT_KEY,
VIGEM_IIDXIO_CONFIG_DEFAULT_CAB_LIGHT_ENABLE_KEYLIGHT_VALUE,
"Enable input based key lighting");
cconfig_util_set_int(
config,
VIGEM_IIDXIO_CONFIG_CAB_LIGHT_LIGHT_MODE_KEY,
VIGEM_IIDXIO_CONFIG_DEFAULT_CAB_LIGHT_LIGHT_MODE_VALUE,
"Different cabinet light modes: 0 = off, 1 = neons sequence, 2 = neons "
"flash on TT spin");
cconfig_util_set_str(
config,
VIGEM_IIDXIO_CONFIG_CAB_LIGHT_TEXT_16SEG_KEY,
VIGEM_IIDXIO_CONFIG_DEFAULT_CAB_LIGHT_TEXT_16SEG_VALUE,
"Display text on 16seg. If text exceeds 9 char display limit, it will "
"scroll + cycle");
cconfig_util_set_int(
config,
VIGEM_IIDXIO_CONFIG_CAB_LIGHT_TEXT_SCROLL_CYCLE_TIME_MS_KEY,
VIGEM_IIDXIO_CONFIG_DEFAULT_CAB_LIGHT_TEXT_SCROLL_CYCLE_TIME_MS_VALUE,
"Cycle time/scroll speed for text exceeding 16seg display length (9) "
"to scroll from right");
}
static void _vigem_iidxio_config_get(
struct vigem_iidxio_config *vigem_config, struct cconfig *config)
{
if (!cconfig_util_get_bool(
config,
VIGEM_IIDXIO_CONFIG_TT_ANALOG_RELATIVE_KEY,
&vigem_config->tt.analog.relative,
VIGEM_IIDXIO_CONFIG_DEFAULT_TT_ANALOG_RELATIVE_VALUE)) {
log_warning(
"Invalid value for key '%s' specified, fallback "
"to default '%d'",
VIGEM_IIDXIO_CONFIG_TT_ANALOG_RELATIVE_KEY,
VIGEM_IIDXIO_CONFIG_DEFAULT_TT_ANALOG_RELATIVE_VALUE);
}
if (!cconfig_util_get_int(
config,
VIGEM_IIDXIO_CONFIG_TT_ANALOG_RELATIVE_SENSITIVITY_KEY,
&vigem_config->tt.analog.relative_sensitivity,
VIGEM_IIDXIO_CONFIG_DEFAULT_TT_ANALOG_RELATIVE_SENSITIVITY_VALUE)) {
log_warning(
"Invalid value for key '%s' specified, fallback "
"to default '%d'",
VIGEM_IIDXIO_CONFIG_TT_ANALOG_RELATIVE_SENSITIVITY_KEY,
VIGEM_IIDXIO_CONFIG_DEFAULT_TT_ANALOG_RELATIVE_SENSITIVITY_VALUE);
}
if (!cconfig_util_get_int(
config,
VIGEM_IIDXIO_CONFIG_TT_BUTTON_DEBOUNCE_KEY,
&vigem_config->tt.button.debounce,
VIGEM_IIDXIO_CONFIG_DEFAULT_TT_BUTTON_DEBOUNCE_VALUE)) {
log_warning(
"Invalid value for key '%s' specified, fallback "
"to default '%d'",
VIGEM_IIDXIO_CONFIG_TT_BUTTON_DEBOUNCE_KEY,
VIGEM_IIDXIO_CONFIG_DEFAULT_TT_BUTTON_DEBOUNCE_VALUE);
}
if (!cconfig_util_get_int(
config,
VIGEM_IIDXIO_CONFIG_TT_BUTTON_THRESHOLD_KEY,
&vigem_config->tt.button.threshold,
VIGEM_IIDXIO_CONFIG_DEFAULT_TT_BUTTON_THRESHOLD_VALUE)) {
log_warning(
"Invalid value for key '%s' specified, fallback "
"to default '%d'",
VIGEM_IIDXIO_CONFIG_TT_BUTTON_THRESHOLD_KEY,
VIGEM_IIDXIO_CONFIG_DEFAULT_TT_BUTTON_THRESHOLD_VALUE);
}
if (!cconfig_util_get_bool(
config,
VIGEM_IIDXIO_CONFIG_TT_DEBUG_OUTPUT_KEY,
&vigem_config->tt.debug_output,
VIGEM_IIDXIO_CONFIG_DEFAULT_TT_DEBUG_OUTPUT_VALUE)) {
log_warning(
"Invalid value for key '%s' specified, fallback "
"to default '%d'",
VIGEM_IIDXIO_CONFIG_TT_DEBUG_OUTPUT_KEY,
VIGEM_IIDXIO_CONFIG_DEFAULT_TT_DEBUG_OUTPUT_VALUE);
}
if (!cconfig_util_get_bool(
config,
VIGEM_IIDXIO_CONFIG_CAB_LIGHT_ENABLE_KEYLIGHT_KEY,
&vigem_config->cab_light.enable_keylight,
VIGEM_IIDXIO_CONFIG_DEFAULT_CAB_LIGHT_ENABLE_KEYLIGHT_VALUE)) {
log_warning(
"Invalid value for key '%s' specified, fallback "
"to default '%d'",
VIGEM_IIDXIO_CONFIG_CAB_LIGHT_ENABLE_KEYLIGHT_KEY,
VIGEM_IIDXIO_CONFIG_DEFAULT_CAB_LIGHT_ENABLE_KEYLIGHT_VALUE);
}
if (!cconfig_util_get_int(
config,
VIGEM_IIDXIO_CONFIG_CAB_LIGHT_LIGHT_MODE_KEY,
&vigem_config->cab_light.light_mode,
VIGEM_IIDXIO_CONFIG_DEFAULT_CAB_LIGHT_LIGHT_MODE_VALUE)) {
log_warning(
"Invalid value for key '%s' specified, fallback "
"to default '%d'",
VIGEM_IIDXIO_CONFIG_CAB_LIGHT_LIGHT_MODE_KEY,
VIGEM_IIDXIO_CONFIG_DEFAULT_CAB_LIGHT_LIGHT_MODE_VALUE);
}
if (!cconfig_util_get_str(
config,
VIGEM_IIDXIO_CONFIG_CAB_LIGHT_TEXT_16SEG_KEY,
vigem_config->cab_light.text_16seg,
sizeof(vigem_config->cab_light.text_16seg),
VIGEM_IIDXIO_CONFIG_DEFAULT_CAB_LIGHT_TEXT_16SEG_VALUE)) {
log_warning(
"Invalid value for key '%s' specified, fallback "
"to default '%s'",
VIGEM_IIDXIO_CONFIG_CAB_LIGHT_TEXT_16SEG_KEY,
VIGEM_IIDXIO_CONFIG_DEFAULT_CAB_LIGHT_TEXT_16SEG_VALUE);
}
if (!cconfig_util_get_int(
config,
VIGEM_IIDXIO_CONFIG_CAB_LIGHT_TEXT_SCROLL_CYCLE_TIME_MS_KEY,
&vigem_config->cab_light.text_scroll_cycle_time_ms,
VIGEM_IIDXIO_CONFIG_DEFAULT_CAB_LIGHT_TEXT_SCROLL_CYCLE_TIME_MS_VALUE)) {
log_warning(
"Invalid value for key '%s' specified, fallback "
"to default '%d'",
VIGEM_IIDXIO_CONFIG_CAB_LIGHT_TEXT_SCROLL_CYCLE_TIME_MS_KEY,
VIGEM_IIDXIO_CONFIG_DEFAULT_CAB_LIGHT_TEXT_SCROLL_CYCLE_TIME_MS_VALUE);
}
}
bool vigem_iidxio_config_get(struct vigem_iidxio_config *config_out)
{
struct cconfig *config;
config = cconfig_init();
_vigem_iidxio_config_init(config);
if (!cconfig_main_config_init(
config,
"--config",
"vigem-iidxio.conf",
"--help",
"-h",
"vigem-iidxio",
CCONFIG_CMD_USAGE_OUT_STDOUT)) {
cconfig_finit(config);
return false;
}
_vigem_iidxio_config_get(config_out, config);
cconfig_finit(config);
return true;
}
bt_core_config_ext_bool_get(config, "tt/anlog/relative", &config_out->tt.analog.relative);
bt_core_config_ext_s32_get(config, "tt/anlog/relative_sensitivity", &config_out->tt.analog.relative_sensitivity);
bt_core_config_ext_s32_get(config, "tt/button/debounce", &config_out->tt.button.debounce);
bt_core_config_ext_s32_get(config, "tt/button/threshold", &config_out->tt.button.threshold);
bt_core_config_ext_bool_get(config, "tt/debug_output", &config_out->tt.debug_output);
bt_core_config_ext_bool_get(config, "cab_light/enable_keylight", &config_out->cab_light.enable_keylight);
bt_core_config_ext_s32_get(config, "cab_light/light_mode", &config_out->cab_light.light_mode);
bt_core_config_ext_str_get(config, "cab_light/text_16seg", config_out->cab_light.text_16seg, sizeof(config_out->cab_light.text_16seg));
bt_core_config_ext_s32_get(config, "cab_light/text_scroll_cycle_time_ms", &config_out->cab_light.text_scroll_cycle_time_ms);
}
+6 -5
View File
@@ -1,11 +1,12 @@
#ifndef VIGEM_IIDXIO_CONFIG_H
#define VIGEM_IIDXIO_CONFIG_H
#include <windows.h>
#include <stdbool.h>
#include <stdint.h>
#include "cconfig/cconfig.h"
#include "api/core/config.h"
struct vigem_iidxio_config {
typedef struct vigem_iidxio_config {
struct tt {
struct analog {
bool relative;
@@ -26,8 +27,8 @@ struct vigem_iidxio_config {
char text_16seg[1024 + 1];
int32_t text_scroll_cycle_time_ms;
} cab_light;
};
} vigem_iidxio_config_t;
bool vigem_iidxio_config_get(struct vigem_iidxio_config *config_out);
void vigem_iidxio_config_get(const bt_core_config_t *config, vigem_iidxio_config_t *config_out);
#endif
+29 -6
View File
@@ -7,8 +7,10 @@
#include <ViGEm/Client.h>
#include "core/config-property-node.h"
#include "core/log-bt-ext.h"
#include "core/log-bt.h"
#include "core/log-sink-std.h"
#include "core/thread-crt.h"
#include "iface-core/log.h"
@@ -277,18 +279,39 @@ static void _io_iidx_init(module_io_t **module)
bt_io_iidx_api_set(&api);
}
static void _config_load(vigem_iidxio_config_t *config_out)
{
core_property_t *property;
core_property_result_t property_result;
core_property_node_t node;
core_property_node_result_t node_result;
bt_core_config_t *config;
property_result = core_property_file_load("vigem-iidxio.xml", &property);
core_property_fatal_on_error(property_result);
node_result = core_property_root_node_get(property, &node);
core_property_node_fatal_on_error(node_result);
core_config_property_node_init(&node, &config);
vigem_iidxio_config_get(config, config_out);
core_config_property_node_free(&config);
core_property_free(&property);
}
int main(int argc, char **argv)
{
core_thread_crt_core_api_set();
vigem_iidxio_config_t config;
core_log_bt_core_api_set();
core_thread_crt_core_api_set();
core_config_property_node_core_api_set();
core_log_bt_ext_init_with_stdout();
struct vigem_iidxio_config config;
if (!vigem_iidxio_config_get(&config)) {
return -1;
}
_config_load(&config);
_io_iidx_init(&_module_io_iidx);