Skip to content

Commit f870a53

Browse files
committed
finalize support for the soil moisture sensor
1 parent 0caef70 commit f870a53

File tree

2 files changed

+48
-4
lines changed

2 files changed

+48
-4
lines changed

sfeIoTNodeLoRaWAN/sfeIoTNodeLoRaWAN.cpp

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,8 @@ void sfeIoTNodeLoRaWAN::onInit()
222222
flxRegister(serialBaudRate, "Terminal Baud Rate", "Update terminal baud rate. Changes take effect on restart");
223223
_terminalBaudRate = kDefaultTerminalBaudRate;
224224

225+
enableSoilSensor.setTitle("Devices");
226+
flxRegister(enableSoilSensor, "Soil Moisture Sensor", "Enable GPIO attached Soil Moisture Sensor");
225227
// Advanced settings
226228
verboseDevNames.setTitle("Advanced");
227229
flxRegister(verboseDevNames, "Device Names", "Name always includes the device address");
@@ -361,11 +363,8 @@ void sfeIoTNodeLoRaWAN::onDeviceLoad()
361363
b->on_clicked.call(this, &sfeIoTNodeLoRaWAN::onQwiicButtonEvent);
362364

363365
// setup our soil sensor device
364-
365366
_soilSensor.vccPin = kSoilSensorVCCPin;
366367
_soilSensor.sensorPin = kSoilSensorSensorPin;
367-
_soilSensor.initialize();
368-
flux_add(_soilSensor);
369368
}
370369
//---------------------------------------------------------------------------
371370
//
@@ -411,7 +410,7 @@ bool sfeIoTNodeLoRaWAN::onStart()
411410
else if (device->getKind() == flxDeviceKindSPI)
412411
flxLog_N("%s p%u}", "SPI", device->address());
413412
else if (device->getKind() == flxDeviceKindGPIO)
414-
flxLog_N("%s pin %u}", "GPIO", device->address());
413+
flxLog_N("%s p%u}", "GPIO", device->address());
415414

416415
if (device->nOutputParameters() > 0)
417416
{
@@ -561,6 +560,45 @@ void sfeIoTNodeLoRaWAN::set_local_name(std::string name)
561560
flux.setLocalName(name);
562561
}
563562

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+
}
564602
//---------------------------------------------------------------------------
565603
// Display things during settings edits
566604
//---------------------------------------------------------------------------

sfeIoTNodeLoRaWAN/sfeIoTNodeLoRaWAN.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,9 @@ class sfeIoTNodeLoRaWAN : public flxApplication
111111
bool get_verbose(void);
112112
void set_verbose(bool enable);
113113

114+
bool get_soil_enabled(void);
115+
void set_soil_enabled(bool enable);
116+
114117
void onSettingsEdit(bool bLoading);
115118
void onSystemActivity(void);
116119
void onSystemActivityLow(void);
@@ -177,6 +180,9 @@ class sfeIoTNodeLoRaWAN : public flxApplication
177180
flxPropertyRWBool<sfeIoTNodeLoRaWAN, &sfeIoTNodeLoRaWAN::get_verbose, &sfeIoTNodeLoRaWAN::set_verbose>
178181
verboseEnabled = {false};
179182

183+
flxPropertyRWBool<sfeIoTNodeLoRaWAN, &sfeIoTNodeLoRaWAN::get_soil_enabled, &sfeIoTNodeLoRaWAN::set_soil_enabled>
184+
enableSoilSensor = {false};
185+
180186
private:
181187
friend class sfeNLCommands;
182188
void _displayAboutObjHelper(char, const char *, bool);

0 commit comments

Comments
 (0)