DigitalOutput.hpp
Go to the documentation of this file.
1 /***************************************************************************
2  tag: Peter Soetens Mon Jan 19 14:11:20 CET 2004 DigitalOutput.hpp
3 
4  DigitalOutput.hpp - description
5  -------------------
6  begin : Mon January 19 2004
7  copyright : (C) 2004 Peter Soetens
8  email : peter.soetens@mech.kuleuven.ac.be
9 
10  ***************************************************************************
11  * This library is free software; you can redistribute it and/or *
12  * modify it under the terms of the GNU General Public *
13  * License as published by the Free Software Foundation; *
14  * version 2 of the License. *
15  * *
16  * As a special exception, you may use this file as part of a free *
17  * software library without restriction. Specifically, if other files *
18  * instantiate templates or use macros or inline functions from this *
19  * file, or you compile this file and link it with other files to *
20  * produce an executable, this file does not by itself cause the *
21  * resulting executable to be covered by the GNU General Public *
22  * License. This exception does not however invalidate any other *
23  * reasons why the executable file might be covered by the GNU General *
24  * Public License. *
25  * *
26  * This library is distributed in the hope that it will be useful, *
27  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
28  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
29  * Lesser General Public License for more details. *
30  * *
31  * You should have received a copy of the GNU General Public *
32  * License along with this library; if not, write to the Free Software *
33  * Foundation, Inc., 59 Temple Place, *
34  * Suite 330, Boston, MA 02111-1307 USA *
35  * *
36  ***************************************************************************/
37 #ifndef DIGITAL_OUTPUT_HPP
38 #define DIGITAL_OUTPUT_HPP
39 
40 
41 #include "DigitalOutInterface.hpp"
42 
43 namespace RTT
44 { namespace dev {
45 
55  class RTT_API DigitalOutput
56  {
57  public:
65  DigitalOutput( DigitalOutInterface* dig_out, unsigned int relay_nr, bool _invert=false )
66  : board( dig_out ), relaynumber( relay_nr ), invert(_invert)
67  {}
68 
73  DigitalOutput ( bool initial_state = false )
74  : board( 0 ), relaynumber( 0 ), invert(initial_state)
75  {}
76 
77 
82  {}
83 
88  void setBit( bool on_off )
89  {
90  if(board)
91  board->setBit( relaynumber, on_off != invert );
92  else
93  invert=on_off;
94  }
95 
99  void switchOn()
100  {
101  if(board)
102  board->setBit( relaynumber, !invert );
103  else
104  invert=true;
105  }
106 
110  void switchOff()
111  {
112  if(board)
113  board->setBit( relaynumber, invert );
114  else
115  invert=false;
116  }
117 
123  bool isOn() const
124  {
125  if(board)
126  return invert != board->checkBit( relaynumber );
127  else
128  return invert;
129  }
130 
131  private:
133  unsigned int relaynumber;
134  bool invert;
135  };
136 }}
137 
138 #endif
DigitalOutput(DigitalOutInterface *dig_out, unsigned int relay_nr, bool _invert=false)
DigitalOutInterface * board
void setBit(bool on_off)
Contains TaskContext, Activity, OperationCaller, Operation, Property, InputPort, OutputPort, Attribute.
Definition: Activity.cpp:53
DigitalOutput(bool initial_state=false)


rtt
Author(s): RTT Developers
autogenerated on Fri Oct 25 2019 03:59:32