1

我将 RaspberryPi 和 Qt 用于我读过的嵌入式项目的 Qt QThread。我测试过QThread,它工作得很好。我想在我的线程中控制一些 GPIO 引脚,但这不起作用我的 GPIO 引脚正在工作,我已经测试过了。

这是我的代码:

class referenz_thread:public QThread
{
    Q_OBJECT
    public:
        bool x_isRef;
        bool y_isRef;
        void run()
        {
            x_isRef = false;
            y_isRef = false;

            digitalWrite(x_treiber,1);
            digitalWrite(y_treiber,1);
            digitalWrite(x_richtung,0);
            digitalWrite(y_richtung,1);

            while(1)
            {                
                if(digitalRead(x_end) == 0)
                {
                    digitalWrite(x_treiber,0);
                    x_isRef = true;                    

                }
                if(digitalRead(y_end) == 0)
                {
                    digitalWrite(y_treiber,0);
                    y_isRef = true;                    

                }
                if((x_isRef == true) && (y_isRef == true))
                {                    
                    break;
                }
                digitalWrite(x_v,1);
                digitalWrite(y_v,1);
                delay(1);
                digitalWrite(x_v,0);
                delay(1);
                digitalWrite(x_v,1);
                delay(1);
                digitalWrite(x_v,0);
                digitalWrite(y_v,0);
                delay(1);
            }
         }
    public slots:
};

这是在 MainWindow.cpp

referenz_thread *ref_thread = new referenz_thread();
connect(ui->btn_ref,SIGNAL(clicked()),ref_thread,SLOT(start()));

wiringPiSetup已经在我的 MainThread 中执行了。

4

0 回答 0