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
KL46Z-USBHost/USBHostGPS/USBHostGPS.h@0:65004368569c, 2014-07-01 (annotated)
- Committer:
- AxedaCorp
- Date:
- Tue Jul 01 21:31:54 2014 +0000
- Revision:
- 0:65004368569c
Made initial
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
AxedaCorp | 0:65004368569c | 1 | // Simple USBHost GPS Dongle for FRDM-KL46Z |
AxedaCorp | 0:65004368569c | 2 | #include "USBHost.h" |
AxedaCorp | 0:65004368569c | 3 | |
AxedaCorp | 0:65004368569c | 4 | #define PL2303_SET_LINE_CODING 0x20 |
AxedaCorp | 0:65004368569c | 5 | |
AxedaCorp | 0:65004368569c | 6 | class USBHostGPS : public IUSBEnumerator { |
AxedaCorp | 0:65004368569c | 7 | public: |
AxedaCorp | 0:65004368569c | 8 | |
AxedaCorp | 0:65004368569c | 9 | /** |
AxedaCorp | 0:65004368569c | 10 | * Constructor |
AxedaCorp | 0:65004368569c | 11 | */ |
AxedaCorp | 0:65004368569c | 12 | USBHostGPS(int baud = 38400); |
AxedaCorp | 0:65004368569c | 13 | |
AxedaCorp | 0:65004368569c | 14 | /** |
AxedaCorp | 0:65004368569c | 15 | * Try to connect a USB GPS device |
AxedaCorp | 0:65004368569c | 16 | * |
AxedaCorp | 0:65004368569c | 17 | * @return true if connection was successful |
AxedaCorp | 0:65004368569c | 18 | */ |
AxedaCorp | 0:65004368569c | 19 | bool connect(); |
AxedaCorp | 0:65004368569c | 20 | |
AxedaCorp | 0:65004368569c | 21 | /** |
AxedaCorp | 0:65004368569c | 22 | * Check if a USB GPS is connected |
AxedaCorp | 0:65004368569c | 23 | * |
AxedaCorp | 0:65004368569c | 24 | * @returns true if a mouse is connected |
AxedaCorp | 0:65004368569c | 25 | */ |
AxedaCorp | 0:65004368569c | 26 | bool connected(); |
AxedaCorp | 0:65004368569c | 27 | |
AxedaCorp | 0:65004368569c | 28 | int readNMEA(char* data, int size, int timeout_ms) { |
AxedaCorp | 0:65004368569c | 29 | int result = host->BulkRead(bulk_in, (uint8_t*)data, size, timeout_ms); |
AxedaCorp | 0:65004368569c | 30 | return (result >= 0) ? bulk_in->getLengthTransferred() : 0; |
AxedaCorp | 0:65004368569c | 31 | } |
AxedaCorp | 0:65004368569c | 32 | void attachEvent(void (*ptr)(uint8_t* data, int size)) { |
AxedaCorp | 0:65004368569c | 33 | if (ptr != NULL) { |
AxedaCorp | 0:65004368569c | 34 | onUpdate = ptr; |
AxedaCorp | 0:65004368569c | 35 | } |
AxedaCorp | 0:65004368569c | 36 | } |
AxedaCorp | 0:65004368569c | 37 | void poll() { |
AxedaCorp | 0:65004368569c | 38 | int result = host->BulkRead(bulk_in, buf, sizeof(buf), 0); |
AxedaCorp | 0:65004368569c | 39 | if (result >= 0) { |
AxedaCorp | 0:65004368569c | 40 | if (onUpdate) { |
AxedaCorp | 0:65004368569c | 41 | (*onUpdate)(buf, bulk_in->getLengthTransferred()); |
AxedaCorp | 0:65004368569c | 42 | } |
AxedaCorp | 0:65004368569c | 43 | } |
AxedaCorp | 0:65004368569c | 44 | } |
AxedaCorp | 0:65004368569c | 45 | |
AxedaCorp | 0:65004368569c | 46 | protected: |
AxedaCorp | 0:65004368569c | 47 | //From IUSBEnumerator |
AxedaCorp | 0:65004368569c | 48 | virtual void setVidPid(uint16_t vid, uint16_t pid); |
AxedaCorp | 0:65004368569c | 49 | 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 | 50 | 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 | 51 | |
AxedaCorp | 0:65004368569c | 52 | private: |
AxedaCorp | 0:65004368569c | 53 | USBHost * host; |
AxedaCorp | 0:65004368569c | 54 | USBDeviceConnected* dev; |
AxedaCorp | 0:65004368569c | 55 | USBEndpoint* bulk_in; |
AxedaCorp | 0:65004368569c | 56 | bool dev_connected; |
AxedaCorp | 0:65004368569c | 57 | bool gps_device_found; |
AxedaCorp | 0:65004368569c | 58 | int gps_intf; |
AxedaCorp | 0:65004368569c | 59 | void (*onUpdate)(uint8_t* data, int size); |
AxedaCorp | 0:65004368569c | 60 | uint8_t buf[64]; |
AxedaCorp | 0:65004368569c | 61 | int baud; |
AxedaCorp | 0:65004368569c | 62 | void init(); |
AxedaCorp | 0:65004368569c | 63 | }; |