upm  1.7.1
Sensor/Actuator repository for libmraa (v2.0.0)
buzzer.h
Go to the documentation of this file.
1 /*
2  * Author: Jon Trulson <jtrulson@ics.com>
3  * Copyright (c) 2016 Intel Corporation.
4  *
5  * based on original C++ driver by
6  * Author: Yevgeniy Kiveisha <yevgeniy.kiveisha@intel.com>
7  * Copyright (c) 2014 Intel Corporation.
8  *
9  * Permission is hereby granted, free of charge, to any person obtaining
10  * a copy of this software and associated documentation files (the
11  * "Software"), to deal in the Software without restriction, including
12  * without limitation the rights to use, copy, modify, merge, publish,
13  * distribute, sublicense, and/or sell copies of the Software, and to
14  * permit persons to whom the Software is furnished to do so, subject to
15  * the following conditions:
16  *
17  * The above copyright notice and this permission notice shall be
18  * included in all copies or substantial portions of the Software.
19  *
20  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27  */
28 #pragma once
29 
30 #include <stdlib.h>
31 #include <stdio.h>
32 #include <upm.h>
33 
34 #include <mraa/pwm.h>
35 #include "buzzer_tones.h"
36 
37 #ifdef __cplusplus
38 extern "C" {
39 #endif
40 
52  typedef struct _buzzer_context {
53  mraa_pwm_context pwm;
54 
55  float volume;
56  bool initialized;
57  } *buzzer_context;
58 
65  buzzer_context buzzer_init(int pin);
66 
72  void buzzer_close(buzzer_context dev);
73 
84  upm_result_t buzzer_play_sound(const buzzer_context dev, int note,
85  int delay);
86 
94  upm_result_t buzzer_stop_sound(const buzzer_context dev);
95 
103  void buzzer_set_volume(const buzzer_context dev, float vol);
104 
111  float buzzer_get_volume(const buzzer_context dev);
112 
113 #ifdef __cplusplus
114 }
115 #endif
upm_result_t buzzer_play_sound(const buzzer_context dev, int note, int delay)
Definition: buzzer.c:102
void buzzer_set_volume(const buzzer_context dev, float vol)
Definition: buzzer.c:88
float buzzer_get_volume(const buzzer_context dev)
Definition: buzzer.c:95
upm_result_t buzzer_stop_sound(const buzzer_context dev)
Definition: buzzer.c:126
Definition: buzzer.h:52
buzzer_context buzzer_init(int pin)
Definition: buzzer.c:34
void buzzer_close(buzzer_context dev)
Definition: buzzer.c:72
struct _buzzer_context * buzzer_context