aboutsummaryrefslogtreecommitdiff
path: root/apps
diff options
context:
space:
mode:
Diffstat (limited to 'apps')
-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) {