mirror of
https://github.com/eclipse/upm.git
synced 2025-07-01 09:21:12 +03:00
buzzer: added buzzer with example
Signed-off-by: Yevgeniy Kiveisha <yevgeniy.kiveisha@intel.com>
This commit is contained in:
@ -1,3 +1,4 @@
|
||||
add_subdirectory (hmc5883l)
|
||||
add_subdirectory (grove)
|
||||
add_subdirectory (lcm1602)
|
||||
add_subdirectory (buzzer)
|
||||
|
4
src/buzzer/CMakeLists.txt
Normal file
4
src/buzzer/CMakeLists.txt
Normal file
@ -0,0 +1,4 @@
|
||||
set (libname "buzzer")
|
||||
add_library (buzzer SHARED buzzer.cxx)
|
||||
include_directories (${MAA_INCLUDE_DIR})
|
||||
target_link_libraries (buzzer ${MAA_LIBRARIES})
|
51
src/buzzer/buzzer.cxx
Normal file
51
src/buzzer/buzzer.cxx
Normal file
@ -0,0 +1,51 @@
|
||||
/*
|
||||
* Author: Yevgeniy Kiveisha <yevgeniy.kiveisha@intel.com>
|
||||
* Copyright (c) 2014 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 <iostream>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "buzzer.h"
|
||||
|
||||
using namespace upm;
|
||||
|
||||
Buzzer::Buzzer (int pinNumber) {
|
||||
m_pwm_context = maa_pwm_init (pinNumber);
|
||||
m_name = "Buzzer";
|
||||
}
|
||||
|
||||
int Buzzer::playSound (int note) {
|
||||
maa_pwm_enable (m_pwm_context, 1);
|
||||
maa_pwm_period_us (m_pwm_context, note);
|
||||
maa_pwm_write (m_pwm_context, 50.0);
|
||||
usleep (10000);
|
||||
maa_pwm_enable (m_pwm_context, 0);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Buzzer::~Buzzer() {
|
||||
maa_pwm_close(m_pwm_context);
|
||||
std::cout << "executed maa_pwm_close" << std::endl;
|
||||
}
|
||||
|
53
src/buzzer/buzzer.h
Normal file
53
src/buzzer/buzzer.h
Normal file
@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Author: Yevgeniy Kiveisha <yevgeniy.kiveisha@intel.com>
|
||||
* Copyright (c) 2014 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.
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <maa/pwm.h>
|
||||
|
||||
#define DO 3830000 // 261 Hz
|
||||
#define RE 3400000 // 294 Hz
|
||||
#define MI 3038000 // 329 Hz
|
||||
#define FA 2864000 // 349 Hz
|
||||
#define SOL 2550000 // 392 Hz
|
||||
#define LA 2272000 // 440 Hz
|
||||
#define SI 2028000 // 493 Hz
|
||||
|
||||
namespace upm {
|
||||
|
||||
class Buzzer {
|
||||
public:
|
||||
Buzzer (int pinNumber);
|
||||
~Buzzer ();
|
||||
int playSound (int note);
|
||||
std::string name()
|
||||
{
|
||||
return m_name;
|
||||
}
|
||||
protected:
|
||||
std::string m_name;
|
||||
private:
|
||||
maa_pwm_context m_pwm_context;
|
||||
};
|
||||
}
|
7
src/buzzer/jsupm_buzzer.i
Normal file
7
src/buzzer/jsupm_buzzer.i
Normal file
@ -0,0 +1,7 @@
|
||||
%module jsupm_buzzer
|
||||
|
||||
%{
|
||||
#include "buzzer.h"
|
||||
%}
|
||||
|
||||
%include "buzzer.h"
|
8
src/buzzer/pyupm_buzzer.i
Normal file
8
src/buzzer/pyupm_buzzer.i
Normal file
@ -0,0 +1,8 @@
|
||||
%module pyupm_buzzer
|
||||
|
||||
%feature("autodoc", "3");
|
||||
|
||||
%include "buzzer.h"
|
||||
%{
|
||||
#include "buzzer.h"
|
||||
%}
|
Reference in New Issue
Block a user