Skip to content

Commit

Permalink
pwm_esc: Add 'status' command
Browse files Browse the repository at this point in the history
Signed-off-by: Jukka Laitinen <[email protected]>
  • Loading branch information
jlaitine committed Aug 26, 2024
1 parent 3496d25 commit 285c97c
Showing 1 changed file with 41 additions and 5 deletions.
46 changes: 41 additions & 5 deletions src/drivers/pwm_esc/pwm_esc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,11 @@ class PWMESC : public OutputModuleInterface
*/
static int stop();

/**
* Status of PWMESC driver
*/
static int status();

/**
* Return if the PWMESC driver is already running
*/
Expand Down Expand Up @@ -175,6 +180,11 @@ class PWMESC : public OutputModuleInterface
/* Singleton pointer */
static PWMESC *_instance;

/**
* Status of PWMESC driver
*/
int printStatus();

/**
* Trampoline to the worker task
*/
Expand All @@ -199,9 +209,9 @@ class PWMESC : public OutputModuleInterface
/**
* Get the singleton instance
*/
static inline PWMESC *getInstance()
static inline PWMESC *getInstance(bool allocate = false)
{
if (_instance == nullptr) {
if (_instance == nullptr && allocate) {
/* create the driver */
_instance = new PWMESC();
}
Expand Down Expand Up @@ -483,7 +493,7 @@ PWMESC::start(int argc, char *argv[])
{
int ret = 0;

if (PWMESC::getInstance() == nullptr) {
if (PWMESC::getInstance(true) == nullptr) {
PX4_ERR("Driver allocation failed");
return -1;
}
Expand Down Expand Up @@ -518,7 +528,7 @@ int
PWMESC::stop()
{
if (PWMESC::getInstance() == nullptr) {
PX4_ERR("Driver allocation failed");
PX4_ERR("Not started");
return -1;
}

Expand All @@ -533,12 +543,34 @@ PWMESC::stop()
return 0;
}

int PWMESC::printStatus()
{
_mixing_output.printStatus();
return 0;
}

int
PWMESC::status()
{
if (PWMESC::getInstance() == nullptr) {
PX4_INFO("Not started");
return 0;
}

if (!PWMESC::getInstance()->running()) {
PX4_ERR("Not running");
return -1;
}

return PWMESC::getInstance()->printStatus();
}

int
pwm_esc_main(int argc, char *argv[])
{
/* check for sufficient number of arguments */
if (argc < 2) {
PX4_ERR("Need a command, try 'start' / 'stop'");
PX4_ERR("Need a command, try 'start' / 'stop' / 'status'");
return -1;
}

Expand All @@ -550,5 +582,9 @@ pwm_esc_main(int argc, char *argv[])
return PWMESC::stop();
}

if (!strcmp(argv[1], "status")) {
return PWMESC::status();
}

return 0;
}

0 comments on commit 285c97c

Please sign in to comment.