From f6493150c1a7172bcd8c9cc1790829285f707ee9 Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Wed, 29 Jul 2015 08:52:57 +0200 Subject: o Only discovering sensors if they haven't been discovered before. --- apps/sm-get-value.cpp | 32 +++++++++++++++++--------------- 1 file 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 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) { -- cgit v1.2.3