I’m trying to enhance the Pixymon Program a bit to fit my needs. Now i want to get some data off pixy using the m_interpreter. I have no problem executing something (to change the brightness), but i have no idea how to get the result of a m_interpreter->execute call. Is there a documentation regarding pixymon or can any of the devs help me getting a result
Hello Paul,
There are two threads in PixyMon, one for the gui and one for Pixy communications. Making a call into the interpreter is usually done by the gui thread, so it can’t block to wait for a result. Getting the result from the gui thread has to be asynchronous and can be challenging/confusing. Most calls to Pixy are handled within the Pixy thread, from within the Interpreter class, where you can wait for a result without causing the application to hang.
Hope this helps!
Edward
I wrote a little workaround, i just execute the command, wait some time and then get the result of the plainTextEdit. If anyone is interestes here is my code:
In console.cpp (you need to add those functions to console.h as well)
QString ConsoleWidget::getLastLine(){ QString plainTextEditContents = toPlainText(); QStringList lines = plainTextEditContents.split("\n"); return lines[lines.length()-2]; //-2 because the last line is empty } int ConsoleWidget::getLastResult(){ QString lastLine = this->getLastLine(); lastLine = lastLine.remove("response: ", Qt::CaseSensitive); int pos = lastLine.indexOf("(",0,Qt::CaseInsensitive); lastLine = lastLine.remove(pos, lastLine.length()-pos); return lastLine.toInt(); }
and in the mainwindow.cpp:
void MainWindow::writeResult(){ m_ui->label->setText("Voltage: "+QString::number(m_console->getLastResult())+"mV"); if (m_interpreter){ m_interpreter->execute("run()"); } } void MainWindow::on_tabWidget_currentChanged(int index){ if (m_interpreter){ m_interpreter->execute("pwr_getVin()"); QTimer::singleShot(100,this,SLOT(writeResult())); } }