I2C/SPI require device type in constructor

This commit is contained in:
Daniel Agar
2020-04-01 12:24:22 -04:00
committed by GitHub
parent 04bf9afd1b
commit 02f4ad61ec
128 changed files with 181 additions and 351 deletions
@@ -42,11 +42,9 @@ LeddarOne::LeddarOne(const char *serial_port, uint8_t device_orientation):
{
_serial_port = strdup(serial_port);
_px4_rangefinder.set_device_type(distance_sensor_s::MAV_DISTANCE_SENSOR_LASER);
_px4_rangefinder.set_max_distance(LEDDAR_ONE_MAX_DISTANCE);
_px4_rangefinder.set_min_distance(LEDDAR_ONE_MIN_DISTANCE);
_px4_rangefinder.set_fov(LEDDAR_ONE_FIELD_OF_VIEW);
_px4_rangefinder.set_orientation(device_orientation);
}
LeddarOne::~LeddarOne()
@@ -43,9 +43,9 @@
LidarLiteI2C::LidarLiteI2C(I2CSPIBusOption bus_option, const int bus, const uint8_t rotation, int bus_frequency,
const int address) :
I2C("LL40LS", nullptr, bus, address, bus_frequency),
I2C(DRV_RNG_DEVTYPE_LL40LS, MODULE_NAME, bus, address, bus_frequency),
I2CSPIDriver(MODULE_NAME, px4::device_bus_to_wq(get_device_id()), bus_option, bus),
_px4_rangefinder(0 /* device id not yet used */, ORB_PRIO_DEFAULT, rotation)
_px4_rangefinder(get_device_id(), ORB_PRIO_DEFAULT, rotation)
{
_px4_rangefinder.set_min_distance(LL40LS_MIN_DISTANCE);
_px4_rangefinder.set_max_distance(LL40LS_MAX_DISTANCE);
@@ -135,7 +135,6 @@
#define MAPPYDOT_MAX_DISTANCE (4.f) // meters
#define MAPPYDOT_BUS_CLOCK 400000 // 400kHz bus speed
#define MAPPYDOT_DEVICE_PATH "/dev/mappydot"
/* Configuration Constants */
#define MAPPYDOT_BASE_ADDR 0x08
@@ -222,7 +221,7 @@ private:
MappyDot::MappyDot(I2CSPIBusOption bus_option, const int bus, int bus_frequency) :
I2C("MappyDot", MAPPYDOT_DEVICE_PATH, bus, MAPPYDOT_BASE_ADDR, bus_frequency),
I2C(DRV_DIST_DEVTYPE_MAPPYDOT, MODULE_NAME, bus, MAPPYDOT_BASE_ADDR, bus_frequency),
ModuleParams(nullptr),
I2CSPIDriver(MODULE_NAME, px4::device_bus_to_wq(get_device_id()), bus_option, bus)
{}
@@ -74,7 +74,6 @@ using namespace time_literals;
#define MB12XX_BASE_ADDR 0x70 // 7-bit address is 0x70 = 112. 8-bit address is 0xE0 = 224.
#define MB12XX_MIN_ADDR 0x5A // 7-bit address is 0x5A = 90. 8-bit address is 0xB4 = 180.
#define MB12XX_BUS_SPEED 100000 // 100kHz bus speed.
#define MB12XX_DEVICE_PATH "/dev/mb12xx"
/* MB12xx Registers addresses */
#define MB12XX_TAKE_RANGE_REG 0x51 // Measure range Register.
@@ -179,7 +178,7 @@ private:
};
MB12XX::MB12XX(I2CSPIBusOption bus_option, const int bus, int bus_frequency, int address) :
I2C("MB12xx", MB12XX_DEVICE_PATH, bus, address, bus_frequency),
I2C(DRV_DIST_DEVTYPE_MB12XX, MODULE_NAME, bus, address, bus_frequency),
ModuleParams(nullptr),
I2CSPIDriver(MODULE_NAME, px4::device_bus_to_wq(get_device_id()), bus_option, bus, address)
{
@@ -84,7 +84,7 @@ uint8_t PGA460::calc_checksum(uint8_t *data, const uint8_t size)
int PGA460::close_serial()
{
int ret = px4_close(_fd);
int ret = ::close(_fd);
if (ret != 0) {
PX4_WARN("Could not close serial port");
@@ -292,7 +292,7 @@ float PGA460::get_temperature()
int PGA460::open_serial()
{
_fd = px4_open(_port, O_RDWR | O_NOCTTY | O_NONBLOCK);
_fd = ::open(_port, O_RDWR | O_NOCTTY | O_NONBLOCK);
if (_fd < 0) {
PX4_WARN("Failed to open serial port");
+1 -1
View File
@@ -382,7 +382,7 @@ private:
/** @orb_advert_t orb_advert_t uORB advertisement topic. */
orb_advert_t _distance_sensor_topic{nullptr};
/** @param _fd Returns the file descriptor from px4_open(). */
/** @param _fd Returns the file descriptor from open(). */
int _fd{-1};
/** @param _port Stores the port name. */
@@ -49,8 +49,6 @@ SF0X::SF0X(const char *port, uint8_t rotation) :
/* enforce null termination */
_port[sizeof(_port) - 1] = '\0';
_px4_rangefinder.set_device_type(distance_sensor_s::MAV_DISTANCE_SENSOR_LASER);
}
SF0X::~SF0X()
+1 -3
View File
@@ -75,8 +75,6 @@
/* Configuration Constants */
#define SF1XX_BASEADDR 0x66
#define SF1XX_DEVICE_PATH "/dev/sf1xx"
class SF1XX : public device::I2C, public I2CSPIDriver<SF1XX>
{
@@ -166,7 +164,7 @@ private:
extern "C" __EXPORT int sf1xx_main(int argc, char *argv[]);
SF1XX::SF1XX(I2CSPIBusOption bus_option, const int bus, const uint8_t rotation, int bus_frequency, int address) :
I2C("SF1XX", SF1XX_DEVICE_PATH, bus, address, bus_frequency),
I2C(DRV_DIST_DEVTYPE_SF1XX, MODULE_NAME, bus, address, bus_frequency),
I2CSPIDriver(MODULE_NAME, px4::device_bus_to_wq(get_device_id()), bus_option, bus),
_rotation(rotation)
{
+2 -2
View File
@@ -34,9 +34,9 @@
#include "SRF02.hpp"
SRF02::SRF02(I2CSPIBusOption bus_option, const int bus, const uint8_t rotation, int bus_frequency, int address) :
I2C("SRF02", nullptr, bus, address, bus_frequency),
I2C(DRV_DIST_DEVTYPE_SRF02, MODULE_NAME, bus, address, bus_frequency),
I2CSPIDriver(MODULE_NAME, px4::device_bus_to_wq(get_device_id()), bus_option, bus),
_px4_rangefinder(0 /* device id not yet used */, ORB_PRIO_DEFAULT, rotation)
_px4_rangefinder(get_device_id(), ORB_PRIO_DEFAULT, rotation)
{
_px4_rangefinder.set_max_distance(SRF02_MAX_DISTANCE);
_px4_rangefinder.set_min_distance(SRF02_MIN_DISTANCE);
@@ -74,9 +74,9 @@ static uint8_t crc8(uint8_t *p, uint8_t len)
}
TERARANGER::TERARANGER(I2CSPIBusOption bus_option, const int bus, const uint8_t rotation, int bus_frequency) :
I2C("TERARANGER", nullptr, bus, TERARANGER_ONE_BASEADDR, bus_frequency),
I2C(DRV_DIST_DEVTYPE_TERARANGER, MODULE_NAME, bus, TERARANGER_ONE_BASEADDR, bus_frequency),
I2CSPIDriver(MODULE_NAME, px4::device_bus_to_wq(get_device_id()), bus_option, bus),
_px4_rangefinder(0 /* device id not yet used */, ORB_PRIO_DEFAULT, rotation)
_px4_rangefinder(get_device_id(), ORB_PRIO_DEFAULT, rotation)
{
// up the retries since the device misses the first measure attempts
I2C::_retries = 3;
@@ -60,7 +60,7 @@
#define VL53L0X_BUS_CLOCK 400000 // 400kHz bus clock speed
VL53L0X::VL53L0X(I2CSPIBusOption bus_option, const int bus, const uint8_t rotation, int bus_frequency, int address) :
I2C("VL53L0X", nullptr, bus, address, bus_frequency),
I2C(DRV_DIST_DEVTYPE_VL53L0X, MODULE_NAME, bus, address, bus_frequency),
I2CSPIDriver(MODULE_NAME, px4::device_bus_to_wq(get_device_id()), bus_option, bus),
_px4_rangefinder(0 /* device id not yet used */, ORB_PRIO_DEFAULT, rotation)
{