原谅我,因为我知道这可能是一个非常简单的问题,但我需要另一双眼睛。我的GUI上有一个复选框,这个复选框的状态(开/关)将直接改变我的中断服务例程。这看起来超级简单,但我不能使用:
this->ui->checkBox_2->isChecked();作为一个验证器,由于“无效使用”这个“非成员函数”,我尝试将stateChanged(int ISR )的值保存到我的arg1可以调用的某个指针或变量中,但我想我遇到了作用域问题。欢迎提出任何建议!
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
connect(this->ui->pushButton_8,SIGNAL(clicked()),this,SLOT(on_pushButton_8_clicked()));
//connect(this->ui->checkBox_2,SIGNAL(clicked(bool)),this,SLOT(myInterruptRIGHT));
//connect(this->ui->checkBox_2,SIGNAL(clicked(bool)),this,SLOT(myInterruptLEFT));
// connect(on_checkBox_2_stateChanged(int arg1)(),SIGNAL(clicked(bool checked)),this,SLOT(myInterruptRIGHT));
ui->pushButton->setText("STOP");
ui->verticalSlider->setMinimum(6);
ui->verticalSlider->setMaximum(8);
}
void MainWindow::on_checkBox_2_stateChanged(int arg1)
{
QCheckBox *cb2 = new QCheckBox;
connect(cb2,SIGNAL(stateChanged(int)),this,SLOT(on_checkBox_2_stateChanged(int)));
int sensor = digitalRead(23);
//Does a bunch of stuff
}
void myInterruptRIGHT (void)
{
//if(this->ui->checkBox_2->isChecked())
if(ui->checkBox_2->isChecked())
{ //Does stuff
}
else
{ //more stuff
}
}
PI_THREAD(RightTop)
{
for(;;)
{
wiringPiISR(23,INT_EDGE_RISING,&myInterruptRIGHT);
}
}我为我草率的代码道歉,我已经测试了一堆不同的东西,但没有任何东西被证明是非常有效的。
发布于 2016-08-10 23:56:19
问题1:MainWindow::on_checkBox_2_stateChanged创建复选框并将自己连接到复选框信号的插槽?确保复选框在构造器中的某个地方创建,或者可能在代码的UI预先设计部分中创建。
问题2:PI_THREAD似乎不是Qt线程,无法使用插槽捕获其上的信号。你仍然可以为你的嵌入式应用程序做一些事情。
请注意,我当然不能测试解决方案,但我确实在实际应用程序中应用了类似的技术。您也可以考虑使用std::atomic<T>。
class MainWindow : public QMainWindow
{
public:
QAtomicInt& atomicChkBox2State() {return m_chkBox2StateAtomic;}
//// snip
private:
QAtomicInt m_chkBox2StateAtomic;
//// snip
};
void MainWindow::on_checkBox_2_stateChanged(int state)
{
m_chkBox2StateAtomic = state;
}
// where you create MainWindow you need to get that pointer somehow
static MainWindow* s_pMainWnd;
MainWindow* getMainWindow() {return s_pMainWnd;} // declare it in the .h file
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
s_pMainWnd = &w; // take an address
w.show();
return a.exec();
}
// and that ISR should read the atomic variable in case if does poll for check:
void myInterruptRIGHT (void)
{
// now poll the atomic variable reflecting the state of checkbox
if(getMainWindow()->atomicChkBox2State())
{ //Does stuff
}
else
{ //more stuff
}
}这适用于ISR,当系统中断向量调用时,ISR会不断地轮询原子变量。如果中断服务例程应该从复选框中获得自己终止信号,那么如果不更多地了解您的嵌入式平台“如何从‘端’而不是通过系统中断终止ISR”,我们就无法回答这个问题。
https://stackoverflow.com/questions/38873355
复制相似问题