Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. function arguments coming from two different places

function arguments coming from two different places

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 4 Posters 392 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    russjohn834
    wrote on 17 Jul 2020, 10:20 last edited by russjohn834
    #1

    Hi all,

    I've a basic question.
    I've got a function realtimeDataSlot which takes 6 arguments from two different functions.

    First three values coming from sensorEventHandler
    Last three values are from sensorFilteredEventHandler

    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 and sensorFilteredEventHandler) in order to correctly pass arguments to realtimeDataSlot?

    PS:

    I've given below the current implementation of sensorEventHandler and sensorFilteredEventHandler. The implementation of those functions are slightly different

    void 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 
           
            }
    }
    
    J J 2 Replies Last reply 17 Jul 2020, 10:45
    0
    • R russjohn834
      17 Jul 2020, 10:20

      Hi all,

      I've a basic question.
      I've got a function realtimeDataSlot which takes 6 arguments from two different functions.

      First three values coming from sensorEventHandler
      Last three values are from sensorFilteredEventHandler

      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 and sensorFilteredEventHandler) in order to correctly pass arguments to realtimeDataSlot?

      PS:

      I've given below the current implementation of sensorEventHandler and sensorFilteredEventHandler. The implementation of those functions are slightly different

      void 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 
             
              }
      }
      
      J Offline
      J Offline
      jsulm
      Lifetime Qt Champion
      wrote on 17 Jul 2020, 10:45 last edited by
      #2

      @russjohn834 said in function arguments coming from two different places:

      How to call realtimeDataSlot to pass above parameters as first three arguments

      You can store all 6 last parameters as class members and then pass old 3 together with the new 3

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      R 1 Reply Last reply 17 Jul 2020, 11:11
      5
      • R russjohn834
        17 Jul 2020, 10:20

        Hi all,

        I've a basic question.
        I've got a function realtimeDataSlot which takes 6 arguments from two different functions.

        First three values coming from sensorEventHandler
        Last three values are from sensorFilteredEventHandler

        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 and sensorFilteredEventHandler) in order to correctly pass arguments to realtimeDataSlot?

        PS:

        I've given below the current implementation of sensorEventHandler and sensorFilteredEventHandler. The implementation of those functions are slightly different

        void 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 
               
                }
        }
        
        J Offline
        J Offline
        JonB
        wrote on 17 Jul 2020, 10:46 last edited by JonB
        #3

        @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....

        1 Reply Last reply
        4
        • J jsulm
          17 Jul 2020, 10:45

          @russjohn834 said in function arguments coming from two different places:

          How to call realtimeDataSlot to pass above parameters as first three arguments

          You can store all 6 last parameters as class members and then pass old 3 together with the new 3

          R Offline
          R Offline
          russjohn834
          wrote on 17 Jul 2020, 11:11 last edited by
          #4

          @jsulm

          Could you please show me an example?

          J J 2 Replies Last reply 17 Jul 2020, 11:20
          0
          • R russjohn834
            17 Jul 2020, 11:11

            @jsulm

            Could you please show me an example?

            J Offline
            J Offline
            jsulm
            Lifetime Qt Champion
            wrote on 17 Jul 2020, 11:20 last edited by
            #5

            @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);
            }
            

            https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            2
            • R russjohn834
              17 Jul 2020, 11:11

              @jsulm

              Could you please show me an example?

              J Offline
              J Offline
              J.Hilk
              Moderators
              wrote on 17 Jul 2020, 11:54 last edited by J.Hilk
              #6

              @russjohn834

              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();
              }
              

              Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


              Q: What's that?
              A: It's blue light.
              Q: What does it do?
              A: It turns blue.

              1 Reply Last reply
              2
              • R Offline
                R Offline
                russjohn834
                wrote on 17 Jul 2020, 16:17 last edited by
                #7

                Thanks for your feedback @jsulm @JonB @J-Hilk

                1 Reply Last reply
                0

                6/7

                17 Jul 2020, 11:54

                • Login

                • Login or register to search.
                6 out of 7
                • First post
                  6/7
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved