macro?
This commit is contained in:
14
src/aio.c
14
src/aio.c
@@ -5,29 +5,25 @@
|
||||
|
||||
static const uint8_t buf_size = 32; // needs 32 bc of overflow issue on these aios?
|
||||
|
||||
#define POST_AND_GET_RESP(_req, resp_len) uint8_t req = _req; uint8_t resp[32]; aio_post(aio, &req, 1, resp, resp_len);
|
||||
|
||||
static void aio_post(libusb_device_handle *dev, uint8_t *req, const int req_len, uint8_t *resp, const int resp_len) {
|
||||
libusb_bulk_transfer(dev, 0x01, req, req_len, NULL, 1000);
|
||||
libusb_bulk_transfer(dev, 0x81, resp, resp_len, NULL, 1000);
|
||||
}
|
||||
|
||||
static float aio_get_water_temp(libusb_device_handle* aio) {
|
||||
uint8_t req = 0xa9;
|
||||
uint8_t resp[buf_size];
|
||||
aio_post(aio, &req, sizeof(req), resp, 6);
|
||||
POST_AND_GET_RESP(0xa9, 6);
|
||||
return (float)resp[3] + (float)resp[4] / 10.0f;
|
||||
}
|
||||
|
||||
static uint16_t aio_get_pump_speed(libusb_device_handle* aio) {
|
||||
uint8_t req = 0x31;
|
||||
uint8_t resp[buf_size];
|
||||
aio_post(aio, &req, sizeof(req), resp, 5);
|
||||
POST_AND_GET_RESP(0x31, 5);
|
||||
return resp[3] << 8 | resp[4];
|
||||
}
|
||||
|
||||
static enum aio_pump_mode_t aio_get_pump_mode(libusb_device_handle* aio) {
|
||||
uint8_t req = 0x33;
|
||||
uint8_t resp[buf_size];
|
||||
aio_post(aio, &req, sizeof(req), resp, 4);
|
||||
POST_AND_GET_RESP(0x33, 4);
|
||||
return (enum aio_pump_mode_t)resp[3];
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user