@@ -222,6 +222,8 @@ void sfeIoTNodeLoRaWAN::onInit()
222
222
flxRegister (serialBaudRate, " Terminal Baud Rate" , " Update terminal baud rate. Changes take effect on restart" );
223
223
_terminalBaudRate = kDefaultTerminalBaudRate ;
224
224
225
+ enableSoilSensor.setTitle (" Devices" );
226
+ flxRegister (enableSoilSensor, " Soil Moisture Sensor" , " Enable GPIO attached Soil Moisture Sensor" );
225
227
// Advanced settings
226
228
verboseDevNames.setTitle (" Advanced" );
227
229
flxRegister (verboseDevNames, " Device Names" , " Name always includes the device address" );
@@ -361,11 +363,8 @@ void sfeIoTNodeLoRaWAN::onDeviceLoad()
361
363
b->on_clicked .call (this , &sfeIoTNodeLoRaWAN::onQwiicButtonEvent);
362
364
363
365
// setup our soil sensor device
364
-
365
366
_soilSensor.vccPin = kSoilSensorVCCPin ;
366
367
_soilSensor.sensorPin = kSoilSensorSensorPin ;
367
- _soilSensor.initialize ();
368
- flux_add (_soilSensor);
369
368
}
370
369
// ---------------------------------------------------------------------------
371
370
//
@@ -411,7 +410,7 @@ bool sfeIoTNodeLoRaWAN::onStart()
411
410
else if (device->getKind () == flxDeviceKindSPI)
412
411
flxLog_N (" %s p%u}" , " SPI" , device->address ());
413
412
else if (device->getKind () == flxDeviceKindGPIO)
414
- flxLog_N (" %s pin %u}" , " GPIO" , device->address ());
413
+ flxLog_N (" %s p %u}" , " GPIO" , device->address ());
415
414
416
415
if (device->nOutputParameters () > 0 )
417
416
{
@@ -561,6 +560,45 @@ void sfeIoTNodeLoRaWAN::set_local_name(std::string name)
561
560
flux.setLocalName (name);
562
561
}
563
562
563
+ // ---------------------------------------------------------------------------
564
+ // soil sensor enabled/disable
565
+ // ---------------------------------------------------------------------------
566
+ void sfeIoTNodeLoRaWAN::set_soil_enabled (bool enable)
567
+ {
568
+ // Is the soil sensor in the system?
569
+
570
+ bool active = flux.contains (_soilSensor);
571
+ if (active == enable)
572
+ return ; // same
573
+
574
+ if (enable)
575
+ {
576
+ // is the sensor initialized?
577
+ if (!_soilSensor.isInitialized ())
578
+ {
579
+ // init the sensor - this adds to the device list
580
+ if (_soilSensor.initialize () == false )
581
+ flxLog_W (F (" %s: failed to initialize." ), _soilSensor.name ());
582
+ }
583
+ else
584
+ flux.add (_soilSensor);
585
+ _loraWANLogger.add (_soilSensor);
586
+ _logger.add (_soilSensor);
587
+ }
588
+ else
589
+ {
590
+ flux.remove (_soilSensor);
591
+ _loraWANLogger.remove (_soilSensor);
592
+ _logger.remove (_soilSensor);
593
+ }
594
+
595
+ _soilSensor.isEnabled (enable);
596
+ }
597
+
598
+ bool sfeIoTNodeLoRaWAN::get_soil_enabled (void )
599
+ {
600
+ return flux.contains (_soilSensor);
601
+ }
564
602
// ---------------------------------------------------------------------------
565
603
// Display things during settings edits
566
604
// ---------------------------------------------------------------------------
0 commit comments