BeobotBeoChipListener.H

Go to the documentation of this file.
00001 /*!@file Beobot/BeobotBeoChipListener.H listener for the buttons of the beoChip */
00002 
00003 // //////////////////////////////////////////////////////////////////// //
00004 // The iLab Neuromorphic Vision C++ Toolkit - Copyright (C) 2001 by the //
00005 // 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: Christian Siagian <siagian@usc.edu>
00034 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/Beobot/BeobotBeoChipListener.H $
00035 // $Id: BeobotBeoChipListener.H 8267 2007-04-18 18:24:24Z rjpeters $
00036 //
00037 
00038 #include "Devices/BeoChip.H"
00039 #include "Devices/DeviceOpts.H"
00040 
00041 // ######################################################################
00042 //! Beobot BeoChipListener
00043 class BeobotBeoChipListener : public BeoChipListener
00044 {
00045 public:
00046   BeobotBeoChipListener(nub::soft_ref<BeoChip> bc) :
00047     itsBeoChip(bc), minp0(9999), maxp0(0), minp1(9999), maxp1(0),
00048     counter0(0), counter1(0), kbd(0x1f), moveServo(false) { }
00049 
00050   virtual ~BeobotBeoChipListener() { }
00051 
00052   virtual void event(const BeoChipEventType t, const int valint,
00053                      const float valfloat)
00054   {
00055     LDEBUG("Event: %d val = %d, fval = %f", int(t), valint, valfloat);
00056     switch(t)
00057       {
00058       case PWM0:
00059         if (valint < minp0) minp0 = valint;
00060         else if (valint > maxp0) maxp0 = valint;
00061         if(moveServo)
00062           itsBeoChip->setServo(0, valfloat);
00063         if (++counter0 >= 10)
00064           {
00065             itsBeoChip->lcdPrintf(5, 2, "%04d  %04d-%04d",
00066                                   valint, minp0, maxp0);
00067             itsBeoChip->lcdPrintf(6, 1, "%03d",
00068                                   itsBeoChip->getServoRaw(0));
00069             counter0 = 0;
00070           }
00071         break;
00072       case PWM1:
00073         if (valint < minp1) minp1 = valint;
00074         else if (valint > maxp1) maxp1 = valint;
00075         if(moveServo)
00076           itsBeoChip->setServo(1, valfloat);
00077         if (++counter1 >= 10)
00078           {
00079             itsBeoChip->lcdPrintf(5, 3, "%04d  %04d-%04d",
00080                                   valint, minp1, maxp1);
00081             itsBeoChip->lcdPrintf(17, 1, "%03d",
00082                                   itsBeoChip->getServoRaw(1));
00083             counter1 = 0;
00084           }
00085         break;
00086       case KBD: kbd = valint;  break;
00087       case RESET: LERROR("BeoChip RESET occurred!"); break;
00088       case ECHOREP: LINFO("BeoChip Echo reply received."); break;
00089       case INOVERFLOW: LERROR("BeoChip input overflow!"); break;
00090       case SERIALERROR: LERROR("BeoChip serial error!"); break;
00091       case OUTOVERFLOW: LERROR("BeoChip output overflow!"); break;
00092       default: LERROR("Unknown event %d received!", int(t)); break;
00093       }
00094   }
00095 
00096   nub::soft_ref<BeoChip> itsBeoChip;
00097   int minp0, maxp0, minp1, maxp1;
00098   int counter0, counter1;
00099   int kbd;
00100   bool moveServo;
00101 };
00102 
00103 // ######################################################################
00104 /* So things look consistent in everyone's emacs... */
00105 /* Local Variables: */
00106 /* indent-tabs-mode: nil */
00107 /* End: */
Generated on Sun May 8 08:04:26 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3