Axeda Ready Demo for Freescale FRDM-KL46Z as accident alert system

Dependencies:   FRDM_MMA8451Q KL46Z-USBHost MAG3110 SocketModem TSI mbed FATFileSystem

Fork of AxedaGo-Freescal_FRDM-KL46Z revert by Axeda Corp

Committer:
AxedaCorp
Date:
Wed Jul 02 15:59:38 2014 +0000
Revision:
1:5ad12c581db4
Parent:
0:65004368569c
url ip switch
;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
AxedaCorp 0:65004368569c 1 /* mbed USBHost Library
AxedaCorp 0:65004368569c 2 * Copyright (c) 2006-2013 ARM Limited
AxedaCorp 0:65004368569c 3 *
AxedaCorp 0:65004368569c 4 * Licensed under the Apache License, Version 2.0 (the "License");
AxedaCorp 0:65004368569c 5 * you may not use this file except in compliance with the License.
AxedaCorp 0:65004368569c 6 * You may obtain a copy of the License at
AxedaCorp 0:65004368569c 7 *
AxedaCorp 0:65004368569c 8 * http://www.apache.org/licenses/LICENSE-2.0
AxedaCorp 0:65004368569c 9 *
AxedaCorp 0:65004368569c 10 * Unless required by applicable law or agreed to in writing, software
AxedaCorp 0:65004368569c 11 * distributed under the License is distributed on an "AS IS" BASIS,
AxedaCorp 0:65004368569c 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
AxedaCorp 0:65004368569c 13 * See the License for the specific language governing permissions and
AxedaCorp 0:65004368569c 14 * limitations under the License.
AxedaCorp 0:65004368569c 15 */
AxedaCorp 0:65004368569c 16
AxedaCorp 0:65004368569c 17 #include "USBHost.h"
AxedaCorp 0:65004368569c 18
AxedaCorp 0:65004368569c 19 class USBHostMouse : public IUSBEnumerator {
AxedaCorp 0:65004368569c 20 public:
AxedaCorp 0:65004368569c 21
AxedaCorp 0:65004368569c 22 /**
AxedaCorp 0:65004368569c 23 * Constructor
AxedaCorp 0:65004368569c 24 */
AxedaCorp 0:65004368569c 25 USBHostMouse();
AxedaCorp 0:65004368569c 26
AxedaCorp 0:65004368569c 27 /**
AxedaCorp 0:65004368569c 28 * Try to connect a mouse device
AxedaCorp 0:65004368569c 29 *
AxedaCorp 0:65004368569c 30 * @return true if connection was successful
AxedaCorp 0:65004368569c 31 */
AxedaCorp 0:65004368569c 32 bool connect();
AxedaCorp 0:65004368569c 33
AxedaCorp 0:65004368569c 34 /**
AxedaCorp 0:65004368569c 35 * Check if a mouse is connected
AxedaCorp 0:65004368569c 36 *
AxedaCorp 0:65004368569c 37 * @returns true if a mouse is connected
AxedaCorp 0:65004368569c 38 */
AxedaCorp 0:65004368569c 39 bool connected();
AxedaCorp 0:65004368569c 40
AxedaCorp 0:65004368569c 41 int readReport(uint8_t* data) {
AxedaCorp 0:65004368569c 42 int rc = host->interruptRead(dev, int_in, data, 4);
AxedaCorp 0:65004368569c 43 return rc == USB_TYPE_OK ? 4 : 0;
AxedaCorp 0:65004368569c 44 }
AxedaCorp 0:65004368569c 45 void attachEvent(void (*ptr)(uint8_t* data, int size)) {
AxedaCorp 0:65004368569c 46 if (ptr != NULL) {
AxedaCorp 0:65004368569c 47 onUpdate = ptr;
AxedaCorp 0:65004368569c 48 }
AxedaCorp 0:65004368569c 49 }
AxedaCorp 0:65004368569c 50 void poll() {
AxedaCorp 0:65004368569c 51 USB_TYPE rc = host->interruptRead(dev, int_in, report, sizeof(report));
AxedaCorp 0:65004368569c 52 if (rc == USB_TYPE_OK) {
AxedaCorp 0:65004368569c 53 if (onUpdate) {
AxedaCorp 0:65004368569c 54 (*onUpdate)(report, int_in->getLengthTransferred());
AxedaCorp 0:65004368569c 55 }
AxedaCorp 0:65004368569c 56 }
AxedaCorp 0:65004368569c 57 }
AxedaCorp 0:65004368569c 58
AxedaCorp 0:65004368569c 59 protected:
AxedaCorp 0:65004368569c 60 //From IUSBEnumerator
AxedaCorp 0:65004368569c 61 virtual void setVidPid(uint16_t vid, uint16_t pid);
AxedaCorp 0:65004368569c 62 virtual bool 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
AxedaCorp 0:65004368569c 63 virtual bool useEndpoint(uint8_t intf_nb, ENDPOINT_TYPE type, ENDPOINT_DIRECTION dir); //Must return true if the endpoint will be used
AxedaCorp 0:65004368569c 64
AxedaCorp 0:65004368569c 65 private:
AxedaCorp 0:65004368569c 66 USBHost * host;
AxedaCorp 0:65004368569c 67 USBDeviceConnected * dev;
AxedaCorp 0:65004368569c 68 USBEndpoint * int_in;
AxedaCorp 0:65004368569c 69 uint8_t report[4];
AxedaCorp 0:65004368569c 70
AxedaCorp 0:65004368569c 71 bool dev_connected;
AxedaCorp 0:65004368569c 72 bool mouse_device_found;
AxedaCorp 0:65004368569c 73 int mouse_intf;
AxedaCorp 0:65004368569c 74
AxedaCorp 0:65004368569c 75 uint8_t buttons;
AxedaCorp 0:65004368569c 76 int8_t x;
AxedaCorp 0:65004368569c 77 int8_t y;
AxedaCorp 0:65004368569c 78 int8_t z;
AxedaCorp 0:65004368569c 79
AxedaCorp 0:65004368569c 80 void (*onUpdate)(uint8_t* data, int size);
AxedaCorp 0:65004368569c 81 void (*onButtonUpdate)(uint8_t buttons);
AxedaCorp 0:65004368569c 82 void (*onXUpdate)(int8_t x);
AxedaCorp 0:65004368569c 83 void (*onYUpdate)(int8_t y);
AxedaCorp 0:65004368569c 84 void (*onZUpdate)(int8_t z);
AxedaCorp 0:65004368569c 85 int report_id;
AxedaCorp 0:65004368569c 86 void init();
AxedaCorp 0:65004368569c 87 };
AxedaCorp 0:65004368569c 88