Modificación para implementar SoftSerial
Dependents: neurGAI_Seeed_BLUETOOTH TFG
Fork of BluetoothSerial by
BluetoothSerial.h@1:267fd413fd16, 2015-12-09 (annotated)
- Committer:
- gbm
- Date:
- Wed Dec 09 11:16:13 2015 +0000
- Revision:
- 1:267fd413fd16
- Parent:
- 0:f56002898ee8
Modificaci?n de BluetoothSerial para implementar comunicaci?n SoftSerial
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
yihui | 0:f56002898ee8 | 1 | /** |
yihui | 0:f56002898ee8 | 2 | * The library is for Bluetooth Shield from Seeed Studio |
yihui | 0:f56002898ee8 | 3 | */ |
yihui | 0:f56002898ee8 | 4 | |
yihui | 0:f56002898ee8 | 5 | #ifndef __BLUETOOTH_SERIAL_H__ |
yihui | 0:f56002898ee8 | 6 | #define __BLUETOOTH_SERIAL_H__ |
yihui | 0:f56002898ee8 | 7 | |
yihui | 0:f56002898ee8 | 8 | #include "mbed.h" |
gbm | 1:267fd413fd16 | 9 | #include "SoftSerial.h" |
yihui | 0:f56002898ee8 | 10 | |
yihui | 0:f56002898ee8 | 11 | #define BLUETOOTH_SERIAL_DEFAULT_BAUD 38400 |
yihui | 0:f56002898ee8 | 12 | #define BLUETOOTH_SERIAL_TIMEOUT 10000 |
yihui | 0:f56002898ee8 | 13 | #define BLUETOOTH_SERIAL_EOL "\r\n" |
yihui | 0:f56002898ee8 | 14 | |
yihui | 0:f56002898ee8 | 15 | |
yihui | 0:f56002898ee8 | 16 | class BluetoothSerial : public Stream { |
yihui | 0:f56002898ee8 | 17 | public: |
yihui | 0:f56002898ee8 | 18 | BluetoothSerial(PinName tx, PinName rx); |
yihui | 0:f56002898ee8 | 19 | |
yihui | 0:f56002898ee8 | 20 | /** |
yihui | 0:f56002898ee8 | 21 | * Setup bluetooth module(serial port baud rate) |
yihui | 0:f56002898ee8 | 22 | */ |
yihui | 0:f56002898ee8 | 23 | void setup(); |
yihui | 0:f56002898ee8 | 24 | |
yihui | 0:f56002898ee8 | 25 | /** |
yihui | 0:f56002898ee8 | 26 | * Set bluetooth module as a master |
yihui | 0:f56002898ee8 | 27 | * \param name device name |
yihui | 0:f56002898ee8 | 28 | * \param autoc 1: auto-connection, 0 not |
yihui | 0:f56002898ee8 | 29 | */ |
yihui | 0:f56002898ee8 | 30 | void master(const char *name, uint8_t autoc = 0); |
yihui | 0:f56002898ee8 | 31 | |
yihui | 0:f56002898ee8 | 32 | /** |
yihui | 0:f56002898ee8 | 33 | * Set bluetooth module as a slave |
yihui | 0:f56002898ee8 | 34 | * \param name device name |
yihui | 0:f56002898ee8 | 35 | * \param autoc 1: auto-connection, 0 not |
yihui | 0:f56002898ee8 | 36 | * \param oaut 1: permit paired device to connect, 0: not |
yihui | 0:f56002898ee8 | 37 | */ |
yihui | 0:f56002898ee8 | 38 | void slave(const char *name, uint8_t autoc = 0, uint8_t oaut = 1); |
yihui | 0:f56002898ee8 | 39 | |
yihui | 0:f56002898ee8 | 40 | /** |
yihui | 0:f56002898ee8 | 41 | * Inquire bluetooth devices and connect the specified device |
yihui | 0:f56002898ee8 | 42 | */ |
yihui | 0:f56002898ee8 | 43 | int connect(const char *name); |
yihui | 0:f56002898ee8 | 44 | |
yihui | 0:f56002898ee8 | 45 | /** |
yihui | 0:f56002898ee8 | 46 | * Make the bluetooth module inquirable and available to connect, used in slave mode |
yihui | 0:f56002898ee8 | 47 | */ |
yihui | 0:f56002898ee8 | 48 | int connect(); |
yihui | 0:f56002898ee8 | 49 | |
yihui | 0:f56002898ee8 | 50 | int readable() { |
yihui | 0:f56002898ee8 | 51 | return _serial.readable(); |
yihui | 0:f56002898ee8 | 52 | } |
yihui | 0:f56002898ee8 | 53 | |
yihui | 0:f56002898ee8 | 54 | int writeable() { |
yihui | 0:f56002898ee8 | 55 | return _serial.writeable(); |
yihui | 0:f56002898ee8 | 56 | } |
yihui | 0:f56002898ee8 | 57 | |
yihui | 0:f56002898ee8 | 58 | |
yihui | 0:f56002898ee8 | 59 | protected: |
yihui | 0:f56002898ee8 | 60 | virtual int _getc(); |
yihui | 0:f56002898ee8 | 61 | virtual int _putc(int c); |
yihui | 0:f56002898ee8 | 62 | |
yihui | 0:f56002898ee8 | 63 | void clear(); |
yihui | 0:f56002898ee8 | 64 | int readline(uint8_t *buf, int len, uint32_t timeout = 0); |
yihui | 0:f56002898ee8 | 65 | |
gbm | 1:267fd413fd16 | 66 | SoftSerial _serial; |
yihui | 0:f56002898ee8 | 67 | uint8_t _buf[64]; |
yihui | 0:f56002898ee8 | 68 | }; |
yihui | 0:f56002898ee8 | 69 | |
yihui | 0:f56002898ee8 | 70 | #endif // __BLUETOOTH_SERIAL_H__ |