From ba72e93ffb7f1d6d8ba8a3902f26b3ad9f87dca1 Mon Sep 17 00:00:00 2001 From: Florian Achermann Date: Tue, 1 Jun 2021 14:28:35 +0200 Subject: [PATCH] Fill in the instance of the hall sensor msg with the i2c address --- src/drivers/si7210/si7210.cpp | 2 +- src/drivers/si7210/si7210.h | 11 +++++------ src/drivers/si7210/si7210_main.cpp | 7 +++++-- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/drivers/si7210/si7210.cpp b/src/drivers/si7210/si7210.cpp index 6d167b5828..1ce7979ee7 100644 --- a/src/drivers/si7210/si7210.cpp +++ b/src/drivers/si7210/si7210.cpp @@ -276,7 +276,7 @@ int SI7210::collect() /* generate a new report */ report.timestamp = hrt_absolute_time(); - report.instance = 0; //TODO: _instance + report.instance = _i2c_address; report.mag_t = (float)(magRawData - MAG_BIAS) * MAG_CONV; report.temp_c = (float)((tempRawData & ~0x8000) >> 3); report.temp_c = _tempGain * (TEMP_CONV_A2 * report.temp_c * report.temp_c + TEMP_CONV_A1 * report.temp_c + TEMP_CONV_A0 diff --git a/src/drivers/si7210/si7210.h b/src/drivers/si7210/si7210.h index 794b03b09c..5eee584abc 100644 --- a/src/drivers/si7210/si7210.h +++ b/src/drivers/si7210/si7210.h @@ -49,10 +49,7 @@ #include #include -#define I2C_ADDRESS_0_SI7210 0x30 /* SI7210 I2C address */ -#define I2C_ADDRESS_1_SI7210 0x31 /* SI7210 I2C address */ -#define I2C_ADDRESS_2_SI7210 0x32 /* SI7210 I2C address */ -#define I2C_ADDRESS_3_SI7210 0x33 /* SI7210 I2C address */ +#define I2C_ADDRESS_SI7210 0x30 /* Default SI7210 I2C address */ #define SI7210_MAX_DATA_RATE 50 @@ -115,11 +112,12 @@ class SI7210 : public Vane, public I2CSPIDriver { public: - SI7210(I2CSPIBusOption bus_option, const int bus, int bus_frequency, int address = I2C_ADDRESS_0_SI7210, + SI7210(I2CSPIBusOption bus_option, const int bus, int bus_frequency, int address = I2C_ADDRESS_SI7210, bool keep_retrying = false) : Vane(bus, bus_frequency, address, SI7210_CONVERSION_INTERVAL), I2CSPIDriver(MODULE_NAME, px4::device_bus_to_wq(get_device_id()), bus_option, bus, address), - _keep_retrying{keep_retrying} + _keep_retrying{keep_retrying}, + _i2c_address{address} { } @@ -188,6 +186,7 @@ private: uint16_t _scale{0}; const bool _keep_retrying; State _state{State::RequireConfig}; + int _i2c_address; }; #endif /* SI7210_HPP_ */ diff --git a/src/drivers/si7210/si7210_main.cpp b/src/drivers/si7210/si7210_main.cpp index 8d6ee358da..1364682713 100644 --- a/src/drivers/si7210/si7210_main.cpp +++ b/src/drivers/si7210/si7210_main.cpp @@ -70,7 +70,7 @@ SI7210::print_usage() PRINT_MODULE_USAGE_SUBCATEGORY("airspeed_sensor"); PRINT_MODULE_USAGE_COMMAND("start"); PRINT_MODULE_USAGE_PARAMS_I2C_SPI_DRIVER(true, false); - PRINT_MODULE_USAGE_PARAMS_I2C_ADDRESS(0x30); + PRINT_MODULE_USAGE_PARAMS_I2C_ADDRESS(I2C_ADDRESS_SI7210); PRINT_MODULE_USAGE_PARAMS_I2C_KEEP_RUNNING_FLAG(); PRINT_MODULE_USAGE_DEFAULT_COMMANDS(); } @@ -81,9 +81,12 @@ si7210_main(int argc, char *argv[]) using ThisDriver = SI7210; BusCLIArguments cli{true, false}; cli.default_i2c_frequency = 100000; - cli.i2c_address = I2C_ADDRESS_2_SI7210; + cli.i2c_address = I2C_ADDRESS_SI7210; cli.support_keep_running = true; + int ch; + while ((ch = cli.getopt(argc, argv, "")) != EOF) {} + const char *verb = cli.parseDefaultArguments(argc, argv); if (!verb) {