aboutsummaryrefslogtreecommitdiff
path: root/src/drivers/airspeed
diff options
context:
space:
mode:
authorLorenz Meier <lm@inf.ethz.ch>2014-04-20 21:43:18 +0200
committerLorenz Meier <lm@inf.ethz.ch>2014-04-20 21:43:18 +0200
commit709d104de44b1cf7e338f4ae25e8b1fdc336a279 (patch)
tree51590d8d6c9f93b3004097e97c877744d76e7d54 /src/drivers/airspeed
parent071f9c648b71a421f12f6968a9367c5219abf076 (diff)
downloadpx4-firmware-709d104de44b1cf7e338f4ae25e8b1fdc336a279.tar.gz
px4-firmware-709d104de44b1cf7e338f4ae25e8b1fdc336a279.tar.bz2
px4-firmware-709d104de44b1cf7e338f4ae25e8b1fdc336a279.zip
airspeed driver: Do not spam the console on error, report the system change only once
Diffstat (limited to 'src/drivers/airspeed')
-rw-r--r--src/drivers/airspeed/airspeed.cpp41
-rw-r--r--src/drivers/airspeed/airspeed.h7
2 files changed, 32 insertions, 16 deletions
diff --git a/src/drivers/airspeed/airspeed.cpp b/src/drivers/airspeed/airspeed.cpp
index 524151c90..109c50287 100644
--- a/src/drivers/airspeed/airspeed.cpp
+++ b/src/drivers/airspeed/airspeed.cpp
@@ -82,10 +82,12 @@ Airspeed::Airspeed(int bus, int address, unsigned conversion_interval, const cha
_buffer_overflows(perf_alloc(PC_COUNT, "airspeed_buffer_overflows")),
_max_differential_pressure_pa(0),
_sensor_ok(false),
+ _last_published_sensor_ok(true), /* initialize differently to force publication */
_measure_ticks(0),
_collect_phase(false),
_diff_pres_offset(0.0f),
_airspeed_pub(-1),
+ _subsys_pub(-1),
_class_instance(-1),
_conversion_interval(conversion_interval),
_sample_perf(perf_alloc(PC_ELAPSED, "airspeed_read")),
@@ -344,22 +346,6 @@ Airspeed::start()
/* schedule a cycle to start things */
work_queue(HPWORK, &_work, (worker_t)&Airspeed::cycle_trampoline, this, 1);
-
- /* notify about state change */
- struct subsystem_info_s info = {
- true,
- true,
- true,
- SUBSYSTEM_TYPE_DIFFPRESSURE
- };
- static orb_advert_t pub = -1;
-
- if (pub > 0) {
- orb_publish(ORB_ID(subsystem_info), pub, &info);
-
- } else {
- pub = orb_advertise(ORB_ID(subsystem_info), &info);
- }
}
void
@@ -369,11 +355,34 @@ Airspeed::stop()
}
void
+Airspeed::update_status()
+{
+ if (_sensor_ok != _last_published_sensor_ok) {
+ /* notify about state change */
+ struct subsystem_info_s info = {
+ true,
+ true,
+ _sensor_ok,
+ SUBSYSTEM_TYPE_DIFFPRESSURE
+ };
+
+ if (_subsys_pub > 0) {
+ orb_publish(ORB_ID(subsystem_info), _subsys_pub, &info);
+ } else {
+ _subsys_pub = orb_advertise(ORB_ID(subsystem_info), &info);
+ }
+
+ _last_published_sensor_ok = _sensor_ok;
+ }
+}
+
+void
Airspeed::cycle_trampoline(void *arg)
{
Airspeed *dev = (Airspeed *)arg;
dev->cycle();
+ dev->update_status();
}
void
diff --git a/src/drivers/airspeed/airspeed.h b/src/drivers/airspeed/airspeed.h
index 186602eda..0b8e949c9 100644
--- a/src/drivers/airspeed/airspeed.h
+++ b/src/drivers/airspeed/airspeed.h
@@ -118,14 +118,21 @@ protected:
virtual int measure() = 0;
virtual int collect() = 0;
+ /**
+ * Update the subsystem status
+ */
+ void update_status();
+
work_s _work;
float _max_differential_pressure_pa;
bool _sensor_ok;
+ bool _last_published_sensor_ok;
int _measure_ticks;
bool _collect_phase;
float _diff_pres_offset;
orb_advert_t _airspeed_pub;
+ orb_advert_t _subsys_pub;
int _class_instance;