chuniio: Add input config

This commit is contained in:
Tau 2019-11-17 13:11:49 -05:00
parent 39abee3a75
commit beeebf3946
4 changed files with 73 additions and 15 deletions

View File

@ -5,21 +5,21 @@
#include <stdint.h>
#include "chuniio/chuniio.h"
#include "chuniio/config.h"
static unsigned int __stdcall chuni_io_slider_thread_proc(void *ctx);
static const int chuni_io_slider_keys[] = {
'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L',
};
static bool chuni_io_coin;
static uint16_t chuni_io_coins;
static uint8_t chuni_io_hand_pos;
static HANDLE chuni_io_slider_thread;
static bool chuni_io_slider_stop_flag;
static struct chuni_io_config chuni_io_cfg;
HRESULT chuni_io_jvs_init(void)
{
chuni_io_config_load(&chuni_io_cfg, L".\\segatools.ini");
return S_OK;
}
@ -29,7 +29,7 @@ void chuni_io_jvs_read_coin_counter(uint16_t *out)
return;
}
if (GetAsyncKeyState('3')) {
if (GetAsyncKeyState(chuni_io_cfg.vk_coin)) {
if (!chuni_io_coin) {
chuni_io_coin = true;
chuni_io_coins++;
@ -45,15 +45,15 @@ void chuni_io_jvs_poll(uint8_t *opbtn, uint8_t *beams)
{
size_t i;
if (GetAsyncKeyState('1')) {
if (GetAsyncKeyState(chuni_io_cfg.vk_test)) {
*opbtn |= 0x01; /* Test */
}
if (GetAsyncKeyState('2')) {
if (GetAsyncKeyState(chuni_io_cfg.vk_service)) {
*opbtn |= 0x02; /* Service */
}
if (GetAsyncKeyState(VK_SPACE)) {
if (GetAsyncKeyState(chuni_io_cfg.vk_ir)) {
if (chuni_io_hand_pos < 6) {
chuni_io_hand_pos++;
}
@ -114,21 +114,18 @@ void chuni_io_slider_set_leds(const uint8_t *rgb)
static unsigned int __stdcall chuni_io_slider_thread_proc(void *ctx)
{
chuni_io_slider_callback_t callback;
uint8_t pressure_val;
uint8_t pressure[32];
size_t i;
callback = ctx;
while (!chuni_io_slider_stop_flag) {
for (i = 0 ; i < 8 ; i++) {
if (GetAsyncKeyState(chuni_io_slider_keys[i]) & 0x8000) {
pressure_val = 128;
for (i = 0 ; i < _countof(pressure) ; i++) {
if (GetAsyncKeyState(chuni_io_cfg.vk_cell[i]) & 0x8000) {
pressure[i] = 128;
} else {
pressure_val = 0;
pressure[i] = 0;
}
memset(&pressure[28 - 4 * i], pressure_val, 4);
}
callback(pressure);

43
chuniio/config.c Normal file
View File

@ -0,0 +1,43 @@
#include <windows.h>
#include <assert.h>
#include <stddef.h>
#include <stdio.h>
#include "chuniio/config.h"
static const int chuni_io_default_cells[] = {
'L', 'L', 'L', 'L',
'K', 'K', 'K', 'K',
'J', 'J', 'J', 'J',
'H', 'H', 'H', 'H',
'G', 'G', 'G', 'G',
'F', 'F', 'F', 'F',
'D', 'D', 'D', 'D',
'S', 'S', 'S', 'S',
};
void chuni_io_config_load(
struct chuni_io_config *cfg,
const wchar_t *filename)
{
wchar_t key[16];
int i;
assert(cfg != NULL);
assert(filename != NULL);
cfg->vk_test = GetPrivateProfileIntW(L"io3", L"test", '1', filename);
cfg->vk_service = GetPrivateProfileIntW(L"io3", L"service", '2', filename);
cfg->vk_coin = GetPrivateProfileIntW(L"io3", L"coin", '3', filename);
cfg->vk_ir = GetPrivateProfileIntW(L"io3", L"ir", VK_SPACE, filename);
for (i = 0 ; i < 32 ; i++) {
swprintf_s(key, _countof(key), L"cell%i", i + 1);
cfg->vk_cell[i] = GetPrivateProfileIntW(
L"slider",
key,
chuni_io_default_cells[i],
filename);
}
}

16
chuniio/config.h Normal file
View File

@ -0,0 +1,16 @@
#pragma once
#include <stddef.h>
#include <stdint.h>
struct chuni_io_config {
uint8_t vk_test;
uint8_t vk_service;
uint8_t vk_coin;
uint8_t vk_ir;
uint8_t vk_cell[32];
};
void chuni_io_config_load(
struct chuni_io_config *cfg,
const wchar_t *filename);

View File

@ -8,5 +8,7 @@ chuniio_dll = shared_library(
sources : [
'chuniio.c',
'chuniio.h',
'config.c',
'config.h',
],
)