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
Revision 1:cf4d7779d9d6, committed 2014-07-25
- Comitter:
- screamer
- Date:
- Fri Jul 25 10:25:45 2014 +0000
- Parent:
- 0:f56002898ee8
- Commit message:
- Add param to setup for baud speed;; Add pin() method to change the pin;
Changed in this revision
| BluetoothSerial.cpp | Show annotated file Show diff for this revision Revisions of this file |
| BluetoothSerial.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/BluetoothSerial.cpp Thu Feb 20 03:30:43 2014 +0000
+++ b/BluetoothSerial.cpp Fri Jul 25 10:25:45 2014 +0000
@@ -1,4 +1,3 @@
-
#include "BluetoothSerial.h"
#include <string.h>
@@ -14,6 +13,11 @@
_serial.baud(BLUETOOTH_SERIAL_DEFAULT_BAUD);
}
+void BluetoothSerial::setup(int baud)
+{
+ _serial.baud(baud);
+}
+
void BluetoothSerial::master(const char *name, uint8_t autoc)
{
@@ -31,6 +35,18 @@
_serial.printf("\r\n+STAUTO=%d\r\n", autoc ? 1 : 0);
}
+void BluetoothSerial::pin(int pin)
+{
+ _serial.puts("\r\n+STWMOD=0\r\n");
+ _serial.printf("\r\n+STPIN=%s\r\n", pin);
+}
+
+void BluetoothSerial::pin(const char *pin)
+{
+ _serial.puts("\r\n+STWMOD=0\r\n");
+ _serial.printf("\r\n+STPIN=%s\r\n", pin);
+}
+
int BluetoothSerial::connect()
{
clear();
@@ -87,9 +103,7 @@
break;
}
}
-
}
-
}
LOG("BT: CONNECTING\r\n");
@@ -152,7 +166,7 @@
LOG("Too long line, the buffer is not enough\r\n");
return -(get + 1);
}
-
+
count = timeout;
}
--- a/BluetoothSerial.h Thu Feb 20 03:30:43 2014 +0000
+++ b/BluetoothSerial.h Fri Jul 25 10:25:45 2014 +0000
@@ -11,7 +11,9 @@
#define BLUETOOTH_SERIAL_TIMEOUT 10000
#define BLUETOOTH_SERIAL_EOL "\r\n"
-
+/**
+ * The BluetoothSerial class
+ */
class BluetoothSerial : public Stream {
public:
BluetoothSerial(PinName tx, PinName rx);
@@ -20,7 +22,13 @@
* Setup bluetooth module(serial port baud rate)
*/
void setup();
-
+
+ /**
+ * Setup bluetooth module(serial port baud rate)
+ * \param baud baud rate
+ */
+ void setup(int baud);
+
/**
* Set bluetooth module as a master
* \param name device name
@@ -35,6 +43,19 @@
* \param oaut 1: permit paired device to connect, 0: not
*/
void slave(const char *name, uint8_t autoc = 0, uint8_t oaut = 1);
+
+ /**
+ * Set pin for the bluetooth connection
+ * \param pin pin string
+ */
+ void pin(int pin = 0);
+
+ /**
+ * Set pin for the bluetooth connection
+ * \param pin pin string
+ */
+ void pin(const char *pin);
+
/**
* Inquire bluetooth devices and connect the specified device
