Tekkotsu Homepage
Demos
Overview
Downloads
Dev. Resources
Reference
Credits

LedNode.h

Go to the documentation of this file.
00001 //-*-c++-*-
00002 #ifndef INCLUDED_LedNode_h_
00003 #define INCLUDED_LedNode_h_
00004 
00005 #include "MCNode.h"
00006 #include "Motion/LedMC.h"
00007 
00008 //! A simple StateNode that executes a LedMC motion command and throws a status event upon completion
00009 /*! Extends MCNode slightly so that each time the LedMC is accessed, any flash commands are reset.
00010  *  This allows a flash to be triggered each time the node starts */
00011 class LedNode : public MCNode<LedMC> {
00012 public:
00013   //! default constructor, use type name as instance name
00014   LedNode() : MCNode<LedMC>("LedNode","LedNode"), lastAccess(0) {}
00015   
00016   //! constructor, take an instance name
00017   LedNode(const std::string& nm) : MCNode<LedMC>("LedNode",nm), lastAccess(0) {}
00018   
00019   static std::string getClassDescription() { return "Displays a pattern on the LEDs for as long as the state is active"; }
00020   virtual std::string getDescription() const { return getClassDescription(); }
00021   
00022 protected:
00023   //! constructor for subclasses (which would need to provide a different class name)
00024   LedNode(const std::string &class_name, const std::string &node_name) : MCNode<LedMC>(class_name,node_name), lastAccess(0) {}
00025   
00026   //! extends MCNode implementation so that each time the LedMC is accessed, any flash commands are reset.
00027   virtual SharedObject<LedMC>& getPrivateMC() {
00028     unsigned int curtime=get_time();
00029     bool isFirstCreation=(mc==NULL);
00030     SharedObject<LedMC>& l=MCNode<LedMC>::getPrivateMC();
00031     if(!isFirstCreation)
00032       l->extendFlash(curtime-lastAccess);
00033     lastAccess=curtime;
00034     return l;
00035   }
00036   
00037   unsigned int lastAccess; //!< stores time of last call to getPrivateMC()
00038 };
00039 
00040 /*! @file
00041  * @brief Defines LedNode, a simple StateNode that runs a LedMC motion command and throws a status event upon completion
00042  * @author dst (Creator)
00043  *
00044  * $Author: ejt $
00045  * $Name: tekkotsu-4_0 $
00046  * $Revision: 1.8 $
00047  * $State: Exp $
00048  * $Date: 2006/09/16 17:32:38 $
00049  */
00050 
00051 #endif

Tekkotsu v4.0
Generated Thu Nov 22 00:54:53 2007 by Doxygen 1.5.4