所使用的开发板:友善之臂tiny6140
widget.h
#ifndef WIDGET_H
#define WIDGET_H
#include #include namespace Ui {
class Widget;
}
class TMainForm : public QWidget
{
Q_OBJECT
public:
TMainForm(QWidget * parent = 0, const char * name = 0, Qt::WFlags f = 0);
virtual ~TMainForm() {}
protected:
void timerEvent (QTimerEvent *);
private:
QLCDNumber* m_label;
Ui::Widget *ui;
};
#endif // WIDGET_Hwidget.cpp
#include "widget.h"
#include "ui_widget.h"#include #include #include #include #include #include #include #include #include #include TMainForm::TMainForm(QWidget *parent, const char *name, Qt::WFlags f)
{
//setCaption( "ADC-Testing" );
m_label = new QLCDNumber(this);
m_label->setGeometry(10,10, 100, 50);
m_label->setSegmentStyle(QLCDNumber::Flat);
startTimer(500);
}void TMainForm::timerEvent ( QTimerEvent * )
{
int fd = ::open("/dev/adc", 0);
if (fd < 0)
{
return;
}
char buffer[30] = "";
int len = ::read(fd, buffer,
sizeof buffer -1);
if(len > 0)
{
buffer[len] =' ';
int value=-1
sscanf(buffer,"%d",&value);
m_label->display(value);
}
::close(fd);}main.cpp
#include#include "widget.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
TMainForm w;
w.show();
return a.exec();
}亲测可用,如有疑惑,可留言。