Skip to content

Commit

Permalink
Merge pull request #237 from es-ude/102-integrate-cexception-into-sen…
Browse files Browse the repository at this point in the history
…sor-libraries

Integrate CException into SHT3x library
  • Loading branch information
DavidFederl authored Jul 29, 2024
2 parents 271b495 + b26b17e commit 8cd2e92
Show file tree
Hide file tree
Showing 10 changed files with 753 additions and 479 deletions.
16 changes: 10 additions & 6 deletions src/sensor/sht3x/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
add_library(sensor_lib_sht3x INTERFACE)
target_include_directories(sensor_lib_sht3x INTERFACE ${CMAKE_CURRENT_LIST_DIR}/include)
target_sources(sensor_lib_sht3x INTERFACE
${CMAKE_CURRENT_LIST_DIR}/Sht3x.c)
target_link_libraries(sensor_lib_sht3x INTERFACE
add_library(sensor_lib_sht3x STATIC
${CMAKE_CURRENT_LIST_DIR}/Sht3x.c
)
target_include_directories(sensor_lib_sht3x INTERFACE
${CMAKE_CURRENT_LIST_DIR}/include
)
target_link_libraries(sensor_lib_sht3x PUBLIC
CException
)
target_link_libraries(sensor_lib_sht3x PRIVATE
common_lib
sleep_interface
i2c_interface
)
53 changes: 41 additions & 12 deletions src/sensor/sht3x/README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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)
----

Expand Down
Loading

0 comments on commit 8cd2e92

Please sign in to comment.