From b26b17e9da02761fa38859c77382289bf53b58fd Mon Sep 17 00:00:00 2001 From: "David P. Federl" Date: Mon, 29 Jul 2024 12:44:17 +0200 Subject: [PATCH] docs(sht3x): update sensor README BREAKING CHANGE: - Library now uses CException for exception handling - Library is not STATIC --- src/sensor/sht3x/README.adoc | 53 ++++++++++++++++++----- test/hardware/Sensors/HardwaretestSht3x.c | 2 - 2 files changed, 41 insertions(+), 14 deletions(-) diff --git a/src/sensor/sht3x/README.adoc b/src/sensor/sht3x/README.adoc index c60bd4a5..b7ade74c 100644 --- a/src/sensor/sht3x/README.adoc +++ b/src/sensor/sht3x/README.adoc @@ -23,36 +23,65 @@ include::include/Sht3x.h[tags=prototypes] .main.c [source,c] ---- -#include "sht3x/Sht3x.h" -#include "hardware/i2cConfig.h" +#include "CException.h" +#include "hardware/i2c.h" + +#include "Common.h" +#include "I2c.h" +#include "Sht3x.h" +#include "EnV5HwConfiguration.h" + +i2cConfiguration_t i2cConfig = { + .i2cInstance = I2C_INSTANCE, + .frequency = I2C_FREQUENCY_IN_HZ, + .sdaPin = I2C_SDA_PIN, + .sclPin = I2C_SCL_PIN, +}; +sht3xSensorConfiguration_t sensor = { + .i2c_host = SHT_HOST, + .i2c_slave_address = SHT_SLAVE, +}; int main(void) { - sht3xErrorCode_t errorCode = sht3xInit(i2c0); // <1> - if (errorCode != SHT3X_NO_ERROR) { - return errorCode; // <2> + i2cErrorCode = i2cInit(&i2cConfig); //<1> + if (i2cErrorCode != I2C_NO_ERROR) { + PRINT("Initialise I2C failed!"); + return i2cErrorCode; } - float temperature, humidity; - errorCode = sht3xGetTemperatureAndHumidity(&temperature, &humidity); // <3> - if (errorCode != SHT3X_NO_ERROR) { - return errorCode; //<2> + CEXCEPTION_T exception; + Try { + sht3xInit(sensor); //<2> + float temperature, humidity; + sht3xGetTemperatureAndHumidity(&temperature, &humidity); //<3> + } + Catch (exception) { //<4> + return exception; } return 0; } ---- -<1> Initialize Sensor *ALWAYS REQUIRED* -<2> Handle possible errors +<1> Initilaize I2C +<2> Initialize Sensor <3> Read Temperature and Humidity +<4> Handle possible errors .CMakeLists.txt [source,CMake] ---- add_executable(my-sht3x-app main.c) target_link_libraries(my-sht3x-app + pico_stdlib + pico_stdio_usb hardware_i2c # <1> - sensor_lib_sht3x) # <2> + + common_lib + enV5_hw_configuration + i2c_interface + sensor_lib_sht3x # <2> +) create_enV5_executable(my-sht3x-app) ---- diff --git a/test/hardware/Sensors/HardwaretestSht3x.c b/test/hardware/Sensors/HardwaretestSht3x.c index 0e14a6ad..0d62b30a 100644 --- a/test/hardware/Sensors/HardwaretestSht3x.c +++ b/test/hardware/Sensors/HardwaretestSht3x.c @@ -1,7 +1,5 @@ #define SOURCE_FILE "SHT3X-Test" -#include - #include "CException.h" #include "hardware/i2c.h" #include "pico/bootrom.h"