forked from Dniel97/segatools
board/io3.c: Tweak ADC polling interface
This commit is contained in:
parent
5e823a9e22
commit
8158d01ed9
20
board/io3.c
20
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);
|
if (io3->ops->read_analogs != NULL) {
|
||||||
} else {
|
io3->ops->read_analogs(io3->ops_ctx, analogs, req.nanalogs);
|
||||||
state = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
hr = iobuf_write_be16(resp_buf, state);
|
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) {
|
|
||||||
case 0:
|
|
||||||
/* Wheel */
|
/* 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) {
|
||||||
|
analogs[1] = xi.Gamepad.bRightTrigger << 8;
|
||||||
|
}
|
||||||
|
|
||||||
/* Brake */
|
/* Brake */
|
||||||
return xi.Gamepad.bLeftTrigger << 8;
|
|
||||||
|
|
||||||
default:
|
if (nanalogs > 2) {
|
||||||
return 0;
|
analogs[2] = xi.Gamepad.bLeftTrigger << 8;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user