From 34836a2b21dcb7afd4863589676ef589d8ff1589 Mon Sep 17 00:00:00 2001 From: Alessandro Simovic Date: Tue, 23 Jan 2018 10:51:10 +0100 Subject: [PATCH] libtunes: allow custom tune (id 0) to be used to stop playback. Override flag must still be set to true! --- src/lib/tunes/tunes.cpp | 1 + src/systemcmds/tune_control/tune_control.cpp | 19 +++++++++++++++---- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/lib/tunes/tunes.cpp b/src/lib/tunes/tunes.cpp index d0b4646038..90e1d4226b 100644 --- a/src/lib/tunes/tunes.cpp +++ b/src/lib/tunes/tunes.cpp @@ -94,6 +94,7 @@ int Tunes::set_control(const tune_control_s &tune_control) switch (tune_control.tune_id) { case static_cast(TuneID::CUSTOM): if (_tune == nullptr || tune_control.tune_override) { + _tune = nullptr; // remove tune in case of override _frequency = (unsigned)tune_control.frequency; _duration = (unsigned)tune_control.duration; _silence = (unsigned)tune_control.silence; diff --git a/src/systemcmds/tune_control/tune_control.cpp b/src/systemcmds/tune_control/tune_control.cpp index 11a4228c9c..592ae1f401 100644 --- a/src/systemcmds/tune_control/tune_control.cpp +++ b/src/systemcmds/tune_control/tune_control.cpp @@ -71,6 +71,8 @@ usage() "\t-d \t\tDuration of the tone in us\n" "\t-s \t\tStrength of the tone between 0-100\n" "\t-m \t\tMelody in a string form ex: \"MFT200e8a8a\"\n" + "\n" + "tune_control stop \t\t Stops playback, useful for repeated tunes\n" ); } @@ -185,7 +187,7 @@ tune_control_main(int argc, char *argv[]) usleep(duration + silence); exit_counter++; - // exit if the loop is doing more thatn 50 iteration + // exit if the loop is doing too many iterations if (exit_counter > MAX_NOTE_ITERATION) { break; } @@ -193,7 +195,7 @@ tune_control_main(int argc, char *argv[]) PX4_INFO("Playback finished."); - } else { + } else { // tune id instead of string has been provided if (tune_control.tune_id == 0) { tune_control.tune_id = 1; } @@ -210,13 +212,22 @@ tune_control_main(int argc, char *argv[]) usleep(500000); exit_counter++; - // exit if the loop is doing more thatn 50 iteration + // exit if the loop is doing too many iterations if (exit_counter > MAX_NOTE_ITERATION) { break; } } - } else { + } else if (!strcmp(argv[myoptind], "stop")) { + PX4_INFO("Stopping playback..."); + tune_control.tune_id = 0; + tune_control.frequency = 0; + tune_control.duration = 0; + tune_control.silence = 0; + tune_control.tune_override = true; + publish_tune_control(tune_control); + + } else { usage(); return 1; }