aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTrygve Laugstøl <trygvis@inamo.no>2015-07-29 08:52:57 +0200
committerTrygve Laugstøl <trygvis@inamo.no>2015-07-29 08:52:57 +0200
commitf6493150c1a7172bcd8c9cc1790829285f707ee9 (patch)
treed476cc9e0e7b29cd498caf3bc13e21b5f5dce366
parentd720fa36ad4768ed1b948a92ba5287c30093fbec (diff)
downloadble-toys-f6493150c1a7172bcd8c9cc1790829285f707ee9.tar.gz
ble-toys-f6493150c1a7172bcd8c9cc1790829285f707ee9.tar.bz2
ble-toys-f6493150c1a7172bcd8c9cc1790829285f707ee9.tar.xz
ble-toys-f6493150c1a7172bcd8c9cc1790829285f707ee9.zip
o Only discovering sensors if they haven't been discovered before.
-rw-r--r--apps/sm-get-value.cpp32
1 files changed, 17 insertions, 15 deletions
diff --git a/apps/sm-get-value.cpp b/apps/sm-get-value.cpp
index 5d66320..43729d8 100644
--- a/apps/sm-get-value.cpp
+++ b/apps/sm-get-value.cpp
@@ -142,28 +142,30 @@ public:
void withConnection(sample_format_type format, shared_ptr<BluetoothGatt> gatt) {
SoilMoisture soilMoisture = SoilMoisture::create(gatt);
- const int sensorCount = soilMoisture.getSensorCount();
+ if (sensors.empty()) {
- if (sensorCount == 0) {
- throw runtime_error("Sensor count is 0");
- }
+ const int sensorCount = soilMoisture.getSensorCount();
- // If the user didn't specify any sensors, add all.
- if (sensors.size() == 0) {
- for (unsigned int i = 0; i < sensorCount; i++) {
- sensorIndexes.push_back(i);
+ if (sensorCount == 0) {
+ throw runtime_error("Sensor count is 0");
}
- }
- for_each(begin(sensorIndexes), end(sensorIndexes), [&](auto i) {
- if (i >= sensorCount) {
- // Ignore invalid sensors
- return;
+ // If the user didn't specify any sensors, add all.
+ if (sensors.size() == 0) {
+ for (unsigned int i = 0; i < sensorCount; i++) {
+ sensorIndexes.push_back(i);
+ }
}
- sensors.push_back(make_pair(i, soilMoisture.getName(i)));
- });
+ for_each(begin(sensorIndexes), end(sensorIndexes), [&](auto i) {
+ if (i >= sensorCount) {
+ // Ignore invalid sensors
+ return;
+ }
+ sensors.push_back(make_pair(i, soilMoisture.getName(i)));
+ });
+ }
auto mac = gatt->getDevice().getMac().str();
if (!loop) {