diff --git a/src/drivers/tone_alarm/ToneAlarm.cpp b/src/drivers/tone_alarm/ToneAlarm.cpp index 86a01360b0..bd5d12c6a8 100644 --- a/src/drivers/tone_alarm/ToneAlarm.cpp +++ b/src/drivers/tone_alarm/ToneAlarm.cpp @@ -75,19 +75,10 @@ int ToneAlarm::init() void ToneAlarm::next_note() { if (!_should_run) { - if (_tune_control_sub >= 0) { - orb_unsubscribe(_tune_control_sub); - } - _running = false; return; } - // Subscribe to tune_control. - if (_tune_control_sub < 0) { - _tune_control_sub = orb_subscribe(ORB_ID(tune_control)); - } - // Check for updates orb_update(); @@ -136,11 +127,8 @@ void ToneAlarm::Run() void ToneAlarm::orb_update() { // Check for updates - bool updated = false; - orb_check(_tune_control_sub, &updated); - - if (updated) { - orb_copy(ORB_ID(tune_control), _tune_control_sub, &_tune); + if (_tune_control_sub.updated()) { + _tune_control_sub.copy(&_tune); if (_tune.timestamp > 0) { _play_tone = _tunes.set_control(_tune) == 0; diff --git a/src/drivers/tone_alarm/ToneAlarm.h b/src/drivers/tone_alarm/ToneAlarm.h index 0816ad9ce6..90cb46db45 100644 --- a/src/drivers/tone_alarm/ToneAlarm.h +++ b/src/drivers/tone_alarm/ToneAlarm.h @@ -47,8 +47,10 @@ #include #include #include -#include +#include +#include +#include #if !defined(UNUSED) # define UNUSED(a) ((void)(a)) @@ -109,7 +111,7 @@ private: unsigned int _silence_length{0}; ///< If nonzero, silence before next note. - int _tune_control_sub{-1}; + uORB::Subscription _tune_control_sub{ORB_ID(tune_control)}; tune_control_s _tune{};