aboutsummaryrefslogtreecommitdiff
path: root/apps
diff options
context:
space:
mode:
authorTrygve Laugstøl <trygvis@inamo.no>2018-11-23 09:40:48 +0100
committerTrygve Laugstøl <trygvis@inamo.no>2018-11-23 09:40:48 +0100
commit2034b1bb10720a2f0e6cc97427346f2320c115bc (patch)
treec382c6e404d48078aac71e2fd3f7f34587b99e7b /apps
parent0e2228fae626ec617a6a1f042ceb6dbdbd774558 (diff)
downloadble-toys-2034b1bb10720a2f0e6cc97427346f2320c115bc.tar.gz
ble-toys-2034b1bb10720a2f0e6cc97427346f2320c115bc.tar.bz2
ble-toys-2034b1bb10720a2f0e6cc97427346f2320c115bc.tar.xz
ble-toys-2034b1bb10720a2f0e6cc97427346f2320c115bc.zip
o Starting to handle notifications and indications
Cleaning up: o Using more of the shared_ptr typedefs. o Adding code styles used by CLion.
Diffstat (limited to 'apps')
-rw-r--r--apps/SoilMoisture.cpp16
-rw-r--r--apps/SoilMoisture.h12
-rw-r--r--apps/ble-read-characteristic.cpp8
3 files changed, 20 insertions, 16 deletions
diff --git a/apps/SoilMoisture.cpp b/apps/SoilMoisture.cpp
index 3129564..fcf81bd 100644
--- a/apps/SoilMoisture.cpp
+++ b/apps/SoilMoisture.cpp
@@ -62,18 +62,18 @@ void createSetUpdateInterval(ByteBuffer buffer, uint8_t sensor, uint8_t interval
.write8(interval_in_seconds);
}
-SoilMoisture SoilMoisture::create(shared_ptr<BluetoothGatt> gatt) {
+SoilMoisture SoilMoisture::create(BluetoothGattPtr gatt) {
gatt->discoverServices();
- o<shared_ptr<BluetoothGattService>> s = gatt->findService(soil_moisture_service);
+ auto s = gatt->findService(soil_moisture_service);
if (!s) {
throw runtime_error("The device is missing the soil moisture service");
}
- shared_ptr<BluetoothGattService> &service = *s;
+ auto &service = *s;
- o<shared_ptr<BluetoothGattCharacteristic>> c = service->findCharacteristic(soil_moisture_characteristic);
+ auto c = service->findCharacteristic(soil_moisture_characteristic);
if (!c) {
throw runtime_error("The device is missing the soil moisture characteristic");
@@ -86,8 +86,8 @@ SoilMoisture SoilMoisture::create(shared_ptr<BluetoothGatt> gatt) {
return SoilMoisture(gatt, service, c.operator*(), temperature, light);
}
-SoilMoisture::SoilMoisture(const shared_ptr<BluetoothGatt> &gatt,
- const shared_ptr<BluetoothGattService> &s,
+SoilMoisture::SoilMoisture(const BluetoothGattPtr &gatt,
+ const BluetoothGattServicePtr &s,
const BluetoothGattCharacteristicPtr &soilMoistureCharacteristic,
const o<BluetoothGattCharacteristicPtr> temperatureCharacteristic,
const o<BluetoothGattCharacteristicPtr> lightCharacteristic)
@@ -192,5 +192,5 @@ void SoilMoisture::setLight(uint8_t light, uint8_t value) {
bitset<8> b0 = responseBytes.read8();
}
-}
-}
+} // namespace sensor
+} // namespace trygvis
diff --git a/apps/SoilMoisture.h b/apps/SoilMoisture.h
index 4e6ae17..a46afeb 100644
--- a/apps/SoilMoisture.h
+++ b/apps/SoilMoisture.h
@@ -29,7 +29,7 @@ extern const Uuid soil_moisture_characteristic;
class SoilMoisture {
public:
- static SoilMoisture create(shared_ptr<BluetoothGatt> gatt);
+ static SoilMoisture create(BluetoothGattPtr gatt);
uint8_t getSensorCount();
@@ -44,16 +44,16 @@ public:
void setLight(uint8_t light, uint8_t value);
private:
- SoilMoisture(const shared_ptr<BluetoothGatt> &gatt,
- const shared_ptr<BluetoothGattService> &s,
- const shared_ptr<BluetoothGattCharacteristic> &soilMoistureCharacteristic,
+ SoilMoisture(const BluetoothGattPtr &gatt,
+ const BluetoothGattServicePtr &s,
+ const BluetoothGattCharacteristicPtr &soilMoistureCharacteristic,
const o<BluetoothGattCharacteristicPtr> temperatureCharacteristic,
const o<BluetoothGattCharacteristicPtr> lightCharacteristic);
void writeAndRead(const BluetoothGattCharacteristicPtr &c, ByteBuffer &requestBytes);
- shared_ptr<BluetoothGatt> gatt;
- shared_ptr<BluetoothGattService> s;
+ BluetoothGattPtr gatt;
+ BluetoothGattServicePtr s;
const BluetoothGattCharacteristicPtr soilMoistureCharacteristic;
const o<BluetoothGattCharacteristicPtr> temperatureCharacteristic;
const o<BluetoothGattCharacteristicPtr> lightCharacteristic;
diff --git a/apps/ble-read-characteristic.cpp b/apps/ble-read-characteristic.cpp
index 8efcb3b..ecdb471 100644
--- a/apps/ble-read-characteristic.cpp
+++ b/apps/ble-read-characteristic.cpp
@@ -109,8 +109,12 @@ public:
cccd->setValue(ByteBuffer::wrapInitialized(BluetoothGattDescriptor::ENABLE_NOTIFICATION_VALUE));
gatt->write(cccd);
- cout << "sleeping" << endl;
- std::this_thread::sleep_for(10s);
+ auto end = std::chrono::system_clock::now() + 10s;
+
+ do {
+ cerr << "Processing messages" << endl;
+ gatt->process(2s);
+ } while(std::chrono::system_clock::now() < end);
}
} else {
cout << "Unsupported op mode." << endl;