mirror of
https://gitea.tendokyu.moe/Dniel97/segatools.git
synced 2024-11-27 22:40:48 +01:00
board/io3.c: Tweak ADC polling interface
This commit is contained in:
parent
5e823a9e22
commit
8158d01ed9
22
board/io3.c
22
board/io3.c
@ -481,7 +481,7 @@ static HRESULT io3_cmd_read_analogs(
|
|||||||
struct iobuf *resp_buf)
|
struct iobuf *resp_buf)
|
||||||
{
|
{
|
||||||
struct jvs_req_read_analogs req;
|
struct jvs_req_read_analogs req;
|
||||||
uint16_t state;
|
uint16_t analogs[8];
|
||||||
uint8_t i;
|
uint8_t i;
|
||||||
HRESULT hr;
|
HRESULT hr;
|
||||||
|
|
||||||
@ -493,6 +493,12 @@ static HRESULT io3_cmd_read_analogs(
|
|||||||
return hr;
|
return hr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (req.nanalogs > _countof(analogs)) {
|
||||||
|
dprintf("JVS I/O: Invalid analog count %i\n", req.nanalogs);
|
||||||
|
|
||||||
|
return E_FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
//dprintf("JVS I/O: Read analogs, nanalogs=%i\n", req.nanalogs);
|
//dprintf("JVS I/O: Read analogs, nanalogs=%i\n", req.nanalogs);
|
||||||
|
|
||||||
/* Write report byte */
|
/* Write report byte */
|
||||||
@ -505,14 +511,14 @@ static HRESULT io3_cmd_read_analogs(
|
|||||||
|
|
||||||
/* Write analogs */
|
/* Write analogs */
|
||||||
|
|
||||||
for (i = 0 ; i < req.nanalogs ; i++) {
|
memset(analogs, 0, sizeof(analogs));
|
||||||
if (io3->ops->read_analog != NULL) {
|
|
||||||
state = io3->ops->read_analog(io3->ops_ctx, i);
|
|
||||||
} else {
|
|
||||||
state = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
hr = iobuf_write_be16(resp_buf, state);
|
if (io3->ops->read_analogs != NULL) {
|
||||||
|
io3->ops->read_analogs(io3->ops_ctx, analogs, req.nanalogs);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i = 0 ; i < req.nanalogs ; i++) {
|
||||||
|
hr = iobuf_write_be16(resp_buf, analogs[i]);
|
||||||
|
|
||||||
if (FAILED(hr)) {
|
if (FAILED(hr)) {
|
||||||
return hr;
|
return hr;
|
||||||
|
@ -17,7 +17,7 @@ struct io3_ops {
|
|||||||
void (*reset)(void *ctx);
|
void (*reset)(void *ctx);
|
||||||
void (*write_gpio)(void *ctx, uint32_t state);
|
void (*write_gpio)(void *ctx, uint32_t state);
|
||||||
void (*read_switches)(void *ctx, struct io3_switch_state *out);
|
void (*read_switches)(void *ctx, struct io3_switch_state *out);
|
||||||
uint16_t (*read_analog)(void *ctx, uint8_t analog_no);
|
void (*read_analogs)(void *ctx, uint16_t *analogs, uint8_t nanalogs);
|
||||||
uint16_t (*read_coin_counter)(void *ctx, uint8_t slot_no);
|
uint16_t (*read_coin_counter)(void *ctx, uint8_t slot_no);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -17,13 +17,16 @@
|
|||||||
|
|
||||||
#include "util/dprintf.h"
|
#include "util/dprintf.h"
|
||||||
|
|
||||||
|
static void idz_jvs_read_analogs(
|
||||||
|
void *ctx,
|
||||||
|
uint16_t *analogs,
|
||||||
|
uint8_t nanalogs);
|
||||||
static void idz_jvs_read_switches(void *ctx, struct io3_switch_state *out);
|
static void idz_jvs_read_switches(void *ctx, struct io3_switch_state *out);
|
||||||
static uint16_t idz_jvs_read_analog(void *ctx, uint8_t analog_no);
|
|
||||||
static uint16_t idz_jvs_read_coin_counter(void *ctx, uint8_t slot_no);
|
static uint16_t idz_jvs_read_coin_counter(void *ctx, uint8_t slot_no);
|
||||||
|
|
||||||
static const struct io3_ops idz_jvs_io3_ops = {
|
static const struct io3_ops idz_jvs_io3_ops = {
|
||||||
.read_switches = idz_jvs_read_switches,
|
.read_switches = idz_jvs_read_switches,
|
||||||
.read_analog = idz_jvs_read_analog,
|
.read_analogs = idz_jvs_read_analogs,
|
||||||
.read_coin_counter = idz_jvs_read_coin_counter,
|
.read_coin_counter = idz_jvs_read_coin_counter,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -127,23 +130,23 @@ static void idz_jvs_read_switches(void *ctx, struct io3_switch_state *out)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint16_t idz_jvs_read_analog(void *ctx, uint8_t analog_no)
|
static void idz_jvs_read_analogs(
|
||||||
|
void *ctx,
|
||||||
|
uint16_t *analogs,
|
||||||
|
uint8_t nanalogs)
|
||||||
{
|
{
|
||||||
XINPUT_STATE xi;
|
XINPUT_STATE xi;
|
||||||
int left;
|
int left;
|
||||||
int right;
|
int right;
|
||||||
|
|
||||||
if (analog_no > 2) {
|
assert(analogs != NULL);
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
memset(&xi, 0, sizeof(xi));
|
memset(&xi, 0, sizeof(xi));
|
||||||
XInputGetState(0, &xi);
|
XInputGetState(0, &xi);
|
||||||
|
|
||||||
switch (analog_no) {
|
/* Wheel */
|
||||||
case 0:
|
|
||||||
/* Wheel */
|
|
||||||
|
|
||||||
|
if (nanalogs > 0) {
|
||||||
left = xi.Gamepad.sThumbLX;
|
left = xi.Gamepad.sThumbLX;
|
||||||
|
|
||||||
if (left < -XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE) {
|
if (left < -XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE) {
|
||||||
@ -164,18 +167,19 @@ static uint16_t idz_jvs_read_analog(void *ctx, uint8_t analog_no)
|
|||||||
right = 0;
|
right = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0x8000 + (left + right) / 2;
|
analogs[0] = 0x8000 + (left + right) / 2;
|
||||||
|
}
|
||||||
|
|
||||||
case 1:
|
/* Accel */
|
||||||
/* Accel */
|
|
||||||
return xi.Gamepad.bRightTrigger << 8;
|
|
||||||
|
|
||||||
case 2:
|
if (nanalogs > 1) {
|
||||||
/* Brake */
|
analogs[1] = xi.Gamepad.bRightTrigger << 8;
|
||||||
return xi.Gamepad.bLeftTrigger << 8;
|
}
|
||||||
|
|
||||||
default:
|
/* Brake */
|
||||||
return 0;
|
|
||||||
|
if (nanalogs > 2) {
|
||||||
|
analogs[2] = xi.Gamepad.bLeftTrigger << 8;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user