MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    init_time=0;
    data = -1;
    count_graph =0;
    dbaddr = "/home/uday/qtProjects/finaltrialqtplotting/sensorDatabase.db";
    ui->customPlot->xAxis->setTickLabelType(QCPAxis::ltDateTime);
    ui->customPlot->xAxis->setDateTimeFormat("hh:mm:ss");
    ui->customPlot->xAxis->setAutoTickStep(false);
    ui->customPlot->xAxis->setTickStep(3);
    ui->customPlot->axisRect()->setupFullAxesBox();


    ui->customPlot->xAxis->setLabel("Time(s)");
    ui->customPlot->yAxis->setLabel("Temperature");
    ui->customPlot->yAxis->setRange(0, 400);

    // make left and bottom axes transfer their ranges to right and top axes:
    connect(ui->customPlot->xAxis, SIGNAL(rangeChanged(QCPRange)), ui->customPlot->xAxis2, SLOT(setRange(QCPRange)));
    connect(ui->customPlot->yAxis, SIGNAL(rangeChanged(QCPRange)), ui->customPlot->yAxis2, SLOT(setRange(QCPRange)));

    // setup a timer that repeatedly calls MainWindow::realtimeDataSlot:
    connect(&dataTimer, SIGNAL(timeout()), this, SLOT(realtimeDataSlot()));
    dataTimer.start(500); // Interval 0 means to refresh as fast as possible

}
void rpm1gauge::setupRealtimeDataDemo(QCustomPlot *customPlot)
{
  customPlot->addGraph();                                               //line graph
  customPlot->graph(0)->setPen(QPen(mColor));
  customPlot->addGraph();                                               //dot for new data
  customPlot->graph(1)->setPen(QPen(mColor));
  customPlot->graph(1)->setLineStyle(QCPGraph::lsNone);
  customPlot->graph(1)->setScatterStyle(QCPScatterStyle::ssStar);


  customPlot->xAxis->setTickLabelType(QCPAxis::ltDateTime);             //time on x-axis

  customPlot->xAxis->setDateTimeFormat("hh:mm:ss");
  customPlot->xAxis->setAutoTickStep(false);
  customPlot->xAxis->setTickStep(30);                                   //30 second interval ticks
  customPlot->axisRect()->setupFullAxesBox();

  connect(customPlot->xAxis, SIGNAL(rangeChanged(QCPRange)), customPlot->xAxis2, SLOT(setRange(QCPRange)));
  connect(customPlot->yAxis, SIGNAL(rangeChanged(QCPRange)), customPlot->yAxis2, SLOT(setRange(QCPRange)));


  connect(&dataTimer, SIGNAL(timeout()), this, SLOT(realtimeDataSlot()));           //runs rtds function every 300 ms

  dataTimer.start(1000);
}
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    // start tcp socket
    QThread* thread = new QThread;// writetodatabase *database;
    database = new writetodatabase();


    database->moveToThread(thread);
    connect(thread, SIGNAL(started()),  database, SLOT(startDb()));
    connect(database, SIGNAL(finished()), thread, SLOT(quit()));
    connect(database, SIGNAL(finished()), database, SLOT(deleteLater()));
    connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater()));
    connect(this,SIGNAL(sendSetPoint(const QString)),database, SLOT(sendSetPoint(const QString)));

    thread->start();

     connect(ui->sendht, SIGNAL(clicked()), this, SLOT(sliderValue()));

         // setgraphs( ui->qtplot,"Time","Flowrate",14);
          setgraphs( ui->qtplot_2,"Time","Voltage(PWM)",100);
          setgraphs( ui->qtplot_3,"Time","IR Reading",400);

       // setup a timer that repeatedly calls MainWindow::realtimeDataSlot:
        connect(&dataTimer, SIGNAL(timeout()), this, SLOT(realtimeDataSlot()));
          dataTimer.start(500);
}
Example #4
0
void Form::setupRealtimeDataDemo(QCustomPlot *customPlot)
{
#if QT_VERSION < QT_VERSION_CHECK(4, 7, 0)
  QMessageBox::critical(this, "", "You're using Qt < 4.7, the realtime data demo needs functions that are available with Qt 4.7 to work properly");
#endif
  demoName = "Real Time Data Demo";

  customPlot->addGraph(); // blue line
  customPlot->graph(0)->setPen(QPen(Qt::blue));
  customPlot->graph(0)->setBrush(QBrush(QColor(96, 227, 69)));
  customPlot->graph(0)->setAntialiasedFill(true);

  customPlot->addGraph(); // red line
  customPlot->graph(1)->setPen(QPen(Qt::red));
  customPlot->graph(0)->setChannelFillGraph(customPlot->graph(1));

  customPlot->addGraph(); // blue dot
  customPlot->graph(2)->setPen(QPen(Qt::blue));
  customPlot->graph(2)->setLineStyle(QCPGraph::lsNone);
  customPlot->graph(2)->setScatterStyle(QCPScatterStyle::ssDisc);

  customPlot->addGraph(); // red dot
  customPlot->graph(3)->setPen(QPen(Qt::red));
  customPlot->graph(3)->setLineStyle(QCPGraph::lsNone);
  customPlot->graph(3)->setScatterStyle(QCPScatterStyle::ssDisc);

  customPlot->xAxis->setTickLabelType(QCPAxis::ltDateTime);
  customPlot->xAxis->setDateTimeFormat("hh:mm:ss");
  customPlot->xAxis->setAutoTickStep(false);
  customPlot->xAxis->setTickStep(2);
  customPlot->axisRect()->setupFullAxesBox();

  QLinearGradient plotGradient;
  plotGradient.setStart(0, 0);
  plotGradient.setFinalStop(0, 300);
  plotGradient.setColorAt(0, QColor(80, 8, 80));
  plotGradient.setColorAt(1, QColor(0, 0, 0));
  customPlot->setBackground(plotGradient);

  QLinearGradient axisRectGradient;
  axisRectGradient.setStart(0, 0);
  axisRectGradient.setFinalStop(0, 350);
  axisRectGradient.setColorAt(0, QColor(80, 80, 80));
  axisRectGradient.setColorAt(1, QColor(30, 100, 0));
  customPlot->axisRect()->setBackground(axisRectGradient);

  //QPoint pt1(10, 20);

  // setup a timer that repeatedly calls MainWindow::realtimeDataSlot:
 connect(&dataTimer, SIGNAL(timeout()), this, SLOT(realtimeDataSlot()));
  dataTimer.start(1); // Interval 0 means to refresh as fast as possible
}
void MainWindow::easyplot()
{

        ui->customPlot->addGraph(); // blue line
        ui->customPlot->graph(0)->setPen(QPen(Qt::blue));
        ui->customPlot->graph(0)->setAntialiasedFill(false);

        ui->customPlot->addGraph(); // blue dot
        ui->customPlot->graph(1)->setPen(QPen(Qt::blue));
        ui->customPlot->graph(1)->setLineStyle(QCPGraph::lsNone);
        ui->customPlot->graph(1)->setScatterStyle(QCPScatterStyle::ssDisc);

        ui->customPlot->addGraph(); // blue line
        ui->customPlot->graph(2)->setPen(QPen(Qt::red));
        ui->customPlot->graph(2)->setAntialiasedFill(false);

        ui->customPlot->addGraph(); // blue dot
        ui->customPlot->graph(3)->setPen(QPen(Qt::red));
        ui->customPlot->graph(3)->setLineStyle(QCPGraph::lsNone);
        ui->customPlot->graph(3)->setScatterStyle(QCPScatterStyle::ssDisc);

        ui->customPlot->addGraph(); // green line
        ui->customPlot->graph(4)->setPen(QPen(Qt::green));
        ui->customPlot->graph(4)->setAntialiasedFill(false);

        ui->customPlot->addGraph(); // green dot
        ui->customPlot->graph(5)->setPen(QPen(Qt::green));
        ui->customPlot->graph(5)->setLineStyle(QCPGraph::lsNone);
        ui->customPlot->graph(5)->setScatterStyle(QCPScatterStyle::ssDisc);


    ui->customPlot->xAxis->setTickLabelType(QCPAxis::ltDateTime);
    ui->customPlot->xAxis->setDateTimeFormat("hh:mm:ss");
    ui->customPlot->xAxis->setAutoTickStep(false);
    ui->customPlot->xAxis->setTickStep(2);
    ui->customPlot->axisRect()->setupFullAxesBox();


    ui->customPlot->yAxis->setRange(0, 1000);

    // make left and bottom axes transfer their ranges to right and top axes:
//    connect(ui->customPlot->xAxis, SIGNAL(rangeChanged(QCPRange)), ui->customPlot->xAxis2, SLOT(setRange(QCPRange)));
//    connect(ui->customPlot->yAxis, SIGNAL(rangeChanged(QCPRange)), ui->customPlot->yAxis2, SLOT(setRange(QCPRange)));

    // setup a timer that repeatedly calls MainWindow::realtimeDataSlot:
    connect(&dataTimer, SIGNAL(timeout()), this, SLOT(realtimeDataSlot()));
    dataTimer.start(0); // Interval 0 means to refresh as fast as possible

}
void MainWindow::setupRealtimeDataDemo(QCustomPlot *customPlot)
{
#if QT_VERSION < QT_VERSION_CHECK(4, 7, 0)
  QMessageBox::critical(this, "", "You're using Qt < 4.7, the realtime data demo needs functions that are available with Qt 4.7 to work properly");
#endif
  demoName = "Real Time";
    server.show();
  // include this section to fully disable antialiasing for higher performance:
  /*
  customPlot->setNotAntialiasedElements(QCP::aeAll);
  QFont font;
  font.setStyleStrategy(QFont::NoAntialias);
  customPlot->xAxis->setTickLabelFont(font);
  customPlot->yAxis->setTickLabelFont(font);
  customPlot->legend->setFont(font);
  */
  customPlot->addGraph(); // blue line
  customPlot->graph(0)->setPen(QPen(Qt::blue));
  customPlot->graph(0)->setBrush(QBrush(QColor(240, 255, 200)));
  customPlot->graph(0)->setAntialiasedFill(false);
  customPlot->addGraph(); // red line
  customPlot->graph(1)->setPen(QPen(Qt::red));
  customPlot->graph(0)->setChannelFillGraph(customPlot->graph(1));

  customPlot->addGraph(); // blue dot
  customPlot->graph(2)->setPen(QPen(Qt::blue));
  customPlot->graph(2)->setLineStyle(QCPGraph::lsNone);
  customPlot->graph(2)->setScatterStyle(QCPScatterStyle::ssDisc);
  customPlot->addGraph(); // red dot
  customPlot->graph(3)->setPen(QPen(Qt::red));
  customPlot->graph(3)->setLineStyle(QCPGraph::lsNone);
  customPlot->graph(3)->setScatterStyle(QCPScatterStyle::ssDisc);

  customPlot->xAxis->setTickLabelType(QCPAxis::ltDateTime);
  customPlot->xAxis->setDateTimeFormat("hh:mm:ss");
  customPlot->xAxis->setAutoTickStep(false);
  customPlot->xAxis->setTickStep(2);
  customPlot->axisRect()->setupFullAxesBox();

  // make left and bottom axes transfer their ranges to right and top axes:
  connect(customPlot->xAxis, SIGNAL(rangeChanged(QCPRange)), customPlot->xAxis2, SLOT(setRange(QCPRange)));
  connect(customPlot->yAxis, SIGNAL(rangeChanged(QCPRange)), customPlot->yAxis2, SLOT(setRange(QCPRange)));

  // setup a timer that repeatedly calls MainWindow::realtimeDataSlot:
  connect(&dataTimer, SIGNAL(timeout()), this, SLOT(realtimeDataSlot()));
  dataTimer.start(0); // Interval 0 means to refresh as fast as possible
}
void MainWindow::setupRealtimeData(QCustomPlot *customPlot)
{
#if QT_VERSION < QT_VERSION_CHECK(4, 7, 0)
  QMessageBox::critical(this, "", "You're using Qt < 4.7, the realtime data demo needs functions that are available with Qt 4.7 to work properly");
#endif

  customPlot->addGraph(); // blue line
  customPlot->graph(0)->setPen(QPen(Qt::blue));
  customPlot->graph(0)->setBrush(QBrush(QColor(240, 255, 200)));
  customPlot->graph(0)->setAntialiasedFill(false);
  customPlot->graph(0)->setName("valor analogico");
  customPlot->addGraph(); // red line
  customPlot->graph(1)->setPen(QPen(Qt::red));
  customPlot->graph(0)->setChannelFillGraph(customPlot->graph(1));
  customPlot->graph(1)->setName("Valor digital");


  //customPlot->yAxis->setRangeUpper(100); // con esta linea seteo la escala 0-100 en el eje y
  customPlot->xAxis->setTickLabelType(QCPAxis::ltDateTime);
  customPlot->xAxis->setDateTimeFormat("hh:mm:ss");
  customPlot->xAxis->setAutoTickStep(false);
  customPlot->xAxis->setTickStep(2);
  customPlot->axisRect()->setupFullAxesBox();

  // setup legend:
  ui->customPlot->legend->setVisible(true);
  ui->customPlot->axisRect()->insetLayout()->setInsetAlignment(0, Qt::AlignTop|Qt::AlignLeft);//centrado de la leyenda
  ui->customPlot->legend->setBrush(QColor(255, 255, 255, 200));//color de fondo de la leyenda.

  // make left and bottom axes transfer their ranges to right and top axes:
  connect(customPlot->xAxis, SIGNAL(rangeChanged(QCPRange)), customPlot->xAxis2, SLOT(setRange(QCPRange)));
  connect(customPlot->yAxis, SIGNAL(rangeChanged(QCPRange)), customPlot->yAxis2, SLOT(setRange(QCPRange)));

  // setup a timer that repeatedly calls MainWindow::realtimeDataSlot:
  connect(&dataTimer, SIGNAL(timeout()), this, SLOT(realtimeDataSlot()));
  dataTimer.start(0); // Interval 0 means to refresh as fast as possible
}
void MainWindow::readResponse()
{
    //qDebug() << "Data Ready";

//    char c;
//    QString t;

//        while (serial.getChar(&c)) {

//            if (c == '\n') {      //'&' is the terminating character of valid data

//                rx_data = string(response.constData());
//                t = QString::fromStdString(rx_data);
//                double val = t.toDouble();
//                qDebug() << "Data = " << t;
//                if (val < 100)
//                    realtimeDataSlot(val,val,val);
//                else
//                    realtimeDataSlot(0,0,0);
//                response.clear();

//            }
//            else {
//                //if (c != '\n')    // '&' is the starting character of valid data
//                    response.append(c);

//                qDebug() << "Reading..." << c;
//            }
//        }

    //Below is the Code for IMU

    double ax,ay,az,gx,gy,gz;

    char a = '1',c;
    const char* ack = &a;
    serial.write(ack);

    string s = "";

    while (serial.getChar(&c)) {

        if (c == '\r') {      //'&' is the terminating character of valid data

            s = string(response.constData());
            const char* rx_data_char = s.c_str();

//            rx_data = s;
            rx_data.append(rx_data_char);
//            qDebug() << "Data = " << QString::fromStdString(s);
            // double val = rx_data.toDouble();

            if (s[0] == '#' && s[1] == 'G') {
                qDebug() << "Total Data = " << QString::fromStdString(rx_data);
                Reading reading = Reading(rx_data);

                if (reading._validReading) {
                    ax = reading.GetAccelerationXAxis();
                    ay = reading.GetAccelerationYAxis();
                    az = reading.GetAccelerationZAxis();
                    qDebug() << "Xacc = " << ax;
                    qDebug() << "Yacc = " << ay;
                    qDebug() << "Zacc = " << az;
                    qDebug() << "Xgyro = " << reading.GetGyroXAxis();
                    qDebug() << "Ygyro = " << reading.GetGyroYAxis();
                    qDebug() << "Zgyro = " << reading.GetGyroZAxis();
                    realtimeDataSlot(ax,ay,az);
                }
                else
                    qDebug() << "Current String = " << QString::fromStdString(reading._currentString) << " " << QString::fromStdString(reading.GetErrorMessage());
            }
            else
                qDebug() << "Double Extraction Error";

            response.clear();
            if (s[0] == '#' && s[1] == 'G')
                rx_data = "";
            serial.write(ack);
            break;
        }
        else {

            if (c != '\n')
                response.append(c);

            //qDebug() << "Reading..." << c;
        }
    }

}
Example #9
0
MainWindow::MainWindow(QWidget *parent) :
        QMainWindow(parent),
        ui(new Ui::MainWindow)
{

    ui->setupUi(this);


    /////////////////////////////////////
    ///
    ///
    ///
    h_WidgetChannel1 = AddNewChannelWidget( 0, 780, 91 );
    h_WidgetChannel1->SetPosition( 780, 91 );

    h_WidgetChannel2 = AddNewChannelWidget( 1, 780, 170 );
    h_WidgetChannel3 = AddNewChannelWidget( 2, 780, 250 );
    h_WidgetChannel4 = AddNewChannelWidget( 3, 780, 330 );
    h_WidgetChannel5 = AddNewChannelWidget( 4, 780, 410 );


    //////////////////////////////////////
    ///
    ///
    ///
    dwYRange    =   2.0;

    h_Channel1  =   new Channel( ui->customPlot );
    h_Channel2  =   new Channel( ui->customPlot );
    h_Channel3  =   new Channel( ui->customPlot );
    h_Channel4  =   new Channel( ui->customPlot );
    h_Channel5  =   new Channel( ui->customPlot );


    h_Channel1->AddChannel( QPen(Qt::blue) );       h_WidgetChannel1->setLabelColor( Qt::blue );
    h_Channel2->AddChannel( QPen(Qt::red ) );       h_WidgetChannel2->setLabelColor( Qt::red );
    h_Channel3->AddChannel( QPen(Qt::yellow ) );    h_WidgetChannel3->setLabelColor( Qt::yellow );
    h_Channel4->AddChannel( QPen(Qt::black ) );     h_WidgetChannel4->setLabelColor( Qt::black );
    h_Channel5->AddChannel( QPen(Qt::green ) );     h_WidgetChannel5->setLabelColor( Qt::green );

    dwGrid      =   10.0;
    ui->sliderGrid->setValue( 10 );

    ui->customPlot->xAxis->setAutoTickStep( false );
    ui->customPlot->yAxis->setAutoTickStep( false );
    ui->customPlot->xAxis->setTickStep( dwGrid );
    ui->customPlot->axisRect()->setupFullAxesBox( );

    ///
    /// Status bar
    ///
    dwPktCount          =   0;
    dwErrorCount        =   0;
    h_lblSerialPort     =   new QLabel( "Porta fechada" );
    h_lblMsgCount       =   new QLabel( "0" );
    h_lblErrors         =   new QLabel( "Erros: 0" );
    h_lblActiveTime     =   new QLabel( "00:00:00" );

    h_lblSerialPort->setFixedWidth( 200 );
    h_lblMsgCount->setFixedWidth( 100 );
    h_lblErrors->setFixedWidth( 100 );
    h_lblActiveTime->setFixedWidth( 100 );

    ui->statusBar->addWidget( h_lblSerialPort );
    ui->statusBar->addWidget( h_lblMsgCount );
    ui->statusBar->addWidget( h_lblErrors );
    ui->statusBar->addWidget( h_lblActiveTime );

    //////////////////////////////////////////////////////////////////////////////
    ///
    ///
    ui->sliderAmplitude->setValue( 20 ); /// 2.0

    ///
    /// make left and bottom axes transfer their ranges to right and top axes:
    ///
    connect(ui->customPlot->xAxis, SIGNAL(rangeChanged(QCPRange)), ui->customPlot->xAxis2, SLOT(setRange(QCPRange)));
    connect(ui->customPlot->yAxis, SIGNAL(rangeChanged(QCPRange)), ui->customPlot->yAxis2, SLOT(setRange(QCPRange)));

    ///
    ///
    ///
    connect(&dataTimer, SIGNAL(timeout()), this, SLOT(realtimeDataSlot()));
    dataTimer.start( 100 );
    ui->sliderTimer->setValue( 100 );

    ///
    ///
    ///
    connect(&tmrCaptureCountTime, SIGNAL(timeout()), this, SLOT(runningTime()));


    ////////////////////////////
    ///
    ///
    h_RS    =   new SerialCommunication( this );

    connect( h_RS, SIGNAL(DataArrive(QString)), this, SLOT(SerialDataArrive(QString)) );
    h_RS->PopulateSerialList();
    QStringList     serialList = h_RS->getSerialList();

    int i = 0;
    ui->cmbSerialList->clear();
    while ( i != serialList.count() )
    {

        ui->cmbSerialList->addItem( serialList.at( i ) );
        i++;

    }

    h_lblSerialPort->setText( "Porta serial fechada" );


    dwDivisor    =  0;
    ui->sliderDivisor->setValue( 0 );

}
Example #10
0
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow),
    settings(QStandardPaths::writableLocation(QStandardPaths::DataLocation)
             + QDir::separator() + "settings.ini", QSettings::IniFormat),
    first(true),
    started(true)
{
    srand(QDateTime::currentDateTime().toTime_t());
    ui->setupUi(this);

    ui->customPlot->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom | QCP::iSelectAxes |
                                    QCP::iSelectLegend | QCP::iSelectPlottables);

    // Axes
    ui->customPlot->xAxis->setTickLabelType(QCPAxis::ltDateTime);
    ui->customPlot->xAxis->setDateTimeFormat("hh:mm:ss");
    ui->customPlot->xAxis->setAutoTickStep(false);
    ui->customPlot->xAxis->setTickStep(2);
    ui->customPlot->xAxis->setLabel("Time");
    ui->customPlot->xAxis->setLabelPadding(0);
    ui->customPlot->xAxis->setSelectableParts(QCPAxis::spAxis);

    ui->customPlot->yAxis->setRange(-20, 20);
    ui->customPlot->yAxis->setLabel("Acceleration (m/s^2)");
    ui->customPlot->yAxis->setLabelPadding(0);
    ui->customPlot->yAxis->setSelectableParts(QCPAxis::spAxis);

    ui->customPlot->axisRect()->setupFullAxesBox();

    // Legend
    ui->customPlot->legend->setVisible(true);
    QFont legendFont = font();
    legendFont.setPointSize(10);
    ui->customPlot->legend->setFont(legendFont);
    ui->customPlot->legend->setSelectedFont(legendFont);
    ui->customPlot->legend->setSelectableParts(QCPLegend::spNone);

    // X, Y, Z reading graphs
    ui->customPlot->addGraph(); // blue line
    ui->customPlot->graph(0)->setPen(QPen(Qt::blue));
    ui->customPlot->graph(0)->setName("X");
    ui->customPlot->graph(0)->setSelectable(false);
    ui->customPlot->addGraph(); // red line
    ui->customPlot->graph(1)->setPen(QPen(Qt::red));
    ui->customPlot->graph(1)->setName("Y");
    ui->customPlot->graph(1)->setSelectable(false);
    ui->customPlot->addGraph(); // green line
    ui->customPlot->graph(2)->setPen(QPen(Qt::green));
    ui->customPlot->graph(2)->setName("Z");
    ui->customPlot->graph(2)->setSelectable(false);

    // Scale in a particular direction when an axis is selected
    connect(ui->customPlot, SIGNAL(mousePress(QMouseEvent*)), this, SLOT(mousePress()));
    connect(ui->customPlot, SIGNAL(mouseWheel(QWheelEvent*)), this, SLOT(mouseWheel()));

    // Make bottom and left axes transfer their ranges to top and right axes:
    connect(ui->customPlot->xAxis, SIGNAL(rangeChanged(QCPRange)), ui->customPlot->xAxis2, SLOT(setRange(QCPRange)));
    connect(ui->customPlot->yAxis, SIGNAL(rangeChanged(QCPRange)), ui->customPlot->yAxis2, SLOT(setRange(QCPRange)));

    // Adjust the tick marks on x-axis scale
    connect(ui->customPlot->xAxis, SIGNAL(rangeChanged(QCPRange)), this, SLOT(xAxisChanged(QCPRange)));

    // Context menu popup
    ui->customPlot->setContextMenuPolicy(Qt::CustomContextMenu);
    connect(ui->customPlot, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(contextMenuRequest(QPoint)));

    // Buttons
    connect(ui->buttonStartStop, SIGNAL(released()), this, SLOT(pressedStartStop()));
    connect(ui->buttonAnalyze, SIGNAL(released()), this, SLOT(pressedAnalyze()));
    connect(ui->buttonSave, SIGNAL(released()), this, SLOT(pressedSave()));

    // Setup accelerometer
    accelerometer = new QAccelerometer(this);
    accelerometer->setAccelerationMode(QAccelerometer::Combined);
    accelerometer->setDataRate(30);
    accelerometer->addFilter(&filter);

    // We'll always keep it running since on the phone apparently calling
    // stop makes the whole application freeze. Thus, we'll just start/stop
    // recording data not actually requesting data from the accelerometer
    accelerometer->start();

    // Button enabled/disabled coloring
    button_enabled = ui->buttonStartStop->palette();
    button_disabled = ui->buttonStartStop->palette();
    button_enabled.setColor(QPalette::Button, QColor(Qt::white));
    button_disabled.setColor(QPalette::Button, QColor(Qt::lightGray));

    // Load previous settings
    bool timed = settings.value("timed").toBool();
    ui->checkBoxTimed->setChecked(timed);

    // When we start the application, either start it automatically if we're
    // not using a fixed period of time or set it up so we can press Start to
    // start it if we are using a fixed period of time
    if (timed)
        stop();
    else
        start();

    // Setup a timer that repeatedly calls MainWindow::realtimeDataSlot
    connect(&dataTimer, SIGNAL(timeout()), this, SLOT(realtimeDataSlot()));

    // Stop it after a certain period of time
    connect(&finishTimer, SIGNAL(timeout()), this, SLOT(finishSlot()));

    // Start with delay to reduce effect of touching the "Start"
    // button when recording for set amount of time
    connect(&startTimer, SIGNAL(timeout()), this, SLOT(startSlot()));
}
Example #11
0
void Mpu::mpuGraphicPrint(QCustomPlot *customPlot){
    // configure axis rect:
    customPlot->plotLayout()->clear(); // clear default axis rect so we can start from scratch


    // X Gravity
    wideAxisRect1 = new QCPAxisRect(customPlot);
    wideAxisRect1->setupFullAxesBox(true);
    wideAxisRect1->axis(QCPAxis::atTop,0)->setLabel(labelXG);
    wideAxisRect1->axis(QCPAxis::atTop,0)->setLabelColor(QColor(230,230,230,240));
    //wideAxisRect1->axis(QCPAxis::atRight, 0)->setTickLabels(true);
    wideAxisRect1->axis(QCPAxis::atBottom,0)->setTickLabelType(QCPAxis::ltDateTime);
    wideAxisRect1->axis(QCPAxis::atBottom,0)->setDateTimeFormat("hh:mm:ss");
    wideAxisRect1->axis(QCPAxis::atBottom,0)->setAutoTickStep(false);
    wideAxisRect1->axis(QCPAxis::atBottom,0)->setTickStep(2);
    wideAxisRect1->axis(QCPAxis::atTop,0)->setAutoTickStep(false);
    wideAxisRect1->axis(QCPAxis::atTop,0)->setTickStep(2);
    wideAxisRect1->axis(QCPAxis::atLeft,0)->setRange(-210,210);
    wideAxisRect1->setBackground(QColor(230,230,230,240));
    wideAxisRect1->axis(QCPAxis::atBottom, 0)->setTickLabelColor((QColor(230,230,230,240) ));
    wideAxisRect1->axis(QCPAxis::atLeft, 0)->setTickLabelColor((QColor(230,230,230,240) ));

    // Y GRAVITY
    wideAxisRect2 = new QCPAxisRect(customPlot);
    wideAxisRect2->setupFullAxesBox(true);
    wideAxisRect2->axis(QCPAxis::atTop,0)->setLabel(labelYG);
    wideAxisRect2->axis(QCPAxis::atTop,0)->setLabelColor(QColor(230,230,230,240));
    wideAxisRect2->setBackground(QColor(230,230,230,240));
    //wideAxisRect1->axis(QCPAxis::atRight, 0)->setTickLabels(true);
    wideAxisRect2->axis(QCPAxis::atBottom,0)->setTickLabelType(QCPAxis::ltDateTime);
    wideAxisRect2->axis(QCPAxis::atBottom,0)->setDateTimeFormat("hh:mm:ss");
    wideAxisRect2->axis(QCPAxis::atBottom,0)->setAutoTickStep(false);
    wideAxisRect2->axis(QCPAxis::atBottom,0)->setTickStep(2);
    wideAxisRect2->axis(QCPAxis::atTop,0)->setAutoTickStep(false);
    wideAxisRect2->axis(QCPAxis::atTop,0)->setTickStep(2);
    wideAxisRect2->axis(QCPAxis::atLeft,0)->setRange(-210,210);
    wideAxisRect2->axis(QCPAxis::atBottom, 0)->setTickLabelColor((QColor(230,230,230,240) ));
    wideAxisRect2->axis(QCPAxis::atLeft, 0)->setTickLabelColor((QColor(230,230,230,240) ));

    // Z GRAVITY
    wideAxisRect3 = new QCPAxisRect(customPlot);
    wideAxisRect3->setupFullAxesBox(true);
    wideAxisRect3->axis(QCPAxis::atTop,0)->setLabel(labelZG);
    wideAxisRect3->axis(QCPAxis::atTop,0)->setLabelColor(QColor(230,230,230,240));
    wideAxisRect3->setBackground(QColor(230,230,230,240));
    //wideAxisRect3->axis(QCPAxis::atRight, 0)->setTickLabels(true);
    wideAxisRect3->axis(QCPAxis::atBottom,0)->setTickLabelType(QCPAxis::ltDateTime);
    wideAxisRect3->axis(QCPAxis::atBottom,0)->setDateTimeFormat("hh:mm:ss");
    wideAxisRect3->axis(QCPAxis::atBottom,0)->setAutoTickStep(false);
    wideAxisRect3->axis(QCPAxis::atBottom,0)->setTickStep(2);
    wideAxisRect3->axis(QCPAxis::atTop,0)->setAutoTickStep(false);
    wideAxisRect3->axis(QCPAxis::atTop,0)->setTickStep(2);
    wideAxisRect3->axis(QCPAxis::atLeft,0)->setRange(-210,210);
    wideAxisRect3->axis(QCPAxis::atBottom, 0)->setTickLabelColor((QColor(230,230,230,240) ));
    wideAxisRect3->axis(QCPAxis::atLeft, 0)->setTickLabelColor((QColor(230,230,230,240) ));

    // X ACCELERATION
    wideAxisRect4 = new QCPAxisRect(customPlot);
    wideAxisRect4->setupFullAxesBox(true);
    wideAxisRect4->axis(QCPAxis::atTop,0)->setLabel(labelXA);
    wideAxisRect4->axis(QCPAxis::atTop,0)->setLabelColor(QColor(230,230,230,240));
    wideAxisRect4->setBackground(QColor(230,230,230,240));
    //wideAxisRect4->axis(QCPAxis::atRight, 0)->setTickLabels(true);
    wideAxisRect4->axis(QCPAxis::atBottom,0)->setTickLabelType(QCPAxis::ltDateTime);
    wideAxisRect4->axis(QCPAxis::atBottom,0)->setDateTimeFormat("hh:mm:ss");
    wideAxisRect4->axis(QCPAxis::atBottom,0)->setAutoTickStep(false);
    wideAxisRect4->axis(QCPAxis::atBottom,0)->setTickStep(2);
    wideAxisRect4->axis(QCPAxis::atTop,0)->setAutoTickStep(false);
    wideAxisRect4->axis(QCPAxis::atTop,0)->setTickStep(2);
    wideAxisRect4->axis(QCPAxis::atLeft,0)->setRange(-210,210);
    wideAxisRect4->axis(QCPAxis::atBottom, 0)->setTickLabelColor((QColor(230,230,230,240) ));
    wideAxisRect4->axis(QCPAxis::atLeft, 0)->setTickLabelColor((QColor(230,230,230,240) ));

    // Y ACCELERATION
    wideAxisRect5 = new QCPAxisRect(customPlot);
    wideAxisRect5->setupFullAxesBox(true);
    wideAxisRect5->axis(QCPAxis::atTop,0)->setLabel(labelYA);
    wideAxisRect5->axis(QCPAxis::atTop,0)->setLabelColor(QColor(230,230,230,240));
    wideAxisRect5->setBackground(QColor(230,230,230,240));
    //wideAxisRect5->axis(QCPAxis::atRight, 0)->setTickLabels(true);
    wideAxisRect5->axis(QCPAxis::atBottom,0)->setTickLabelType(QCPAxis::ltDateTime);
    wideAxisRect5->axis(QCPAxis::atBottom,0)->setDateTimeFormat("hh:mm:ss");
    wideAxisRect5->axis(QCPAxis::atBottom,0)->setAutoTickStep(false);
    wideAxisRect5->axis(QCPAxis::atBottom,0)->setTickStep(2);
    wideAxisRect5->axis(QCPAxis::atTop,0)->setAutoTickStep(false);
    wideAxisRect5->axis(QCPAxis::atTop,0)->setTickStep(2);
    wideAxisRect5->axis(QCPAxis::atLeft,0)->setRange(-210,210);
    wideAxisRect5->axis(QCPAxis::atBottom, 0)->setTickLabelColor((QColor(230,230,230,240) ));
    wideAxisRect5->axis(QCPAxis::atLeft, 0)->setTickLabelColor((QColor(230,230,230,240) ));

    // Z ACCELERATION
    wideAxisRect6 = new QCPAxisRect(customPlot);
    wideAxisRect6->setupFullAxesBox(true);
    wideAxisRect6->axis(QCPAxis::atTop,0)->setLabel(labelZA);
    wideAxisRect6->axis(QCPAxis::atTop,0)->setLabelColor(labelColor);
    wideAxisRect6->setBackground(QColor(230,230,230,240));
    //wideAxisRect6->axis(QCPAxis::atRight, 0)->setTickLabels(true);
    wideAxisRect6->axis(QCPAxis::atBottom,0)->setTickLabelType(QCPAxis::ltDateTime);
    wideAxisRect6->axis(QCPAxis::atBottom,0)->setDateTimeFormat("hh:mm:ss");
    wideAxisRect6->axis(QCPAxis::atBottom,0)->setAutoTickStep(false);
    wideAxisRect6->axis(QCPAxis::atBottom,0)->setTickStep(2);
    wideAxisRect6->axis(QCPAxis::atTop,0)->setAutoTickStep(false);
    wideAxisRect6->axis(QCPAxis::atTop,0)->setTickStep(2);
    wideAxisRect6->axis(QCPAxis::atLeft,0)->setRange(-210,210);
    wideAxisRect6->axis(QCPAxis::atBottom, 0)->setTickLabelColor((QColor(230,230,230,240) ));
    wideAxisRect6->axis(QCPAxis::atLeft, 0)->setTickLabelColor((QColor(230,230,230,240) ));

    //QCPLayoutGrid *subLayout = new QCPLayoutGrid;
    customPlot->plotLayout()->addElement(0, 0, wideAxisRect1); // insert axis rect in first row
    customPlot->plotLayout()->addElement(0, 1, wideAxisRect2);
    customPlot->plotLayout()->addElement(0, 2, wideAxisRect3);
    customPlot->plotLayout()->addElement(1, 0, wideAxisRect4);
    customPlot->plotLayout()->addElement(1, 1, wideAxisRect5);
    customPlot->plotLayout()->addElement(1, 2, wideAxisRect6);

    marginGroup = new QCPMarginGroup(customPlot);

    wideAxisRect1->setMarginGroup(QCP::msLeft | QCP::msRight, marginGroup);
    wideAxisRect2->setMarginGroup(QCP::msLeft | QCP::msRight, marginGroup);
    wideAxisRect3->setMarginGroup(QCP::msLeft | QCP::msRight, marginGroup);
    wideAxisRect4->setMarginGroup(QCP::msLeft | QCP::msRight, marginGroup);
    wideAxisRect5->setMarginGroup(QCP::msLeft | QCP::msRight, marginGroup);
    wideAxisRect6->setMarginGroup(QCP::msLeft | QCP::msRight, marginGroup);

    // create and configure plottables:
    mainGraph1 = customPlot->addGraph(wideAxisRect1->axis(QCPAxis::atBottom), wideAxisRect1->axis(QCPAxis::atLeft));
    mainGraph1->setPen(QPen(penColor, penSize));// Axe zero

    mainGraph2 = customPlot->addGraph(wideAxisRect2->axis(QCPAxis::atBottom), wideAxisRect2->axis(QCPAxis::atLeft));
    mainGraph2->setPen(QPen(penColor, penSize));

    mainGraph3 = customPlot->addGraph(wideAxisRect3->axis(QCPAxis::atBottom), wideAxisRect3->axis(QCPAxis::atLeft));
    mainGraph3->setPen(QPen(penColor, penSize));

    mainGraph4 = customPlot->addGraph(wideAxisRect4->axis(QCPAxis::atBottom), wideAxisRect4->axis(QCPAxis::atLeft));
    mainGraph4->setPen(QPen(penColor, penSize));

    mainGraph5 = customPlot->addGraph(wideAxisRect5->axis(QCPAxis::atBottom), wideAxisRect5->axis(QCPAxis::atLeft));
    mainGraph5->setPen(QPen(penColor, penSize));

    mainGraph6 = customPlot->addGraph(wideAxisRect6->axis(QCPAxis::atBottom), wideAxisRect6->axis(QCPAxis::atLeft));
    mainGraph6->setPen(QPen(penColor, penSize));

    // rescale axes according to graph's data:
    mainGraph1->rescaleAxes(false);
    mainGraph2->rescaleAxes();
    mainGraph3->rescaleAxes();
    mainGraph4->rescaleAxes();
    mainGraph5->rescaleAxes();
    mainGraph6->rescaleAxes();

    // setup a timer that repeatedly calls MainWindow::realtimeDataSlot:
    connect(&dataTimer, SIGNAL(timeout()), this, SLOT(realtimeDataSlot()));
    dataTimer.start(1); // 1ms  Interval 0 means to refresh as fast as possible
}
void MainWindow::setupRealtimeDataDemo(QCustomPlot *customPlot_0, QCustomPlot *customPlot_1, QCustomPlot *customPlot_2){
    demoName = "Project2 Real-time Plot";
    server.show();
    customPlot_0->addGraph(); // blue line
    customPlot_0->graph(0)->setPen(QPen(Qt::blue));

    customPlot_0->addGraph(); // red line
    customPlot_0->graph(1)->setPen(QPen(Qt::red));

    customPlot_0->addGraph(); //blue dot
    customPlot_0->graph(2)->setPen(QPen(Qt::blue));
    customPlot_0->graph(2)->setLineStyle(QCPGraph::lsNone);
    customPlot_0->graph(2)->setScatterStyle(QCPScatterStyle::ssDisc);

    customPlot_0->addGraph(); // red  dot
    customPlot_0->graph(3)->setPen(QPen(Qt::red));
    customPlot_0->graph(3)->setLineStyle(QCPGraph::lsNone);
    customPlot_0->graph(3)->setScatterStyle(QCPScatterStyle::ssDisc);



    customPlot_0->xAxis->setTickLabelType(QCPAxis::ltDateTime);
    customPlot_0->xAxis->setDateTimeFormat("hh:mm:ss");
    customPlot_0->xAxis->setAutoTickStep(false);
    customPlot_0->xAxis->setTickStep(5);
    customPlot_0->axisRect()->setupFullAxesBox();


    customPlot_1->addGraph(); // blue line
    customPlot_1->graph(0)->setPen(QPen(Qt::blue));
    customPlot_1->graph(0)->setAntialiasedFill(false);

    customPlot_1->addGraph(); // blue dot
    customPlot_1->graph(1)->setPen(QPen(Qt::blue));
    customPlot_1->graph(1)->setLineStyle(QCPGraph::lsNone);
    customPlot_1->graph(1)->setScatterStyle(QCPScatterStyle::ssDisc);

    customPlot_2->addGraph(); // red line
    customPlot_2->graph(0)->setPen(QPen(Qt::red));
    customPlot_2->graph(0)->setAntialiasedFill(false);

    customPlot_2->addGraph(); // red dot
    customPlot_2->graph(1)->setPen(QPen(Qt::red));
    customPlot_2->graph(1)->setLineStyle(QCPGraph::lsNone);
    customPlot_2->graph(1)->setScatterStyle(QCPScatterStyle::ssDisc);

    customPlot_1->xAxis->setTickLabelType(QCPAxis::ltDateTime);
    customPlot_1->xAxis->setDateTimeFormat("hh:mm:ss");
    customPlot_1->xAxis->setAutoTickStep(false);
    customPlot_1->xAxis->setTickStep(5);
    customPlot_1->axisRect()->setupFullAxesBox();

    customPlot_2->xAxis->setTickLabelType(QCPAxis::ltDateTime);
    customPlot_2->xAxis->setDateTimeFormat("hh:mm:ss");
    customPlot_2->xAxis->setAutoTickStep(false);
    customPlot_2->xAxis->setTickStep(5);
    customPlot_2->axisRect()->setupFullAxesBox();

    customPlot_0->yAxis->setRange(0,265);

    customPlot_1->yAxis->setRange(0, 50);
    
    customPlot_2->yAxis->setRange(0,190);


    //********* stop adding


    // make left and bottom axes transfer their ranges to right and top axes:
    connect(customPlot_0->xAxis, SIGNAL(rangeChanged(QCPRange)), customPlot_0->xAxis2, SLOT(setRange(QCPRange)));
//    connect(customPlot_0->yAxis, SIGNAL(rangeChanged(QCPRange)), customPlot_0->yAxis2, SLOT(setRange(QCPRange)));

    //********* added by Peng Li
    connect(customPlot_1->xAxis, SIGNAL(rangeChanged(QCPRange)), customPlot_1->xAxis2, SLOT(setRange(QCPRange)));
//    connect(customPlot_1->yAxis, SIGNAL(rangeChanged(QCPRange)), customPlot_1->yAxis2, SLOT(setRange(QCPRange)));
    //********* stop adding
    connect(customPlot_2->xAxis, SIGNAL(rangeChanged(QCPRange)), customPlot_2->xAxis2, SLOT(setRange(QCPRange)));

    // setup a timer that repeatedly calls MainWindow::realtimeDataSlot:
    connect(&dataTimer, SIGNAL(timeout()), this, SLOT(realtimeDataSlot()));
    dataTimer.start(0); // Interval 0 means to refresh as fast as possible
}