/* get key status from controller */ void nvstusb_get_keys( struct nvstusb_context *ctx, struct nvstusb_keys *keys ) { assert(ctx != 0); assert(keys != 0); uint8_t cmd1[] = { NVSTUSB_CMD_READ | /* read and clear data */ NVSTUSB_CMD_CLEAR, 0x18, /* from address 0x201F (0x2007+0x18) = status? */ 0x03, 0x00 /* read/clear 3 bytes */ }; nvstusb_usb_write_bulk(ctx->device, 2, cmd1, sizeof(cmd1)); uint8_t readBuf[4+cmd1[2]]; nvstusb_usb_read_bulk(ctx->device, 4, readBuf, sizeof(readBuf)); /* readBuf[0] contains the offset (0x18), * readBuf[1] contains the number of read bytes (0x03), * readBuf[2] (msb) and readBuf[3] (lsb) of the bytes sent (sizeof(cmd1)) * readBuf[4] and following contain the requested data */ /* from address 0x201F: * signed 8 bit integer: amount the wheel was turned without the button pressed */ keys->deltaWheel = readBuf[4]; /* from address 0x2020: * signed 8 bit integer: amount the wheel was turned with the button pressed */ keys->pressedDeltaWheel = readBuf[5]; /* from address 0x2021: * bit 0: front button was pressed since last time (presumably fom pin 4 on port C) * bit 1: logic state of pin 7 on port E * bit 2: logic state of pin 2 on port C */ keys->toggled3D = readBuf[6] & 0x01; if(keys->toggled3D) { ctx->toggled3D = !ctx->toggled3D; } }
void nvstusb_DeviceReady(struct nvstusb_context *ctx) { uint8_t readBuf[7]; bool cont = false; while (!cont) { uint8_t vStr[] = { NVSTUSB_CMD_CLEAR | NVSTUSB_CMD_READ, 0x18, 0x03, 0x00 }; nvstusb_usb_write_bulk(ctx->device, 2, vStr, sizeof(vStr)); nvstusb_usb_read_bulk(ctx->device, 4, readBuf, sizeof(readBuf)); uint8_t i; if (readBuf[1] == 0x03 && readBuf[2] == 0x00) cont = true; } }
/* perform swap and toggle eyes hopefully with correct timing */ void nvstusb_swap_eye( struct nvstusb_context *ctx, enum nvstusb_eye eye, int32_t rate ) { assert(ctx != 0); assert(ctx->device != 0); assert(eye == nvstusb_left || eye == nvstusb_right || eye == nvstusb_quad); uint32_t r = NVSTUSB_T0_COUNT(rate); uint8_t buf[8] = { NVSTUSB_CMD_SET_EYE, eye==nvstusb_right ? 0xff:0xfe, 0x00, 0x00, r, r>>8, r>>16, r>>24 }; nvstusb_usb_write_bulk(ctx->device, 1, buf, 8); } /* get key status from controller */ void nvstusb_get_keys( struct nvstusb_context *ctx, struct nvstusb_keys *keys ) { assert(ctx != 0); assert(keys != 0); uint8_t cmd1[] = { NVSTUSB_CMD_READ | /* read and clear data */ NVSTUSB_CMD_CLEAR, 0x18, /* from address 0x201F (0x2007+0x18) = status? */ 0x03, 0x00 /* read/clear 3 bytes */ }; nvstusb_usb_write_bulk(ctx->device, 2, cmd1, sizeof(cmd1)); uint8_t readBuf[4+cmd1[2]]; nvstusb_usb_read_bulk(ctx->device, 4, readBuf, sizeof(readBuf)); /* readBuf[0] contains the offset (0x18), * readBuf[1] contains the number of read bytes (0x03), * readBuf[2] (msb) and readBuf[3] (lsb) of the bytes sent (sizeof(cmd1)) * readBuf[4] and following contain the requested data */ /* from address 0x201F: * signed 8 bit integer: amount the wheel was turned without the button pressed */ keys->deltaWheel = readBuf[4]; /* from address 0x2020: * signed 8 bit integer: amount the wheel was turned with the button pressed */ keys->pressedDeltaWheel = readBuf[5]; /* from address 0x2021: * bit 0: front button was pressed since last time (presumably fom pin 4 on port C) * bit 1: logic state of pin 7 on port E * bit 2: logic state of pin 2 on port C */ keys->toggled3D = readBuf[6] & 0x01; if(keys->toggled3D) { ctx->toggled3D = !ctx->toggled3D; } }