Skip to content

fix issues related to name change #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions src/SparkFun_Soil_Moisture_Sensor.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,18 @@

// To make the Arduino machine happy, include the toolkit header before the core implementation for this device
#include <SparkFun_Toolkit.h>
#include "sfeTk/sfeDevSoilMoisture.h"
#include "sfTk/sfDevSoilMoisture.h"


// Note:
// The core of the implementation for this device library is in the SparkFun Toolkit object sfeDevSoilMoisture,
// contained in the directory sfeTk. This object implements all functionality independent of the bus type, I2C or SPI.
// The core of the implementation for this device library is in the SparkFun Toolkit object sfDevSoilMoisture,
// contained in the directory sfTk. This object implements all functionality independent of the bus type, I2C or SPI.
// The SparkFunSoilMoistureSensorI2C and SparkFunSoilMoistureSensorSPI classes below are the Arduino-specific,
// bus-specific implementations that inherit from the core toolkit class.
//
//-----------------------------------------------------------------------------------------------
// Define our Arduino Object - I2C version
class SparkFunSoilMoistureSensorI2C : public sfeDevSoilMoisture
class SparkFunSoilMoistureSensorI2C : public sfDevSoilMoisture
{
public:
/**
Expand All @@ -45,13 +45,13 @@ class SparkFunSoilMoistureSensorI2C : public sfeDevSoilMoisture
* @param wirePort Wire port to use for I2C communication (default is Wire)
* @return true if successful, false otherwise
*/
bool begin(const uint8_t address = SFE_SOIL_MOISTURE_DEFAULT_I2C_ADDRESS, TwoWire &wirePort = Wire)
bool begin(const uint8_t address = SF_SOIL_MOISTURE_DEFAULT_I2C_ADDRESS, TwoWire &wirePort = Wire)
{
// Setup Arduino I2C bus
_theI2CBus.init(wirePort, address);

// Begin the sensor and make sure it's connected.
return sfeDevSoilMoisture::begin(&_theI2CBus) == kSTkErrOk ? isConnected() : false;
return sfDevSoilMoisture::begin(&_theI2CBus) == ksfTkErrOk ? isConnected() : false;
}

/**
Expand All @@ -64,16 +64,16 @@ class SparkFunSoilMoistureSensorI2C : public sfeDevSoilMoisture
*/
bool isConnected()
{
return _theI2CBus.ping() == kSTkErrOk;
return _theI2CBus.ping() == ksfTkErrOk;
}

private:
sfeTkArdI2C _theI2CBus;
sfTkArdI2C _theI2CBus;
};

