Browse Source

AP_IRLock: allow specification of i2c bus

mission-4.1.18
Andrew Tridgell 8 years ago
parent
commit
2eb363a950
  1. 8
      libraries/AP_IRLock/AP_IRLock_I2C.cpp
  2. 2
      libraries/AP_IRLock/AP_IRLock_I2C.h
  3. 2
      libraries/AP_IRLock/AP_IRLock_SITL.cpp
  4. 2
      libraries/AP_IRLock/AP_IRLock_SITL.h
  5. 2
      libraries/AP_IRLock/IRLock.h

8
libraries/AP_IRLock/AP_IRLock_I2C.cpp

@ -32,9 +32,13 @@ extern const AP_HAL::HAL& hal; @@ -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;
}

2
libraries/AP_IRLock/AP_IRLock_I2C.h

@ -10,7 +10,7 @@ class AP_IRLock_I2C : public IRLock @@ -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();

2
libraries/AP_IRLock/AP_IRLock_SITL.cpp

@ -36,7 +36,7 @@ AP_IRLock_SITL::AP_IRLock_SITL() : @@ -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

2
libraries/AP_IRLock/AP_IRLock_SITL.h

@ -16,7 +16,7 @@ public: @@ -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();

2
libraries/AP_IRLock/IRLock.h

@ -28,7 +28,7 @@ class IRLock @@ -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; }

Loading…
Cancel
Save