From 720676b28c23ae37f71a8ead050938c215a6fd4a Mon Sep 17 00:00:00 2001 From: Jonathan Challinger Date: Tue, 24 Jul 2018 19:00:24 -0700 Subject: [PATCH] AP_Notify: run astyle on ToneAlarm and MMLPlayer --- libraries/AP_Notify/MMLPlayer.cpp | 260 ++++++++++++++++-------------- libraries/AP_Notify/ToneAlarm.cpp | 84 +++++----- libraries/AP_Notify/ToneAlarm.h | 17 +- 3 files changed, 187 insertions(+), 174 deletions(-) diff --git a/libraries/AP_Notify/MMLPlayer.cpp b/libraries/AP_Notify/MMLPlayer.cpp index a2b205481e..87b41652c8 100644 --- a/libraries/AP_Notify/MMLPlayer.cpp +++ b/libraries/AP_Notify/MMLPlayer.cpp @@ -6,14 +6,16 @@ extern const AP_HAL::HAL& hal; -void MMLPlayer::update() { +void MMLPlayer::update() +{ // Check if note is over if (_playing && AP_HAL::micros()-_note_start_us > _note_duration_us) { next_action(); } } -void MMLPlayer::play(const char* string) { +void MMLPlayer::play(const char* string) +{ stop(); _string = string; @@ -30,24 +32,28 @@ void MMLPlayer::play(const char* string) { next_action(); } -void MMLPlayer::stop() { +void MMLPlayer::stop() +{ _playing = false; hal.util->toneAlarm_set_buzzer_tone(0,0); } -void MMLPlayer::start_silence(float duration) { +void MMLPlayer::start_silence(float duration) +{ _note_start_us = AP_HAL::micros(); _note_duration_us = duration*1e6; hal.util->toneAlarm_set_buzzer_tone(0, 0); } -void MMLPlayer::start_note(float duration, float frequency, float volume) { +void MMLPlayer::start_note(float duration, float frequency, float volume) +{ _note_start_us = AP_HAL::micros(); _note_duration_us = duration*1e6; hal.util->toneAlarm_set_buzzer_tone(frequency, volume); } -char MMLPlayer::next_char() { +char MMLPlayer::next_char() +{ while (_string[_next] != '\0' && isspace(_string[_next])) { _next++; } @@ -55,7 +61,8 @@ char MMLPlayer::next_char() { return toupper(_string[_next]); } -uint8_t MMLPlayer::next_number() { +uint8_t MMLPlayer::next_number() +{ uint8_t ret = 0; while (isdigit(next_char())) { ret = (ret*10) + (next_char() - '0'); @@ -64,7 +71,8 @@ uint8_t MMLPlayer::next_number() { return ret; } -size_t MMLPlayer::next_dots() { +size_t MMLPlayer::next_dots() +{ size_t ret = 0; while (next_char() == '.') { ret++; @@ -73,7 +81,8 @@ size_t MMLPlayer::next_dots() { return ret; } -float MMLPlayer::rest_duration(uint32_t rest_length, uint8_t dots) { +float MMLPlayer::rest_duration(uint32_t rest_length, uint8_t dots) +{ float whole_note_period = 240.0f / _tempo; if (rest_length == 0) { rest_length = 1; @@ -90,7 +99,8 @@ float MMLPlayer::rest_duration(uint32_t rest_length, uint8_t dots) { return rest_period; } -void MMLPlayer::next_action() { +void MMLPlayer::next_action() +{ if (_silence_duration > 0) { start_silence(_silence_duration); _silence_duration = 0; @@ -113,129 +123,129 @@ void MMLPlayer::next_action() { _next++; - switch(c) { - case 'V': { - _volume = next_number(); - break; + switch (c) { + case 'V': { + _volume = next_number(); + break; + } + case 'L': { + _default_note_length = next_number(); + if (_default_note_length == 0) { + stop(); + return; } - case 'L': { - _default_note_length = next_number(); - if (_default_note_length == 0) { - stop(); - return; - } - break; + break; + } + case 'O': + _octave = next_number(); + if (_octave > 6) { + _octave = 6; } - case 'O': - _octave = next_number(); - if (_octave > 6) { - _octave = 6; - } + break; + case '<': + if (_octave > 0) { + _octave--; + } + break; + case '>': + if (_octave < 6) { + _octave++; + } + break; + case 'M': + c = next_char(); + if (c == '\0') { + stop(); + return; + } + _next++; + switch (c) { + case 'N': + _note_mode = MODE_NORMAL; break; - case '<': - if (_octave > 0) { - _octave--; - } + case 'L': + _note_mode = MODE_LEGATO; break; - case '>': - if (_octave < 6) { - _octave++; - } + case 'S': + _note_mode = MODE_STACCATO; break; - case 'M': - c = next_char(); - if (c == '\0') { - stop(); - return; - } - _next++; - switch (c) { - case 'N': - _note_mode = MODE_NORMAL; - break; - case 'L': - _note_mode = MODE_LEGATO; - break; - case 'S': - _note_mode = MODE_STACCATO; - break; - case 'F': - _repeat = false; - break; - case 'B': - _repeat = true; - break; - default: - stop(); - return; - } + case 'F': + _repeat = false; break; - case 'R': - case 'P': { + case 'B': + _repeat = true; + break; + default: + stop(); + return; + } + break; + case 'R': + case 'P': { + uint8_t num = next_number(); + uint8_t dots = next_dots(); + start_silence(rest_duration(num, dots)); + return; + } + case 'T': + _tempo = next_number(); + if (_tempo < 32) { + stop(); + return; + } + break; + case 'N': + note = next_number(); + note_length = _default_note_length; + if (note > 84) { + stop(); + return; + } + if (note == 0) { uint8_t num = next_number(); uint8_t dots = next_dots(); start_silence(rest_duration(num, dots)); return; } - case 'T': - _tempo = next_number(); - if (_tempo < 32) { - stop(); - return; - } - break; - case 'N': - note = next_number(); - note_length = _default_note_length; - if (note > 84) { - stop(); - return; - } - if (note == 0) { - uint8_t num = next_number(); - uint8_t dots = next_dots(); - start_silence(rest_duration(num, dots)); - return; - } - break; - case 'A': - case 'B': - case 'C': - case 'D': - case 'E': - case 'F': - case 'G': { - uint8_t note_tab[] = {9,11,0,2,4,5,7}; - note = note_tab[c-'A'] + (_octave*12) + 1; + break; + case 'A': + case 'B': + case 'C': + case 'D': + case 'E': + case 'F': + case 'G': { + uint8_t note_tab[] = {9,11,0,2,4,5,7}; + note = note_tab[c-'A'] + (_octave*12) + 1; - c = next_char(); + c = next_char(); - switch (c) { - case '#': - case '+': - if (note < 84) { - note++; - } - _next++; - break; - case '-': - if (note > 1) { - note--; - } - _next++; - break; - default: - break; + switch (c) { + case '#': + case '+': + if (note < 84) { + note++; } - note_length = next_number(); - if (note_length == 0) { - note_length = _default_note_length; + _next++; + break; + case '-': + if (note > 1) { + note--; } + _next++; + break; + default: break; } - default: - stop(); - return; + note_length = next_number(); + if (note_length == 0) { + note_length = _default_note_length; + } + break; + } + default: + stop(); + return; } } @@ -248,15 +258,15 @@ void MMLPlayer::next_action() { float note_period = 240.0f / (float)_tempo / (float)note_length; switch (_note_mode) { - case MODE_NORMAL: - _silence_duration = note_period/8; - break; - case MODE_STACCATO: - _silence_duration = note_period/4; - break; - case MODE_LEGATO: - _silence_duration = 0; - break; + case MODE_NORMAL: + _silence_duration = note_period/8; + break; + case MODE_STACCATO: + _silence_duration = note_period/4; + break; + case MODE_LEGATO: + _silence_duration = 0; + break; } note_period -= _silence_duration; diff --git a/libraries/AP_Notify/ToneAlarm.cpp b/libraries/AP_Notify/ToneAlarm.cpp index f0327bf1a2..4474892286 100644 --- a/libraries/AP_Notify/ToneAlarm.cpp +++ b/libraries/AP_Notify/ToneAlarm.cpp @@ -32,65 +32,65 @@ extern const AP_HAL::HAL& hal; const ToneAlarm::Tone ToneAlarm::_tones[] { - #define AP_NOTIFY_TONE_QUIET_NEG_FEEDBACK 0 +#define AP_NOTIFY_TONE_QUIET_NEG_FEEDBACK 0 { "MFT200L4<<B#A#2P8B#A#2", false }, - #define AP_NOTIFY_TONE_QUIET_NEU_FEEDBACK 2 +#define AP_NOTIFY_TONE_QUIET_NEU_FEEDBACK 2 { "MFT200L4B#", false }, - #define AP_NOTIFY_TONE_QUIET_POS_FEEDBACK 4 +#define AP_NOTIFY_TONE_QUIET_POS_FEEDBACK 4 { "MFT200L4A#B#", false }, - #define AP_NOTIFY_TONE_LOUD_READY_OR_FINISHED 6 +#define AP_NOTIFY_TONE_LOUD_READY_OR_FINISHED 6 { "MFT100L4>G#6A#6B#4", false }, - #define AP_NOTIFY_TONE_QUIET_READY_OR_FINISHED 7 +#define AP_NOTIFY_TONE_QUIET_READY_OR_FINISHED 7 { "MFT200L4A#A#A#A#", false }, - #define AP_NOTIFY_TONE_QUIET_ARMING_WARNING 9 +#define AP_NOTIFY_TONE_QUIET_ARMING_WARNING 9 { "MNT75L1O2G", false }, - #define AP_NOTIFY_TONE_LOUD_WP_COMPLETE 10 +#define AP_NOTIFY_TONE_LOUD_WP_COMPLETE 10 { "MFT200L8G>C3", false }, - #define AP_NOTIFY_TONE_LOUD_LAND_WARNING_CTS 11 +#define AP_NOTIFY_TONE_LOUD_LAND_WARNING_CTS 11 { "MBT200L2A-G-A-G-A-G-", true }, - #define AP_NOTIFY_TONE_LOUD_VEHICLE_LOST_CTS 12 +#define AP_NOTIFY_TONE_LOUD_VEHICLE_LOST_CTS 12 { "MBT200>A#1", true }, - #define AP_NOTIFY_TONE_LOUD_BATTERY_ALERT_CTS 13 +#define AP_NOTIFY_TONE_LOUD_BATTERY_ALERT_CTS 13 { "MBNT255>A#8A#8A#8A#8A#8A#8A#8A#8A#8A#8A#8A#8A#8A#8A#8A#8", true }, - #define AP_NOTIFY_TONE_QUIET_COMPASS_CALIBRATING_CTS 14 +#define AP_NOTIFY_TONE_QUIET_COMPASS_CALIBRATING_CTS 14 { "MBNT255B", false}, - #define AP_NOTIFY_TONE_LOUD_2 17 +#define AP_NOTIFY_TONE_LOUD_2 17 { "MFT100L8>BB", false}, - #define AP_NOTIFY_TONE_LOUD_3 18 +#define AP_NOTIFY_TONE_LOUD_3 18 { "MFT100L8>BBB", false}, - #define AP_NOTIFY_TONE_LOUD_4 19 +#define AP_NOTIFY_TONE_LOUD_4 19 { "MFT100L8>BBBB", false}, - #define AP_NOTIFY_TONE_LOUD_5 20 +#define AP_NOTIFY_TONE_LOUD_5 20 { "MFT100L8>BBBBB", false}, - #define AP_NOTIFY_TONE_LOUD_6 21 +#define AP_NOTIFY_TONE_LOUD_6 21 { "MFT100L8>BBBBBB", false}, - #define AP_NOTIFY_TONE_LOUD_7 22 +#define AP_NOTIFY_TONE_LOUD_7 22 { "MFT100L8>BBBBBBB", false}, - #define AP_NOTIFY_TONE_TUNING_START 23 +#define AP_NOTIFY_TONE_TUNING_START 23 { "MFT100L20>C#D#", false}, - #define AP_NOTIFY_TONE_TUNING_SAVE 24 +#define AP_NOTIFY_TONE_TUNING_SAVE 24 { "MFT100L10DBDB>", false}, - #define AP_NOTIFY_TONE_TUNING_ERROR 25 +#define AP_NOTIFY_TONE_TUNING_ERROR 25 { "MFT100L10>BBBBBBBB", false}, - #define AP_NOTIFY_TONE_LEAK_DETECTED 26 +#define AP_NOTIFY_TONE_LEAK_DETECTED 26 { "MBT255L8>A+AA-", true}, - #define AP_NOTIFY_TONE_QUIET_SHUTDOWN 27 +#define AP_NOTIFY_TONE_QUIET_SHUTDOWN 27 { "MFMST200L32O3ceP32cdP32ceP32ccc>ctake(HAL_SEMAPHORE_BLOCK_FOREVER); _mml_player.update(); @@ -137,7 +138,8 @@ void ToneAlarm::_timer_task() { } } -void ToneAlarm::play_string(const char *str) { +void ToneAlarm::play_string(const char *str) +{ if (_sem) { _sem->take(HAL_SEMAPHORE_BLOCK_FOREVER); _mml_player.stop(); @@ -148,15 +150,17 @@ void ToneAlarm::play_string(const char *str) { } } -void ToneAlarm::stop_cont_tone() { - if(_cont_tone_playing == _tone_playing) { +void ToneAlarm::stop_cont_tone() +{ + if (_cont_tone_playing == _tone_playing) { play_string(""); _tone_playing = -1; } _cont_tone_playing = -1; } -void ToneAlarm::check_cont_tone() { +void ToneAlarm::check_cont_tone() +{ uint32_t tnow_ms = AP_HAL::millis(); // if we are supposed to be playing a continuous tone, // and it was interrupted, and the interrupting tone has timed out, @@ -186,11 +190,11 @@ void ToneAlarm::update() } if (AP_Notify::flags.compass_cal_running != flags.compass_cal_running) { - if(AP_Notify::flags.compass_cal_running) { + if (AP_Notify::flags.compass_cal_running) { play_tone(AP_NOTIFY_TONE_QUIET_COMPASS_CALIBRATING_CTS); play_tone(AP_NOTIFY_TONE_QUIET_POS_FEEDBACK); } else { - if(_cont_tone_playing == AP_NOTIFY_TONE_QUIET_COMPASS_CALIBRATING_CTS) { + if (_cont_tone_playing == AP_NOTIFY_TONE_QUIET_COMPASS_CALIBRATING_CTS) { stop_cont_tone(); } } @@ -256,7 +260,7 @@ void ToneAlarm::update() } // failsafe initiated mode change - if(AP_Notify::events.failsafe_mode_change) { + if (AP_Notify::events.failsafe_mode_change) { play_tone(AP_NOTIFY_TONE_LOUD_ATTENTION_NEEDED); } @@ -302,7 +306,7 @@ void ToneAlarm::update() if (flags.armed) { // arming tune play_tone(AP_NOTIFY_TONE_QUIET_ARMING_WARNING); - }else{ + } else { // disarming tune play_tone(AP_NOTIFY_TONE_QUIET_NEU_FEEDBACK); if (!flags.leak_detected) { diff --git a/libraries/AP_Notify/ToneAlarm.h b/libraries/AP_Notify/ToneAlarm.h index 80741c39e4..8b88bb6f6b 100644 --- a/libraries/AP_Notify/ToneAlarm.h +++ b/libraries/AP_Notify/ToneAlarm.h @@ -24,8 +24,7 @@ #define AP_NOTIFY_PX4_MAX_TONE_LENGTH_MS 2000 #define AP_NOTIFY_TONEALARM_TONE_BUF_SIZE 512 -class ToneAlarm: public NotifyDevice -{ +class ToneAlarm: public NotifyDevice { public: /// init - initialised the tone alarm bool init(void); @@ -74,11 +73,11 @@ private: struct Tone { const char *str; const uint8_t continuous : 1; + }; + + const static Tone _tones[]; + + AP_HAL::Semaphore* _sem; + MMLPlayer _mml_player; + char _tone_buf[AP_NOTIFY_TONEALARM_TONE_BUF_SIZE]; }; - - const static Tone _tones[]; - - AP_HAL::Semaphore* _sem; - MMLPlayer _mml_player; - char _tone_buf[AP_NOTIFY_TONEALARM_TONE_BUF_SIZE]; -};