libtunes: fixed some type conversions and other minor changes

This commit is contained in:
Alessandro Simovic
2018-03-20 11:03:31 +01:00
committed by Beat Küng
parent 92b89368f1
commit 80d80835a0
3 changed files with 10 additions and 10 deletions
+1 -2
View File
@@ -115,7 +115,6 @@ int Tunes::set_control(const tune_control_s &tune_control)
// Special treatment for custom tunes // Special treatment for custom tunes
if (tune_control.tune_id == static_cast<int>(TuneID::CUSTOM)) { if (tune_control.tune_id == static_cast<int>(TuneID::CUSTOM)) {
_using_custom_msg = true; _using_custom_msg = true;
_tune = nullptr; // remove tune in case of override
_frequency = (unsigned)tune_control.frequency; _frequency = (unsigned)tune_control.frequency;
_duration = (unsigned)tune_control.duration; _duration = (unsigned)tune_control.duration;
_silence = (unsigned)tune_control.silence; _silence = (unsigned)tune_control.silence;
@@ -144,7 +143,7 @@ void Tunes::set_string(const char *const string, uint8_t strength)
} }
int Tunes::get_next_tune(unsigned &frequency, unsigned &duration, int Tunes::get_next_tune(unsigned &frequency, unsigned &duration,
unsigned &silence, unsigned &strength) unsigned &silence, uint8_t &strength)
{ {
int ret = get_next_tune(frequency, duration, silence); int ret = get_next_tune(frequency, duration, silence);
+3 -3
View File
@@ -93,7 +93,7 @@ public:
* *
* @param string tune input string * @param string tune input string
*/ */
void set_string(const char *const string); void set_string(const char *const string, uint8_t strength);
/** /**
* Get next note in the current tune, which has been provided by either * Get next note in the current tune, which has been provided by either
@@ -115,7 +115,7 @@ public:
* @return -1 for error, 0 for play one tone and 1 for continue a sequence * @return -1 for error, 0 for play one tone and 1 for continue a sequence
*/ */
int get_next_tune(unsigned &frequency, unsigned &duration, unsigned &silence, int get_next_tune(unsigned &frequency, unsigned &duration, unsigned &silence,
unsigned &strength); uint8_t &strength);
/** /**
* Get the number of default tunes. This is useful for when a tune is * Get the number of default tunes. This is useful for when a tune is
@@ -148,7 +148,7 @@ private:
unsigned _frequency; unsigned _frequency;
unsigned _duration; unsigned _duration;
unsigned _silence; unsigned _silence;
unsigned _strength; uint8_t _strength;
bool _using_custom_msg = false; bool _using_custom_msg = false;
/** /**
+6 -5
View File
@@ -72,7 +72,7 @@ usage()
"\t-s <strength>\t\tStrength of the tone between 0-100\n" "\t-s <strength>\t\tStrength of the tone between 0-100\n"
"\t-m <melody>\t\tMelody in a string form ex: \"MFT200e8a8a\"\n" "\t-m <melody>\t\tMelody in a string form ex: \"MFT200e8a8a\"\n"
"\n" "\n"
"tune_control stop \t\t Stops playback, useful for repeated tunes\n" "tune_control stop \t\tStops playback, useful for repeated tunes\n"
); );
} }
@@ -147,7 +147,7 @@ tune_control_main(int argc, char *argv[])
break; break;
case 's': case 's':
value = (uint16_t)(strtol(myoptarg, nullptr, 0)); value = (uint8_t)(strtol(myoptarg, nullptr, 0));
if (value > 0 && value < 100) { if (value > 0 && value < 100) {
tune_control.strength = value; tune_control.strength = value;
@@ -170,20 +170,21 @@ tune_control_main(int argc, char *argv[])
return 1; return 1;
} }
unsigned frequency, duration, silence, strength; unsigned frequency, duration, silence;
uint8_t strength;
int exit_counter = 0; int exit_counter = 0;
if (!strcmp(argv[myoptind], "play")) { if (!strcmp(argv[myoptind], "play")) {
if (string_input) { if (string_input) {
PX4_INFO("Start playback..."); PX4_INFO("Start playback...");
tunes.set_string(tune_string); tunes.set_string(tune_string, tune_control.strength);
while (tunes.get_next_tune(frequency, duration, silence, strength) > 0) { while (tunes.get_next_tune(frequency, duration, silence, strength) > 0) {
tune_control.tune_id = 0; tune_control.tune_id = 0;
tune_control.frequency = (uint16_t)frequency; tune_control.frequency = (uint16_t)frequency;
tune_control.duration = (uint32_t)duration; tune_control.duration = (uint32_t)duration;
tune_control.silence = (uint32_t)silence; tune_control.silence = (uint32_t)silence;
tune_control.strength = (uint32_t)strength; tune_control.strength = (uint8_t)strength;
publish_tune_control(tune_control); publish_tune_control(tune_control);
usleep(duration + silence); usleep(duration + silence);
exit_counter++; exit_counter++;