Firmware
Public Types | Public Member Functions | List of all members
Tunes Class Reference

Library for parsing tunes from melody-strings or dedicated tune messages. More...

#include <tunes.h>

Public Types

enum  NoteMode { NORMAL, LEGATO, STACCATO }
 

Public Member Functions

 Tunes (unsigned default_note_length=TUNE_DEFAULT_NOTE_LENGTH, NoteMode default_note_mode=NoteMode::NORMAL, unsigned default_octave=TUNE_DEFAULT_OCTAVE, unsigned default_tempo=TUNE_DEFAULT_TEMPO)
 Constructor with the default parameters set to: default_tempo: TUNE_DEFAULT_TEMPO default_octave: TUNE_DEFAULT_OCTAVE default_note_length: TUNE_DEFAULT_NOTE_LENGTH default_mode: NORMAL.
 
int set_control (const tune_control_s &tune_control)
 Set tune to be played using the message. More...
 
void set_string (const char *const string, uint8_t volume)
 Set tune to be played using a string. More...
 
int get_next_note (unsigned &frequency, unsigned &duration, unsigned &silence)
 Get next note in the current tune, which has been provided by either set_control or play_string. More...
 
int get_next_note (unsigned &frequency, unsigned &duration, unsigned &silence, uint8_t &volume)
 Get next note in the current tune, which has been provided by either set_control or play_string. More...
 
unsigned int get_default_tunes_size () const
 Get the number of default tunes. More...
 
unsigned int get_maximum_update_interval ()
 

Detailed Description

Library for parsing tunes from melody-strings or dedicated tune messages.

Needs to be instantiated as it keeps track of which tune is to be played next. Also handles repeated tunes.

Member Function Documentation

§ get_default_tunes_size()

unsigned int Tunes::get_default_tunes_size ( ) const
inline

Get the number of default tunes.

This is useful for when a tune is requested via its tune ID.

Returns
Number of default tunes accessible via tune ID

§ get_next_note() [1/2]

int Tunes::get_next_note ( unsigned &  frequency,
unsigned &  duration,
unsigned &  silence 
)

Get next note in the current tune, which has been provided by either set_control or play_string.

Parameters
frequencyreturn frequency value (Hz)
durationreturn duration of the tone (us)
silencereturn silence duration (us)
Returns
-1 for error, 0 for play one tone and 1 for continue a sequence

§ get_next_note() [2/2]

int Tunes::get_next_note ( unsigned &  frequency,
unsigned &  duration,
unsigned &  silence,
uint8_t &  volume 
)

Get next note in the current tune, which has been provided by either set_control or play_string.

Parameters
frequencyreturn frequency value (Hz)
durationreturn duration of the note (us)
silencereturn silence duration (us)
volumereturn the volume level of the note (between 0-100)
Returns
-1 for error, 0 for play one tone and 1 for continue a sequence

§ set_control()

int Tunes::set_control ( const tune_control_s &  tune_control)

Set tune to be played using the message.

If a tune is already being played the call to this function will be ignored, unless the override flag is set or the tune being already played is a repeated tune.

Parameters
tune_controlstruct containig the uORB message
Returns
return -EINVAL if the default tune does not exist.

§ set_string()

void Tunes::set_string ( const char *const  string,
uint8_t  volume 
)

Set tune to be played using a string.

Parses a tune string, formatted with the syntax of the Microsoft GWBasic/QBasic. Ownership of the string is NOT transferred. The string has to be kept in memory for the whole duration of the melody.

Parameters
stringtune input string

The documentation for this class was generated from the following files: