QlightRead package | ESS final project 1.22-beta

/home/ron/Desktop/Frontend/src/mainwindow.cpp

Go to the documentation of this file.
00001 
00042 #include <QtGui>
00043 #include <QDebug>
00044 #include <qwt/qwt.h>
00045 
00046 #include <qextserialport.h>
00047 #include "settings_dialog.h"
00048 #include "mainwindow.h"
00049 #include "dataplot.h"
00050 #include "tools.h"
00051 #include "serial.h"
00052 #include "global_macros.h"
00053 
00054 
00055 const int PLOT_SIZE = 1001;
00056 
00057 
00068 MainWindow::MainWindow()
00069 {
00070     //connect_v = 0;
00071 
00072     for (int i = 0;i<=4095;i++)
00073     {
00074         global_in[i] = '\0';
00075     }
00076     pid = PID;
00077     vid = VID;
00078 
00079 
00080     widget = new QWidget;
00081     setCentralWidget(widget);
00082     QHBoxLayout *Main_layout = new QHBoxLayout(widget);
00083     ab = new QProgressBar();
00084     ib = new QProgressBar;
00085 
00086     QPalette ib_pal = ib->palette();
00087     QPalette ab_pal = ab->palette();
00088 
00089 
00090     ib->setOrientation(Qt::Vertical);
00091     ab->setOrientation(Qt::Vertical);
00092     ib_pal.setColor(QPalette::Highlight, Qt::red);
00093     ab_pal.setColor(QPalette::Highlight, Qt::blue);
00094     ib->setPalette(ib_pal);
00095     ab->setPalette(ab_pal);
00096     QWidget *topFiller = new QWidget;
00097     topFiller->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
00098     curvelayout = new QVBoxLayout;
00099     QWidget *curvep = new QWidget;
00100 
00101 
00102     data = new CurveData( PLOT_SIZE );
00103     plot = new DataPlot(curvep);
00104 
00105     plot->setTitle( QString("Lux over Time") );
00106 
00107 
00108     QVBoxLayout *right_layout = new QVBoxLayout(widget);
00109     QHBoxLayout *right_layout_H1 = new QHBoxLayout;
00110     QHBoxLayout *right_layout_H2 = new QHBoxLayout;
00111     QHBoxLayout *right_layout_H3 = new QHBoxLayout;
00112     QHBoxLayout *progbar = new QHBoxLayout;
00113    // QPushButton *set = new QPushButton("Rescale");
00114 
00115 
00116 
00117 
00118 
00119     bar_l = new QLabel("NULL");
00120     progbar->addWidget(ib);
00121     progbar->addWidget(ab);
00122     ib->setFormat("");
00123     ab->setFormat("");
00124     QLabel *C_v = new QLabel("<h2><b><font size=3>Current Value: </font></b></h2>");
00125     QLabel *A_v = new QLabel("<h2><b><font size=3>Average Value: </font></b></h2>");
00126     QLabel *Con_stat = new QLabel("<h2><b><font size=3>Connection: </font></b></h2>");
00127     C_v_i = new QLabel;
00128     A_v_i = new QLabel;
00129     Con_V = new QLabel;
00130     Con_V->setText((tr("No active connection : NULL")));
00131     //t_step = new QSpinBox;
00132  //   unit = new QLabel;
00133   //  unit->setText("ms");
00134 
00135    // t_step->setRange(0,100000);
00136  //   t_step->setValue(500);
00137 
00138     right_layout_H1->addWidget(C_v);
00139     right_layout_H1->addWidget(C_v_i);
00140 
00141     right_layout_H2->addWidget(A_v);
00142     right_layout_H2->addWidget(A_v_i);
00143 
00144     right_layout_H3->addWidget(Con_stat);
00145     right_layout_H3->addWidget(Con_V);
00146 
00147    // right_layout_H3->addWidget(t_step);
00148    // right_layout_H3->addWidget(unit);
00149    // right_layout_H3->addWidget(set);
00150 
00151     right_layout->addLayout(right_layout_H1);
00152     right_layout->addLayout(right_layout_H2);
00153     right_layout->addLayout(right_layout_H3);
00154 
00155 
00156     curvelayout->addWidget(curvep);
00157 
00158 
00159     Main_layout->addLayout(right_layout);
00160     Main_layout->addLayout(progbar);
00161 
00162     Main_layout->addLayout(curvelayout);
00163 
00164 
00165     plot->curve_c->setRawData( data->xc() , data->yc() , PLOT_SIZE );
00166     plot->curve_a->setRawData( data->xa() , data->ya() , PLOT_SIZE );
00167     plot->setAxisAutoScale(QwtPlot::yLeft);
00168     plot->setAxisAutoScale(QwtPlot::xBottom);
00169 
00170 
00171     plot->resize(450,300);
00172 
00173     //update_gui();
00174 
00175     startTimer( 100);
00176 
00177 
00178     QWidget *bottomFiller = new QWidget;
00179     bottomFiller->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
00180   //  connect(t_step,SIGNAL(valueChanged(int)),this,SLOT(startTimer(t_step->value())));
00181 
00182     //connect(set,SIGNAL(clicked()),this, SLOT(restart_timer(t_step->value())));
00183     //connect(set,SIGNAL(clicked()),this,SLOT(update_gui()));
00184    // QObject::connect(t_step,SIGNAL(valueChanged(int)),this,SLOT(restart_timer(t_step->value())));
00185     //QObject::connect(t_step,SIGNAL(valueChanged(int)),this,SLOT(setunit()));
00186     //QObject::connect(t_step,SIGNAL(valueChanged(int)),this,SLOT(rescale_axis(t_step->value())));
00187 
00188     createActions();
00189     createMenus();
00190     QIcon icon(QString::fromUtf8(":/icon/TS.ico"));
00191     ib->setRange(10,610);
00192     ab->setRange(10,610);
00193 
00194     setWindowIcon(icon);
00195     setWindowTitle(tr("QLightread - By Trilog Studios  <Not Connected>"));
00196 
00197     amount = 0;
00198     av= 0.0;
00199 
00200 }
00201 
00202 
00214 void MainWindow::timerEvent( QTimerEvent* )
00215 {
00216     qDebug() << "running timer\n" << "connect_v :: "<< connect_v << "\n" << "amount :: "<< amount <<"\n";
00217 
00218     int temp = 0;
00219 
00220 
00221     if (connect_v !=0)
00222     {
00223         amount++;
00224 
00225         if (connect_v == 2 || connect_v == 3)
00226         {
00227             serial_receive();
00228 
00229 
00230         }
00231         if (connect_v == 1)
00232         {
00233             int r;
00234             r=libusb_bulk_transfer(devh, DATAINEP, &indata[0], DATAINSIZE, &transferred,0);
00235             if (r!=0)
00236             {
00237                 fprintf(stderr, "failed to read!!!! %d\n", r);
00238                 connect_v = 0;
00239                 return;
00240             }
00241             else
00242                 qDebug() << "Reading bulk usb:: got"<< indata << "\n";
00243 
00244             temp = atoi(( char *)indata);
00245         }
00246         else
00247         {
00248             connect_v = 0;
00249             amount--;
00250         }
00251 
00252         update_gui(1,(double) temp);
00253     }
00254 
00255     double out = 0.0;
00256     //static double phase = 0.0;
00257 
00258 
00259 
00260 
00261 
00262     // data->dc_y[0] = 10*cos(phase +M_PI);
00263     // data->da_y[0] = (-1)*10*cos(phase +M_PI+2);
00264 
00265     //Data_output.append(dtemp);
00266     //Plot_data_output.append(ptemp);
00267 }
00268 
00279 void MainWindow::restart_timer(int timer_value)
00280 {
00281     startTimer(timer_value);
00282 }
00283 
00294 void MainWindow::rescale_axis(int timer)
00295 {
00296      plot->setAxisScale(QwtPlot::xBottom, 0 , timer );
00297 }
00298 
00310 void MainWindow::connect_U()
00311 {
00312 
00313 
00314     if ( connect_v == 1)
00315     {
00316        // disconnect_interface *dilg(this);
00317         //dilg.show();
00318         return;
00319 
00320     }
00321     else
00322         connect_v = 0;
00323 
00324     devh = NULL;
00325 
00326 
00327     //libusb_device  **devh; //pointer to pointer of device, used to retrieve a list of devices
00328     libusb_context *ctx = NULL; //a libusb session
00329     int r; //for  return values
00330 
00331     qDebug() << "in usb";
00332     r = libusb_init(NULL);
00333     if (r < 0)
00334     {
00335         QMessageBox::critical(this, tr("Error Initializing libUSB!"), tr("An Error has occured while initialzing libUSB. Please verify that you have permission to access USB devices!"));
00336         Con_V->setText(tr("No active connection : USB-Error <libUSB init failed>"));
00337         return;
00338 
00339 
00340     }
00341     r = find_estick_device(&devh);
00342     qDebug() << "finddev";
00343     if (r < 0)
00344     {
00345         QMessageBox::critical(this, tr("Error connecting to specified usb device!"), tr("An Error has occured while opening device handel of USB. Please verify that the correct eStick is connected, an the right firmware is flashed!"));
00346         Con_V->setText(tr("No active connection : USB-Error <No Device found>"));
00347         return;
00348     }
00349 
00350     r = libusb_claim_interface(devh, 0);
00351     qDebug() << "claim dev";
00352     if (r < 0 )
00353     {
00354         QMessageBox::critical(this, tr("Error Claiming device!"), tr("You either dont have permission to control USB-devices, or another program is using it!"));
00355         Con_V->setText(tr("No active connection : USB-Error <Claim unsucessfull>"));
00356         return;
00357     }
00358     else
00359     {
00360         Con_V->setText(tr("Active connection : USB < 0x03eb || 0x0666>"));
00361         custom_title_set("USB");
00362         connect_v =1;
00363     }
00364 
00365 
00366    // libusb_free_device_list(devs, 1); //free the list, unref the devices in it
00367     //libusb_exit(devh); //close the session
00368 
00369 
00370 }
00371 
00383 void MainWindow::connect_B()
00384 {
00385 
00386     if(connect_v != 0)
00387     {
00388         QMessageBox::information(this,tr("Connection already exists"),tr("You are already connected. Please disconnect before reconnecting!"));
00389         return;
00390     }
00391     else
00392     {
00393         connect_v = 1;
00394         QString dDev;
00395         QString str;
00396         int leng;
00397 
00398         QFile serial_dev(SERIAL_SETTINGS_TSS);
00399         serial_dev.open(QIODevice::ReadOnly);
00400 
00401         QTextStream fs(&serial_dev);    // read the data serialized from the file
00402 
00403         str.clear();
00404         while (!fs.atEnd())
00405         {
00406             leng = 0;
00407             leng = str.length();
00408             if (str[0] == '#')
00409                 continue;
00410             if ((str[0] =='d') && (str[3] == '_') && (str[6] == 'v'))//default devices
00411             {
00412                 for (int i = 10;i <=leng;i++)
00413                 {
00414                     if (str[i] == '>')
00415                         dDev[i-10]='\0';
00416                     else
00417                         dDev[i-10]=str[i];
00418 
00419                 }
00420 
00421             }
00422         }
00423 
00424         PortSettings portSettings;
00425         portSettings.BaudRate = BAUD115200;
00426         portSettings.DataBits = DATA_8;
00427         portSettings.Parity = PAR_NONE;
00428         portSettings.StopBits = STOP_2;
00429         portSettings.FlowControl = FLOW_OFF;
00430         portSettings.Timeout_Millisec = 10;
00431 
00432         port = new QextSerialPort(dDev,portSettings);
00433 
00434 
00435 
00436 
00437         bool res = false;
00438         res = port->open(QextSerialPort::ReadOnly);
00439 
00440         if(res)
00441         {
00442           qDebug() <<"Connected to Bluetooth Device\n";
00443         }
00444         else
00445         {
00446             qDebug() <<"Connection to Bluetooth Device failed!!\n";
00447             connect_v = 0;
00448             return;
00449         }
00450 
00451    }
00452 }
00453 
00465 void MainWindow::connect_S()
00466 {
00467     if(connect_v != 0)
00468     {
00469         QMessageBox::information(this,tr("Connection already exists"),tr("You are already connected. Please disconnect before reconnecting!"));
00470         return;
00471     }
00472     else
00473     {
00474         connect_v = 1;
00475 
00476         QString dDev;
00477         QString str;
00478         int leng;
00479 
00480         QFile usb(SERIAL_SETTINGS_TSS);
00481         usb.open(QIODevice::ReadOnly);
00482 
00483         QTextStream fs(&usb);    // read the data serialized from the file
00484 
00485         str.clear();
00486         while (!fs.atEnd())
00487         {
00488             leng = 0;
00489             str=fs.readLine();
00490             leng = str.length();
00491             if (str[0] == '#')
00492                 continue;
00493             if ((str[0] =='d') && (str[3] == '_') && (str[6] == 'v'))//default devices
00494         {
00495             for (int i = 10;i <=leng;i++)
00496             {
00497                 if (str[i] == '>')
00498                     dDev[i-10]='\0';
00499                 else
00500                     dDev[i-10]=str[i];
00501 
00502 
00503             }
00504 
00505 
00506         }
00507         }
00508 
00509         PortSettings portSettings;
00510         portSettings.BaudRate = BAUD9600;
00511         portSettings.DataBits = DATA_8;
00512         portSettings.Parity = PAR_NONE;
00513         portSettings.StopBits = STOP_1;
00514         portSettings.FlowControl = FLOW_OFF;
00515         portSettings.Timeout_Millisec = 0;
00516 
00517         QextSerialPort* port = new QextSerialPort(dDev,portSettings);
00518         bool res = false;
00519         res = port->open(QextSerialPort::ReadOnly);
00520 
00521 
00522         if(res)
00523         {
00524             qDebug() <<"Connected!!\n";
00525         }
00526         else
00527         {
00528             qDebug() <<"Connection failed!!\n";
00529             connect_v = 0;
00530         }
00531 
00532         //QString message("010C\r");
00533        // int total = port->write(message.toAscii(),message.length());
00534         QString line;
00535         line.append(port->readAll());
00536         qDebug() << "Serial Port output " << line <<"\n";
00537        // port->close();
00538 
00539     }
00540 }
00541 
00552 void MainWindow:: data_viewer()
00553 {
00554 
00555     DataViewDialog *dataview = new DataViewDialog(this);
00556     dataview->show();
00557 }
00558 
00569 void MainWindow::save_plot()
00570 {
00571     QString fileName = QFileDialog::getSaveFileName(this,
00572                         tr("Choose a file name"), ".",
00573                         tr("Plot Data [*.tsp] (*.tsp)"));
00574 
00575     if (fileName.isEmpty())
00576         return;
00577     if ( (fileName[fileName.length()-4] == '.') && (fileName[fileName.length()-1]) == 'p' )
00578     {
00579         fileName[fileName.length()-4] ='.';
00580         fileName[fileName.length()-3] ='t';
00581         fileName[fileName.length()-2] ='s';
00582         fileName[fileName.length()-1] ='p';
00583         fileName[fileName.length()-4] ='\0';
00584     }
00585     else
00586         fileName.append(".tsp");
00587 
00588     write_to_file(fileName,Plot_data_output);
00589 
00590 
00591 }
00592 
00604 void MainWindow::clear_plot()
00605 {
00606     for ( int i = PLOT_SIZE - 1; i > 0; i-- )
00607        data->dc_y[i] = data->dc_y[i-1];
00608     for ( int i = PLOT_SIZE - 1; i > 0; i-- )
00609        data->da_y[i] = data->da_y[i-1];
00610     for(int i = 0 ; i <= PLOT_SIZE; i++)
00611     {
00612         data->dc_y[i] = 0;
00613         data->da_y[i] = 0;
00614     }
00615 
00616   //  plot->curve->
00617 
00618 }
00619 
00630 void MainWindow::Save_C()
00631 {
00632         s_fileC = QFileDialog::getSaveFileName(this, tr("Save File"), "/home", tr("Captured Data [*.tsd] (*.tsd)"));
00633 
00634     if (s_fileC.isEmpty())
00635         return;
00636     if ( (s_fileC[s_fileC.length()-4] == '.' ) && (s_fileC[s_fileC.length()-1] == 'd'))
00637     {
00638         s_fileC[s_fileC.length()-4] ='.';
00639         s_fileC[s_fileC.length()-3] ='t';
00640         s_fileC[s_fileC.length()-2] ='s';
00641         s_fileC[s_fileC.length()-1] ='d';
00642         s_fileC[s_fileC.length()-4] ='\0';
00643     }
00644     else
00645         s_fileC.append(".tsd");
00646 
00647     write_to_file(s_fileC,Data_output);
00648 
00649 
00650 }
00651 
00662 void MainWindow::set_Serial()
00663 {
00664 
00665     SDeviceEditDialog *serialset = new SDeviceEditDialog(this);
00666     serialset->setWindowTitle("Serial Interface Settings");
00667     serialset->resize(220,210);
00668     serialset->show();
00669 
00670 
00671 }
00672 void MainWindow::set_USB()
00683 {
00684 
00685     DeviceEditDialog *usbe = new DeviceEditDialog(1,this);
00686     usbe->setWindowTitle("USB Settings!");
00687     usbe->resize(290,180);
00688     usbe->show();
00689 
00690 
00691 }
00692 
00703 void MainWindow::set_Blue()
00704 {
00705     BDeviceEditDialog *blue_dev = new BDeviceEditDialog(this);
00706     //blue_dev->windowTitle("Bluetooth Settings");
00707     blue_dev->resize(220,210);
00708     blue_dev->show();
00709 
00710 }
00711 
00722 void MainWindow::set_Prog()
00723 {
00724     ProgEditDialog *prog= new ProgEditDialog(this);
00725     prog->resize(342,235);
00726     prog->show();
00727 
00728 }
00729 
00740 void MainWindow::about()
00741 {
00742     TSabout *abt = new TSabout(this);
00743     abt->setWindowTitle(tr("About QlightRead"));
00744     abt->resize(465,670);
00745     abt->show();
00746 
00747     }
00748 
00759 void MainWindow::aboutQt()
00760 {
00761     }
00762 
00773 void MainWindow::createActions()
00774 {
00775 
00776 
00777     usbAct = new QAction(tr("&USB"), this);
00778     usbAct->setShortcuts(QKeySequence::Underline);
00779     usbAct->setStatusTip(tr("Connects to USB interface"));
00780     connect(usbAct, SIGNAL(triggered()), this, SLOT(connect_U()));
00781 
00782 
00783     datav = new QAction(tr("&Data Viewer"), this);
00784     datav->setShortcuts(QKeySequence::Replace);
00785     datav->setStatusTip(tr("Opens Data view Window"));
00786     connect(datav, SIGNAL(triggered()), this, SLOT( data_viewer()));
00787 
00788     serialAct = new QAction(tr("&Serial"), this);
00789     serialAct->setShortcuts(QKeySequence::Save);
00790     serialAct->setStatusTip(tr("Connects to Serial interface"));
00791     connect(serialAct, SIGNAL(triggered()), this, SLOT(connect_S()));
00792 
00793 
00794     blueAct = new QAction(tr("&Bluetooth"), this);
00795     blueAct->setShortcuts(QKeySequence::Bold);
00796     blueAct->setStatusTip(tr("Connect to Bluetooth Interface"));
00797     connect(blueAct, SIGNAL(triggered()), this, SLOT(connect_B()));
00798 
00799 
00800     exitAct = new QAction(tr("E&xit"), this);
00801     exitAct->setShortcuts(QKeySequence::Quit);
00802     exitAct->setStatusTip(tr("Exit the application"));
00803     connect(exitAct, SIGNAL(triggered()), this, SLOT(close()));
00804 
00805 
00806 
00807     save_PAct = new QAction(tr("&Save plot"), this);
00808    // save_PAct->setShortcuts(QKeySequence::Save);
00809     save_PAct->setStatusTip(tr("Saves graph to file"));
00810     connect(save_PAct, SIGNAL(triggered()), this, SLOT(save_plot()));
00811 
00812 
00813     clear_PAct = new QAction(tr("&Clear plot"), this);
00814     clear_PAct->setShortcuts(QKeySequence::Copy);
00815     clear_PAct->setStatusTip(tr("Clears plot area"));
00816     connect(clear_PAct, SIGNAL(triggered()), this, SLOT(clear_plot()));
00817 
00818 
00819     save_CAct = new QAction(tr("&Save data"), this);
00820     //save_CAct->setShortcuts(tr("Ctrl+D+S"));
00821     save_CAct->setStatusTip(tr("Saves captured data to file"));
00822     connect(save_CAct, SIGNAL(triggered()), this, SLOT(Save_C()));
00823 
00824     set_mserial = new QAction(tr("&Serial Device"), this);
00825    // set_usbAct->setShortcuts(tr("Ctrl+S+S"));
00826     set_mserial->setStatusTip(tr("Serial Settings"));
00827     connect(set_mserial, SIGNAL(triggered()), this, SLOT(set_Serial()));
00828 
00829     set_usbAct = new QAction(tr("&USB Device"), this);
00830    // set_usbAct->setShortcuts(tr("Ctrl+S+U"));
00831     set_usbAct->setStatusTip(tr("USB Settings"));
00832     connect(set_usbAct, SIGNAL(triggered()), this, SLOT(set_USB()));
00833 
00834     set_blueAct = new QAction(tr("&Bluetooth Device"), this);
00835    // set_blueAct->setShortcuts(tr("Ctrl+S+B"));
00836     set_blueAct->setStatusTip(tr("Bluetooth Settings"));
00837     connect(set_blueAct, SIGNAL(triggered()), this, SLOT(set_Blue()));
00838 
00839     set_progAct = new QAction(tr("&Preferences"), this);
00840    // set_progAct->setShortcuts(tr("Ctrl+S+P"));
00841     set_progAct->setStatusTip(tr("Program Settings"));
00842     connect(set_progAct, SIGNAL(triggered()), this, SLOT(set_Prog()));
00843 
00844 
00845     aboutAct = new QAction(tr("&About"), this);
00846     aboutAct->setStatusTip(tr("Show the application's About box"));
00847     connect(aboutAct, SIGNAL(triggered()), this, SLOT(about()));
00848 
00849     aboutQtAct = new QAction(tr("About &Qt"), this);
00850     aboutQtAct->setStatusTip(tr("Show the Qt library's About box"));
00851     connect(aboutQtAct, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
00852     connect(aboutQtAct, SIGNAL(triggered()), this, SLOT(aboutQt()));
00853 
00854 }
00855 
00866 void MainWindow::createMenus()
00867 {
00868 
00869     //File
00870     fileMenu = menuBar()->addMenu(tr("&File"));
00871     connectd= fileMenu->addMenu("Connect to Device");
00872     connectd->addAction(blueAct);
00873     connectd->addAction(serialAct);
00874     connectd->addAction(usbAct);
00875 
00876     fileMenu->addSeparator();
00877     fileMenu->addAction(exitAct);
00878 
00879     //Data Plot
00880     plotMenu = menuBar()->addMenu(tr("&Save Data"));
00881     plotMenu->addAction(save_CAct);
00882     plotMenu->addAction(save_PAct);
00883     plotMenu->addSeparator();
00884     plotMenu->addAction(clear_PAct);
00885 
00886 
00887 
00888     //Settings
00889     settingMenu = menuBar()->addMenu(tr("&Settings"));
00890     devices = settingMenu->addMenu("Devices");
00891     devices->addAction(set_blueAct);
00892     devices->addAction(set_mserial);
00893     devices->addAction(set_usbAct);
00894 
00895 
00896     settingMenu->addSeparator();
00897     settingMenu->addAction(set_progAct);
00898 
00899 
00900 
00901 
00902     //Data Capture
00903     dataMenu = menuBar()->addMenu(tr("&Tools"));
00904     dataMenu->addAction(datav);
00905 
00906     //Help
00907     helpMenu = menuBar()->addMenu(tr("&Help"));
00908     helpMenu->addAction(aboutAct);
00909     helpMenu->addAction(aboutQtAct);
00910 
00911 
00912 }
00913 
00924 void MainWindow::serial_receive()
00925 {
00926     if (port->isOpen())
00927     {
00928         qint64 numBytes , i;
00929         //char buff[4096];
00930         if(port->bytesAvailable())
00931         {
00932             numBytes = port->bytesAvailable();
00933             if(numBytes > sizeof(global_in))
00934                numBytes = sizeof(global_in);
00935             i = port->read(global_in,numBytes);
00936          }
00937          if(disc_flag == 1)
00938          {
00939               port->close();
00940               connect_v = 0;
00941           }
00942         }
00943         else
00944         {
00945             QMessageBox::information(this,tr("Error port not open!"),tr("An error has occured, desired port has not been opened. please connect to device!"));
00946             //port->close;
00947             qDebug() <<"Port has no valid identifier";
00948         }
00949 }
00950 
00961 void MainWindow::update_gui(int mode, double value)
00962 {
00963     double lightmesure = 0.0;
00964     if (mode == 1)
00965     {
00966         for ( int i = PLOT_SIZE - 1; i > 0; i-- )
00967            data->dc_y[i] = data->dc_y[i-1];
00968         for ( int i = PLOT_SIZE - 1; i > 0; i-- )
00969            data->da_y[i] = data->da_y[i-1];
00970         lightmesure = ((0.94 * value) + 6);
00971         qDebug() << "value recieved: "<< value << "\nCalculated Value: "<< lightmesure;
00972         av=av+lightmesure;
00973 
00974         if(amount >0)
00975             data->da_y[0] = (int)(av/amount);
00976           data->dc_y[0] = (int) lightmesure;
00977         C_v_i->setNum(lightmesure);
00978         A_v_i->setNum(av/amount);
00979         ib->setValue(lightmesure);
00980         ab->setValue(av/amount);
00981         plot->replot();
00982      }
00983 
00984     if (mode == 2)
00985     {
00986         double currentvalue = 0.0;
00987         double lightmesure = 0.0;
00988 
00989         for (double k = 10.0; k<=600;k++)
00990         {
00991             amount=amount+1;
00992             for ( int i = PLOT_SIZE - 1; i > 0; i-- )
00993                 data->dc_y[i] = data->dc_y[i-1];
00994             sleep(0.01);
00995             currentvalue = (k);
00996 
00997             QString temp;
00998             //temp.append(global_in);
00999             //qDebug() << temp << "testn "<< global_in;
01000             //currentvalue = temp.toDouble();
01001             lightmesure = ((0.94 * currentvalue) + 6);
01002             qDebug() << "value recieved: "<<currentvalue << "\nCalculated Value: "<< lightmesure;
01003             av=av+lightmesure;
01004             data->dc_y[0] =lightmesure;
01005 
01006             C_v_i->setNum(lightmesure);
01007             A_v_i->setNum(av/amount);
01008             ib->setValue(lightmesure);
01009             ab->setValue(av/amount);
01010             plot->replot();
01011         }
01012 
01013     }
01014 
01015 
01016 
01017 }
01018 
01029 void MainWindow::write_to_file(QString fileName, QString pstr)
01030 {
01031     QFile file(fileName);
01032     if (!file.open(QFile::WriteOnly | QFile::Text)) {
01033         QMessageBox::warning(this, tr("QlightSens"),
01034                              tr("Cannot write file %1:\n%2.")
01035                              .arg(fileName)
01036                              .arg(file.errorString()));
01037         return;
01038     }
01039     QTextStream out(&file);
01040     QApplication::setOverrideCursor(Qt::WaitCursor);
01041     out <<pstr<< endl;
01042     //out <<"<0001:00000>\n";
01043     QApplication::restoreOverrideCursor();
01044     QString test;
01045     test.append("Saved '%1' ");
01046     //test.append((QString *)file.size());
01047     test.append("bytes written!");
01048     statusBar()->showMessage(tr("Saved '%1'").arg(fileName), 2000);
01049 
01050 
01051 }
01052 
01063 void MainWindow::custom_title_set(QString C_dev){
01064     QString temp;
01065     temp.clear();
01066     temp.append(TITLE_STRING);
01067     temp.append(" <Connected> <");
01068     temp.append(C_dev);
01069     temp.append(">");
01070     setWindowTitle(temp);
01071 }
 All Classes Files Functions Variables Defines