Browse Source

tone_alarm move to px4 work queue

sbg
Daniel Agar 6 years ago
parent
commit
da6210151c
  1. 17
      src/drivers/tone_alarm/ToneAlarm.cpp
  2. 11
      src/drivers/tone_alarm/ToneAlarm.h

17
src/drivers/tone_alarm/ToneAlarm.cpp

@ -40,7 +40,8 @@ @@ -40,7 +40,8 @@
#include <px4_time.h>
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() @@ -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() @@ -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() @@ -177,9 +179,6 @@ void ToneAlarm::stop_note()
ToneAlarmInterface::stop_note();
}
struct work_s ToneAlarm::_work = {};
/**
* Local functions in support of the shell command.
*/

11
src/drivers/tone_alarm/ToneAlarm.h

@ -46,7 +46,7 @@ @@ -46,7 +46,7 @@
#include <lib/drivers/tone_alarm/ToneAlarmInterface.h>
#include <lib/tunes/tunes.h>
#include <px4_defines.h>
#include <px4_workqueue.h>
#include <px4_work_queue/ScheduledWorkItem.hpp>
#include <string.h>
@ -54,7 +54,7 @@ @@ -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: @@ -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: @@ -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: @@ -115,6 +114,4 @@ private:
tune_control_s _tune{};
Tunes _tunes = Tunes();
static work_s _work;
};

Loading…
Cancel
Save