function arguments coming from two different places
-
Hi all,
I've a basic question.
I've got a functionrealtimeDataSlot
which takes 6 arguments from two different functions.First three values coming from
sensorEventHandler
Last three values are fromsensorFilteredEventHandler
The whole idea is draw real-time graph inside
realtimeDataSlot
using 6 values from two functions:void MainWindow::realtimeDataSlot(double axS, double ayS, double azS, double aV, double aH, double aP) { static QTime time(QTime::currentTime()); // calculate two new data points: double key = time.elapsed()/1000.0; // time elapsed since start of demo, in seconds static double lastPointKey = 0; if (key-lastPointKey > 0.02) // at most add point every 2 ms { // 0,1,2 values coming from sensorEventHandler and 3,4,5 coming from sensorFilteredEventHandler ui->customPlot->graph(0)->addData(key, axS); ui->customPlot->graph(1)->addData(key, ayS); ui->customPlot->graph(2)->addData(key, azS); ui->customPlot->graph(3)->addData(key, aV); ui->customPlot->graph(4)->addData(key, aH); ui->customPlot->graph(5)->addData(key, aP); lastPointKey = key; } // make key axis range scroll with the data (at a constant range size of 8): ui->customPlot->xAxis->setRange(key, 8, Qt::AlignRight); ui->customPlot->replot(); }
My question is how do I modify those two functions (
sensorEventHandler
andsensorFilteredEventHandler
) in order to correctly pass arguments torealtimeDataSlot
?PS:
I've given below the current implementation of
sensorEventHandler
andsensorFilteredEventHandler
. The implementation of those functions are slightly differentvoid MainWindow::sensorEventHandler(SENSOR_ACCEL_DATA_T *sample) { int16_t axS = sample->accel_xs; int16_t ayS = sample->accel_ys; int16_t azS = sample->accel_xs; // How to call `realtimeDataSlot` to pass above parameters as first three arguments } void MainWindow::sensorFilteredEventHandler(int16_t sensor_role, int16_t filter_output) { static int16_t filter_outputs[3] = {0,0,0}; filter_outputs[sensor_role] = filter_output; int16_t aV; int16_t aH; int16_t aP; if(sensor_role == 5 && startBtnStatus == true) { aV = (double)filter_outputs[0]; aH = (double)filter_outputs[1]; aP = (double)filter_outputs[2]; // How to call `realtimeDataSlot` to pass above parameters as last three arguments } }
-
Hi all,
I've a basic question.
I've got a functionrealtimeDataSlot
which takes 6 arguments from two different functions.First three values coming from
sensorEventHandler
Last three values are fromsensorFilteredEventHandler
The whole idea is draw real-time graph inside
realtimeDataSlot
using 6 values from two functions:void MainWindow::realtimeDataSlot(double axS, double ayS, double azS, double aV, double aH, double aP) { static QTime time(QTime::currentTime()); // calculate two new data points: double key = time.elapsed()/1000.0; // time elapsed since start of demo, in seconds static double lastPointKey = 0; if (key-lastPointKey > 0.02) // at most add point every 2 ms { // 0,1,2 values coming from sensorEventHandler and 3,4,5 coming from sensorFilteredEventHandler ui->customPlot->graph(0)->addData(key, axS); ui->customPlot->graph(1)->addData(key, ayS); ui->customPlot->graph(2)->addData(key, azS); ui->customPlot->graph(3)->addData(key, aV); ui->customPlot->graph(4)->addData(key, aH); ui->customPlot->graph(5)->addData(key, aP); lastPointKey = key; } // make key axis range scroll with the data (at a constant range size of 8): ui->customPlot->xAxis->setRange(key, 8, Qt::AlignRight); ui->customPlot->replot(); }
My question is how do I modify those two functions (
sensorEventHandler
andsensorFilteredEventHandler
) in order to correctly pass arguments torealtimeDataSlot
?PS:
I've given below the current implementation of
sensorEventHandler
andsensorFilteredEventHandler
. The implementation of those functions are slightly differentvoid MainWindow::sensorEventHandler(SENSOR_ACCEL_DATA_T *sample) { int16_t axS = sample->accel_xs; int16_t ayS = sample->accel_ys; int16_t azS = sample->accel_xs; // How to call `realtimeDataSlot` to pass above parameters as first three arguments } void MainWindow::sensorFilteredEventHandler(int16_t sensor_role, int16_t filter_output) { static int16_t filter_outputs[3] = {0,0,0}; filter_outputs[sensor_role] = filter_output; int16_t aV; int16_t aH; int16_t aP; if(sensor_role == 5 && startBtnStatus == true) { aV = (double)filter_outputs[0]; aH = (double)filter_outputs[1]; aP = (double)filter_outputs[2]; // How to call `realtimeDataSlot` to pass above parameters as last three arguments } }
@russjohn834 said in function arguments coming from two different places:
How to call
realtimeDataSlot
to pass above parameters as first three argumentsYou can store all 6 last parameters as class members and then pass old 3 together with the new 3
-
Hi all,
I've a basic question.
I've got a functionrealtimeDataSlot
which takes 6 arguments from two different functions.First three values coming from
sensorEventHandler
Last three values are fromsensorFilteredEventHandler
The whole idea is draw real-time graph inside
realtimeDataSlot
using 6 values from two functions:void MainWindow::realtimeDataSlot(double axS, double ayS, double azS, double aV, double aH, double aP) { static QTime time(QTime::currentTime()); // calculate two new data points: double key = time.elapsed()/1000.0; // time elapsed since start of demo, in seconds static double lastPointKey = 0; if (key-lastPointKey > 0.02) // at most add point every 2 ms { // 0,1,2 values coming from sensorEventHandler and 3,4,5 coming from sensorFilteredEventHandler ui->customPlot->graph(0)->addData(key, axS); ui->customPlot->graph(1)->addData(key, ayS); ui->customPlot->graph(2)->addData(key, azS); ui->customPlot->graph(3)->addData(key, aV); ui->customPlot->graph(4)->addData(key, aH); ui->customPlot->graph(5)->addData(key, aP); lastPointKey = key; } // make key axis range scroll with the data (at a constant range size of 8): ui->customPlot->xAxis->setRange(key, 8, Qt::AlignRight); ui->customPlot->replot(); }
My question is how do I modify those two functions (
sensorEventHandler
andsensorFilteredEventHandler
) in order to correctly pass arguments torealtimeDataSlot
?PS:
I've given below the current implementation of
sensorEventHandler
andsensorFilteredEventHandler
. The implementation of those functions are slightly differentvoid MainWindow::sensorEventHandler(SENSOR_ACCEL_DATA_T *sample) { int16_t axS = sample->accel_xs; int16_t ayS = sample->accel_ys; int16_t azS = sample->accel_xs; // How to call `realtimeDataSlot` to pass above parameters as first three arguments } void MainWindow::sensorFilteredEventHandler(int16_t sensor_role, int16_t filter_output) { static int16_t filter_outputs[3] = {0,0,0}; filter_outputs[sensor_role] = filter_output; int16_t aV; int16_t aH; int16_t aP; if(sensor_role == 5 && startBtnStatus == true) { aV = (double)filter_outputs[0]; aH = (double)filter_outputs[1]; aP = (double)filter_outputs[2]; // How to call `realtimeDataSlot` to pass above parameters as last three arguments } }
@russjohn834
I don't understand. You can't have a function which takes 6 arguments, and somehow call it from two other functions each providing 3 arguments "at the same time"! You have to re-architect, like gathering 3 of them first and then calling your 6-arg-func with those plus the new 3.... -
@russjohn834 said in function arguments coming from two different places:
How to call
realtimeDataSlot
to pass above parameters as first three argumentsYou can store all 6 last parameters as class members and then pass old 3 together with the new 3
Could you please show me an example?
-
Could you please show me an example?
@russjohn834 Come on this is simple stuff:
class MainWindow... private: double axS; double ayS; double azS; double aV; double aH; double aP ... void MainWindow::sensorEventHandler(SENSOR_ACCEL_DATA_T *sample) { axS = sample->accel_xs; ayS = sample->accel_ys; azS = sample->accel_xs; realtimeDataSlot(axS, ayS, azS, aV, aH, aP); }
-
Could you please show me an example?
I highly doubt this makes it any clearer but here ya go 🤓
enum UpdateState : unsigned char{ None = 0b00000000, Set1 = 0b00000001, Set2 = 0b00000010 }; struct CollectedData { int para1; int para2; int para3; bool para4; bool para5; QString para6; } m_collectData; int main(int argc, char *argv[]) { QApplication app(argc, argv); UpdateState state(None); auto checkUpdateAndEmit = [&state]()->void{ if(state & Set1 && state & Set2){ //emit myFunction(m_collectData.para1, m_collectData.para2, m_collectData.para3, m_collectData.para4, m_collectData.para5, m_collectData.para6); qDebug() << "Now Everything up to date" << m_collectData.para1 << m_collectData.para2 << m_collectData.para3 << m_collectData.para4 << m_collectData.para5 << m_collectData.para6; state = None; } }; QTimer signalFromSet1, signalFromSet2; QObject::connect(&signalFromSet1, &QTimer::timeout, [=,&state]()->void{ m_collectData.para1 = 1; m_collectData.para2 = 2; m_collectData.para3 = 3; state = static_cast<UpdateState>(state | UpdateState::Set1); checkUpdateAndEmit(); }); QObject::connect(&signalFromSet2, &QTimer::timeout, [=,&state]()->void{ m_collectData.para4 = true; m_collectData.para5 = false; m_collectData.para6 = QTime::currentTime().toString(); state = static_cast<UpdateState>(state | UpdateState::Set2); checkUpdateAndEmit(); }); signalFromSet1.start(50); signalFromSet2.start(2000); return app.exec(); }