mirror of
https://github.com/eclipse/upm.git
synced 2025-03-15 13:07:40 +03:00
buzzer: fix for PWM frequencies
Signed-off-by: Kiveisha Yevgeniy <yevgeniy.kiveisha@intel.com>
This commit is contained in:
parent
d00500ba12
commit
b1e548ae8a
@ -25,20 +25,8 @@
|
||||
#include <unistd.h>
|
||||
#include <iostream>
|
||||
#include <signal.h>
|
||||
|
||||
#include "buzzer.h"
|
||||
|
||||
int running = 0;
|
||||
|
||||
void
|
||||
sig_handler(int signo)
|
||||
{
|
||||
printf("got signal\n");
|
||||
if (signo == SIGINT) {
|
||||
printf("exiting application\n");
|
||||
running = 1;
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char **argv) {
|
||||
@ -51,13 +39,10 @@ main(int argc, char **argv) {
|
||||
std::cout << sound->name() << std::endl;
|
||||
// play sound (DO, RE, ME, etc...)
|
||||
|
||||
signal(SIGINT, sig_handler);
|
||||
|
||||
while (!running) {
|
||||
for (int chord_ind = 0; chord_ind < 9; chord_ind++) {
|
||||
std::cout << sound->playSound(chord[chord_ind]) << std::endl;
|
||||
usleep(1000);
|
||||
}
|
||||
for (int chord_ind = 0; chord_ind < 7; chord_ind++) {
|
||||
// play one second for each chord
|
||||
std::cout << sound->playSound(chord[chord_ind], 1000000) << std::endl;
|
||||
usleep(100000);
|
||||
}
|
||||
//! [Interesting]
|
||||
|
||||
|
@ -34,14 +34,14 @@ Buzzer::Buzzer (int pinNumber) {
|
||||
m_name = "Buzzer";
|
||||
}
|
||||
|
||||
int Buzzer::playSound (int note) {
|
||||
int Buzzer::playSound (int note, int delay) {
|
||||
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_pulsewidth_us (m_pwm_context, note / 2);
|
||||
usleep (delay);
|
||||
maa_pwm_enable (m_pwm_context, 0);
|
||||
|
||||
return 0;
|
||||
return note;
|
||||
}
|
||||
|
||||
Buzzer::~Buzzer() {
|
||||
|
@ -26,13 +26,13 @@
|
||||
#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
|
||||
#define DO 3300 // 261 Hz 3830
|
||||
#define RE 2930 // 294 Hz
|
||||
#define MI 2600 // 329 Hz
|
||||
#define FA 2460 // 349 Hz
|
||||
#define SOL 2190 // 392 Hz
|
||||
#define LA 1960 // 440 Hz
|
||||
#define SI 1750 // 493 Hz
|
||||
|
||||
namespace upm {
|
||||
|
||||
@ -41,7 +41,7 @@ namespace upm {
|
||||
*
|
||||
* This file defines the Buzzer C++ interface for libbuzzer
|
||||
*
|
||||
* @snippet es08a.cxx Interesting
|
||||
* @snippet buzzer-sound.cxx Interesting
|
||||
*
|
||||
*/
|
||||
class Buzzer {
|
||||
@ -62,8 +62,9 @@ class Buzzer {
|
||||
* Play chords.
|
||||
*
|
||||
* @param note chords (DO, RE, ME, etc...)
|
||||
* @param delay time in microsec for playing the sound
|
||||
*/
|
||||
int playSound (int note);
|
||||
int playSound (int note, int delay);
|
||||
|
||||
/**
|
||||
* Return name of the component
|
||||
|
Loading…
x
Reference in New Issue
Block a user