mini2440之--pwm程序
来源:互联网 发布:云计算 虚拟化 编辑:程序博客网 时间:2024/05/22 07:40
如图所示,图中用到了:PixmapLabel,TextLabel,LCDNumber,GroupBox,PushButton组件
pwm.h
#ifndef MYHELLOFORM_H
#define MYHELLOFORM_H
#include "pwm_base.h"
#include <qpixmap.h>
class MyPwmForm : public PwmBaseForm
{
Q_OBJECT
public:
MyPwmForm( QWidget* parent = 0, const char* name = 0, WFlags fl = 0 );
virtual ~MyPwmForm();
//const QPixmap *eddy;
int freq;
//int fd;
private slots:
void buzzInc();
void buzzDec();
void buzzON();
void buzzOFF();
};
#endif // MYHELLOFORM_H
pwm.cpp
#include "pwm.h"
#include <qlabel.h>
#include <qlcdnumber.h>
#include <qpushbutton.h>
#include <qbutton.h>
#include <qtopia/qpeapplication.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#include <termios.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/ioctl.h>
static int fd;
#define PWM_IOCTL_SET_FREQ1
#define PWM_IOCTL_STOP2
MyPwmForm::MyPwmForm( QWidget* parent, const char* name, WFlags fl)
:PwmBaseForm(parent, name, fl)
{
fd = -1;
freq = 1000;
LCDNumber1->setDecMode();
LCDNumber1->display(freq);
PushButton1->setEnabled( 0 );
PushButton2->setEnabled( 0 );
//PushButton1->show();
//PushButton2->hide();
connect(PushButton1,SIGNAL(clicked()),this,SLOT(buzzInc()));
connect(PushButton2,SIGNAL(clicked()),this,SLOT(buzzDec()));
connect(PushButton3,SIGNAL(clicked()),this,SLOT(buzzON()));
connect(PushButton4,SIGNAL(clicked()),this,SLOT(buzzOFF()));
}
MyPwmForm::~MyPwmForm()
{
buzzOFF();
}
static void close_buzzer(void)
{
if (fd >= 0) {
::ioctl(fd, PWM_IOCTL_STOP);
::close(fd);
fd = -1;
}
}
static void set_buzzer_freq(int freq)
{
// this IOCTL command is the key to set frequency
int ret = ::ioctl(fd, PWM_IOCTL_SET_FREQ, freq);
if(ret < 0) {
::perror("set the frequency of the buzzer");
::exit(1);
}
}
void MyPwmForm::buzzON()
{
fd = ::open("/dev/pwm", 0);
if (fd < 0) {
::perror("open pwm_buzzer device");
::exit(1);
}
set_buzzer_freq(freq);
LCDNumber2->display(fd);
// any function exit call will stop the buzzer
::atexit(close_buzzer);
PushButton1->setEnabled( 1 );
PushButton2->setEnabled( 1 );
}
void MyPwmForm::buzzOFF()
{
int ret = ::ioctl(fd, PWM_IOCTL_STOP);//PWM_IOCTL_STOP= 2
//int ret = ::ioctl(fd, 2);
LCDNumber2->display(fd);
if(ret < 0) {
::perror("stop the buzzer");
::exit(1);
}
::close(fd);
PushButton1->setEnabled( 0 );
PushButton2->setEnabled( 0 );
//::exit(0);// exit the program directly
}
void MyPwmForm::buzzInc()
{
if( freq < 20000 )
freq += 10;
LCDNumber1->display(freq);
set_buzzer_freq(freq);
}
void MyPwmForm::buzzDec()
{
if( freq > 11 )
freq -= 10 ;
LCDNumber1->display(freq);
set_buzzer_freq(freq);
}
0 0
- mini2440之--pwm程序
- mini2440裸机之PWM
- mini2440裸机之PWM
- mini2440驱动分析之PWM
- mini2440驱动分析之PWM
- mini2440之PWM混杂驱动分析
- mini2440硬件篇之PWM定时器
- mini2440的pwm驱动程序和测试程序详解
- mini2440的pwm驱动程序和测试程序详解
- mini2440的pwm驱动程序和测试程序详解
- mini2440的pwm驱动程序和测试程序详解
- mini2440的pwm驱动程序和测试程序详解
- MINI2440开发板PWM驱动与测试程序简要分析
- mini2440的pwm驱动程序和测试程序详解
- mini2440的pwm驱动程序和测试程序详解
- mini2440之--hello程序
- mini2440之--leds程序
- mini2440之--button程序
- C风格字符串和C++标准库
- C++ enum
- csdn外链工具最新版本,QQ1922028080栽
- Windows Mobile系统PDA进行GPS导航的入门知识
- (六) 图算法
- mini2440之--pwm程序
- java 环境变量设置
- uva 10981 - String Morphing(记忆化+离散)
- 智能服务机器人底层移动平台嵌入式STC12C5A60S2与战舰开发板学习笔记
- csdn博客群发工具诚招代理,QQ1922028080藏
- 启动服务管理
- strok函数用法
- In App Purchases(IAP 应用程序內购买): 完全攻略
- 线程异常处理