Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
Firmware
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Alberto Ruiz Garcia
Firmware
Commits
e9ea7ab6
Commit
e9ea7ab6
authored
8 years ago
by
Simone Guscetti
Committed by
Daniel Agar
7 years ago
Browse files
Options
Downloads
Patches
Plain Diff
lib tunes: clean up
parent
dcfd2f15
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/lib/tunes/tunes.cpp
+1
-3
1 addition, 3 deletions
src/lib/tunes/tunes.cpp
src/lib/tunes/tunes.h
+51
-30
51 additions, 30 deletions
src/lib/tunes/tunes.h
with
52 additions
and
33 deletions
src/lib/tunes/tunes.cpp
+
1
−
3
View file @
e9ea7ab6
...
...
@@ -254,7 +254,7 @@ unsigned Tunes::next_dots()
int
Tunes
::
next_note
(
unsigned
&
frequency
,
unsigned
&
duration
,
unsigned
&
silence
)
{
// make sure we still have a tune
- may be removed by the write / ioctl handler
// make sure we still have a tune
if
((
_next
==
nullptr
)
||
(
_tune
==
nullptr
))
{
return
TUNE_ERROR
;
}
...
...
@@ -263,7 +263,6 @@ int Tunes::next_note(unsigned &frequency, unsigned &duration, unsigned &silence)
unsigned
note
=
0
;
unsigned
note_length
=
_note_length
;
// NOTE: is this while loop necessary?
while
(
note
==
0
)
{
// we always need at least one character from the string
int
c
=
next_char
();
...
...
@@ -441,7 +440,6 @@ tune_end:
return
TUNE_CONTINUE
;
}
else
{
_default_tune_number
=
0
;
return
TUNE_STOP
;
}
}
This diff is collapsed.
Click to expand it.
src/lib/tunes/tunes.h
+
51
−
30
View file @
e9ea7ab6
...
...
@@ -53,45 +53,66 @@ public:
Tunes
();
Tunes
(
unsigned
tempo
,
unsigned
octave
,
unsigned
note_length
,
NoteMode
mode
);
~
Tunes
()
=
default
;
/**
* parse a tune_control_s in frequency(Hz), duration(us) and silence(us).
*
* @param tune_control struct containig the uORB message
* @param frequency return frequency value (Hz)
* @param duration return duration of the tone (us)
* @param silence return silance duration (us)
* @return -1 for error, 0 for play one tone and 1 for continue a sequence
*/
int
parse_cmd
(
tune_control_s
&
tune_control
,
unsigned
&
frequency
,
unsigned
&
duration
,
unsigned
&
silence
);
/**
* parse a tune string, formatted with the syntax of the Microsoft GWBasic/QBasic, in frequency(Hz),
* duration(us) and silence(us).
*
* @param string tune input string
* @param frequency return frequency value (Hz)
* @param duration return duration of the tone (us)
* @param silence return silance duration (us)
* @return -1 for error, 0 for play one tone and 1 for continue a sequence
*/
int
parse_string
(
const
char
*
string
,
unsigned
&
frequency
,
unsigned
&
duration
,
unsigned
&
silence
);
private:
static
const
unsigned
_tune_max
=
1024
*
8
;
// be reasonable about user tunes
static
const
char
*
_default_tunes
[
TONE_NUMBER_OF_TUNES
];
static
const
char
*
_tune_names
[
TONE_NUMBER_OF_TUNES
];
static
const
uint8_t
_note_tab
[];
unsigned
_default_tune_number
;
// number of currently playing default tune (0 for none)
const
char
*
_user_tune
;
const
char
*
_tune
=
nullptr
;
// current tune string
const
char
*
_next
=
nullptr
;
// next note in the string
unsigned
_tempo
;
unsigned
_note_length
;
NoteMode
_note_mode
;
unsigned
_octave
;
unsigned
_default_tempo
=
120
;
unsigned
_default_note_length
=
4
;
NoteMode
_default_mode
=
NoteMode
::
MODE_NORMAL
;
unsigned
_default_octave
=
4
;
// unsigned _silence_length; // if nonzero, silence before next note
bool
_repeat
;
// if true, tune restarts at end
int
_cbrk
;
//if true, no audio output
static
const
char
*
_default_tunes
[
TONE_NUMBER_OF_TUNES
];
static
const
uint8_t
_note_tab
[];
bool
_repeat
;
// if true, tune restarts at end
const
char
*
_tune
=
nullptr
;
// current tune string
const
char
*
_next
=
nullptr
;
// next note in the string
unsigned
_tempo
;
unsigned
_note_length
;
NoteMode
_note_mode
;
unsigned
_octave
;
unsigned
_default_tempo
=
120
;
unsigned
_default_note_length
=
4
;
NoteMode
_default_mode
=
NoteMode
::
MODE_NORMAL
;
unsigned
_default_octave
=
4
;
/**
* Convert note to frequency
* @param note
* @return frequency
*
* @param note unsigned value of the semitone from C
* @return frequency (Hz)
*/
uint32_t
note_to_frequency
(
unsigned
note
);
// Calculate the duration in microseconds of play and silence for a
// note given the current tempo, length and mode and the number of
// dots following in the play string.
//
/**
* Calculate the duration in microseconds of play and silence for a
* note given the current tempo, length and mode and the number of
* dots following in the play string.
*
* @param silence return silence duration (us)
* @param note_length note length
* @param dots extention of the note length
* @return duration of the note (us)
*/
unsigned
note_duration
(
unsigned
&
silence
,
unsigned
note_length
,
unsigned
dots
);
// Calculate the duration in microseconds of a rest corresponding to
...
...
@@ -99,7 +120,7 @@ private:
//
unsigned
rest_duration
(
unsigned
rest_length
,
unsigned
dots
);
// Parse the next note out of the string
and play it
// Parse the next note out of the string
//
int
next_note
(
unsigned
&
frequency
,
unsigned
&
duration
,
unsigned
&
silence
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment