From d1c346595c93d833327bc332498995c9543d4b3b Mon Sep 17 00:00:00 2001 From: icex2 Date: Sat, 17 Aug 2024 12:50:14 +0200 Subject: [PATCH] refact(iidxio-bio2): Use new config api Summary: Test Plan: Summary: Test Plan: --- Module.mk | 4 +- dist/iidx/iidxio-bio2.conf | 8 --- dist/iidx/iidxio-bio2.xml | 6 +++ src/main/bio2drv/Module.mk | 2 +- src/main/bio2drv/config-bio2.c | 75 ---------------------------- src/main/bio2drv/config-bio2.h | 19 ------- src/main/bio2drv/config.c | 11 ++++ src/main/bio2drv/config.h | 15 ++++++ src/main/iidxio-bio2/Module.mk | 3 +- src/main/iidxio-bio2/iidxio-bio2.def | 3 +- src/main/iidxio-bio2/iidxio.c | 51 ++++++++----------- 11 files changed, 61 insertions(+), 136 deletions(-) delete mode 100644 dist/iidx/iidxio-bio2.conf create mode 100644 dist/iidx/iidxio-bio2.xml delete mode 100644 src/main/bio2drv/config-bio2.c delete mode 100644 src/main/bio2drv/config-bio2.h create mode 100644 src/main/bio2drv/config.c create mode 100644 src/main/bio2drv/config.h diff --git a/Module.mk b/Module.mk index 2594f34..4301af7 100644 --- a/Module.mk +++ b/Module.mk @@ -495,7 +495,7 @@ $(zipdir)/iidx-hwio-x86.zip: \ build/bin/indep-32/iidxio-ezusb2.dll \ build/bin/indep-32/vigem-iidxio.exe \ dist/iidx/eamio-icca.xml \ - dist/iidx/iidxio-bio2.conf \ + dist/iidx/iidxio-bio2.xml \ dist/iidx/vigem-iidxio.conf \ | $(zipdir)/ $(V)echo ... $@ @@ -509,7 +509,7 @@ $(zipdir)/iidx-hwio-x64.zip: \ build/bin/indep-64/iidxio-ezusb2.dll \ build/bin/indep-64/vigem-iidxio.exe \ dist/iidx/eamio-icca.xml \ - dist/iidx/iidxio-bio2.conf \ + dist/iidx/iidxio-bio2.xml \ dist/iidx/vigem-iidxio.conf \ | $(zipdir)/ $(V)echo ... $@ diff --git a/dist/iidx/iidxio-bio2.conf b/dist/iidx/iidxio-bio2.conf deleted file mode 100644 index 4b42af0..0000000 --- a/dist/iidx/iidxio-bio2.conf +++ /dev/null @@ -1,8 +0,0 @@ -# Autodetect BIO2 port (default: on) -bio2.autodetect=true - -# BIO2 serial port. Optional, if autodetect property is turned on -bio2.port=COM4 - -# BIO2 bus baudrate (real devices expect 115200) -bio2.baud=115200 \ No newline at end of file diff --git a/dist/iidx/iidxio-bio2.xml b/dist/iidx/iidxio-bio2.xml new file mode 100644 index 0000000..8014568 --- /dev/null +++ b/dist/iidx/iidxio-bio2.xml @@ -0,0 +1,6 @@ + + + 1 + COM4 + 115200 + \ No newline at end of file diff --git a/src/main/bio2drv/Module.mk b/src/main/bio2drv/Module.mk index 9e5e92b..2da24e1 100644 --- a/src/main/bio2drv/Module.mk +++ b/src/main/bio2drv/Module.mk @@ -5,7 +5,7 @@ libs_bio2drv := \ aciodrv \ src_bio2drv := \ + config.c \ detect.c \ - config-bio2.c \ bi2a-iidx.c \ bi2a-sdvx.c \ diff --git a/src/main/bio2drv/config-bio2.c b/src/main/bio2drv/config-bio2.c deleted file mode 100644 index f166476..0000000 --- a/src/main/bio2drv/config-bio2.c +++ /dev/null @@ -1,75 +0,0 @@ -#include "bio2drv/config-bio2.h" - -#include "cconfig/cconfig-util.h" - -#include "iface-core/log.h" - -#define BIO2DRV_CONFIG_BIO2_AUTO_KEY "bio2.autodetect" -#define BIO2DRV_CONFIG_BIO2_PORT_KEY "bio2.port" -#define BIO2DRV_CONFIG_BIO2_BAUD_KEY "bio2.baud" - -#define BIO2DRV_CONFIG_BIO2_DEFAULT_AUTO_VALUE true -#define BIO2DRV_CONFIG_BIO2_DEFAULT_PORT_VALUE "COM4" -#define BIO2DRV_CONFIG_BIO2_DEFAULT_BAUD_VALUE 115200 - -void bio2drv_config_bio2_init(struct cconfig *config) -{ - cconfig_util_set_bool( - config, - BIO2DRV_CONFIG_BIO2_AUTO_KEY, - BIO2DRV_CONFIG_BIO2_DEFAULT_AUTO_VALUE, - "Autodetect BIO2 port (default: on)"); - - cconfig_util_set_str( - config, - BIO2DRV_CONFIG_BIO2_PORT_KEY, - BIO2DRV_CONFIG_BIO2_DEFAULT_PORT_VALUE, - "BIO2 serial port. Optional, if autodetect property is turned on"); - - cconfig_util_set_int( - config, - BIO2DRV_CONFIG_BIO2_BAUD_KEY, - BIO2DRV_CONFIG_BIO2_DEFAULT_BAUD_VALUE, - "BIO2 bus baudrate (real devices expect 115200)"); -} - -void bio2drv_config_bio2_get( - struct bio2drv_config_bio2 *config_bio2, struct cconfig *config) -{ - if (!cconfig_util_get_bool( - config, - BIO2DRV_CONFIG_BIO2_AUTO_KEY, - &config_bio2->autodetect, - BIO2DRV_CONFIG_BIO2_DEFAULT_AUTO_VALUE)) { - log_warning( - "Invalid value for key '%s' specified, fallback " - "to default '%d'", - BIO2DRV_CONFIG_BIO2_AUTO_KEY, - BIO2DRV_CONFIG_BIO2_DEFAULT_AUTO_VALUE); - } - - if (!cconfig_util_get_str( - config, - BIO2DRV_CONFIG_BIO2_PORT_KEY, - config_bio2->port, - sizeof(config_bio2->port) - 1, - BIO2DRV_CONFIG_BIO2_DEFAULT_PORT_VALUE)) { - log_warning( - "Invalid value for key '%s' specified, fallback " - "to default '%s'", - BIO2DRV_CONFIG_BIO2_PORT_KEY, - BIO2DRV_CONFIG_BIO2_DEFAULT_PORT_VALUE); - } - - if (!cconfig_util_get_int( - config, - BIO2DRV_CONFIG_BIO2_BAUD_KEY, - &config_bio2->baud, - BIO2DRV_CONFIG_BIO2_DEFAULT_BAUD_VALUE)) { - log_warning( - "Invalid value for key '%s' specified, fallback " - "to default '%d'", - BIO2DRV_CONFIG_BIO2_BAUD_KEY, - BIO2DRV_CONFIG_BIO2_DEFAULT_BAUD_VALUE); - } -} diff --git a/src/main/bio2drv/config-bio2.h b/src/main/bio2drv/config-bio2.h deleted file mode 100644 index a626e86..0000000 --- a/src/main/bio2drv/config-bio2.h +++ /dev/null @@ -1,19 +0,0 @@ -#ifndef BIO2DRV_CONFIG_BIO2_H -#define BIO2DRV_CONFIG_BIO2_H - -#include - -#include "cconfig/cconfig.h" - -struct bio2drv_config_bio2 { - bool autodetect; - char port[64]; - int32_t baud; -}; - -void bio2drv_config_bio2_init(struct cconfig *config); - -void bio2drv_config_bio2_get( - struct bio2drv_config_bio2 *config_bio2, struct cconfig *config); - -#endif diff --git a/src/main/bio2drv/config.c b/src/main/bio2drv/config.c new file mode 100644 index 0000000..8782cb6 --- /dev/null +++ b/src/main/bio2drv/config.c @@ -0,0 +1,11 @@ +#include "bio2drv/config.h" + +#include "core/config-ext.h" + +void bio2drv_config_bio2_get( + const bt_core_config_t *config, bio2drv_config_t *config_out) +{ + bt_core_config_ext_bool_get(config, "autodetect", &config_out->autodetect); + bt_core_config_ext_str_get(config, "port", config_out->port, sizeof(config_out->port)); + bt_core_config_ext_s32_get(config, "baud", &config_out->baud); +} \ No newline at end of file diff --git a/src/main/bio2drv/config.h b/src/main/bio2drv/config.h new file mode 100644 index 0000000..b229e28 --- /dev/null +++ b/src/main/bio2drv/config.h @@ -0,0 +1,15 @@ +#ifndef BIO2DRV_CONFIG_BIO2_H +#define BIO2DRV_CONFIG_BIO2_H + +#include "api/core/config.h" + +typedef struct bio2drv_config { + bool autodetect; + char port[64]; + int32_t baud; +} bio2drv_config_t; + +void bio2drv_config_bio2_get( + const bt_core_config_t *config, bio2drv_config_t *config_out); + +#endif diff --git a/src/main/iidxio-bio2/Module.mk b/src/main/iidxio-bio2/Module.mk index c374a13..e03d04b 100644 --- a/src/main/iidxio-bio2/Module.mk +++ b/src/main/iidxio-bio2/Module.mk @@ -2,17 +2,18 @@ dlls += iidxio-bio2 ldflags_iidxio-bio2 := \ -lsetupapi \ + -lws2_32 \ libs_iidxio-bio2 := \ core \ aciodrv \ bio2drv \ - cconfig \ util \ iface \ module \ iface-io \ iface-core \ + security \ src_iidxio-bio2 := \ iidxio.c \ diff --git a/src/main/iidxio-bio2/iidxio-bio2.def b/src/main/iidxio-bio2/iidxio-bio2.def index 848c574..c34605f 100644 --- a/src/main/iidxio-bio2/iidxio-bio2.def +++ b/src/main/iidxio-bio2/iidxio-bio2.def @@ -2,8 +2,9 @@ LIBRARY iidxio EXPORTS ; Bemanitools 6 API + bt_module_core_config_api_set bt_module_core_log_api_set - bt_module_core_thread_api_set + bt_module_configure_do bt_module_io_iidx_api_get ; Direct API diff --git a/src/main/iidxio-bio2/iidxio.c b/src/main/iidxio-bio2/iidxio.c index f1dbb63..e885c0d 100644 --- a/src/main/iidxio-bio2/iidxio.c +++ b/src/main/iidxio-bio2/iidxio.c @@ -10,22 +10,26 @@ #include "aciodrv/device.h" +#include "api/core/config.h" #include "api/core/log.h" #include "api/core/thread.h" #include "bio2drv/bi2a-iidx.h" -#include "bio2drv/config-bio2.h" +#include "bio2drv/config.h" #include "bio2drv/detect.h" +#include "iface-core/config.h" #include "iface-core/log.h" #include "iface-core/thread.h" -#include "cconfig/cconfig-main.h" - +#include "sdk/module/core/config.h" +#include "sdk/module/configure.h" #include "sdk/module/core/log.h" #include "sdk/module/core/thread.h" #include "sdk/module/io/iidx.h" +static bio2drv_config_t _iidxio_bio2_config; + static char autodetect_buffer[512]; static atomic_bool running; @@ -61,32 +65,9 @@ static bool _bio2_iidx_io_poll( bool bt_io_iidx_init() { - struct cconfig *config; - struct bio2drv_config_bio2 config_bio2; + const char *selected_port = _iidxio_bio2_config.port; - config = cconfig_init(); - - bio2drv_config_bio2_init(config); - - if (!cconfig_main_config_init( - config, - "--bio2-config", - "iidxio-bio2.conf", - "--help", - "-h", - "iidxio-bio2", - CCONFIG_CMD_USAGE_OUT_STDOUT)) { - cconfig_finit(config); - exit(EXIT_FAILURE); - } - - bio2drv_config_bio2_get(&config_bio2, config); - - cconfig_finit(config); - - const char *selected_port = config_bio2.port; - - if (config_bio2.autodetect) { + if (_iidxio_bio2_config.autodetect) { log_info("Attempting autodetect"); if (bio2drv_detect( @@ -101,7 +82,7 @@ bool bt_io_iidx_init() } // BIO2's cannot share a bus with anything else, so use device directly - bio2_device_ctx = aciodrv_device_open_path(selected_port, config_bio2.baud); + bio2_device_ctx = aciodrv_device_open_path(selected_port, _iidxio_bio2_config.baud); if (bio2_device_ctx == NULL) { log_info("Opening BIO2 device on [%s] failed", selected_port); @@ -344,6 +325,11 @@ bool bt_io_iidx_ep3_16seg_send(const char *text) return true; } +void bt_module_core_config_api_set(const bt_core_config_api_t *api) +{ + bt_core_config_api_set(api); +} + void bt_module_core_log_api_set(const bt_core_log_api_t *api) { bt_core_log_api_set(api); @@ -354,6 +340,13 @@ void bt_module_core_thread_api_set(const bt_core_thread_api_t *api) bt_core_thread_api_set(api); } +bool bt_module_configure_do(const bt_core_config_t *config) +{ + bio2drv_config_bio2_get(config, &_iidxio_bio2_config); + + return true; +} + void bt_module_io_iidx_api_get(bt_io_iidx_api_t *api) { api->version = 1;