upm  1.7.1
Sensor/Actuator repository for libmraa (v2.0.0)
speaker.h
Go to the documentation of this file.
1 /*
2  * Author: Jon Trulson <jtrulson@ics.com>
3  * Copyright (c) 2017 Intel Corporation.
4  *
5  * Based on original C++ driver by:
6  * Author: Zion Orent <sorent@ics.com>
7  * Copyright (c) 2014 Intel Corporation.
8  *
9  * The MIT License
10  *
11  * Permission is hereby granted, free of charge, to any person obtaining
12  * a copy of this software and associated documentation files (the
13  * "Software"), to deal in the Software without restriction, including
14  * without limitation the rights to use, copy, modify, merge, publish,
15  * distribute, sublicense, and/or sell copies of the Software, and to
16  * permit persons to whom the Software is furnished to do so, subject to
17  * the following conditions:
18  *
19  * The above copyright notice and this permission notice shall be
20  * included in all copies or substantial portions of the Software.
21  *
22  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29  */
30 #pragma once
31 
32 #include <unistd.h>
33 #include <mraa/gpio.h>
34 #include <mraa/pwm.h>
35 
36 #include <upm.h>
37 
38 #ifdef __cplusplus
39 extern "C" {
40 #endif
41 
53  typedef struct _speaker_context {
54  // gpio version
55  mraa_gpio_context gpio;
56 
57  // pwm version
58  mraa_pwm_context pwm;
59 
60  // are using the original GPIO mechanism or PWM?
61  bool is_pwm;
62  // default frequency, or last frequency specified
63  unsigned int default_freq;
64  } *speaker_context;
65 
75 
86 
93 
100  void speaker_play_all(const speaker_context dev);
101 
114  void speaker_play_sound(const speaker_context dev, char letter, bool sharp,
115  const char *vocal_weight);
116 
131  upm_result_t speaker_emit(const speaker_context dev, unsigned int freq,
132  unsigned int emit_ms);
133 
147  upm_result_t speaker_set_frequency(const speaker_context dev,
148  unsigned int freq);
149 
158  void speaker_on(const speaker_context dev);
159 
167  void speaker_off(const speaker_context dev);
168 
169 #ifdef __cplusplus
170 }
171 #endif
void speaker_close(speaker_context dev)
Definition: speaker.c:130
upm_result_t speaker_set_frequency(const speaker_context dev, unsigned int freq)
Definition: speaker.c:146
void speaker_play_all(const speaker_context dev)
Definition: speaker.c:237
upm_result_t speaker_emit(const speaker_context dev, unsigned int freq, unsigned int emit_ms)
Definition: speaker.c:193
void speaker_on(const speaker_context dev)
Definition: speaker.c:215
struct _speaker_context * speaker_context
Definition: speaker.h:53
void speaker_off(const speaker_context dev)
Definition: speaker.c:227
speaker_context speaker_init_pwm(int pin)
Definition: speaker.c:109
void speaker_play_sound(const speaker_context dev, char letter, bool sharp, const char *vocal_weight)
Definition: speaker.c:260
speaker_context speaker_init(int pin)
Definition: speaker.c:88