diff --git a/src/drivers/tone_alarm/ToneAlarm.cpp b/src/drivers/tone_alarm/ToneAlarm.cpp index 7acacf18458..86a01360b06 100644 --- a/src/drivers/tone_alarm/ToneAlarm.cpp +++ b/src/drivers/tone_alarm/ToneAlarm.cpp @@ -40,7 +40,8 @@ #include ToneAlarm::ToneAlarm() : - CDev(TONE_ALARM0_DEVICE_PATH) + CDev(TONE_ALARM0_DEVICE_PATH), + ScheduledWorkItem(px4::wq_configurations::hp_default) { } @@ -65,7 +66,9 @@ int ToneAlarm::init() ToneAlarmInterface::init(); _running = true; - work_queue(HPWORK, &_work, (worker_t)&ToneAlarm::next_trampoline, this, 0); + + ScheduleNow(); + return OK; } @@ -122,13 +125,12 @@ void ToneAlarm::next_note() } // Schedule a callback when the note should stop. - work_queue(HPWORK, &_work, (worker_t)&ToneAlarm::next_trampoline, this, USEC2TICK(duration)); + ScheduleDelayed(duration); } -void ToneAlarm::next_trampoline(void *argv) +void ToneAlarm::Run() { - ToneAlarm *toneAlarm = (ToneAlarm *)argv; - toneAlarm->next_note(); + next_note(); } void ToneAlarm::orb_update() @@ -177,9 +179,6 @@ void ToneAlarm::stop_note() ToneAlarmInterface::stop_note(); } - -struct work_s ToneAlarm::_work = {}; - /** * Local functions in support of the shell command. */ diff --git a/src/drivers/tone_alarm/ToneAlarm.h b/src/drivers/tone_alarm/ToneAlarm.h index 9bb533cd7ae..0816ad9ce68 100644 --- a/src/drivers/tone_alarm/ToneAlarm.h +++ b/src/drivers/tone_alarm/ToneAlarm.h @@ -46,7 +46,7 @@ #include #include #include -#include +#include #include @@ -54,7 +54,7 @@ # define UNUSED(a) ((void)(a)) #endif -class ToneAlarm : public cdev::CDev +class ToneAlarm : public cdev::CDev, public px4::ScheduledWorkItem { public: ToneAlarm(); @@ -63,7 +63,7 @@ public: /** * @brief Initializes the character device and hardware registers. */ - int init(); + int init() override; /** * @brief Prints the driver status to the console. @@ -79,9 +79,8 @@ protected: /** * @brief Trampoline for the work queue. - * @param argv Pointer to the task startup arguments. */ - static void next_trampoline(void *argv); + void Run() override; /** * @brief Updates the uORB topics for local subscribers. @@ -115,6 +114,4 @@ private: tune_control_s _tune{}; Tunes _tunes = Tunes(); - - static work_s _work; };