diff --git a/components/ads7138/include/ads7138.hpp b/components/ads7138/include/ads7138.hpp index b1403d5ce..ff345d280 100644 --- a/components/ads7138/include/ads7138.hpp +++ b/components/ads7138/include/ads7138.hpp @@ -166,6 +166,8 @@ class Ads7138 { bool statistics_enabled = true; ///< Enable statistics collection (min, max, recent) write_fn write; ///< Function to write to the ADC read_fn read; ///< Function to read from the ADC + bool auto_init = true; ///< Automatically initialize the ADC on construction. If false, + ///< initialize() must be called before any other functions. espp::Logger::Verbosity log_level{espp::Logger::Verbosity::WARN}; ///< Verbosity for the logger. }; @@ -174,7 +176,7 @@ class Ads7138 { * @param config Configuration structure. */ Ads7138(const Config &config) - : mode_(config.mode), avdd_mv_(config.avdd_volts * 1000.0f) // Convert to mV + : config_(config), mode_(config.mode), avdd_mv_(config.avdd_volts * 1000.0f) // Convert to mV , data_format_(config.oversampling_ratio == OversamplingRatio::NONE ? DataFormat::RAW : DataFormat::AVERAGED), @@ -183,9 +185,21 @@ class Ads7138 { oversampling_ratio_(config.oversampling_ratio), address_(config.device_address), write_(config.write), read_(config.read), logger_({.tag = "Ads7138", .level = config.log_level}) { - init(config); + // initialize the ADC + if (config.auto_init) { + initialize(); + } } + /** + * @brief Initialize the ADC + * This function uses the configuration structure passed to the + * constructor to configure the ADC. + * @note This function must be called before any other functions as it + * configures the ADC pins and sets the mode. + */ + void initialize() { init(config_); } + /** * @brief Communicate with the ADC to get the analog value for the channel * and return it. @@ -1313,6 +1327,8 @@ class Ads7138 { write_(address_, data_with_header, total_len); } + Config config_; + Mode mode_; float avdd_mv_; DataFormat data_format_; diff --git a/docs/adc/adc_types.html b/docs/adc/adc_types.html index 1858b1b38..e63dc73ea 100644 --- a/docs/adc/adc_types.html +++ b/docs/adc/adc_types.html @@ -141,7 +141,7 @@
Initialize the ADC This function uses the configuration structure passed to the constructor to configure the ADC.
+Note
+This function must be called before any other functions as it configures the ADC pins and sets the mode.
+Automatically initialize the ADC on construction. If false, initialize() must be called before any other functions.
+Warning
-doxygenfunction: Unable to resolve function “to_time_t” with arguments None in doxygen xml output for project “esp-docs” from directory: /Users/bob/esp-cpp/espp/doc/_build/en/esp32/xml_in/. +
doxygenfunction: Unable to resolve function “to_time_t” with arguments None in doxygen xml output for project “esp-docs” from directory: /Users/bob/backbone/lodestone/components/espp/doc/_build/en/esp32/xml_in/. Potential matches:
- template<typename TP> std::time_t to_time_t(TP tp)
diff --git a/docs/ftp/index.html b/docs/ftp/index.html
index b32770103..7f54b458a 100644
--- a/docs/ftp/index.html
+++ b/docs/ftp/index.html
@@ -130,7 +130,7 @@
Construct the Aw9523 and configure it.
+Construct the Aw9523. Initialization called separately.
config – Config structure for configuring the AW9523
@@ -404,6 +405,12 @@Initialize the component class.
+Read the output pin values on the provided port.
+port – The Port for which to read the pins
+The pin values as an 8 bit mask.
+Read the output pin values on both Port 0 and Port 1.
+The pin values as a 16 bit mask (P0_0 lsb, P1_7 msb).
+