diff --git a/src/SparkFun_Soil_Moisture_Sensor.h b/src/SparkFun_Soil_Moisture_Sensor.h index 3666a0e..7b2727a 100644 --- a/src/SparkFun_Soil_Moisture_Sensor.h +++ b/src/SparkFun_Soil_Moisture_Sensor.h @@ -21,18 +21,18 @@ // To make the Arduino machine happy, include the toolkit header before the core implementation for this device #include -#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: /** @@ -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; } /** @@ -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: /** @@ -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; }; \ No newline at end of file diff --git a/src/sfeTk/sfeDevSoilMoisture.cpp b/src/sfTk/sfDevSoilMoisture.cpp similarity index 74% rename from src/sfeTk/sfeDevSoilMoisture.cpp rename to src/sfTk/sfDevSoilMoisture.cpp index 510f27b..1cd47f3 100644 --- a/src/sfeTk/sfeDevSoilMoisture.cpp +++ b/src/sfTk/sfDevSoilMoisture.cpp @@ -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 @@ -14,7 +14,7 @@ */ -#include "sfeDevSoilMoisture.h" +#include "sfDevSoilMoisture.h" // Impl for the core driver @@ -48,34 +48,34 @@ // 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); @@ -83,13 +83,13 @@ sfeTkError_t sfeDevSoilMoisture::LEDOn(void) //---------------------------------------------------------------------------------------- // 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; @@ -97,53 +97,53 @@ uint16_t sfeDevSoilMoisture::readMoistureValue(void) //---------------------------------------------------------------------------------------- // 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; } diff --git a/src/sfeTk/sfeDevSoilMoisture.h b/src/sfTk/sfDevSoilMoisture.h similarity index 79% rename from src/sfeTk/sfeDevSoilMoisture.h rename to src/sfTk/sfDevSoilMoisture.h index 685144d..e610bac 100644 --- a/src/sfeTk/sfeDevSoilMoisture.h +++ b/src/sfTk/sfDevSoilMoisture.h @@ -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 @@ -20,18 +20,18 @@ #include // include the sparkfun toolkit headers -#include +#include // Bus interfaces -#include -#include +#include +#include /** * @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 @@ -39,7 +39,7 @@ * 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 @@ -47,12 +47,12 @@ * 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} { } @@ -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 @@ -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 @@ -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 \ No newline at end of file +}; // class sfDevSoilMoisture \ No newline at end of file