Skip to content

Commit

Permalink
tone_alarm move to px4 work queue
Browse files Browse the repository at this point in the history
  • Loading branch information
dagar committed May 24, 2019
1 parent 8c3821c commit da62101
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 16 deletions.
17 changes: 8 additions & 9 deletions src/drivers/tone_alarm/ToneAlarm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
}

Expand All @@ -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;
}

Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -177,9 +179,6 @@ void ToneAlarm::stop_note()
ToneAlarmInterface::stop_note();
}


struct work_s ToneAlarm::_work = {};

/**
* Local functions in support of the shell command.
*/
Expand Down
11 changes: 4 additions & 7 deletions src/drivers/tone_alarm/ToneAlarm.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@
#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>


#if !defined(UNUSED)
# define UNUSED(a) ((void)(a))
#endif

class ToneAlarm : public cdev::CDev
class ToneAlarm : public cdev::CDev, public px4::ScheduledWorkItem
{
public:
ToneAlarm();
Expand All @@ -63,7 +63,7 @@ class ToneAlarm : public cdev::CDev
/**
* @brief Initializes the character device and hardware registers.
*/
int init();
int init() override;

/**
* @brief Prints the driver status to the console.
Expand All @@ -79,9 +79,8 @@ class ToneAlarm : public cdev::CDev

/**
* @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.
Expand Down Expand Up @@ -115,6 +114,4 @@ class ToneAlarm : public cdev::CDev
tune_control_s _tune{};

Tunes _tunes = Tunes();

static work_s _work;
};

0 comments on commit da62101

Please sign in to comment.