pwm:ensure that a rate of 0 will invoke the ioctl

Prior to onshot being added to the system. The -r of the
   "rate" command would not invoke the ioctl PWM_SERVO_SET_UPDATE_RATE
   when -r was not provided on the command line. This may have been a
   feature or a bug.

   When onshot was added to the pwm command a bug was intorduced
   that precluded the ioctl PWM_SERVO_SET_UPDATE_RATE from being
   called on -r 0.

   This commit fixes that issue, and preserves the "prio to oneshot"
   behavior of the "rate" command when -r is not specified.
This commit is contained in:
David Sidrane
2017-04-24 15:54:26 -10:00
committed by Lorenz Meier
parent 44a507fcfe
commit 0a1fbef8c8
+10 -5
View File
@@ -92,7 +92,7 @@ usage(const char *reason)
"\t[-g <channel group>]\t(e.g. 0,1,2)\n" "\t[-g <channel group>]\t(e.g. 0,1,2)\n"
"\t[-m <channel mask> ]\t(e.g. 0xF)\n" "\t[-m <channel mask> ]\t(e.g. 0xF)\n"
"\t[-a]\t\t\tConfigure all outputs\n" "\t[-a]\t\t\tConfigure all outputs\n"
"\t-r <alt_rate>\t\tPWM rate (50 to 400 Hz)\n" "\t-r <alt_rate>\t\tPWM rate (0 - oneshot, 50 to 400 Hz)\n"
"\n" "\n"
"failsafe ...\t\t\tFailsafe PWM\n" "failsafe ...\t\t\tFailsafe PWM\n"
"disarmed ...\t\t\tDisarmed PWM\n" "disarmed ...\t\t\tDisarmed PWM\n"
@@ -169,7 +169,7 @@ int
pwm_main(int argc, char *argv[]) pwm_main(int argc, char *argv[])
{ {
const char *dev = PWM_OUTPUT0_DEVICE_PATH; const char *dev = PWM_OUTPUT0_DEVICE_PATH;
unsigned alt_rate = 0; int alt_rate = -1; // Default to indicate not set.
uint32_t alt_channel_groups = 0; uint32_t alt_channel_groups = 0;
bool alt_channels_set = false; bool alt_channels_set = false;
bool print_verbose = false; bool print_verbose = false;
@@ -262,7 +262,6 @@ pwm_main(int argc, char *argv[])
case 'r': case 'r':
alt_rate = get_parameter_value(myoptarg, "PWM Rate"); alt_rate = get_parameter_value(myoptarg, "PWM Rate");
break; break;
default: default:
@@ -347,8 +346,14 @@ pwm_main(int argc, char *argv[])
} else if (oneshot || !strcmp(command, "rate")) { } else if (oneshot || !strcmp(command, "rate")) {
/* change alternate PWM rate or set oneshot */ /* Change alternate PWM rate or set oneshot
if (oneshot || alt_rate > 0) { * Either the "oneshot" command was used
* and/OR -r was provided on command line and has changed the alt_rate
* to the non default of -1, so we will issue the PWM_SERVO_SET_UPDATE_RATE
* ioctl
*/
if (oneshot || alt_rate >= 0) {
ret = px4_ioctl(fd, PWM_SERVO_SET_UPDATE_RATE, oneshot ? 0 : alt_rate); ret = px4_ioctl(fd, PWM_SERVO_SET_UPDATE_RATE, oneshot ? 0 : alt_rate);
if (ret != OK) { if (ret != OK) {