Skip to content

Commit

Permalink
docs(sht3x): update sensor README
Browse files Browse the repository at this point in the history
BREAKING CHANGE:
  - Library now uses CException for exception handling
  - Library is not STATIC
  • Loading branch information
DavidFederl committed Jul 29, 2024
1 parent ec2086a commit b26b17e
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 14 deletions.
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
2 changes: 0 additions & 2 deletions test/hardware/Sensors/HardwaretestSht3x.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#define SOURCE_FILE "SHT3X-Test"

#include <stdio.h>

#include "CException.h"
#include "hardware/i2c.h"
#include "pico/bootrom.h"
Expand Down

0 comments on commit b26b17e

Please sign in to comment.