Based on myBlueUSB and rosserial_mbed

Dependencies:   mbed myUSBHost AvailableMemory myBlueUSB

Committer:
OTL
Date:
Sat Sep 17 14:24:13 2011 +0000
Revision:
1:18139954944b
Parent:
0:7684b95768c7
remove m3pi and main

Who changed what in which revision?

UserRevisionLine numberNew contents of line
OTL 0:7684b95768c7 1 /*
OTL 0:7684b95768c7 2 * MbedBT
OTL 0:7684b95768c7 3 *
OTL 0:7684b95768c7 4 * 2011/09/14 by OTL
OTL 0:7684b95768c7 5 */
OTL 0:7684b95768c7 6
OTL 0:7684b95768c7 7 #ifndef MBEDBT_H_
OTL 0:7684b95768c7 8 #define MBEDBT_H_
OTL 0:7684b95768c7 9
OTL 0:7684b95768c7 10 #include"mbed.h"
OTL 0:7684b95768c7 11 #include "btserial.h"
OTL 0:7684b95768c7 12 #include "ftclasslibusbdevbt.h"
OTL 0:7684b95768c7 13
OTL 0:7684b95768c7 14 extern int state;
OTL 0:7684b95768c7 15
OTL 0:7684b95768c7 16 void test_tick() {
OTL 0:7684b95768c7 17 USBLoop();
OTL 0:7684b95768c7 18 printf("tick\n");
OTL 0:7684b95768c7 19 }
OTL 0:7684b95768c7 20
OTL 0:7684b95768c7 21 class MbedBT {
OTL 0:7684b95768c7 22 public:
OTL 0:7684b95768c7 23 MbedBT(){
OTL 0:7684b95768c7 24 timer_.start();
OTL 0:7684b95768c7 25 }
OTL 0:7684b95768c7 26 void init() {
OTL 0:7684b95768c7 27 USBInit();
OTL 0:7684b95768c7 28
OTL 0:7684b95768c7 29 while(state != 1) {
OTL 0:7684b95768c7 30 USBLoop();
OTL 0:7684b95768c7 31 }
OTL 0:7684b95768c7 32
OTL 0:7684b95768c7 33 printf("Ready to open ports!!!!!!!!!!!!!\n");
OTL 0:7684b95768c7 34 InitFtBtDeviceList();
OTL 0:7684b95768c7 35 int n = GetNrOfFtBtDevices();
OTL 0:7684b95768c7 36 printf("%d ft BT devices have been found\n", n);
OTL 0:7684b95768c7 37 if (n > 0) {
OTL 0:7684b95768c7 38 ftbtdev *d = GetFtUsbDeviceHandle(0);
OTL 0:7684b95768c7 39 if (d==0) printf("could not get device handle\n");
OTL 0:7684b95768c7 40 int sock = OpenFtBtDevice(d);
OTL 0:7684b95768c7 41 }
OTL 0:7684b95768c7 42 bluetooth_ = new btserial(1);
OTL 0:7684b95768c7 43 // bluetooth_->baud(57600);
OTL 0:7684b95768c7 44 }
OTL 0:7684b95768c7 45
OTL 0:7684b95768c7 46 int read() {
OTL 0:7684b95768c7 47 return bluetooth_->getc();
OTL 0:7684b95768c7 48 }
OTL 0:7684b95768c7 49 void write(uint8_t* data, int length) {
OTL 0:7684b95768c7 50 bluetooth_->write(data, length);
OTL 0:7684b95768c7 51 }
OTL 0:7684b95768c7 52
OTL 0:7684b95768c7 53 unsigned long time() {
OTL 0:7684b95768c7 54 return timer_.read_ms();
OTL 0:7684b95768c7 55 }
OTL 0:7684b95768c7 56 ~MbedBT() {
OTL 0:7684b95768c7 57 delete bluetooth_;
OTL 0:7684b95768c7 58 // ticker_.dettach();
OTL 0:7684b95768c7 59 }
OTL 0:7684b95768c7 60 protected:
OTL 0:7684b95768c7 61 btserial* bluetooth_;
OTL 0:7684b95768c7 62 // Ticker ticker_;
OTL 0:7684b95768c7 63 Timer timer_;
OTL 0:7684b95768c7 64 };
OTL 0:7684b95768c7 65
OTL 0:7684b95768c7 66
OTL 0:7684b95768c7 67 #endif /* MBEDBT_H_ */