Skip to content
Snippets Groups Projects
Commit 80d80835 authored by Alessandro Simovic's avatar Alessandro Simovic Committed by Beat Küng
Browse files

libtunes: fixed some type conversions and other minor changes

parent 92b89368
No related branches found
No related tags found
No related merge requests found
......@@ -115,7 +115,6 @@ int Tunes::set_control(const tune_control_s &tune_control)
// Special treatment for custom tunes
if (tune_control.tune_id == static_cast<int>(TuneID::CUSTOM)) {
_using_custom_msg = true;
_tune = nullptr; // remove tune in case of override
_frequency = (unsigned)tune_control.frequency;
_duration = (unsigned)tune_control.duration;
_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,
unsigned &silence, unsigned &strength)
unsigned &silence, uint8_t &strength)
{
int ret = get_next_tune(frequency, duration, silence);
......
......@@ -93,7 +93,7 @@ public:
*
* @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
......@@ -115,7 +115,7 @@ public:
* @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,
unsigned &strength);
uint8_t &strength);
/**
* Get the number of default tunes. This is useful for when a tune is
......@@ -148,7 +148,7 @@ private:
unsigned _frequency;
unsigned _duration;
unsigned _silence;
unsigned _strength;
uint8_t _strength;
bool _using_custom_msg = false;
/**
......
......@@ -72,7 +72,7 @@ usage()
"\t-s <strength>\t\tStrength of the tone between 0-100\n"
"\t-m <melody>\t\tMelody in a string form ex: \"MFT200e8a8a\"\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;
case 's':
value = (uint16_t)(strtol(myoptarg, nullptr, 0));
value = (uint8_t)(strtol(myoptarg, nullptr, 0));
if (value > 0 && value < 100) {
tune_control.strength = value;
......@@ -170,20 +170,21 @@ tune_control_main(int argc, char *argv[])
return 1;
}
unsigned frequency, duration, silence, strength;
unsigned frequency, duration, silence;
uint8_t strength;
int exit_counter = 0;
if (!strcmp(argv[myoptind], "play")) {
if (string_input) {
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) {
tune_control.tune_id = 0;
tune_control.frequency = (uint16_t)frequency;
tune_control.duration = (uint32_t)duration;
tune_control.silence = (uint32_t)silence;
tune_control.strength = (uint32_t)strength;
tune_control.strength = (uint8_t)strength;
publish_tune_control(tune_control);
usleep(duration + silence);
exit_counter++;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment