feat(jbio-h44b): Use new config api

Summary:

Test Plan:
Summary:

Test Plan:
This commit is contained in:
icex2 2024-08-17 12:51:00 +02:00
parent f9f930112d
commit 3008a1410d
8 changed files with 47 additions and 96 deletions

View File

@ -616,7 +616,7 @@ $(zipdir)/jb-hwio.zip: \
build/bin/indep-32/eamio-icca.dll \
build/bin/indep-32/jbio-magicbox.dll \
build/bin/indep-32/jbio-p4io.dll \
dist/jb/jbio-h44b.conf \
dist/jb/jbio-h44b.xml \
dist/jb/eamio-icca.xml \
| $(zipdir)/
$(V)echo ... $@

View File

@ -1,5 +0,0 @@
# H44B serial port
h44b.port=COM2
# H44B bus baudrate (real devices expect 57600)
h44b.baud=57600

7
dist/jb/jbio-h44b.xml vendored Normal file
View File

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="Shift-JIS"?>
<jbio-h44b>
<!-- H44B serial port -->
<port __type="str">COM2</port>
<!-- H44B bus baudrate (real devices expect 57600) -->
<baud __type="s32">57600</baud>
</jbio-h44b>

View File

@ -1,19 +1,21 @@
dlls += jbio-p4io
ldflags_jbio-p4io := \
-lsetupapi
src_jbio-p4io := \
config-h44b.c \
h44b.c \
jbio.c \
-lsetupapi \
-lws2_32 \
libs_jbio-p4io := \
core \
aciodrv \
cconfig \
p4iodrv \
util \
iface \
module \
iface-core \
iface-acio \
security \
src_jbio-p4io := \
config-h44b.c \
h44b.c \
jbio.c \

View File

@ -1,55 +1,11 @@
#include "cconfig/cconfig-util.h"
#include "iface-core/log.h"
#include "core/config-ext.h"
#include "jbio-p4io/config-h44b.h"
#define JBIO_CONFIG_H44B_PORT_KEY "h44b.port"
#define JBIO_CONFIG_H44B_BAUD_KEY "h44b.baud"
#define JBIO_CONFIG_H44B_DEFAULT_PORT_VALUE "COM2"
#define JBIO_CONFIG_H44B_DEFAULT_BAUD_VALUE 57600
void jbio_config_h44b_init(struct cconfig *config)
{
cconfig_util_set_str(
config,
JBIO_CONFIG_H44B_PORT_KEY,
JBIO_CONFIG_H44B_DEFAULT_PORT_VALUE,
"H44B serial port");
cconfig_util_set_int(
config,
JBIO_CONFIG_H44B_BAUD_KEY,
JBIO_CONFIG_H44B_DEFAULT_BAUD_VALUE,
"H44B bus baudrate (real devices expect 57600)");
}
void jbio_config_h44b_get(
struct h44b_config *config_h44b, struct cconfig *config)
const bt_core_config_t *config,
h44b_config_t *config_out)
{
if (!cconfig_util_get_str(
config,
JBIO_CONFIG_H44B_PORT_KEY,
config_h44b->port,
sizeof(config_h44b->port) - 1,
JBIO_CONFIG_H44B_DEFAULT_PORT_VALUE)) {
log_warning(
"Invalid value for key '%s' specified, fallback "
"to default '%s'",
JBIO_CONFIG_H44B_PORT_KEY,
JBIO_CONFIG_H44B_DEFAULT_PORT_VALUE);
}
if (!cconfig_util_get_int(
config,
JBIO_CONFIG_H44B_BAUD_KEY,
&config_h44b->baud,
JBIO_CONFIG_H44B_DEFAULT_BAUD_VALUE)) {
log_warning(
"Invalid value for key '%s' specified, fallback "
"to default '%d'",
JBIO_CONFIG_H44B_BAUD_KEY,
JBIO_CONFIG_H44B_DEFAULT_BAUD_VALUE);
}
bt_core_config_str_get(config, "h44b/port", config_out->port, sizeof(config_out->port));
bt_core_config_s32_get(config, "h44b/baud", &config_out->baud);
}

View File

@ -1,18 +1,15 @@
#ifndef JBIO_CONFIG_H44B_H
#define JBIO_CONFIG_H44B_H
#include <windows.h>
#include "api/core/config.h"
#include "cconfig/cconfig.h"
struct h44b_config {
typedef struct h44b_config {
char port[64];
int32_t baud;
};
void jbio_config_h44b_init(struct cconfig *config);
} h44b_config_t;
void jbio_config_h44b_get(
struct h44b_config *config_h44b, struct cconfig *config);
const bt_core_config_t *config,
h44b_config_t *config_out);
#endif

View File

@ -2,7 +2,9 @@ LIBRARY jbio
EXPORTS
; Bemanitools 6 API
bt_module_core_config_api_set
bt_module_core_log_api_set
bt_module_configure_do
bt_module_io_jb_api_get
; Direct API

View File

@ -9,9 +9,8 @@
#include "api/core/log.h"
#include "cconfig/cconfig-main.h"
#include "iface-acio/mgr.h"
#include "iface-core/config.h"
#include "iface-core/log.h"
#include "jbio-p4io/config-h44b.h"
@ -21,9 +20,13 @@
#include "p4iodrv/device.h"
#include "sdk/module/core/config.h"
#include "sdk/module/configure.h"
#include "sdk/module/core/log.h"
#include "sdk/module/io/jb.h"
static h44b_config_t _jbio_p4io_config_h44b;
static struct p4iodrv_ctx *p4io_ctx;
static uint16_t jb_io_panels;
static uint8_t jb_io_sys_buttons;
@ -47,29 +50,6 @@ static void _bt_io_jb_module_acio_mgr_init(module_acio_mgr_t **module)
bool bt_io_jb_init()
{
struct cconfig *config;
struct h44b_config config_h44b;
config = cconfig_init();
jbio_config_h44b_init(config);
if (!cconfig_main_config_init(
config,
"--h44b-config",
"jbio-h44b.conf",
"--help",
"-h",
"jbio-h44b",
CCONFIG_CMD_USAGE_OUT_STDOUT)) {
cconfig_finit(config);
exit(EXIT_FAILURE);
}
jbio_config_h44b_get(&config_h44b, config);
cconfig_finit(config);
_bt_io_jb_module_acio_mgr_init(&acio_mgr_module);
p4io_ctx = p4iodrv_open();
@ -79,7 +59,7 @@ bool bt_io_jb_init()
// some people use p4io just for acio_mgrs and have no lights. Soft fail
// when h44b is not able to be connected instead of returning false
lights_present = jb_io_h44b_init(config_h44b.port, config_h44b.baud);
lights_present = jb_io_h44b_init(_jbio_p4io_config_h44b.port, _jbio_p4io_config_h44b.baud);
if (!lights_present) {
log_warning("Could not connect to H44B, lights disabled");
}
@ -239,11 +219,23 @@ bool bt_io_jb_coin_blocker_set(bool blocked)
return p4iodrv_cmd_coinstock(p4io_ctx, coin);
}
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);
}
bool bt_module_configure_do(const bt_core_config_t *config)
{
jbio_config_h44b_get(config, &_jbio_p4io_config_h44b);
return true;
}
void bt_module_io_jb_api_get(bt_io_jb_api_t *api)
{
api->version = 1;