From d720fa36ad4768ed1b948a92ba5287c30093fbec Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Sun, 26 Jul 2015 18:33:15 +0200 Subject: o Overhaul of the bluetooth code. - Adding support for reading FLOAT (specified in IEEE 11073-20601) values from a bluetooth device. - More shared pointers to help keep track of the object's lifecycle. Makes sure that the connections are released back to Linux, Linux is way to sensitive with crashing applications. o Adding support for reading the temperature sensors from the SoilMoisture device. --- ble/Bluetooth.cpp | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) (limited to 'ble/Bluetooth.cpp') diff --git a/ble/Bluetooth.cpp b/ble/Bluetooth.cpp index 3db0bfc..13c81b3 100644 --- a/ble/Bluetooth.cpp +++ b/ble/Bluetooth.cpp @@ -201,19 +201,26 @@ BluetoothAdapter::BluetoothAdapter() { BluetoothAdapter::~BluetoothAdapter() { } +// ----------------------------------------------------------------------- +// Bluetooth System. This is not sub-classed by implementations. +// ----------------------------------------------------------------------- + BluetoothSystem::BluetoothSystem() { } BluetoothSystem::~BluetoothSystem() { - shutdown(); + adapters.clear(); } -shared_ptr getAdapter(int hciDevice) { - return getAdapterImpl(hciDevice); -} +shared_ptr BluetoothSystem::getAdapter(string name) { + auto it = adapters.find(name); + + if (it == adapters.end()) { + auto adapter = adapters[name] = getAdapterImpl(name); + return adapter; + } -void shutdown() { - shutdownImpl(); + return it->second; } uuid_t makeUuid(const uuid_t base, uint8_t a, uint8_t b) { -- cgit v1.2.3