arduino-esp32/libraries/BluetoothSerial/src/BluetoothSerial.h

62 lines
1.7 KiB
C
Raw Normal View History

// Copyright 2018 Evandro Luis Copercini
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef _BLUETOOTH_SERIAL_H_
#define _BLUETOOTH_SERIAL_H_
#include "sdkconfig.h"
#if defined(CONFIG_BT_ENABLED) && defined(CONFIG_BLUEDROID_ENABLED)
#include "Arduino.h"
#include "Stream.h"
#include <esp_spp_api.h>
class BluetoothSerial: public Stream
{
public:
BluetoothSerial(void);
~BluetoothSerial(void);
Support for Master mode, Pin and SSP (#3219) * 20190916 - initial: support for Master mode, Pin and SSP * 20190916 - initial: Add example app for Master mode * 20190916 - initial: Force another build * 20190916 - connect would use resolved address as preference and remove now redundant _remote_address * 20190916 - rework set/reset/default pin logic * 20190916 - cleanup: remove static vars, add/use constants, fix typos * 20190916 - fix build issues and implement geoup events for status verification. * 20190916 - remove extra lines,misc * 20190916 - rework ESP_BT_GAP_DISC_RES_EVT, added SPP_DISCONNECTED bit for disconnect event. + timeout for disconnect() * 20190916 - Small log change to improve log sequencing * 20190916 - remove static from local vars * 20190916 - Limited scope and duration for the scan, log device address during scan in info mode as it is very difficult to find out sometimes. Fixed get_name_from_eir() not resetting the name when called. * 20190916 - break property for loop during scan when name matches. * 20190916 - misc * 20190916 - SPP_DISCONNECT state updates * 20190916 - formatting, remove some strange syntax from initiator code * 20190916 - Add comments to the example about connect(...) usage and timeouts * 20190916 - fix disconnect() without timeout * 20190916 - Add example comment to view BT address and name during connect(name) * 20190916 - wording in example comments * 20190916 - rework connect() and disconnect() methods to help with concurrency and more authoritative status returned back to caller. Automatic disconnect in connect() methods * 20190916 - optimize code * 20190916 - optimize code - more * 20190916 - add timeout for pin set * 20190916 - change scan mode to ESP_BT_SCAN_MODE_CONNECTABLE_DISCOVERABLE * 20190916 - update example code slightly * 20190916 - increase READY_TIMEOUT to 10 secs * 20190916 - typo in example and move waitForConnect() to static area * 20190916 - update example comments * 20190916 - update example comments * 20190916 - update example comments * 20190916 - add new example to remove paired devices from ESP32 * 20190916 - correct typo in example * 20190916 - update example comment, add remove_bond_device() method for convenience. * 20190916 - reword example comment. * 20190916 - rename remove_bond_device() * 20190916 - rename removePairedDevice() to unpairDevice() * 20190916 - code review changes * 20190916 - fix return value in setup() od example
2019-10-01 16:34:46 +02:00
bool begin(String localName=String(), bool isMaster=false);
int available(void);
int peek(void);
bool hasClient(void);
int read(void);
size_t write(uint8_t c);
size_t write(const uint8_t *buffer, size_t size);
void flush();
void end(void);
esp_err_t register_callback(esp_spp_cb_t * callback);
Support for Master mode, Pin and SSP (#3219) * 20190916 - initial: support for Master mode, Pin and SSP * 20190916 - initial: Add example app for Master mode * 20190916 - initial: Force another build * 20190916 - connect would use resolved address as preference and remove now redundant _remote_address * 20190916 - rework set/reset/default pin logic * 20190916 - cleanup: remove static vars, add/use constants, fix typos * 20190916 - fix build issues and implement geoup events for status verification. * 20190916 - remove extra lines,misc * 20190916 - rework ESP_BT_GAP_DISC_RES_EVT, added SPP_DISCONNECTED bit for disconnect event. + timeout for disconnect() * 20190916 - Small log change to improve log sequencing * 20190916 - remove static from local vars * 20190916 - Limited scope and duration for the scan, log device address during scan in info mode as it is very difficult to find out sometimes. Fixed get_name_from_eir() not resetting the name when called. * 20190916 - break property for loop during scan when name matches. * 20190916 - misc * 20190916 - SPP_DISCONNECT state updates * 20190916 - formatting, remove some strange syntax from initiator code * 20190916 - Add comments to the example about connect(...) usage and timeouts * 20190916 - fix disconnect() without timeout * 20190916 - Add example comment to view BT address and name during connect(name) * 20190916 - wording in example comments * 20190916 - rework connect() and disconnect() methods to help with concurrency and more authoritative status returned back to caller. Automatic disconnect in connect() methods * 20190916 - optimize code * 20190916 - optimize code - more * 20190916 - add timeout for pin set * 20190916 - change scan mode to ESP_BT_SCAN_MODE_CONNECTABLE_DISCOVERABLE * 20190916 - update example code slightly * 20190916 - increase READY_TIMEOUT to 10 secs * 20190916 - typo in example and move waitForConnect() to static area * 20190916 - update example comments * 20190916 - update example comments * 20190916 - update example comments * 20190916 - add new example to remove paired devices from ESP32 * 20190916 - correct typo in example * 20190916 - update example comment, add remove_bond_device() method for convenience. * 20190916 - reword example comment. * 20190916 - rename remove_bond_device() * 20190916 - rename removePairedDevice() to unpairDevice() * 20190916 - code review changes * 20190916 - fix return value in setup() od example
2019-10-01 16:34:46 +02:00
void enableSSP();
bool setPin(const char *pin);
bool connect(String remoteName);
bool connect(uint8_t remoteAddress[]);
bool connect();
bool connected(int timeout=0);
bool isReady(bool checkMaster=false, int timeout=0);
bool disconnect();
bool unpairDevice(uint8_t remoteAddress[]);
private:
String local_name;
};
#endif
#endif