|
-
-
- #include <Arduino.h>
- #include "USBHost_t36.h"
-
-
- void MouseController::init()
- {
- USBHIDParser::driver_ready_for_hid_collection(this);
- BluetoothController::driver_ready_for_bluetooth(this);
- }
-
-
- hidclaim_t MouseController::claim_collection(USBHIDParser *driver, Device_t *dev, uint32_t topusage)
- {
-
- if (topusage != 0x10002) return CLAIM_NO;
-
- if (mydevice != NULL && dev != mydevice) return CLAIM_NO;
- mydevice = dev;
- collections_claimed++;
- return CLAIM_REPORT;
- }
-
- void MouseController::disconnect_collection(Device_t *dev)
- {
- if (--collections_claimed == 0) {
- mydevice = NULL;
- }
- }
-
- void MouseController::hid_input_begin(uint32_t topusage, uint32_t type, int lgmin, int lgmax)
- {
-
- hid_input_begin_ = true;
- }
-
- void MouseController::hid_input_data(uint32_t usage, int32_t value)
- {
-
- uint32_t usage_page = usage >> 16;
- usage &= 0xFFFF;
- if (usage_page == 9 && usage >= 1 && usage <= 8) {
- if (value == 0) {
- buttons &= ~(1 << (usage -1));
- } else {
- buttons |= (1 << (usage -1));
- }
- } else if (usage_page == 1) {
- switch (usage) {
- case 0x30:
- mouseX = value;
- break;
- case 0x31:
- mouseY = value;
- break;
- case 0x32:
- wheelH = value;
- break;
- case 0x38:
- wheel = value;
- break;
- }
- } else if (usage_page == 12) {
- if (usage == 0x238) {
- wheelH = value;
- }
- }
- }
-
- void MouseController::hid_input_end()
- {
- if (hid_input_begin_) {
- mouseEvent = true;
- hid_input_begin_ = false;
- }
- }
-
- void MouseController::mouseDataClear() {
- mouseEvent = false;
- buttons = 0;
- mouseX = 0;
- mouseY = 0;
- wheel = 0;
- wheelH = 0;
- }
-
-
- bool MouseController::claim_bluetooth(BluetoothController *driver, uint32_t bluetooth_class)
- {
-
- USBHDBGSerial.printf("MouseController Controller::claim_bluetooth - Class %x\n", bluetooth_class);
- if ((((bluetooth_class & 0xff00) == 0x2500) || (((bluetooth_class & 0xff00) == 0x500))) && (bluetooth_class & 0x80)) {
- USBHDBGSerial.printf("MouseController::claim_bluetooth TRUE\n");
- btdevice = (Device_t*)driver;
- return true;
- }
- return false;
- }
-
- bool MouseController::process_bluetooth_HID_data(const uint8_t *data, uint16_t length)
- {
-
-
-
-
-
-
-
- if (length == 0) return false;
- #ifdef USBHOST_PRINT_DEBUG
- USBHDBGSerial.printf("MouseController::process_bluetooth_HID_data %d\n", length);
- USBHDBGSerial.printf(" Mouse Data: ");
- const uint8_t *p = (const uint8_t *)data;
- uint16_t len = length;
- do {
- if (*p < 16) USBHDBGSerial.print('0');
- USBHDBGSerial.print(*p++, HEX);
- USBHDBGSerial.print(' ');
- } while (--len);
- USBHDBGSerial.println();
- #endif
-
- if (data[0] != 2) return false;
- buttons = data[1];
- mouseX = (int8_t)data[2];
- mouseY = (int8_t)data[3];
- if (length >= 5) {
- wheel = (int8_t)data[4];
- if (length >= 6) {
- wheelH = (int8_t)data[5];
- }
- }
- mouseEvent = true;
-
- return true;
- }
-
- void MouseController::release_bluetooth()
- {
-
- }
|