upm  1.7.1
Sensor/Actuator repository for libmraa (v2.0.0)
Data Structures | Functions | Typedefs
Include dependency graph for speaker.h:

API Description

/*
* Author: Jon Trulson <jtrulson@ics.com>
* Copyright (c) 2017 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <unistd.h>
#include <stdio.h>
#include "speaker.h"
int main ()
{
// Instantiate a Speaker on digital pin D2
if (!speaker)
{
printf("speaker_init() failed\n");
return 1;
}
// Play all 7 of the lowest notes
speaker_play_all(speaker);
// Play a medium C-sharp
speaker_play_sound(speaker, 'c', true, "med");
printf("Exiting\n");
speaker_close(speaker);
return 0;
}

Go to the source code of this file.

Data Structures

struct  _speaker_context
 

Functions

speaker_context speaker_init (int pin)
 
speaker_context speaker_init_pwm (int pin)
 
void speaker_close (speaker_context dev)
 
void speaker_play_all (const speaker_context dev)
 
void speaker_play_sound (const speaker_context dev, char letter, bool sharp, const char *vocal_weight)
 
upm_result_t speaker_emit (const speaker_context dev, unsigned int freq, unsigned int emit_ms)
 
upm_result_t speaker_set_frequency (const speaker_context dev, unsigned int freq)
 
void speaker_on (const speaker_context dev)
 
void speaker_off (const speaker_context dev)
 

Typedefs

typedef struct _speaker_contextspeaker_context
 

Function Documentation

speaker_context speaker_init ( int  pin)

Speaker GPIO init. In this mode, only the speaker_play_all() and speaker_play_sound() function will work. The other functions only support PWM mode (see speaker_init_pwm()).

Parameters
pinDigital pin to use
Returns
Device context

Here is the call graph for this function:

Here is the caller graph for this function:

speaker_context speaker_init_pwm ( int  pin)

Speaker PWM init. In this mode a PWM pin is used to emit tones (within the capabilities of your PWM hardware). speaker_play_all() and speaker_play_sound() will not operate in this mode. The default frequency is set to 1KHz.

Parameters
pinDigital PWM capable pin to use
Returns
Device context

Here is the call graph for this function:

Here is the caller graph for this function:

void speaker_close ( speaker_context  dev)

Speaker close function

Parameters
devDevice context

Here is the call graph for this function:

Here is the caller graph for this function:

void speaker_play_all ( const speaker_context  dev)

Plays all alto notes (lowest notes). This function only operates in GPIO mode.

Parameters
devDevice context

Here is the call graph for this function:

Here is the caller graph for this function:

void speaker_play_sound ( const speaker_context  dev,
char  letter,
bool  sharp,
const char *  vocal_weight 
)

Plays a sound and a note whether it's sharp or not. This function only operates in GPIO mode.

Parameters
devDevice context
letterCharacter name of the note ('a', 'b', 'c', 'd', 'e', 'f', or 'g')
sharpIf true, plays a sharp version of the note; otherwise, does not play the note
vocalWeightString to determine whether to play a low ("low"), a medium ("med"), or a high ("high") note

Here is the caller graph for this function:

upm_result_t speaker_emit ( const speaker_context  dev,
unsigned int  freq,
unsigned int  emit_ms 
)

Emit a specific frequency for a given period of time and return. This function only operates when in PWM mode (ie: the speaker context was initialized with speaker_init_pwm()). The frequency is limited to between 50-32000Hz. In addition, the allowable frequencies may be restricted further by the capabilities of your PWM hardware.

Parameters
devDevice context
freqThe frequency to emit. Must be between 50 and 32000Hz inclusive.
emit_msThe number of milliseconds to emit the frequency.
Returns
UPM result

Here is the call graph for this function:

Here is the caller graph for this function:

upm_result_t speaker_set_frequency ( const speaker_context  dev,
unsigned int  freq 
)

Set a default frequency to be used with speaker_on() and speaker_off(). This function only operates when in PWM mode (ie: the speaker context was initialized with speaker_init_pwm()). The frequency is limited to between 50-32000Hz. In addition, the allowable frequencies may be restricted further by the capabilities of your PWM hardware.

Parameters
devDevice context
freqThe frequency to emit. Must be between 50 and 32000Hz inclusive.
Returns
UPM result

Here is the caller graph for this function:

void speaker_on ( const speaker_context  dev)

Turn the speaker on, and emit the frequency last specified with speaker_set_frequency() or speaker_emit(). This function only operates when in PWM mode (ie: the speaker context was initialized with speaker_init_pwm()).

Parameters
devDevice context

Here is the call graph for this function:

Here is the caller graph for this function:

void speaker_off ( const speaker_context  dev)

Turn the speaker off. This function only operates when in PWM mode (ie: the speaker context was initialized with speaker_init_pwm()).

Parameters
devDevice context

Here is the caller graph for this function:

Typedef Documentation

Device context