From c03f5d390925203a63711d6a1043359997e73234 Mon Sep 17 00:00:00 2001 From: icex2 Date: Sat, 17 Aug 2024 12:51:00 +0200 Subject: [PATCH] refact(vigem-iidxio): Use new config api Summary: Test Plan: --- Module.mk | 4 +- dist/iidx/vigem-iidxio.conf | 26 ---- dist/iidx/vigem-iidxio.xml | 29 ++++ src/main/vigem-iidxio/Module.mk | 7 +- src/main/vigem-iidxio/config.c | 251 ++------------------------------ src/main/vigem-iidxio/config.h | 11 +- src/main/vigem-iidxio/main.c | 35 ++++- 7 files changed, 82 insertions(+), 281 deletions(-) delete mode 100644 dist/iidx/vigem-iidxio.conf create mode 100644 dist/iidx/vigem-iidxio.xml diff --git a/Module.mk b/Module.mk index feab0ab..dc74549 100644 --- a/Module.mk +++ b/Module.mk @@ -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 $@ $^ diff --git a/dist/iidx/vigem-iidxio.conf b/dist/iidx/vigem-iidxio.conf deleted file mode 100644 index 08cd05d..0000000 --- a/dist/iidx/vigem-iidxio.conf +++ /dev/null @@ -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 \ No newline at end of file diff --git a/dist/iidx/vigem-iidxio.xml b/dist/iidx/vigem-iidxio.xml new file mode 100644 index 0000000..44f9e86 --- /dev/null +++ b/dist/iidx/vigem-iidxio.xml @@ -0,0 +1,29 @@ + + + + + + 0 + + 1024 + + + + 0 + + + + 1 + + 0 + + + + 500 + + \ No newline at end of file diff --git a/src/main/vigem-iidxio/Module.mk b/src/main/vigem-iidxio/Module.mk index 656fc77..d2419ca 100644 --- a/src/main/vigem-iidxio/Module.mk +++ b/src/main/vigem-iidxio/Module.mk @@ -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 \ diff --git a/src/main/vigem-iidxio/config.c b/src/main/vigem-iidxio/config.c index 89a61c7..6bdf434 100644 --- a/src/main/vigem-iidxio/config.c +++ b/src/main/vigem-iidxio/config.c @@ -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); +} \ No newline at end of file diff --git a/src/main/vigem-iidxio/config.h b/src/main/vigem-iidxio/config.h index f4f0446..db45421 100644 --- a/src/main/vigem-iidxio/config.h +++ b/src/main/vigem-iidxio/config.h @@ -1,11 +1,12 @@ #ifndef VIGEM_IIDXIO_CONFIG_H #define VIGEM_IIDXIO_CONFIG_H -#include +#include +#include -#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 \ No newline at end of file diff --git a/src/main/vigem-iidxio/main.c b/src/main/vigem-iidxio/main.c index 1d26d01..179e89b 100644 --- a/src/main/vigem-iidxio/main.c +++ b/src/main/vigem-iidxio/main.c @@ -7,8 +7,10 @@ #include +#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);