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
Diff: BluetoothSerial.h
- Revision:
- 0:f56002898ee8
- Child:
- 1:cf4d7779d9d6
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/BluetoothSerial.h Thu Feb 20 03:30:43 2014 +0000
@@ -0,0 +1,69 @@
+/**
+ * The library is for Bluetooth Shield from Seeed Studio
+ */
+
+#ifndef __BLUETOOTH_SERIAL_H__
+#define __BLUETOOTH_SERIAL_H__
+
+#include "mbed.h"
+
+#define BLUETOOTH_SERIAL_DEFAULT_BAUD 38400
+#define BLUETOOTH_SERIAL_TIMEOUT 10000
+#define BLUETOOTH_SERIAL_EOL "\r\n"
+
+
+class BluetoothSerial : public Stream {
+public:
+ BluetoothSerial(PinName tx, PinName rx);
+
+ /**
+ * Setup bluetooth module(serial port baud rate)
+ */
+ void setup();
+
+ /**
+ * Set bluetooth module as a master
+ * \param name device name
+ * \param autoc 1: auto-connection, 0 not
+ */
+ void master(const char *name, uint8_t autoc = 0);
+
+ /**
+ * Set bluetooth module as a slave
+ * \param name device name
+ * \param autoc 1: auto-connection, 0 not
+ * \param oaut 1: permit paired device to connect, 0: not
+ */
+ void slave(const char *name, uint8_t autoc = 0, uint8_t oaut = 1);
+
+ /**
+ * Inquire bluetooth devices and connect the specified device
+ */
+ int connect(const char *name);
+
+ /**
+ * Make the bluetooth module inquirable and available to connect, used in slave mode
+ */
+ int connect();
+
+ int readable() {
+ return _serial.readable();
+ }
+
+ int writeable() {
+ return _serial.writeable();
+ }
+
+
+protected:
+ virtual int _getc();
+ virtual int _putc(int c);
+
+ void clear();
+ int readline(uint8_t *buf, int len, uint32_t timeout = 0);
+
+ Serial _serial;
+ uint8_t _buf[64];
+};
+
+#endif // __BLUETOOTH_SERIAL_H__