//-----------------------------------------------------------------------------------------------
// Define our Arduino Object - SPI version
class SparkFunSoilMoistureSensorSPI : public sfeDevSoilMoisture
class SparkFunSoilMoistureSensorSPI : public sfDevSoilMoisture
{
public:
/**
Expand All @@ -96,9 +96,9 @@ class SparkFunSoilMoistureSensorSPI : public sfeDevSoilMoisture
_theSPIBus.init(spiPort, spiSettings, csPin, true);

// Begin the sensor with the SPI bus connection
return (sfeDevSoilMoisture::begin(&_theSPIBus) == kSTkErrOk);
return (sfDevSoilMoisture::begin(&_theSPIBus) == ksfTkErrOk);
}

private:
sfeTkArdSPI _theSPIBus;
sfTkArdSPI _theSPIBus;
};
50 changes: 25 additions & 25 deletions src/sfeTk/sfeDevSoilMoisture.cpp → src/sfTk/sfDevSoilMoisture.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* @file sfeDevSoilMoisture.cpp
* @file sfDevSoilMoisture.cpp
* @brief Implementation file for the soil moisture sensor class
*
* This file contains the implementation of the soil moisture sensor class, including
Expand All @@ -14,7 +14,7 @@
*/


#include "sfeDevSoilMoisture.h"
#include "sfDevSoilMoisture.h"

// Impl for the core driver

Expand Down Expand Up @@ -48,102 +48,102 @@
// Core object implementation
//---------------------------------------------------------------------
// start up the sensor
sfeTkError_t sfeDevSoilMoisture::begin(sfeTkIBus *theBus)
sfTkError_t sfDevSoilMoisture::begin(sfTkIBus *theBus)
{
// Nullptr check
if (theBus == nullptr)
return kSTkErrBusNotInit;
return ksfTkErrBusNotInit;

// Set bus pointer
_theBus = theBus;

return kSTkErrOk;
return ksfTkErrOk;
}

//----------------------------------------------------------------------------------------
// LED off command
sfeTkError_t sfeDevSoilMoisture::LEDOff(void)
sfTkError_t sfDevSoilMoisture::LEDOff(void)
{
if (_theBus == nullptr)
return kSTkErrBusNotInit;
return ksfTkErrBusNotInit;

// Send the command to turn the LED off
return _theBus->writeByte(kCommandLEDOff);
}
//----------------------------------------------------------------------------------------
// LED on command
sfeTkError_t sfeDevSoilMoisture::LEDOn(void)
sfTkError_t sfDevSoilMoisture::LEDOn(void)
{
if (_theBus == nullptr)
return kSTkErrBusNotInit;
return ksfTkErrBusNotInit;

// Send the command to turn the LED on
return _theBus->writeByte(kCommandLEDOn);
}

//----------------------------------------------------------------------------------------
// Read the moisture value from the sensor - returns a resistance reading between 0 and 1023
uint16_t sfeDevSoilMoisture::readMoistureValue(void)
uint16_t sfDevSoilMoisture::readMoistureValue(void)
{
if (_theBus == nullptr)
return 0;

uint16_t value = 0;
if (_theBus->readRegisterWord(kCommandGetValue, value) != kSTkErrOk)
if (_theBus->readRegisterWord(kCommandGetValue, value) != ksfTkErrOk)
return 0;

return value;
}

//----------------------------------------------------------------------------------------
// Returns the moisture ratio from the sensor (0 - 1.0)
float sfeDevSoilMoisture::readMoistureRatio(void)
float sfDevSoilMoisture::readMoistureRatio(void)
{
if (_theBus == nullptr)
return 0.0;

return (((float)SFE_SOIL_MOISTURE_MAX_VALUE - (float)readMoistureValue()) / (float)SFE_SOIL_MOISTURE_MAX_VALUE);
return (((float)SF_SOIL_MOISTURE_MAX_VALUE - (float)readMoistureValue()) / (float)SF_SOIL_MOISTURE_MAX_VALUE);
}

//----------------------------------------------------------------------------------------
// Returns the moisture percentage from the sensor (0 - 100%)
float sfeDevSoilMoisture::readMoisturePercentage(void)
float sfDevSoilMoisture::readMoisturePercentage(void)
{
return readMoistureRatio() * 100.0;
}
//----------------------------------------------------------------------------------------
// Change the I2C address of the sensor
sfeTkError_t sfeDevSoilMoisture::setI2CAddress(uint8_t newAddress)
sfTkError_t sfDevSoilMoisture::setI2CAddress(uint8_t newAddress)
{
if (_theBus == nullptr)
return kSTkErrBusNotInit;
return ksfTkErrBusNotInit;

// Validate the new address
if (newAddress < 0x07 || newAddress > 0x78)
return kSTkErrFail;
return ksfTkErrFail;

// If in I2C mode, is the address the same as the current address?
if (_theBus->type() == kBusTypeI2C && ((sfeTkII2C *)_theBus)->address() == newAddress)
return kSTkErrOk;
if (_theBus->type() == ksfTkBusTypeI2C && ((sfTkII2C *)_theBus)->address() == newAddress)
return ksfTkErrOk;

// Send the command to change the address. NOTE: Because of how the sensor works,
// the following will return an error (since the sensor side resets the bus)
(void)_theBus->writeRegisterByte(kCommandChangeAddress, newAddress);

return kSTkErrOk;
return ksfTkErrOk;
}
//----------------------------------------------------------------------------------------
// Return the address of the sensor bus. For I2C this is the address of the sensor, for
// SPI this is the CS pin
uint8_t sfeDevSoilMoisture::address(void)
uint8_t sfDevSoilMoisture::address(void)
{
if (_theBus == nullptr)
return 0;

if (_theBus->type() == kBusTypeSPI)
return ((sfeTkISPI *)_theBus)->cs();
else if (_theBus->type() == kBusTypeI2C)
return ((sfeTkII2C *)_theBus)->address();
if (_theBus->type() == ksfTkBusTypeSPI)
return ((sfTkISPI *)_theBus)->cs();
else if (_theBus->type() == ksfTkBusTypeI2C)
return ((sfTkII2C *)_theBus)->address();

return 0;
}
46 changes: 23 additions & 23 deletions src/sfeTk/sfeDevSoilMoisture.h → src/sfTk/sfDevSoilMoisture.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* @file sfeDevSoilMoisture.h
* @file sfDevSoilMoisture.h
* @brief Header file for the soil moisture sensor class
*
* This file contains the class definition for the soil moisture sensor, including
Expand All @@ -20,39 +20,39 @@
#include <stdint.h>

// include the sparkfun toolkit headers
#include <sfeTk/sfeToolkit.h>
#include <sfTk/sfToolkit.h>

// Bus interfaces
#include <sfeTk/sfeTkII2C.h>
#include <sfeTk/sfeTkISPI.h>
#include <sfTk/sfTkII2C.h>
#include <sfTk/sfTkISPI.h>

/**
* @brief Default I2C address for the soil moisture sensor
*
* This macro defines the default I2C address (0x28) used by the soil moisture sensor.
*/
#define SFE_SOIL_MOISTURE_DEFAULT_I2C_ADDRESS 0x28
#define SF_SOIL_MOISTURE_DEFAULT_I2C_ADDRESS 0x28

/**
* @brief Maximum value for the soil moisture sensor
*
* This macro defines the maximum value (1023) for the soil moisture sensor,
* which corresponds to the highest reading from the 10-bit ADC. 2^10 = 1024-1
*/
#define SFE_SOIL_MOISTURE_MAX_VALUE 1023
#define SF_SOIL_MOISTURE_MAX_VALUE 1023

/**
* @brief Class representing the soil moisture sensor
*
* This class provides an interface to the soil moisture sensor, allowing for
* initialization, reading moisture values and controlling the on-board LED.
*/
class sfeDevSoilMoisture
class sfDevSoilMoisture
{

public:
// ctor
sfeDevSoilMoisture() : _theBus{nullptr}
sfDevSoilMoisture() : _theBus{nullptr}
{
}

Expand All @@ -63,36 +63,36 @@ class sfeDevSoilMoisture
* communication with the sensor using the provided I2C bus interface.
*
* @param theBus Pointer to an I2C toolkit object. If nullptr, uses previously set bus
* @return kSTkErrOk if initialization succeeds
* @return kSTkErrBusNotInit if no valid bus interface is provided
* @return ksfTkErrOk if initialization succeeds
* @return ksfTkErrBusNotInit if no valid bus interface is provided
*/
sfeTkError_t begin(sfeTkIBus *theBus = nullptr);
sfTkError_t begin(sfTkIBus *theBus = nullptr);

/**
* @brief Turns off the on-board LED
*
* Disables the sensor's built-in LED
*
* @return kSTkErrOk if LED was successfully turned off
* @return kSTkErrBusNotInit if no bus interface is configured
* @return kSTkErrFail if sensor doesn't respond or a communication error occurs
* @return ksfTkErrOk if LED was successfully turned off
* @return ksfTkErrBusNotInit if no bus interface is configured
* @return ksfTkErrFail if sensor doesn't respond or a communication error occurs
*
* @see LEDOn()
*/
sfeTkError_t LEDOff(void);
sfTkError_t LEDOff(void);

/**
* @brief Turns on the on-board LED
*
* Enables the sensor's built-in LED by sending the appropriate command
*
* @return kSTkErrOk if LED was successfully turned on
* @return kSTkErrBusNotInit if no bus interface is configured
* @return kSTkErrFail if sensor doesn't respond or a communication error occurs
* @return ksfTkErrOk if LED was successfully turned on
* @return ksfTkErrBusNotInit if no bus interface is configured
* @return ksfTkErrFail if sensor doesn't respond or a communication error occurs
*
* @see LEDOff()
*/
sfeTkError_t LEDOn(void);
sfTkError_t LEDOn(void);

/**
* @brief Reads the moisture value from the sensor
Expand Down Expand Up @@ -134,10 +134,10 @@ class sfeDevSoilMoisture
* for all future I2C communication with the sensor. This value is persistent
*
* @param newAddress The new I2C address to assign to the sensor
* @return kSTkErrOk if successful, otherwise an error code
* @return ksfTkErrOk if successful, otherwise an error code
* @note If communicating via I2C, the provided address is used for future I2C communication
*/
sfeTkError_t setI2CAddress(uint8_t newAddress);
sfTkError_t setI2CAddress(uint8_t newAddress);

/**
* @brief Returns the current address of the sensor
Expand All @@ -156,6 +156,6 @@ class sfeDevSoilMoisture
* This member variable holds a pointer to the bus interface (I2C or SPI) used
* for communication with the soil moisture sensor.
*/
sfeTkIBus *_theBus;
sfTkIBus *_theBus;

}; // class sfeDevSoilMoisture
}; // class sfDevSoilMoisture