aboutsummaryrefslogtreecommitdiff
path: root/src/drivers/lsm303d
diff options
context:
space:
mode:
authorLorenz Meier <lm@inf.ethz.ch>2013-12-07 10:34:25 +0100
committerLorenz Meier <lm@inf.ethz.ch>2013-12-10 12:05:14 +0100
commit3d27dd7246c660bb0a00caae3cd0b0e66bfa6467 (patch)
tree2b7b8374edc0a63bfb9b4b9093952cba0c8f9466 /src/drivers/lsm303d
parent0456ee2364600ba6b5a9f109c7464a71579e7d58 (diff)
downloadpx4-firmware-3d27dd7246c660bb0a00caae3cd0b0e66bfa6467.tar.gz
px4-firmware-3d27dd7246c660bb0a00caae3cd0b0e66bfa6467.tar.bz2
px4-firmware-3d27dd7246c660bb0a00caae3cd0b0e66bfa6467.zip
Made all usual suspects default to their custom names and only register the default name if its not already taken by someone else
Diffstat (limited to 'src/drivers/lsm303d')
-rw-r--r--src/drivers/lsm303d/lsm303d.cpp33
1 files changed, 24 insertions, 9 deletions
diff --git a/src/drivers/lsm303d/lsm303d.cpp b/src/drivers/lsm303d/lsm303d.cpp
index 6010a2ad7..a3409cbac 100644
--- a/src/drivers/lsm303d/lsm303d.cpp
+++ b/src/drivers/lsm303d/lsm303d.cpp
@@ -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)