mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-20 02:03:34 +08:00
Made all usual suspects default to their custom names and only register the default name if its not already taken by someone else
This commit is contained in:
@@ -80,7 +80,8 @@ static const int ERROR = -1;
|
||||
#define DIR_WRITE (0<<7)
|
||||
#define ADDR_INCREMENT (1<<6)
|
||||
|
||||
|
||||
#define LSM303D_DEVICE_PATH_MAG "/dev/lsm303d_mag"
|
||||
#define LSM303D_DEVICE_PATH_ACCEL "/dev/lsm303d_accel"
|
||||
|
||||
/* register addresses: A: accel, M: mag, T: temp */
|
||||
#define ADDR_WHO_AM_I 0x0F
|
||||
@@ -585,6 +586,20 @@ LSM303D::init()
|
||||
|
||||
reset();
|
||||
|
||||
/* try to claim the generic accel node as well - it's OK if we fail at this */
|
||||
ret = register_driver(ACCEL_DEVICE_PATH, &fops, 0666, (void *)this);
|
||||
|
||||
if (ret == OK) {
|
||||
log("default accel device");
|
||||
}
|
||||
|
||||
/* try to claim the generic accel node as well - it's OK if we fail at this */
|
||||
mag_ret = register_driver(MAG_DEVICE_PATH, &fops, 0666, (void *)this);
|
||||
|
||||
if (mag_ret == OK) {
|
||||
log("default mag device");
|
||||
}
|
||||
|
||||
/* advertise mag topic */
|
||||
struct mag_report zero_mag_report;
|
||||
memset(&zero_mag_report, 0, sizeof(zero_mag_report));
|
||||
@@ -1670,7 +1685,7 @@ LSM303D::toggle_logging()
|
||||
}
|
||||
|
||||
LSM303D_mag::LSM303D_mag(LSM303D *parent) :
|
||||
CDev("LSM303D_mag", MAG_DEVICE_PATH),
|
||||
CDev("LSM303D_mag", "/dev/lsm303d_mag"),
|
||||
_parent(parent)
|
||||
{
|
||||
}
|
||||
@@ -1736,7 +1751,7 @@ start()
|
||||
errx(0, "already started");
|
||||
|
||||
/* create the driver */
|
||||
g_dev = new LSM303D(1 /* XXX magic number */, ACCEL_DEVICE_PATH, (spi_dev_e)PX4_SPIDEV_ACCEL_MAG);
|
||||
g_dev = new LSM303D(1 /* XXX magic number */, LSM303D_DEVICE_PATH_MAG, (spi_dev_e)PX4_SPIDEV_ACCEL_MAG);
|
||||
|
||||
if (g_dev == nullptr) {
|
||||
warnx("failed instantiating LSM303D obj");
|
||||
@@ -1747,7 +1762,7 @@ start()
|
||||
goto fail;
|
||||
|
||||
/* set the poll rate to default, starts automatic data collection */
|
||||
fd = open(ACCEL_DEVICE_PATH, O_RDONLY);
|
||||
fd = open(LSM303D_DEVICE_PATH_ACCEL, O_RDONLY);
|
||||
|
||||
if (fd < 0)
|
||||
goto fail;
|
||||
@@ -1755,7 +1770,7 @@ start()
|
||||
if (ioctl(fd, SENSORIOCSPOLLRATE, SENSOR_POLLRATE_DEFAULT) < 0)
|
||||
goto fail;
|
||||
|
||||
fd_mag = open(MAG_DEVICE_PATH, O_RDONLY);
|
||||
fd_mag = open(LSM303D_DEVICE_PATH_MAG, O_RDONLY);
|
||||
|
||||
/* don't fail if open cannot be opened */
|
||||
if (0 <= fd_mag) {
|
||||
@@ -1790,10 +1805,10 @@ test()
|
||||
int ret;
|
||||
|
||||
/* get the driver */
|
||||
fd_accel = open(ACCEL_DEVICE_PATH, O_RDONLY);
|
||||
fd_accel = open(LSM303D_DEVICE_PATH_ACCEL, O_RDONLY);
|
||||
|
||||
if (fd_accel < 0)
|
||||
err(1, "%s open failed", ACCEL_DEVICE_PATH);
|
||||
err(1, "%s open failed", LSM303D_DEVICE_PATH_ACCEL);
|
||||
|
||||
/* do a simple demand read */
|
||||
sz = read(fd_accel, &accel_report, sizeof(accel_report));
|
||||
@@ -1819,10 +1834,10 @@ test()
|
||||
struct mag_report m_report;
|
||||
|
||||
/* get the driver */
|
||||
fd_mag = open(MAG_DEVICE_PATH, O_RDONLY);
|
||||
fd_mag = open(LSM303D_DEVICE_PATH_MAG, O_RDONLY);
|
||||
|
||||
if (fd_mag < 0)
|
||||
err(1, "%s open failed", MAG_DEVICE_PATH);
|
||||
err(1, "%s open failed", LSM303D_DEVICE_PATH_MAG);
|
||||
|
||||
/* check if mag is onboard or external */
|
||||
if ((ret = ioctl(fd_mag, MAGIOCGEXTERNAL, 0)) < 0)
|
||||
|
||||
Reference in New Issue
Block a user