Skip to content

Commit

Permalink
Merge pull request #8 from optimeas/device-path
Browse files Browse the repository at this point in the history
sensirion_i2c_hal_init: add parameter to specify the device path
  • Loading branch information
psachs authored Jul 31, 2024
2 parents fc0da53 + 7aac1f4 commit acbbaa9
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
8 changes: 7 additions & 1 deletion sen5x_i2c_example_usage.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,16 @@
* #define printf(...)
*/

/**
* Linux specific configuration. Adjust the following define to the device path
* of your sensor.
*/
#define I2C_DEVICE_PATH "/dev/i2c-1"

int main(void) {
int16_t error = 0;

sensirion_i2c_hal_init();
sensirion_i2c_hal_init(I2C_DEVICE_PATH);

error = sen5x_device_reset();
if (error) {
Expand Down
10 changes: 2 additions & 8 deletions sensirion_i2c_hal.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,6 @@
#include <sys/ioctl.h>
#include <unistd.h>

/**
* Linux specific configuration. Adjust the following define to the device path
* of your sensor.
*/
#define I2C_DEVICE_PATH "/dev/i2c-1"

/**
* The following define was taken from i2c-dev.h. Alternatively the header file
* can be included. The define was added in Linux v3.10 and never changed since
Expand All @@ -64,9 +58,9 @@ static uint8_t i2c_address = 0;
* Initialize all hard- and software components that are needed for the I2C
* communication.
*/
void sensirion_i2c_hal_init(void) {
void sensirion_i2c_hal_init(const char* device_path) {
/* open i2c adapter */
i2c_device = open(I2C_DEVICE_PATH, O_RDWR);
i2c_device = open(device_path, O_RDWR);
if (i2c_device == -1)
return; /* no error handling */
}
Expand Down
2 changes: 1 addition & 1 deletion sensirion_i2c_hal.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ int16_t sensirion_i2c_hal_select_bus(uint8_t bus_idx);
* Initialize all hard- and software components that are needed for the I2C
* communication.
*/
void sensirion_i2c_hal_init(void);
void sensirion_i2c_hal_init(const char* device_path);

/**
* Release all resources initialized by sensirion_i2c_hal_init().
Expand Down

0 comments on commit acbbaa9

Please sign in to comment.