00001 /*************************************************************************** 00002 tag: Peter Soetens Sat May 21 20:15:51 CEST 2005 TemplateDigitalIn.hpp 00003 00004 TemplateDigitalIn.hpp - description 00005 ------------------- 00006 begin : Sat May 21 2005 00007 copyright : (C) 2005 Peter Soetens 00008 email : peter.soetens@mech.kuleuven.ac.be 00009 00010 *************************************************************************** 00011 * This library is free software; you can redistribute it and/or * 00012 * modify it under the terms of the GNU Lesser General Public * 00013 * License as published by the Free Software Foundation; either * 00014 * version 2.1 of the License, or (at your option) any later version. * 00015 * * 00016 * This library is distributed in the hope that it will be useful, * 00017 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00018 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * 00019 * Lesser General Public License for more details. * 00020 * * 00021 * You should have received a copy of the GNU Lesser General Public * 00022 * License along with this library; if not, write to the Free Software * 00023 * Foundation, Inc., 59 Temple Place, * 00024 * Suite 330, Boston, MA 02111-1307 USA * 00025 * * 00026 ***************************************************************************/ 00027 00028 00029 #ifndef TEMPLATEDIGITALIN_HPP 00030 #define TEMPLATEDIGITALIN_HPP 00031 00032 #include "rtt/dev/DigitalInInterface.hpp" 00033 00034 namespace RTT 00035 { 00044 class TemplateDigitalIn 00045 { 00046 public: 00050 TemplateDigitalIn() 00051 : bit_status(0) 00052 { 00053 } 00054 00055 bool isOn( unsigned int bit ) const 00056 { return bit_status >> bit & 0x1; } 00057 00058 bool isOff( unsigned int bit ) const 00059 { return !isOn(bit); } 00060 00061 bool readBit( unsigned int bit ) const 00062 { return isOn(bit); } 00063 00064 unsigned int readSequence(unsigned int start_bit, unsigned int stop_bit) const 00065 { 00066 unsigned int result = bit_status >> start_bit; 00067 return result & ( 1 << (stop_bit-start_bit+1) ) - 1; 00068 } 00069 00070 protected: 00075 unsigned int bit_status; 00076 }; 00077 00078 } 00079 00080 00081 #endif 00082 00083