Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: Shield_Seeed_Bluetooth
Fork of BluetoothSerial by
BluetoothSerial.h
00001 /** 00002 * The library is for Bluetooth Shield from Seeed Studio 00003 */ 00004 00005 #ifndef __BLUETOOTH_SERIAL_H__ 00006 #define __BLUETOOTH_SERIAL_H__ 00007 00008 #include "mbed.h" 00009 00010 #define BLUETOOTH_SERIAL_DEFAULT_BAUD 38400 00011 #define BLUETOOTH_SERIAL_TIMEOUT 10000 00012 #define BLUETOOTH_SERIAL_EOL "\r\n" 00013 00014 /** 00015 * The BluetoothSerial class 00016 */ 00017 class BluetoothSerial : public Stream { 00018 public: 00019 BluetoothSerial(PinName tx, PinName rx); 00020 00021 /** 00022 * Setup bluetooth module(serial port baud rate) 00023 */ 00024 void setup(); 00025 00026 /** 00027 * Setup bluetooth module(serial port baud rate) 00028 * \param baud baud rate 00029 */ 00030 void setup(int baud); 00031 00032 /** 00033 * Set bluetooth module as a master 00034 * \param name device name 00035 * \param autoc 1: auto-connection, 0 not 00036 */ 00037 void master(const char *name, uint8_t autoc = 0); 00038 00039 /** 00040 * Set bluetooth module as a slave 00041 * \param name device name 00042 * \param autoc 1: auto-connection, 0 not 00043 * \param oaut 1: permit paired device to connect, 0: not 00044 */ 00045 void slave(const char *name, uint8_t autoc = 0, uint8_t oaut = 1); 00046 00047 /** 00048 * Set pin for the bluetooth connection 00049 * \param pin pin string 00050 */ 00051 void pin(int pin = 0); 00052 00053 /** 00054 * Set pin for the bluetooth connection 00055 * \param pin pin string 00056 */ 00057 void pin(const char *pin); 00058 00059 00060 /** 00061 * Inquire bluetooth devices and connect the specified device 00062 */ 00063 int connect(const char *name); 00064 00065 /** 00066 * Make the bluetooth module inquirable and available to connect, used in slave mode 00067 */ 00068 int connect(); 00069 00070 int readable() { 00071 return _serial.readable(); 00072 } 00073 00074 int writeable() { 00075 return _serial.writeable(); 00076 } 00077 00078 00079 protected: 00080 virtual int _getc(); 00081 virtual int _putc(int c); 00082 00083 void clear(); 00084 int readline(uint8_t *buf, int len, uint32_t timeout = 0); 00085 00086 Serial _serial; 00087 uint8_t _buf[64]; 00088 }; 00089 00090 #endif // __BLUETOOTH_SERIAL_H__
Generated on Thu Jul 21 2022 08:37:15 by
1.7.2
