diff --git a/Module.mk b/Module.mk index ba4c12a..1beca4b 100644 --- a/Module.mk +++ b/Module.mk @@ -682,6 +682,7 @@ $(zipdir)/sdvx-hwio-x86.zip: \ dist/sdvx/eamio-icca.xml \ dist/sdvx/sdvxio-bio2.xml \ dist/sdvx/sdvxio-kfca.xml \ + dist/sdvx/vigem-sdvxio.xml \ | $(zipdir)/ $(V)echo ... $@ $(V)zip -j $@ $^ @@ -695,6 +696,7 @@ $(zipdir)/sdvx-hwio-x64.zip: \ dist/sdvx/eamio-icca.xml \ dist/sdvx/sdvxio-bio2.xml \ dist/sdvx/sdvxio-kfca.xml \ + dist/sdvx/vigem-sdvxio.xml \ | $(zipdir)/ $(V)echo ... $@ $(V)zip -j $@ $^ diff --git a/dist/sdvx/vigem-sdvxio.xml b/dist/sdvx/vigem-sdvxio.xml new file mode 100644 index 0000000..0e99984 --- /dev/null +++ b/dist/sdvx/vigem-sdvxio.xml @@ -0,0 +1,8 @@ + + + 1 + 0 + 128 + 64 + 48 + \ No newline at end of file diff --git a/src/main/vigem-sdvxio/Module.mk b/src/main/vigem-sdvxio/Module.mk index 7c3e08e..d06fc68 100644 --- a/src/main/vigem-sdvxio/Module.mk +++ b/src/main/vigem-sdvxio/Module.mk @@ -8,17 +8,18 @@ cppflags_vigem-sdvxio := \ ldflags_vigem-sdvxio := \ -lsetupapi \ + -lws2_32 \ libs_vigem-sdvxio := \ core \ - cconfig \ - util \ vigemstub \ module \ iface \ iface-io \ iface-core \ + security \ + util \ src_vigem-sdvxio := \ + config.c \ main.c \ - config-vigem-sdvxio.c \ diff --git a/src/main/vigem-sdvxio/config-vigem-sdvxio.c b/src/main/vigem-sdvxio/config-vigem-sdvxio.c deleted file mode 100644 index 7cc3233..0000000 --- a/src/main/vigem-sdvxio/config-vigem-sdvxio.c +++ /dev/null @@ -1,149 +0,0 @@ -#include "cconfig/cconfig-main.h" -#include "cconfig/cconfig-util.h" - -#include "iface-core/log.h" - -#include "vigem-sdvxio/config-vigem-sdvxio.h" - -#define VIGEM_SDVXIO_CONFIG_ENABLE_KEYLIGHT_KEY "sdvxio.enable_keylight" -#define VIGEM_SDVXIO_CONFIG_RELATIVE_ANALOG_KEY "sdvxio.use_relative_analog" -#define VIGEM_SDVXIO_CONFIG_PWM_WINGS_KEY "sdvxio.pwm_wings" -#define VIGEM_SDVXIO_CONFIG_PWM_CONTROLLER_KEY "sdvxio.pwm_controller" -#define VIGEM_SDVXIO_CONFIG_AMP_VOLUME_KEY "sdvxio.amp_volume" - -#define VIGEM_SDVXIO_CONFIG_DEFAULT_ENABLE_KEYLIGHT_VALUE true -#define VIGEM_SDVXIO_CONFIG_DEFAULT_RELATIVE_ANALOG_VALUE false -#define VIGEM_SDVXIO_CONFIG_DEFAULT_PWM_WINGS_VALUE 128 -#define VIGEM_SDVXIO_CONFIG_DEFAULT_PWM_CONTROLLER_VALUE 64 -#define VIGEM_SDVXIO_CONFIG_DEFAULT_AMP_VOLUME_VALUE 48 - -static void vigem_sdvxio_config_init(struct cconfig *config) -{ - cconfig_util_set_bool( - config, - VIGEM_SDVXIO_CONFIG_ENABLE_KEYLIGHT_KEY, - VIGEM_SDVXIO_CONFIG_DEFAULT_ENABLE_KEYLIGHT_VALUE, - "Enable input based key lighting"); - - cconfig_util_set_bool( - config, - VIGEM_SDVXIO_CONFIG_RELATIVE_ANALOG_KEY, - VIGEM_SDVXIO_CONFIG_DEFAULT_RELATIVE_ANALOG_VALUE, - "Use relative mode analog mapping"); - - cconfig_util_set_int( - config, - VIGEM_SDVXIO_CONFIG_PWM_WINGS_KEY, - VIGEM_SDVXIO_CONFIG_DEFAULT_PWM_WINGS_VALUE, - "Brightness to set wings to (0-255)"); - - cconfig_util_set_int( - config, - VIGEM_SDVXIO_CONFIG_PWM_CONTROLLER_KEY, - VIGEM_SDVXIO_CONFIG_DEFAULT_PWM_CONTROLLER_VALUE, - "Brightness to set control deck to (0-255)"); - - cconfig_util_set_int( - config, - VIGEM_SDVXIO_CONFIG_AMP_VOLUME_KEY, - VIGEM_SDVXIO_CONFIG_DEFAULT_AMP_VOLUME_VALUE, - "SDVXIO digital amp volume (0-96) 0 is high, 96 is low."); -} - -static void vigem_sdvxio_config_get( - struct vigem_sdvxio_config *vigem_config, struct cconfig *config) -{ - if (!cconfig_util_get_bool( - config, - VIGEM_SDVXIO_CONFIG_ENABLE_KEYLIGHT_KEY, - &vigem_config->enable_keylight, - VIGEM_SDVXIO_CONFIG_DEFAULT_ENABLE_KEYLIGHT_VALUE)) { - log_warning( - "Invalid value for key '%s' specified, fallback " - "to default '%d'", - VIGEM_SDVXIO_CONFIG_ENABLE_KEYLIGHT_KEY, - VIGEM_SDVXIO_CONFIG_DEFAULT_ENABLE_KEYLIGHT_VALUE); - } - - if (!cconfig_util_get_bool( - config, - VIGEM_SDVXIO_CONFIG_RELATIVE_ANALOG_KEY, - &vigem_config->relative_analog, - VIGEM_SDVXIO_CONFIG_DEFAULT_RELATIVE_ANALOG_VALUE)) { - log_warning( - "Invalid value for key '%s' specified, fallback " - "to default '%d'", - VIGEM_SDVXIO_CONFIG_RELATIVE_ANALOG_KEY, - VIGEM_SDVXIO_CONFIG_DEFAULT_RELATIVE_ANALOG_VALUE); - } - - if (!cconfig_util_get_int( - config, - VIGEM_SDVXIO_CONFIG_PWM_WINGS_KEY, - &vigem_config->pwm_wings, - VIGEM_SDVXIO_CONFIG_DEFAULT_PWM_WINGS_VALUE)) { - log_warning( - "Invalid value for key '%s' specified, fallback " - "to default '%d'", - VIGEM_SDVXIO_CONFIG_PWM_WINGS_KEY, - VIGEM_SDVXIO_CONFIG_DEFAULT_PWM_WINGS_VALUE); - } - - if (!cconfig_util_get_int( - config, - VIGEM_SDVXIO_CONFIG_PWM_CONTROLLER_KEY, - &vigem_config->pwm_controller, - VIGEM_SDVXIO_CONFIG_DEFAULT_PWM_CONTROLLER_VALUE)) { - log_warning( - "Invalid value for key '%s' specified, fallback " - "to default '%d'", - VIGEM_SDVXIO_CONFIG_PWM_CONTROLLER_KEY, - VIGEM_SDVXIO_CONFIG_DEFAULT_PWM_CONTROLLER_VALUE); - } - - if (!cconfig_util_get_int( - config, - VIGEM_SDVXIO_CONFIG_AMP_VOLUME_KEY, - &vigem_config->amp_volume, - VIGEM_SDVXIO_CONFIG_DEFAULT_AMP_VOLUME_VALUE)) { - log_warning( - "Invalid value for key '%s' specified, fallback " - "to default '%d'", - VIGEM_SDVXIO_CONFIG_AMP_VOLUME_KEY, - VIGEM_SDVXIO_CONFIG_DEFAULT_AMP_VOLUME_VALUE); - } -} - -bool get_vigem_sdvxio_config(struct vigem_sdvxio_config *config_out) -{ - struct cconfig *config; - - config = cconfig_init(); - - vigem_sdvxio_config_init(config); - - if (!cconfig_main_config_init( - config, - "--config", - "vigem-sdvxio.conf", - "--help", - "-h", - "vigem-sdvxio", - CCONFIG_CMD_USAGE_OUT_STDOUT)) { - cconfig_finit(config); - return false; - } - - vigem_sdvxio_config_get(config_out, config); - - cconfig_finit(config); - - if (config_out->pwm_controller > 255) { - config_out->pwm_controller = 255; - } - - if (config_out->pwm_wings > 255) { - config_out->pwm_wings = 255; - } - return true; -} diff --git a/src/main/vigem-sdvxio/config-vigem-sdvxio.h b/src/main/vigem-sdvxio/config-vigem-sdvxio.h deleted file mode 100644 index b689735..0000000 --- a/src/main/vigem-sdvxio/config-vigem-sdvxio.h +++ /dev/null @@ -1,18 +0,0 @@ -#ifndef VIGEM_SDVXIO_CONFIG_H -#define VIGEM_SDVXIO_CONFIG_H - -#include - -#include "cconfig/cconfig.h" - -struct vigem_sdvxio_config { - bool enable_keylight; - bool relative_analog; - int32_t pwm_wings; - int32_t pwm_controller; - int32_t amp_volume; -}; - -bool get_vigem_sdvxio_config(struct vigem_sdvxio_config *config_out); - -#endif \ No newline at end of file diff --git a/src/main/vigem-sdvxio/config.c b/src/main/vigem-sdvxio/config.c new file mode 100644 index 0000000..6b59f62 --- /dev/null +++ b/src/main/vigem-sdvxio/config.c @@ -0,0 +1,14 @@ +#include "core/config-ext.h" + +#include "vigem-sdvxio/config.h" + +void vigem_sdvxio_config_get( + const bt_core_config_t *config, + vigem_sdvxio_config_t *config_out) +{ + bt_core_config_ext_bool_get(config, "enable_keylight", &config_out->enable_keylight); + bt_core_config_ext_bool_get(config, "use_relative_analog", &config_out->relative_analog); + bt_core_config_ext_s32_get(config, "pwm_wings", &config_out->pwm_wings); + bt_core_config_ext_s32_get(config, "pwm_controller", &config_out->pwm_controller); + bt_core_config_ext_s32_get(config, "amp_volume", &config_out->amp_volume); +} \ No newline at end of file diff --git a/src/main/vigem-sdvxio/config.h b/src/main/vigem-sdvxio/config.h new file mode 100644 index 0000000..eebe5b8 --- /dev/null +++ b/src/main/vigem-sdvxio/config.h @@ -0,0 +1,21 @@ +#ifndef VIGEM_SDVXIO_CONFIG_H +#define VIGEM_SDVXIO_CONFIG_H + +#include +#include + +#include "api/core/config.h" + +typedef struct vigem_sdvxio_config { + bool enable_keylight; + bool relative_analog; + int32_t pwm_wings; + int32_t pwm_controller; + int32_t amp_volume; +} vigem_sdvxio_config_t; + +void vigem_sdvxio_config_get( + const bt_core_config_t *config, + vigem_sdvxio_config_t *config_out); + +#endif \ No newline at end of file diff --git a/src/main/vigem-sdvxio/main.c b/src/main/vigem-sdvxio/main.c index b578c1b..2c92461 100644 --- a/src/main/vigem-sdvxio/main.c +++ b/src/main/vigem-sdvxio/main.c @@ -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" @@ -23,7 +25,7 @@ #include "vigemstub/helper.h" -#include "vigem-sdvxio/config-vigem-sdvxio.h" +#include "vigem-sdvxio/config.h" #define ANALOG_FIXED_SENSITIVITY 1024 @@ -149,17 +151,39 @@ static void _io_sdvx_init(module_io_t **module) bt_io_sdvx_api_set(&api); } +static void _config_load(vigem_sdvxio_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-sdvxio.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_sdvxio_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_sdvxio_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_sdvxio_config config; - if (!get_vigem_sdvxio_config(&config)) { - exit(EXIT_FAILURE); - } + _config_load(&config); _io_sdvx_init(&_module_io_sdvx);