Add jbio-magicbox.dll
This commit is contained in:
@@ -0,0 +1,11 @@
|
||||
dlls += jbio-magicbox
|
||||
imps += ch341
|
||||
|
||||
deplibs_jbio-magicbox := \
|
||||
ch341 \
|
||||
|
||||
src_jbio-magicbox := \
|
||||
jbio.c \
|
||||
|
||||
libs_jbio-magicbox := \
|
||||
util \
|
||||
@@ -0,0 +1,11 @@
|
||||
LIBRARY jbio
|
||||
|
||||
EXPORTS
|
||||
jb_io_fini
|
||||
jb_io_get_panel_inputs
|
||||
jb_io_get_sys_inputs
|
||||
jb_io_init
|
||||
jb_io_read_inputs
|
||||
jb_io_set_loggers
|
||||
jb_io_set_rgb_led
|
||||
jb_io_write_outputs
|
||||
@@ -0,0 +1,139 @@
|
||||
// This implementation is ported from the device.dll source graciously
|
||||
// provided by zyp
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
#include "bemanitools/jbio.h"
|
||||
#include "imports/ch341.h"
|
||||
#include "util/defs.h"
|
||||
|
||||
static uint16_t jb_io_panels;
|
||||
static uint8_t jb_io_sys_buttons;
|
||||
|
||||
static bool is_initialized = false;
|
||||
|
||||
log_formatter_t jb_io_log_misc;
|
||||
log_formatter_t jb_io_log_info;
|
||||
log_formatter_t jb_io_log_warning;
|
||||
log_formatter_t jb_io_log_fatal;
|
||||
|
||||
void jb_io_set_loggers(
|
||||
log_formatter_t misc,
|
||||
log_formatter_t info,
|
||||
log_formatter_t warning,
|
||||
log_formatter_t fatal)
|
||||
{
|
||||
jb_io_log_misc = misc;
|
||||
jb_io_log_info = info;
|
||||
jb_io_log_warning = warning;
|
||||
jb_io_log_fatal = fatal;
|
||||
}
|
||||
|
||||
bool jb_io_init(
|
||||
thread_create_t thread_create,
|
||||
thread_join_t thread_join,
|
||||
thread_destroy_t thread_destroy)
|
||||
{
|
||||
if(CH341OpenDevice(0) < 0) {
|
||||
jb_io_log_warning("jbio", "Can't open CH341 device.\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
is_initialized = true;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void jb_io_fini(void)
|
||||
{
|
||||
CH341CloseDevice(0);
|
||||
}
|
||||
|
||||
static const uint32_t magic_panel_mappings[] = {
|
||||
(1 << 0x08),
|
||||
(1 << 0x0a),
|
||||
(1 << 0x0c),
|
||||
(1 << 0x0e),
|
||||
(1 << 0x07),
|
||||
(1 << 0x05),
|
||||
(1 << 0x03),
|
||||
(1 << 0x01),
|
||||
(1 << 0x09),
|
||||
(1 << 0x0b),
|
||||
(1 << 0x0d),
|
||||
(1 << 0x0f),
|
||||
(1 << 0x06),
|
||||
(1 << 0x04),
|
||||
(1 << 0x02),
|
||||
(1 << 0x00),
|
||||
};
|
||||
|
||||
static const uint32_t magic_sys_mappings[] = {
|
||||
(1 << 0x11), // TEST
|
||||
(1 << 0x10), // SERVICE
|
||||
(1 << 0x13), // COIN
|
||||
};
|
||||
|
||||
bool jb_io_read_inputs(void)
|
||||
{
|
||||
// Read IO board
|
||||
unsigned long n;
|
||||
union {
|
||||
uint32_t dword;
|
||||
uint8_t bytes[4];
|
||||
} input;
|
||||
|
||||
input.dword = -1;
|
||||
jb_io_panels = 0;
|
||||
jb_io_sys_buttons = 0;
|
||||
|
||||
CH341EppSetAddr(0, 255);
|
||||
CH341EppSetAddr(0, 1);
|
||||
CH341EppSetAddr(0, 255);
|
||||
CH341EppSetAddr(0, 0);
|
||||
n = 1;
|
||||
CH341EppReadData(0, &input.bytes[0], &n);
|
||||
CH341EppSetAddr(0, 255);
|
||||
CH341EppSetAddr(0, 0);
|
||||
n = 1;
|
||||
CH341EppReadData(0, &input.bytes[1], &n);
|
||||
CH341EppSetAddr(0, 255);
|
||||
CH341EppSetAddr(0, 0);
|
||||
n = 1;
|
||||
CH341EppReadData(0, &input.bytes[2], &n);
|
||||
CH341EppSetAddr(0, 255);
|
||||
|
||||
for (uint8_t i = 0; i < lengthof(magic_panel_mappings); i++) {
|
||||
if((input.dword & magic_panel_mappings[i]) == 0) {
|
||||
jb_io_panels |= 1 << i;
|
||||
}
|
||||
}
|
||||
for (uint8_t i = 0; i < lengthof(magic_sys_mappings); i++) {
|
||||
if((input.dword & magic_sys_mappings[i]) == 0) {
|
||||
jb_io_sys_buttons |= 1 << i;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool jb_io_write_outputs(void)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
uint8_t jb_io_get_sys_inputs(void)
|
||||
{
|
||||
return jb_io_sys_buttons;
|
||||
}
|
||||
|
||||
uint16_t jb_io_get_panel_inputs(void)
|
||||
{
|
||||
return jb_io_panels;
|
||||
}
|
||||
|
||||
void jb_io_set_rgb_led(enum jb_io_rgb_led unit, uint8_t r, uint8_t g, uint8_t b)
|
||||
{
|
||||
// I mean I guess there's reactive LEDs on the sides? I'm not going to the
|
||||
// effort to work out if they're controllable or not
|
||||
}
|
||||
Reference in New Issue
Block a user