うおーるぼっとをWiiリモコンでコントロールする新しいプログラムです。 以前のものより、Wiiリモコンが早く繋がる様になりました。 It is a program which controls A with the Wii remote. ※ A Bluetooth dongle and a Wii remote control are needed.

Dependencies:   USBHost mbed FATFileSystem mbed-rtos

Committer:
jksoft
Date:
Mon Jun 10 16:01:50 2013 +0000
Revision:
0:fccb789424fc
1.0

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jksoft 0:fccb789424fc 1 /* mbed USBHost Library
jksoft 0:fccb789424fc 2 * Copyright (c) 2006-2013 ARM Limited
jksoft 0:fccb789424fc 3 *
jksoft 0:fccb789424fc 4 * Licensed under the Apache License, Version 2.0 (the "License");
jksoft 0:fccb789424fc 5 * you may not use this file except in compliance with the License.
jksoft 0:fccb789424fc 6 * You may obtain a copy of the License at
jksoft 0:fccb789424fc 7 *
jksoft 0:fccb789424fc 8 * http://www.apache.org/licenses/LICENSE-2.0
jksoft 0:fccb789424fc 9 *
jksoft 0:fccb789424fc 10 * Unless required by applicable law or agreed to in writing, software
jksoft 0:fccb789424fc 11 * distributed under the License is distributed on an "AS IS" BASIS,
jksoft 0:fccb789424fc 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
jksoft 0:fccb789424fc 13 * See the License for the specific language governing permissions and
jksoft 0:fccb789424fc 14 * limitations under the License.
jksoft 0:fccb789424fc 15 */
jksoft 0:fccb789424fc 16
jksoft 0:fccb789424fc 17 #include "USBHostMouse.h"
jksoft 0:fccb789424fc 18
jksoft 0:fccb789424fc 19 #if USBHOST_MOUSE
jksoft 0:fccb789424fc 20
jksoft 0:fccb789424fc 21 USBHostMouse::USBHostMouse() {
jksoft 0:fccb789424fc 22 host = USBHost::getHostInst();
jksoft 0:fccb789424fc 23 init();
jksoft 0:fccb789424fc 24 }
jksoft 0:fccb789424fc 25
jksoft 0:fccb789424fc 26 void USBHostMouse::init() {
jksoft 0:fccb789424fc 27 dev = NULL;
jksoft 0:fccb789424fc 28 int_in = NULL;
jksoft 0:fccb789424fc 29 onUpdate = NULL;
jksoft 0:fccb789424fc 30 onButtonUpdate = NULL;
jksoft 0:fccb789424fc 31 onXUpdate = NULL;
jksoft 0:fccb789424fc 32 onYUpdate = NULL;
jksoft 0:fccb789424fc 33 onZUpdate = NULL;
jksoft 0:fccb789424fc 34 report_id = 0;
jksoft 0:fccb789424fc 35 dev_connected = false;
jksoft 0:fccb789424fc 36 mouse_device_found = false;
jksoft 0:fccb789424fc 37 mouse_intf = -1;
jksoft 0:fccb789424fc 38
jksoft 0:fccb789424fc 39 buttons = 0;
jksoft 0:fccb789424fc 40 x = 0;
jksoft 0:fccb789424fc 41 y = 0;
jksoft 0:fccb789424fc 42 z = 0;
jksoft 0:fccb789424fc 43 }
jksoft 0:fccb789424fc 44
jksoft 0:fccb789424fc 45 bool USBHostMouse::connected() {
jksoft 0:fccb789424fc 46 return dev_connected;
jksoft 0:fccb789424fc 47 }
jksoft 0:fccb789424fc 48
jksoft 0:fccb789424fc 49 bool USBHostMouse::connect() {
jksoft 0:fccb789424fc 50
jksoft 0:fccb789424fc 51 if (dev_connected) {
jksoft 0:fccb789424fc 52 return true;
jksoft 0:fccb789424fc 53 }
jksoft 0:fccb789424fc 54
jksoft 0:fccb789424fc 55 for (uint8_t i = 0; i < MAX_DEVICE_CONNECTED; i++) {
jksoft 0:fccb789424fc 56 if ((dev = host->getDevice(i)) != NULL) {
jksoft 0:fccb789424fc 57
jksoft 0:fccb789424fc 58 if(host->enumerate(dev, this))
jksoft 0:fccb789424fc 59 break;
jksoft 0:fccb789424fc 60
jksoft 0:fccb789424fc 61 if (mouse_device_found) {
jksoft 0:fccb789424fc 62
jksoft 0:fccb789424fc 63 int_in = dev->getEndpoint(mouse_intf, INTERRUPT_ENDPOINT, IN);
jksoft 0:fccb789424fc 64 if (!int_in)
jksoft 0:fccb789424fc 65 break;
jksoft 0:fccb789424fc 66
jksoft 0:fccb789424fc 67 USB_INFO("New Mouse device: VID:%04x PID:%04x [dev: %p - intf: %d]", dev->getVid(), dev->getPid(), dev, mouse_intf);
jksoft 0:fccb789424fc 68 dev->setName("Mouse", mouse_intf);
jksoft 0:fccb789424fc 69 host->registerDriver(dev, mouse_intf, this, &USBHostMouse::init);
jksoft 0:fccb789424fc 70
jksoft 0:fccb789424fc 71 int_in->attach(this, &USBHostMouse::rxHandler);
jksoft 0:fccb789424fc 72 host->interruptRead(dev, int_in, report, int_in->getSize(), false);
jksoft 0:fccb789424fc 73
jksoft 0:fccb789424fc 74 dev_connected = true;
jksoft 0:fccb789424fc 75 return true;
jksoft 0:fccb789424fc 76 }
jksoft 0:fccb789424fc 77 }
jksoft 0:fccb789424fc 78 }
jksoft 0:fccb789424fc 79 init();
jksoft 0:fccb789424fc 80 return false;
jksoft 0:fccb789424fc 81 }
jksoft 0:fccb789424fc 82
jksoft 0:fccb789424fc 83 void USBHostMouse::rxHandler() {
jksoft 0:fccb789424fc 84 int len_listen = int_in->getSize();
jksoft 0:fccb789424fc 85 int len = int_in->getLengthTransferred();
jksoft 0:fccb789424fc 86
jksoft 0:fccb789424fc 87 if (onUpdate) {
jksoft 0:fccb789424fc 88 (*onUpdate)(report[0] & 0x07, report[1], report[2], report[3]);
jksoft 0:fccb789424fc 89 }
jksoft 0:fccb789424fc 90
jksoft 0:fccb789424fc 91 if (onButtonUpdate && (buttons != (report[0] & 0x07))) {
jksoft 0:fccb789424fc 92 (*onButtonUpdate)(report[0] & 0x07);
jksoft 0:fccb789424fc 93 }
jksoft 0:fccb789424fc 94
jksoft 0:fccb789424fc 95 if (onXUpdate && (x != report[1])) {
jksoft 0:fccb789424fc 96 (*onXUpdate)(report[1]);
jksoft 0:fccb789424fc 97 }
jksoft 0:fccb789424fc 98
jksoft 0:fccb789424fc 99 if (onYUpdate && (y != report[2])) {
jksoft 0:fccb789424fc 100 (*onYUpdate)(report[2]);
jksoft 0:fccb789424fc 101 }
jksoft 0:fccb789424fc 102
jksoft 0:fccb789424fc 103 if (onZUpdate && (z != report[3])) {
jksoft 0:fccb789424fc 104 (*onZUpdate)(report[3]);
jksoft 0:fccb789424fc 105 }
jksoft 0:fccb789424fc 106
jksoft 0:fccb789424fc 107 // update mouse state
jksoft 0:fccb789424fc 108 buttons = report[0] & 0x07;
jksoft 0:fccb789424fc 109 x = report[1];
jksoft 0:fccb789424fc 110 y = report[2];
jksoft 0:fccb789424fc 111 z = report[3];
jksoft 0:fccb789424fc 112
jksoft 0:fccb789424fc 113 if (dev)
jksoft 0:fccb789424fc 114 host->interruptRead(dev, int_in, report, len_listen, false);
jksoft 0:fccb789424fc 115 }
jksoft 0:fccb789424fc 116
jksoft 0:fccb789424fc 117 /*virtual*/ void USBHostMouse::setVidPid(uint16_t vid, uint16_t pid)
jksoft 0:fccb789424fc 118 {
jksoft 0:fccb789424fc 119 // we don't check VID/PID for mouse driver
jksoft 0:fccb789424fc 120 }
jksoft 0:fccb789424fc 121
jksoft 0:fccb789424fc 122 /*virtual*/ bool USBHostMouse::parseInterface(uint8_t intf_nb, uint8_t intf_class, uint8_t intf_subclass, uint8_t intf_protocol) //Must return true if the interface should be parsed
jksoft 0:fccb789424fc 123 {
jksoft 0:fccb789424fc 124 if ((mouse_intf == -1) &&
jksoft 0:fccb789424fc 125 (intf_class == HID_CLASS) &&
jksoft 0:fccb789424fc 126 (intf_subclass == 0x01) &&
jksoft 0:fccb789424fc 127 (intf_protocol == 0x02)) {
jksoft 0:fccb789424fc 128 mouse_intf = intf_nb;
jksoft 0:fccb789424fc 129 return true;
jksoft 0:fccb789424fc 130 }
jksoft 0:fccb789424fc 131 return false;
jksoft 0:fccb789424fc 132 }
jksoft 0:fccb789424fc 133
jksoft 0:fccb789424fc 134 /*virtual*/ bool USBHostMouse::useEndpoint(uint8_t intf_nb, ENDPOINT_TYPE type, ENDPOINT_DIRECTION dir) //Must return true if the endpoint will be used
jksoft 0:fccb789424fc 135 {
jksoft 0:fccb789424fc 136 if (intf_nb == mouse_intf) {
jksoft 0:fccb789424fc 137 if (type == INTERRUPT_ENDPOINT && dir == IN) {
jksoft 0:fccb789424fc 138 mouse_device_found = true;
jksoft 0:fccb789424fc 139 return true;
jksoft 0:fccb789424fc 140 }
jksoft 0:fccb789424fc 141 }
jksoft 0:fccb789424fc 142 return false;
jksoft 0:fccb789424fc 143 }
jksoft 0:fccb789424fc 144
jksoft 0:fccb789424fc 145 #endif