Tekkotsu Homepage
Demos
Overview
Downloads
Dev. Resources
Reference
Credits

OutputCmd.h

Go to the documentation of this file.
00001 //-*-c++-*-
00002 #ifndef INCLUDED_OutputCmd_h
00003 #define INCLUDED_OutputCmd_h
00004 
00005 //! This object holds all the information needed to control a single output
00006 class OutputCmd {
00007 public:
00008 
00009   OutputCmd() : value(0), weight(0) {} //!< Constructor
00010   OutputCmd(float v) : value(v), weight(1) {} //!< Constructor (provides implicit conversion from float)
00011   OutputCmd(float v, float w) : value(v), weight(w) {} //!< Constructor
00012   OutputCmd(const OutputCmd& a, const OutputCmd& b, float w) : value(a.value*w+b.value*(1-w)), weight(a.weight*w+b.value*(1-w)) {} //!< Constructor, see set(a,b,w)
00013   
00014   //! assignment from another OutputCmd (just copy everything, straightforward)
00015   OutputCmd& operator=(const OutputCmd& oc) { value=oc.value; weight=oc.weight; return *this; }
00016   //! assignment from a float, set weight to 1
00017   OutputCmd& operator=(float v) { value=v; weight=1; return *this; }
00018 
00019   inline void set(float v, float w=1) { value=v; weight=w; } //!< sets the value to @a v and weight to @a w
00020   inline void set(const OutputCmd& a, const OutputCmd& b, float w) { value=a.value*w+b.value*(1-w); weight=a.weight*w+b.weight*(1-w); } //!< sets the value to a weighted average of @a a and @a b (higher @a w, more @a a)
00021   inline void unset() { value=weight=0; } //!< sets value and weight to 0
00022   bool operator==(const OutputCmd& c) const { return value==c.value && weight==c.weight; } //!< tests for equality of weight and value
00023   bool operator!=(const OutputCmd& c) const { return value!=c.value || weight!=c.weight; } //!< tests for inequality of weight and value
00024 
00025   float value; //!< value of the output
00026   float weight; //!< weight to be used in averaging, 0 to "fall through"
00027   static OutputCmd unused; //!< handy sometimes for returning a reference to a 0,0 cmd
00028 };
00029 
00030 /*! @file
00031  * @brief Describes OutputCmd, holds information needed to control a single output
00032  * @author ejt (Creator)
00033  */
00034 
00035 #endif

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