うおーるぼっとを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
USBHostBTstack/USBHostBTstack.h@0:fccb789424fc, 2013-06-10 (annotated)
- Committer:
- jksoft
- Date:
- Mon Jun 10 16:01:50 2013 +0000
- Revision:
- 0:fccb789424fc
1.0
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jksoft | 0:fccb789424fc | 1 | #include "USBHostConf.h" |
jksoft | 0:fccb789424fc | 2 | #include "USBHost.h" |
jksoft | 0:fccb789424fc | 3 | #pragma once |
jksoft | 0:fccb789424fc | 4 | |
jksoft | 0:fccb789424fc | 5 | #define TEST_ASSERT(A) while(!(A)){fprintf(stderr,"\n\n%s@%d %s ASSERT!\n\n",__PRETTY_FUNCTION__,__LINE__,#A);exit(1);}; |
jksoft | 0:fccb789424fc | 6 | |
jksoft | 0:fccb789424fc | 7 | struct Packet { |
jksoft | 0:fccb789424fc | 8 | uint8_t type; |
jksoft | 0:fccb789424fc | 9 | uint8_t* buf; |
jksoft | 0:fccb789424fc | 10 | uint16_t len; |
jksoft | 0:fccb789424fc | 11 | }; |
jksoft | 0:fccb789424fc | 12 | |
jksoft | 0:fccb789424fc | 13 | /** |
jksoft | 0:fccb789424fc | 14 | * A class to communicate a BTstack |
jksoft | 0:fccb789424fc | 15 | */ |
jksoft | 0:fccb789424fc | 16 | class USBHostBTstack : public IUSBEnumerator { |
jksoft | 0:fccb789424fc | 17 | public: |
jksoft | 0:fccb789424fc | 18 | /** |
jksoft | 0:fccb789424fc | 19 | * Constructor |
jksoft | 0:fccb789424fc | 20 | * |
jksoft | 0:fccb789424fc | 21 | */ |
jksoft | 0:fccb789424fc | 22 | USBHostBTstack(); |
jksoft | 0:fccb789424fc | 23 | |
jksoft | 0:fccb789424fc | 24 | /** |
jksoft | 0:fccb789424fc | 25 | * Check if a BTstack device is connected |
jksoft | 0:fccb789424fc | 26 | * |
jksoft | 0:fccb789424fc | 27 | * @return true if a BTstack device is connected |
jksoft | 0:fccb789424fc | 28 | */ |
jksoft | 0:fccb789424fc | 29 | bool connected(); |
jksoft | 0:fccb789424fc | 30 | |
jksoft | 0:fccb789424fc | 31 | /** |
jksoft | 0:fccb789424fc | 32 | * Try to connect to a BTstack device |
jksoft | 0:fccb789424fc | 33 | * |
jksoft | 0:fccb789424fc | 34 | * @return true if connection was successful |
jksoft | 0:fccb789424fc | 35 | */ |
jksoft | 0:fccb789424fc | 36 | bool connect(); |
jksoft | 0:fccb789424fc | 37 | |
jksoft | 0:fccb789424fc | 38 | int open(); |
jksoft | 0:fccb789424fc | 39 | int send_packet(uint8_t packet_type, uint8_t* packet, int size); |
jksoft | 0:fccb789424fc | 40 | void register_packet_handler( void (*pMethod)(uint8_t, uint8_t*, uint16_t)); |
jksoft | 0:fccb789424fc | 41 | void poll(); |
jksoft | 0:fccb789424fc | 42 | |
jksoft | 0:fccb789424fc | 43 | protected: |
jksoft | 0:fccb789424fc | 44 | //From IUSBEnumerator |
jksoft | 0:fccb789424fc | 45 | virtual void setVidPid(uint16_t vid, uint16_t pid); |
jksoft | 0:fccb789424fc | 46 | 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 |
jksoft | 0:fccb789424fc | 47 | virtual bool useEndpoint(uint8_t intf_nb, ENDPOINT_TYPE type, ENDPOINT_DIRECTION dir); //Must return true if the endpoint will be used |
jksoft | 0:fccb789424fc | 48 | |
jksoft | 0:fccb789424fc | 49 | private: |
jksoft | 0:fccb789424fc | 50 | USBHost * host; |
jksoft | 0:fccb789424fc | 51 | USBDeviceConnected * dev; |
jksoft | 0:fccb789424fc | 52 | bool dev_connected; |
jksoft | 0:fccb789424fc | 53 | uint8_t int_report[64]; |
jksoft | 0:fccb789424fc | 54 | uint8_t bulk_report[64]; |
jksoft | 0:fccb789424fc | 55 | USBEndpoint * int_in; |
jksoft | 0:fccb789424fc | 56 | USBEndpoint * bulk_in; |
jksoft | 0:fccb789424fc | 57 | USBEndpoint * bulk_out; |
jksoft | 0:fccb789424fc | 58 | bool ep_int_in; |
jksoft | 0:fccb789424fc | 59 | bool ep_bulk_in; |
jksoft | 0:fccb789424fc | 60 | bool ep_bulk_out; |
jksoft | 0:fccb789424fc | 61 | |
jksoft | 0:fccb789424fc | 62 | bool btstack_device_found; |
jksoft | 0:fccb789424fc | 63 | int btstack_intf; |
jksoft | 0:fccb789424fc | 64 | void (*m_pCb)(uint8_t, uint8_t*, uint16_t); |
jksoft | 0:fccb789424fc | 65 | Mail<Packet, 2> mail_box; |
jksoft | 0:fccb789424fc | 66 | void int_rxHandler(); |
jksoft | 0:fccb789424fc | 67 | void bulk_rxHandler(); |
jksoft | 0:fccb789424fc | 68 | void init(); |
jksoft | 0:fccb789424fc | 69 | }; |
jksoft | 0:fccb789424fc | 70 | |
jksoft | 0:fccb789424fc | 71 | void _debug_bytes(const char* pretty, int line, const char* s, uint8_t* buf, int len); |