基于Qt4.7的ADC测试程序

2019-07-12 23:24发布

所使用的开发板:友善之臂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_H widget.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] ='