Tekkotsu Homepage
Demos
Overview
Downloads
Dev. Resources
Reference
Credits

SensorObserverControl.h

Go to the documentation of this file.
00001 //-*-c++-*-
00002 #ifndef INCLUDED_SensorObserverControl_h_
00003 #define INCLUDED_SensorObserverControl_h_
00004 
00005 #include "ControlBase.h"
00006 #include "Events/EventListener.h"
00007 #include "StringInputControl.h"
00008 #include "ToggleControl.h"
00009 #include <fstream>
00010 
00011 //! allows logging of sensor information to the console or file
00012 class SensorObserverControl : public ControlBase, public EventListener {
00013 public:
00014   //!constructor
00015   SensorObserverControl();
00016 
00017   //!opens a custom (embedded) menu to toggle individual sensors
00018   virtual ControlBase* doSelect();
00019   
00020   virtual void refresh();
00021 
00022   //!sends all events received to stdout and/or logfile
00023   virtual void processEvent(const EventBase& event);
00024 
00025 protected:
00026   //!checks to see if logfilePath differs from the StringInputControl's value and switches it if it is
00027   void checkLogFile();
00028 
00029   //!update the real-time sub-control view (#rtCtl)
00030   void updateRT();
00031 
00032   //! The real time view for SensorObserverControl is split into a separate class for more straightfoward handling of refreshes
00033   class RTViewControl : public ControlBase, public EventListener {
00034   public:
00035     //!constructor, pass pointer to SensorObserverControl which contains it
00036     RTViewControl(SensorObserverControl* p) : ControlBase("Real-time View"), EventListener(), parent(p), period(500) {}
00037     virtual void processEvent(const EventBase& /*event*/) { refresh(); } //!< causes control to refresh whenever an event (i.e. timer) is received
00038     virtual void refresh();
00039     virtual void pause();
00040     virtual void deactivate();
00041     virtual void setPeriod(unsigned int x); //!< sets #period
00042   protected:
00043     SensorObserverControl* parent; //!< a back pointer to SensorObserverControl which contains it so updateRT can be triggered
00044     unsigned int period; //!< the time to wait between automatic refreshes
00045   private:
00046     RTViewControl(const RTViewControl& ); //!< don't call
00047     RTViewControl& operator=(const RTViewControl& ); //!< don't call
00048   };
00049   friend class RTViewControl;
00050   
00051   //!address of the logfile, if any (empty string is no logfile)
00052   std::string logfilePath;
00053 
00054   //!if a filename is given, events are logged to here
00055   std::ofstream logfile;
00056 
00057   ControlBase * helpCtl; //!< control containing help info
00058   ControlBase * sensorCtl; //!< control of sensor selectors
00059   ControlBase * buttonCtl; //!< control of buttons selectors
00060   ControlBase * outputCtl; //!< control of outputs selectors
00061   ControlBase * dutyCtl; //!< control of duty selectors
00062   ToggleControl * consoleCtl; //!< turn logging to the console on and off
00063   StringInputControl * fileCtl; //!< turn logging to a file on and off
00064   RTViewControl * rtCtl; //!< a submenu containing real-time view of current values
00065   StringInputControl * rtFreqCtl; //!< the frequency at which rtCtl should be updated
00066 
00067   unsigned int numListeners; //!< count of active console or file control so we know if we're actually logging
00068 
00069 private:
00070   SensorObserverControl(const SensorObserverControl& ); //!< don't call
00071   SensorObserverControl& operator=(const SensorObserverControl& ); //!< don't call
00072 
00073 };
00074 
00075 /*! @file
00076  * @brief Describes SensorObserverControl which allows logging of sensor information to the console or file
00077  * @author ejt (Creator)
00078  */
00079 
00080 #endif

Tekkotsu v5.1CVS
Generated Mon May 9 04:58:50 2016 by Doxygen 1.6.3