feat(vigem-sdvxio): Use new config api

Summary:

Test Plan:
This commit is contained in:
icex2
2024-08-17 12:51:00 +02:00
parent d98311762b
commit 04603a9591
8 changed files with 79 additions and 176 deletions

View File

@@ -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 $@ $^

8
dist/sdvx/vigem-sdvxio.xml vendored Normal file
View File

@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="Shift-JIS"?>
<vigem-sdvxio>
<enable_keylight __type="bool">1</enable_keylight>
<use_relative_analog __type="bool">0</use_relative_analog>
<pwm_wings __type="s32">128</pwm_wings>
<pwm_controller __type="s32">64</pwm_controller>
<amp_volume __type="s32">48</amp_volume>
</vigem-sdvxio>

View File

@@ -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 \

View File

@@ -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;
}

View File

@@ -1,18 +0,0 @@
#ifndef VIGEM_SDVXIO_CONFIG_H
#define VIGEM_SDVXIO_CONFIG_H
#include <windows.h>
#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

View File

@@ -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);
}

View File

@@ -0,0 +1,21 @@
#ifndef VIGEM_SDVXIO_CONFIG_H
#define VIGEM_SDVXIO_CONFIG_H
#include <stdbool.h>
#include <stdint.h>
#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

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"
@@ -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);