diff --git a/libraries/AP_IRLock/AP_IRLock_I2C.cpp b/libraries/AP_IRLock/AP_IRLock_I2C.cpp index ce2dfef5d1..d0af466ac1 100644 --- a/libraries/AP_IRLock/AP_IRLock_I2C.cpp +++ b/libraries/AP_IRLock/AP_IRLock_I2C.cpp @@ -32,9 +32,13 @@ extern const AP_HAL::HAL& hal; #define IRLOCK_SYNC 0xAA55AA55 -void AP_IRLock_I2C::init() +void AP_IRLock_I2C::init(int8_t bus) { - dev = std::move(hal.i2c_mgr->get_device(1, IRLOCK_I2C_ADDRESS)); + if (bus < 0) { + // default to i2c external bus + bus = 1; + } + dev = std::move(hal.i2c_mgr->get_device(bus, IRLOCK_I2C_ADDRESS)); if (!dev) { return; } diff --git a/libraries/AP_IRLock/AP_IRLock_I2C.h b/libraries/AP_IRLock/AP_IRLock_I2C.h index 80238a41df..1262eaefc1 100644 --- a/libraries/AP_IRLock/AP_IRLock_I2C.h +++ b/libraries/AP_IRLock/AP_IRLock_I2C.h @@ -10,7 +10,7 @@ class AP_IRLock_I2C : public IRLock { public: // init - initialize sensor library - void init(); + void init(int8_t bus) override; // retrieve latest sensor data - returns true if new data is available bool update(); diff --git a/libraries/AP_IRLock/AP_IRLock_SITL.cpp b/libraries/AP_IRLock/AP_IRLock_SITL.cpp index 32d44c02df..5601347e2a 100644 --- a/libraries/AP_IRLock/AP_IRLock_SITL.cpp +++ b/libraries/AP_IRLock/AP_IRLock_SITL.cpp @@ -36,7 +36,7 @@ AP_IRLock_SITL::AP_IRLock_SITL() : sock(true) {} -void AP_IRLock_SITL::init() +void AP_IRLock_SITL::init(int8_t bus) { SITL::SITL *sitl = (SITL::SITL *)AP_Param::find_object("SIM_"); // try to bind to a specific port so that if we restart ArduPilot diff --git a/libraries/AP_IRLock/AP_IRLock_SITL.h b/libraries/AP_IRLock/AP_IRLock_SITL.h index e43a79470a..9f59c99a79 100644 --- a/libraries/AP_IRLock/AP_IRLock_SITL.h +++ b/libraries/AP_IRLock/AP_IRLock_SITL.h @@ -16,7 +16,7 @@ public: AP_IRLock_SITL(); // init - initialize sensor library - virtual void init(); + virtual void init(int8_t bus); // retrieve latest sensor data - returns true if new data is available virtual bool update(); diff --git a/libraries/AP_IRLock/IRLock.h b/libraries/AP_IRLock/IRLock.h index f8e802a8e1..6d888b2568 100644 --- a/libraries/AP_IRLock/IRLock.h +++ b/libraries/AP_IRLock/IRLock.h @@ -28,7 +28,7 @@ class IRLock public: // init - initialize sensor library // library won't be useable unless this is first called - virtual void init() = 0; + virtual void init(int8_t bus) = 0; // true if irlock sensor is online and healthy bool healthy() const { return _flags.healthy; }