Make PWM_RATE configurable via QGroundControl

This commit is contained in:
Anton Matosov
2016-11-19 15:14:18 +01:00
committed by Lorenz Meier
parent 81dc20ea86
commit 4edd12c44a
4 changed files with 62 additions and 42 deletions
+41 -40
View File
@@ -112,6 +112,44 @@ usage(const char *reason)
}
static unsigned
get_parameter_value(const char *option, const char* paramDescription)
{
unsigned result_value = 0;
/* check if this is a param name */
if (strncmp("p:", option, 2) == 0) {
char paramName[32];
strncpy(paramName, option + 2, 16);
/* user wants to use a param name */
param_t parm = param_find(paramName);
if (parm != PARAM_INVALID) {
int32_t pwm_parm;
int gret = param_get(parm, &pwm_parm);
if (gret == 0) {
result_value = pwm_parm;
} else {
errx(gret, "PARAM '%s' LOAD FAIL", paramDescription);
}
} else {
errx(1, "PARAM '%s' NAME NOT FOUND", paramName);
}
} else {
char *ep;
result_value = strtoul(option, &ep, 0);
if (*ep != '\0') {
errx(1, "BAD '%s'", paramDescription);
}
}
return result_value;
}
int
pwm_main(int argc, char *argv[])
{
@@ -190,48 +228,12 @@ pwm_main(int argc, char *argv[])
break;
case 'p': {
/* check if this is a param name */
if (strncmp("p:", optarg, 2) == 0) {
char buf[32];
strncpy(buf, optarg + 2, 16);
/* user wants to use a param name */
param_t parm = param_find(buf);
if (parm != PARAM_INVALID) {
int32_t pwm_parm;
int gret = param_get(parm, &pwm_parm);
if (gret == 0) {
pwm_value = pwm_parm;
} else {
usage("PARAM LOAD FAIL");
}
} else {
usage("PARAM NAME NOT FOUND");
}
} else {
pwm_value = strtoul(optarg, &ep, 0);
}
if (*ep != '\0') {
usage("BAD PWM VAL");
}
}
case 'p':
pwm_value = get_parameter_value(optarg, "PWM Value");
break;
case 'r':
alt_rate = strtoul(optarg, &ep, 0);
if (*ep != '\0') {
usage("BAD rate VAL");
}
alt_rate = get_parameter_value(optarg, "PWM Rate");
break;
@@ -888,4 +890,3 @@ pwm_main(int argc, char *argv[])
usage(NULL);
return 0;
}