aboutsummaryrefslogtreecommitdiff
path: root/src/drivers/bma180
diff options
context:
space:
mode:
authorLorenz Meier <lm@inf.ethz.ch>2014-01-14 15:40:46 +0100
committerLorenz Meier <lm@inf.ethz.ch>2014-01-14 15:40:46 +0100
commitd19971065140bdfbbe5972f2a394597504abef9e (patch)
tree47f4c08d75a3088806736e091b6338e4d1d48861 /src/drivers/bma180
parent1f5eda37abffc10b51e4bcd94efa18c1dc76d21f (diff)
downloadpx4-firmware-d19971065140bdfbbe5972f2a394597504abef9e.tar.gz
px4-firmware-d19971065140bdfbbe5972f2a394597504abef9e.tar.bz2
px4-firmware-d19971065140bdfbbe5972f2a394597504abef9e.zip
Fixed up init sequence of all sensors - we can publish in interrupt context, but not advertise! All advertisements now contain valid data
Diffstat (limited to 'src/drivers/bma180')
-rw-r--r--src/drivers/bma180/bma180.cpp22
1 files changed, 16 insertions, 6 deletions
diff --git a/src/drivers/bma180/bma180.cpp b/src/drivers/bma180/bma180.cpp
index df4e8f998..e43a34805 100644
--- a/src/drivers/bma180/bma180.cpp
+++ b/src/drivers/bma180/bma180.cpp
@@ -153,6 +153,7 @@ private:
float _accel_range_scale;
float _accel_range_m_s2;
orb_advert_t _accel_topic;
+ int _class_instance;
unsigned _current_lowpass;
unsigned _current_range;
@@ -238,6 +239,7 @@ BMA180::BMA180(int bus, spi_dev_e device) :
_accel_range_scale(0.0f),
_accel_range_m_s2(0.0f),
_accel_topic(-1),
+ _class_instance(-1),
_current_lowpass(0),
_current_range(0),
_sample_perf(perf_alloc(PC_ELAPSED, "bma180_read"))
@@ -282,11 +284,6 @@ BMA180::init()
if (_reports == nullptr)
goto out;
- /* advertise sensor topic */
- struct accel_report zero_report;
- memset(&zero_report, 0, sizeof(zero_report));
- _accel_topic = orb_advertise(ORB_ID(sensor_accel), &zero_report);
-
/* perform soft reset (p48) */
write_reg(ADDR_RESET, SOFT_RESET);
@@ -322,6 +319,19 @@ BMA180::init()
ret = ERROR;
}
+ _class_instance = register_class_devname(ACCEL_DEVICE_PATH);
+
+ /* advertise sensor topic, measure manually to initialize valid report */
+ measure();
+
+ if (_class_instance == CLASS_DEVICE_PRIMARY) {
+ struct accel_report arp;
+ _reports->get(&arp);
+
+ /* measurement will have generated a report, publish */
+ _accel_topic = orb_advertise(ORB_ID(sensor_accel), &arp);
+ }
+
out:
return ret;
}
@@ -723,7 +733,7 @@ BMA180::measure()
poll_notify(POLLIN);
/* publish for subscribers */
- if !(_pub_blocked)
+ if (_accel_topic > 0 && !(_pub_blocked))
orb_publish(ORB_ID(sensor_accel), _accel_topic, &report);
/* stop the perf counter */