buzzer: C implementation; C++ wraps C
Signed-off-by: Jon Trulson <jtrulson@ics.com>
This commit is contained in:
@@ -1,4 +1,8 @@
|
||||
/*
|
||||
* Author: Jon Trulson <jtrulson@ics.com>
|
||||
* Copyright (c) 2016 Intel Corporation.
|
||||
*
|
||||
* based on original C++ driver by
|
||||
* Author: Yevgeniy Kiveisha <yevgeniy.kiveisha@intel.com>
|
||||
* Copyright (c) 2014 Intel Corporation.
|
||||
*
|
||||
@@ -24,69 +28,62 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <mraa/pwm.h>
|
||||
|
||||
#define DO 3800 // 262 Hz - C4
|
||||
#define RE 3400 // 294 Hz - D
|
||||
#define MI 3000 // 330 Hz - E
|
||||
#define FA 2900 // 349 Hz - F
|
||||
#define SOL 2550 // 392 Hz - G
|
||||
#define LA 2270 // 440 Hz - A
|
||||
#define SI 2000 // 494 Hz - B
|
||||
#include <buzzer.h>
|
||||
|
||||
namespace upm {
|
||||
|
||||
/**
|
||||
* @brief Buzzer library
|
||||
* @defgroup buzzer libupm-buzzer
|
||||
* @ingroup seeed pwm sound gsk
|
||||
*/
|
||||
/**
|
||||
* @brief Buzzer library
|
||||
* @defgroup buzzer libupm-buzzer
|
||||
* @ingroup seeed pwm sound gsk
|
||||
*/
|
||||
|
||||
/**
|
||||
* @library buzzer
|
||||
* @sensor buzzer
|
||||
* @comname Grove Buzzer
|
||||
* @type sound
|
||||
* @man seeed
|
||||
* @con pwm
|
||||
* @kit gsk
|
||||
*
|
||||
* @brief API for the Buzzer component
|
||||
*
|
||||
* This module defines the Buzzer interface for libbuzzer.
|
||||
* This sensor can make different tones when connected to
|
||||
* a pin capable of analog pulse-width modulation. It emits
|
||||
* sound using a piezoelectric material that vibrates at different
|
||||
* frequencies based on the input voltage.
|
||||
*
|
||||
* @image html buzzer.jpg
|
||||
* @snippet buzzer-sound.cxx Interesting
|
||||
*/
|
||||
class Buzzer {
|
||||
/**
|
||||
* @library buzzer
|
||||
* @sensor buzzer
|
||||
* @comname Grove Buzzer
|
||||
* @type sound
|
||||
* @man seeed
|
||||
* @con pwm
|
||||
* @kit gsk
|
||||
*
|
||||
* @brief API for the Buzzer component
|
||||
*
|
||||
* This module defines the Buzzer interface for libbuzzer.
|
||||
* This sensor can make different tones when connected to
|
||||
* a pin capable of analog pulse-width modulation. It emits
|
||||
* sound using a piezoelectric material that vibrates at different
|
||||
* frequencies based on the input voltage.
|
||||
*
|
||||
* @image html buzzer.jpg
|
||||
* @snippet buzzer-sound.cxx Interesting
|
||||
*/
|
||||
|
||||
class Buzzer {
|
||||
public:
|
||||
/**
|
||||
* Instantiates a Buzzer object.
|
||||
*
|
||||
* @param pinNumber Buzzer pin number
|
||||
*/
|
||||
Buzzer (int pinNumber);
|
||||
Buzzer(int pinNumber);
|
||||
|
||||
/**
|
||||
* Buzzer object destructor.
|
||||
*/
|
||||
~Buzzer ();
|
||||
~Buzzer();
|
||||
|
||||
/**
|
||||
* Plays a tone for a certain amount of time or indefinitely. When delay
|
||||
* is not used, the sound can be stopped by calling stopSound().
|
||||
*
|
||||
* @param note Note to play (DO, RE, MI, etc.) or frequency
|
||||
* @param delay Time in microseconds for which to play the sound; if the value is
|
||||
* 0, the sound is played indefinitely
|
||||
* @param delay Time in microseconds for which to play the
|
||||
* sound; if the value is 0, the sound is played indefinitely
|
||||
*
|
||||
* @return Note played
|
||||
*/
|
||||
int playSound (int note, int delay);
|
||||
int playSound(int note, int delay);
|
||||
|
||||
/**
|
||||
* Stops the sound currently playing. Should be called when playSound()
|
||||
@@ -120,8 +117,6 @@ class Buzzer {
|
||||
}
|
||||
protected:
|
||||
std::string m_name;
|
||||
private:
|
||||
mraa_pwm_context m_pwm_context;
|
||||
float m_volume;
|
||||
};
|
||||
buzzer_context m_buzzer;
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user