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
5214642b
Commit
5214642b
authored
8 years ago
by
Simone Guscetti
Committed by
Daniel Agar
7 years ago
Browse files
Options
Downloads
Patches
Plain Diff
tunes lib: Minor changes
parent
546a92af
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/lib/tunes/tunes.cpp
+8
-10
8 additions, 10 deletions
src/lib/tunes/tunes.cpp
src/lib/tunes/tunes.h
+28
-15
28 additions, 15 deletions
src/lib/tunes/tunes.h
src/systemcmds/tune_control/tune_control.cpp
+2
-2
2 additions, 2 deletions
src/systemcmds/tune_control/tune_control.cpp
with
38 additions
and
27 deletions
src/lib/tunes/tunes.cpp
+
8
−
10
View file @
5214642b
...
...
@@ -49,8 +49,6 @@
#define BEAT_TIME_CONVERSION_US BEAT_TIME_CONVERSION_MS * 1000
#define BEAT_TIME_CONVERSION BEAT_TIME_CONVERSION_US
using
namespace
output
;
// initialise default tunes
const
char
*
Tunes
::
_default_tunes
[]
=
{
""
,
// empty to align with the index
...
...
@@ -84,7 +82,7 @@ Tunes::Tunes(unsigned default_tempo, unsigned default_octave, unsigned default_n
config_tone
();
}
Tunes
::
Tunes
()
:
Tunes
(
120
,
4
,
4
,
NoteMode
::
MODE_
NORMAL
)
Tunes
::
Tunes
()
:
Tunes
(
120
,
4
,
4
,
NoteMode
::
NORMAL
)
{
}
...
...
@@ -100,7 +98,7 @@ void Tunes::config_tone()
_octave
=
_default_octave
;
}
int
Tunes
::
parse_cmd
(
struc
t
tune_control_s
&
tune_control
,
unsigned
&
frequency
,
unsigned
&
duration
,
unsigned
&
silence
)
int
Tunes
::
parse_cmd
(
cons
t
tune_control_s
&
tune_control
,
unsigned
&
frequency
,
unsigned
&
duration
,
unsigned
&
silence
)
{
int
continue_sequnece
=
0
;
...
...
@@ -168,16 +166,16 @@ unsigned Tunes::note_duration(unsigned &silence, unsigned note_length, unsigned
unsigned
note_period
=
whole_note_period
/
note_length
;
switch
(
_note_mode
)
{
case
MODE_
NORMAL
:
case
NoteMode
::
NORMAL
:
silence
=
note_period
/
8
;
break
;
case
MODE_
STACCATO
:
case
NoteMode
::
STACCATO
:
silence
=
note_period
/
4
;
break
;
case
NoteMode
::
LEGATO
:
default:
case
MODE_LEGATO
:
silence
=
0
;
break
;
}
...
...
@@ -317,15 +315,15 @@ int Tunes::next_note(unsigned &frequency, unsigned &duration, unsigned &silence)
switch
(
c
)
{
case
'N'
:
_note_mode
=
MODE_
NORMAL
;
_note_mode
=
NoteMode
::
NORMAL
;
break
;
case
'L'
:
_note_mode
=
MODE_
LEGATO
;
_note_mode
=
NoteMode
::
LEGATO
;
break
;
case
'S'
:
_note_mode
=
MODE_
STACCATO
;
_note_mode
=
NoteMode
::
STACCATO
;
break
;
case
'F'
:
...
...
This diff is collapsed.
Click to expand it.
src/lib/tunes/tunes.h
+
28
−
15
View file @
5214642b
...
...
@@ -42,16 +42,25 @@
// TODO: find better way to include the number of tunes, maybe include them in the lib directly?
#include
<drivers/drv_tone_alarm.h>
namespace
output
{
enum
NoteMode
{
MODE_NORMAL
,
MODE_LEGATO
,
MODE_STACCATO
};
class
Tunes
{
public:
enum
class
NoteMode
{
NORMAL
,
LEGATO
,
STACCATO
};
/**
* Constructor with the default parameter set to:
* default_tempo: 120
* default_octave: 4
* default_note_length: 4
* default_mode: NORMAL
*/
Tunes
();
Tunes
(
unsigned
tempo
,
unsigned
octave
,
unsigned
note_length
,
NoteMode
mode
);
/**
* Constructor that can set the default parameters
*/
Tunes
(
unsigned
default_tempo
,
unsigned
default_octave
,
unsigned
default_note_length
,
NoteMode
default_mode
);
~
Tunes
()
=
default
;
/**
...
...
@@ -63,7 +72,7 @@ public:
* @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
);
int
parse_cmd
(
const
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),
...
...
@@ -80,10 +89,10 @@ public:
private
:
static
const
char
*
_default_tunes
[
TONE_NUMBER_OF_TUNES
];
static
const
uint8_t
_note_tab
[];
bool
_repeat
;
// if true, tune restarts at end
bool
_repeat
;
//
/<
if true, tune restarts at end
const
char
*
_tune
=
nullptr
;
// current tune string
const
char
*
_next
=
nullptr
;
// next note in the string
const
char
*
_tune
=
nullptr
;
//
/<
current tune string
const
char
*
_next
=
nullptr
;
//
/<
next note in the string
unsigned
_tempo
;
unsigned
_note_length
;
...
...
@@ -92,7 +101,7 @@ private:
unsigned
_default_tempo
=
120
;
unsigned
_default_note_length
=
4
;
NoteMode
_default_mode
=
NoteMode
::
MODE_
NORMAL
;
NoteMode
_default_mode
=
NoteMode
::
NORMAL
;
unsigned
_default_octave
=
4
;
/**
...
...
@@ -133,12 +142,16 @@ private:
//
unsigned
next_number
();
// Consume dot characters from the string, returning the number consumed.
//
/**
* Consume dot characters from the string
*
* @return number of consumed dots
*/
unsigned
next_dots
();
/**
* set the tune parameters to default
*/
void
config_tone
();
};
}
/* output */
This diff is collapsed.
Click to expand it.
src/systemcmds/tune_control/tune_control.cpp
+
2
−
2
View file @
5214642b
...
...
@@ -68,7 +68,7 @@ usage()
"
\t
-t <defualt tunes>
\t
Play the default (1...15) (default=1)
\n
"
"
\t
-f <frequency>
\t\t
Frequency from 0-20kHz
\n
"
"
\t
-d <duration>
\t\t
Duration of the tone in us
\n
"
"
\t
-s <strength>
\t\t
Streng
h
t of the tone between 0-100
\n
"
"
\t
-s <strength>
\t\t
Strengt
h
of the tone between 0-100
\n
"
"
\t
-m <melody>
\t\t
Melody in a string form ex:
\"
MFT200e8a8a
\"\n
"
);
}
...
...
@@ -88,7 +88,7 @@ static void publish_tune_control(tune_control_s &tune_control)
int
tune_control_main
(
int
argc
,
char
*
argv
[])
{
output
::
Tunes
tunes
;
Tunes
tunes
;
bool
string_input
=
false
;
const
char
*
tune_string
=
NULL
;
int
myoptind
=
1
;
...
...
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