tune control: added the possibility to set tunes with a string

minor changes
This commit is contained in:
Simone Guscetti
2017-02-17 11:10:23 +01:00
committed by Daniel Agar
parent 7f1f3fa367
commit f7aad844a3
2 changed files with 48 additions and 32 deletions

View File

@@ -33,7 +33,7 @@
px4_add_module( px4_add_module(
MODULE systemcmds__tune_control MODULE systemcmds__tune_control
MAIN tune_control MAIN tune_control
STACK_MAIN 2500 STACK_MAIN 2500 # TODO: choose an appropriate stack size
COMPILE_FLAGS COMPILE_FLAGS
SRCS SRCS
tune_control.cpp tune_control.cpp

View File

@@ -127,16 +127,33 @@ int
tune_control_main(int argc, char *argv[]) tune_control_main(int argc, char *argv[])
{ {
output::Tunes tunes; output::Tunes tunes;
bool string_input = false;
const char *tune_string = NULL;
int myoptind = 1; int myoptind = 1;
int ch; int ch;
const char *myoptarg = NULL; const char *myoptarg = NULL;
uint8_t value; uint8_t value;
tune_control_s tune_control = {}; tune_control_s tune_control = {};
tune_control.tune_id = tune_control_s::STARTUP; tune_control.tune_id = 0;
tune_control.strength = 40; tune_control.strength = 40;
while ((ch = px4_getopt(argc, argv, "t:", &myoptind, &myoptarg)) != EOF) { while ((ch = px4_getopt(argc, argv, "f:d:t:s:", &myoptind, &myoptarg)) != EOF) {
switch (ch) { switch (ch) {
case 'f':
if ((uint16_t)(strtol(myoptarg, NULL, 0)) > 0 && (uint16_t)(strtol(myoptarg, NULL, 0)) < 22000) {
tune_control.frequency = (uint16_t)(strtol(myoptarg, NULL, 0));
} else {
usage();
return 1;
}
break;
case 'd':
tune_control.duration = (uint16_t)(strtol(myoptarg, NULL, 0));
break;
case 't': case 't':
value = (uint8_t)(strtol(myoptarg, NULL, 0)); value = (uint8_t)(strtol(myoptarg, NULL, 0));
@@ -150,23 +167,12 @@ tune_control_main(int argc, char *argv[])
break; break;
case 'l':
// led_control.led_mask = 1 << strtol(myoptarg, NULL, 0);
break;
case 'n':
// led_control.num_blinks = strtol(myoptarg, NULL, 0);
break;
case 's': case 's':
if (!strcmp(myoptarg, "fast")) { string_input = true;
// blink_speed = led_control_s::MODE_BLINK_FAST;
} else if (!strcmp(myoptarg, "normal")) { // TODO: check if the string is a valid tune sequence
// blink_speed = led_control_s::MODE_BLINK_NORMAL; if (1) {
tune_string = myoptarg;
} else if (!strcmp(myoptarg, "slow")) {
// blink_speed = led_control_s::MODE_BLINK_SLOW;
} else { } else {
usage(); usage();
@@ -195,27 +201,37 @@ tune_control_main(int argc, char *argv[])
return 1; return 1;
} }
if (!strcmp(argv[myoptind], "test")) { unsigned frequency, duration, silence;
PX4_INFO("Publishing standard tune %d", tune_control.tune_id);
publish_tune_control(tune_control); if (!strcmp(argv[myoptind], "play")) {
if (string_input) {
PX4_INFO("Start playback...");
while (tunes.parse_string(tune_string, frequency, duration, silence) > 0) {
tune_control.tune_id = 0;
tune_control.frequency = (uint16_t)frequency;
tune_control.duration = (uint32_t)duration;
publish_tune_control(tune_control);
usleep(duration + silence);
}
PX4_INFO("Playback finished.")
} else {
if (tune_control.tune_id == 0) {
tune_control.tune_id = 1;
}
PX4_INFO("Publishing standard tune %d", tune_control.tune_id);
publish_tune_control(tune_control);
}
} else if (!strcmp(argv[myoptind], "libtest")) { } else if (!strcmp(argv[myoptind], "libtest")) {
unsigned frequency, duration, silence;
while (tunes.parse_cmd(tune_control, frequency, duration, silence) > 0) { while (tunes.parse_cmd(tune_control, frequency, duration, silence) > 0) {
PX4_INFO("frequency: %d, duration %d, silence %d", frequency, duration, silence); PX4_INFO("frequency: %d, duration %d, silence %d", frequency, duration, silence);
usleep(500000); usleep(500000);
} }
/*} else if (!strcmp(argv[myoptind], "off")) {
led_control.mode = led_control_s::MODE_OFF;
} else if (!strcmp(argv[myoptind], "reset")) {
led_control.mode = led_control_s::MODE_DISABLED;
} else if (!strcmp(argv[myoptind], "blink")) {
led_control.mode = blink_speed;*/
} else { } else {
usage(); usage();
return 1; return 1;