forked from TeamTofuShop/segatools
board/io3.c: Tweak ADC polling interface
This commit is contained in:
22
board/io3.c
22
board/io3.c
@ -481,7 +481,7 @@ static HRESULT io3_cmd_read_analogs(
|
||||
struct iobuf *resp_buf)
|
||||
{
|
||||
struct jvs_req_read_analogs req;
|
||||
uint16_t state;
|
||||
uint16_t analogs[8];
|
||||
uint8_t i;
|
||||
HRESULT hr;
|
||||
|
||||
@ -493,6 +493,12 @@ static HRESULT io3_cmd_read_analogs(
|
||||
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);
|
||||
|
||||
/* Write report byte */
|
||||
@ -505,14 +511,14 @@ static HRESULT io3_cmd_read_analogs(
|
||||
|
||||
/* Write analogs */
|
||||
|
||||
for (i = 0 ; i < req.nanalogs ; i++) {
|
||||
if (io3->ops->read_analog != NULL) {
|
||||
state = io3->ops->read_analog(io3->ops_ctx, i);
|
||||
} else {
|
||||
state = 0;
|
||||
}
|
||||
memset(analogs, 0, sizeof(analogs));
|
||||
|
||||
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)) {
|
||||
return hr;
|
||||
|
@ -17,7 +17,7 @@ struct io3_ops {
|
||||
void (*reset)(void *ctx);
|
||||
void (*write_gpio)(void *ctx, uint32_t state);
|
||||
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);
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user