BeoChipMainForm.qt.C

Go to the documentation of this file.
00001 /*!@file Qt4/BeoChipMainForm.qt.C */
00002 
00003 // //////////////////////////////////////////////////////////////////// //
00004 // The iLab Neuromorphic Vision C++ Toolkit - Copyright (C) 2000-2005   //
00005 // by the University of Southern California (USC) and the iLab at USC.  //
00006 // See http://iLab.usc.edu for information about this project.          //
00007 // //////////////////////////////////////////////////////////////////// //
00008 // Major portions of the iLab Neuromorphic Vision Toolkit are protected //
00009 // under the U.S. patent ``Computation of Intrinsic Perceptual Saliency //
00010 // in Visual Environments, and Applications'' by Christof Koch and      //
00011 // Laurent Itti, California Institute of Technology, 2001 (patent       //
00012 // pending; application number 09/912,225 filed July 23, 2001; see      //
00013 // http://pair.uspto.gov/cgi-bin/final/home.pl for current status).     //
00014 // //////////////////////////////////////////////////////////////////// //
00015 // This file is part of the iLab Neuromorphic Vision C++ Toolkit.       //
00016 //                                                                      //
00017 // The iLab Neuromorphic Vision C++ Toolkit is free software; you can   //
00018 // redistribute it and/or modify it under the terms of the GNU General  //
00019 // Public License as published by the Free Software Foundation; either  //
00020 // version 2 of the License, or (at your option) any later version.     //
00021 //                                                                      //
00022 // The iLab Neuromorphic Vision C++ Toolkit is distributed in the hope  //
00023 // that it will be useful, but WITHOUT ANY WARRANTY; without even the   //
00024 // implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      //
00025 // PURPOSE.  See the GNU General Public License for more details.       //
00026 //                                                                      //
00027 // You should have received a copy of the GNU General Public License    //
00028 // along with the iLab Neuromorphic Vision C++ Toolkit; if not, write   //
00029 // to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,   //
00030 // Boston, MA 02111-1307 USA.                                           //
00031 // //////////////////////////////////////////////////////////////////// //
00032 //
00033 // Primary maintainer for this file:
00034 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/Qt4/BeoChipMainForm.qt.C $
00035 // $Id: BeoChipMainForm.qt.C 12962 2010-03-06 02:13:53Z irock $
00036 //
00037 
00038 #include "Qt4/BeoChipMainForm.qt.H"
00039 
00040 // Qt3 to Qt4 transition notes: the code here was copied from the old Qt/BeoChipMainForm.ui.h
00041 // Also see here for tips: http://qt.nokia.com/doc/4.6/porting4-designer.html
00042 
00043 // ######################################################################
00044 BeoChipMainForm::BeoChipMainForm( QWidget* parent, Qt::WindowFlags fl ) :
00045   QDialog(parent, fl)
00046 {
00047   setupUi(this);
00048 }
00049 
00050 // ######################################################################
00051 BeoChipMainForm::~BeoChipMainForm()
00052 { }
00053 
00054 // ######################################################################
00055 void BeoChipMainForm::init(ModelManager* mgr, nub::soft_ref<BeoChip> thebc)
00056 {
00057     manager = mgr;
00058     bc = thebc;
00059 
00060     // make sure we report the correct serial device in use:
00061     labelSerDev->setText((std::string("Serial Dev: ") +
00062         bc->getModelParamString("BeoChipDeviceName")).c_str());
00063 
00064     // reset the BeoChip and our displays:
00065     bc->resetChip();
00066 
00067     // start a timer:
00068     startTimer(25);
00069 }
00070 
00071 // ######################################################################
00072 void BeoChipMainForm::beoChipReset()
00073 {
00074     LINFO("Resetting form...");
00075     sliderSSC0->setValue(127); servo[0] = 127;
00076     sliderSSC1->setValue(127); servo[1] = 127;
00077     sliderSSC2->setValue(127);        servo[2] = 127;
00078     sliderSSC3->setValue(127); servo[3] = 127;
00079     sliderSSC4->setValue(127); servo[4] = 127;
00080     sliderSSC5->setValue(127); servo[5] = 127;
00081     sliderSSC6->setValue(127); servo[6] = 127;
00082     sliderSSC7->setValue(127); servo[7] = 127;
00083     checkBoxOut0->setChecked(false); dout[0] = false;
00084     checkBoxOut1->setChecked(false); dout[1] = false;
00085     checkBoxOut2->setChecked(false); dout[2] = false;
00086     checkBoxOut3->setChecked(false); dout[3] = false;
00087     checkDebounce->setChecked(true); debounce = false;
00088     for (int i = 0; i < 5; i ++) din[i] = true;
00089     for (int i = 0; i < 2; i ++) { ain[i] = 0; pin[i] = 0; }
00090 
00091     // get BeoChip display going:
00092     bc->lcdClear();   // 01234567890123456789
00093     bc->lcdPrintf(0, 0, "test-BeoChipQt   1.0");
00094     bc->lcdSetAnimation(2);
00095     bc->captureAnalog(0, true);
00096     bc->captureAnalog(1, true);
00097     bc->debounceKeyboard(true);
00098     bc->captureKeyboard(true);
00099     bc->capturePulse(0, true);
00100     bc->capturePulse(1, true);
00101     for (int i = 0; i < 7; i ++) bc->setServoRaw(i, 127);
00102     for (int i = 0; i < 3; i ++) bc->setDigitalOut(i, false);
00103 }
00104 
00105 // ######################################################################
00106 void BeoChipMainForm::showDin(const int num, const bool state)
00107 {
00108     if (num < 0 || num > 4) LERROR("Invalid digital input number %d ignored", num);
00109     else din[num] = state;
00110 }
00111 
00112 // ######################################################################
00113 void BeoChipMainForm::showAnalog(const int num, const int val)
00114 {
00115     if (num < 0 || num > 1) LERROR("Invalid analog input number %d ignored", num);
00116     else ain[num] = val;
00117 }
00118 
00119 // ######################################################################
00120 void BeoChipMainForm::showPWM(const int num, const int val)
00121 {
00122     if (num < 0 || num > 1) LERROR("Invalid PWM input number %d ignored", num);
00123     else pin[num] = val;
00124 }
00125 
00126 // ######################################################################
00127 void BeoChipMainForm::sliderSSC0_valueChanged( int val )
00128 { servo[0] = val; }
00129 
00130 void BeoChipMainForm::sliderSSC1_valueChanged( int val )
00131 { servo[1] = val; }
00132 
00133 void BeoChipMainForm::sliderSSC2_valueChanged( int val )
00134 { servo[2] = val; }
00135 
00136 void BeoChipMainForm::sliderSSC3_valueChanged( int val )
00137 { servo[3] = val; }
00138 
00139 void BeoChipMainForm::sliderSSC4_valueChanged( int val )
00140 { servo[4] = val; }
00141 
00142 void BeoChipMainForm::sliderSSC5_valueChanged( int val )
00143 { servo[5] = val; }
00144 
00145 void BeoChipMainForm::sliderSSC6_valueChanged( int val )
00146 { servo[6] = val; }
00147 
00148 void BeoChipMainForm::sliderSSC7_valueChanged( int val )
00149 { servo[7] = val; }
00150 
00151 // ######################################################################
00152 void BeoChipMainForm::radioButtonDec_clicked()
00153 {
00154     radioButtonHex->setChecked(FALSE);
00155     radioButtonDec->setChecked(TRUE);
00156     lCDNumberSSC0->setDecMode();
00157     lCDNumberSSC1->setDecMode();
00158     lCDNumberSSC2->setDecMode();
00159     lCDNumberSSC3->setDecMode();
00160     lCDNumberSSC4->setDecMode();
00161     lCDNumberSSC5->setDecMode();
00162     lCDNumberSSC6->setDecMode();
00163     lCDNumberSSC7->setDecMode();
00164     lCDNumberA0->setDecMode();
00165     lCDNumberA1->setDecMode();
00166     lCDNumberPWM0->setDecMode();
00167     lCDNumberPWM1->setDecMode();
00168 }
00169 
00170 // ######################################################################
00171 void BeoChipMainForm::radioButtonHex_clicked()
00172 {
00173     radioButtonHex->setChecked(TRUE);
00174     radioButtonDec->setChecked(FALSE);
00175     lCDNumberSSC0->setHexMode();
00176     lCDNumberSSC1->setHexMode();
00177     lCDNumberSSC2->setHexMode();
00178     lCDNumberSSC3->setHexMode();
00179     lCDNumberSSC4->setHexMode();
00180     lCDNumberSSC5->setHexMode();
00181     lCDNumberSSC6->setHexMode();
00182     lCDNumberSSC7->setHexMode();
00183     lCDNumberA0->setHexMode();
00184     lCDNumberA1->setHexMode();
00185     lCDNumberPWM0->setHexMode();
00186     lCDNumberPWM1->setHexMode();
00187 }
00188 
00189 // ######################################################################
00190 void BeoChipMainForm::checkDebounce_stateChanged( int s )
00191 { if (s) debounce = true; else debounce = false; }
00192 
00193 // ######################################################################
00194 void BeoChipMainForm::pushButtonReset_clicked()
00195 {
00196 LINFO("Reset button clicked!");
00197     bc->resetChip(); // our BeoChipListener should in turn call resetBeoChip on us
00198 }
00199 
00200 // ######################################################################
00201 void BeoChipMainForm::checkBoxOut3_stateChanged( int s )
00202 { if (s) dout[3] = true; else dout[3] = false; }
00203 
00204 void BeoChipMainForm::checkBoxOut2_stateChanged( int s )
00205 { if (s) dout[2] = true; else dout[2] = false; }
00206 
00207 void BeoChipMainForm::checkBoxOut1_stateChanged( int s )
00208 { if (s) dout[1] = true; else dout[1] = false; }
00209 
00210 void BeoChipMainForm::checkBoxOut0_stateChanged( int s )
00211 { if (s) dout[0] = true; else dout[0] = false; }
00212 
00213 // ######################################################################
00214 void BeoChipMainForm::timerEvent(QTimerEvent *e)
00215 {
00216     // first, update the BeoChip:
00217     for (int i = 0; i < 8; i ++) bc->setServoRaw(i, servo[i]);
00218     for (int i = 0; i < 4; i ++) bc->setDigitalOut(i, dout[i]);
00219     bc->debounceKeyboard(debounce);
00220 
00221     // also update our displays:
00222     digin0->display(din[0] ? 1 : 0);
00223     digin1->display(din[1] ? 1 : 0);
00224     digin2->display(din[2] ? 1 : 0);
00225     digin3->display(din[3] ? 1 : 0);
00226     digin4->display(din[4] ? 1 : 0);
00227     lCDNumberA0->display(ain[0]);
00228     lCDNumberA1->display(ain[1]);
00229     lCDNumberPWM0->display(pin[0]);
00230     lCDNumberPWM1->display(pin[1]);
00231 }
00232 
00233 // ######################################################################
00234 /* So things look consistent in everyone's emacs... */
00235 /* Local Variables: */
00236 /* mode: c++ */
00237 /* indent-tabs-mode: nil */
00238 /* End: */
Generated on Sun May 8 08:41:16 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3