00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include <rtt/RTT.hpp>
00020
00021 #if defined (OROPKG_OS_LXRT)
00022
00023
00024
00025 #include "CombinedDigitalOutInterface.hpp"
00026 #include <assert.h>
00027
00028 using namespace RTT;
00029
00030
00031
00032
00033 std::vector<bool> channels;
00034
00035 CombinedDigitalOutInterface::CombinedDigitalOutInterface( const std::string& name, RTT::DigitalOutput* digitalout
00036 , unsigned int num_channels, combinetype type)
00037 : DigitalOutInterface(name), _channels(num_channels), _digitalout(digitalout), _combine(type)
00038 {}
00039
00040
00041
00042 CombinedDigitalOutInterface::~CombinedDigitalOutInterface()
00043 {}
00044
00045
00046
00047 void CombinedDigitalOutInterface::switchOn( unsigned int n )
00048 {
00049 assert(n>=0 && n<_channels.size());
00050 _channels[n] = true;
00051
00052 refresh();
00053 }
00054
00055
00056
00057 void CombinedDigitalOutInterface::switchOff( unsigned int n )
00058 {
00059 assert(n>=0 && n<_channels.size());
00060 _channels[n] = false;
00061
00062 refresh();
00063 }
00064
00065
00066
00067 void CombinedDigitalOutInterface::setBit( unsigned int bit, bool value )
00068 {
00069 assert(bit>=0 && bit<_channels.size());
00070 _channels[bit] = value;
00071
00072 refresh();
00073 }
00074
00075
00076
00077 void CombinedDigitalOutInterface::setSequence(unsigned int start_bit, unsigned int stop_bit, unsigned int value)
00078 {
00079 assert(start_bit>=0 && start_bit<_channels.size());
00080 assert(stop_bit>=0 && stop_bit<_channels.size());
00081 assert(start_bit <= stop_bit);
00082
00083 for (unsigned int i=start_bit; i<=stop_bit; i++)
00084 _channels[i] = value;
00085
00086 refresh();
00087 }
00088
00089
00090
00091 bool CombinedDigitalOutInterface::checkBit(unsigned int bit) const
00092 {
00093 assert(bit>=0 && bit<_channels.size());
00094 return _channels[bit];
00095 }
00096
00097
00098
00099 unsigned int CombinedDigitalOutInterface::checkSequence( unsigned int start_bit, unsigned int stop_bit ) const
00100 {
00101 assert(start_bit>=0 && start_bit<_channels.size());
00102 assert(stop_bit>=0 && stop_bit<_channels.size());
00103 assert(start_bit <= stop_bit);
00104
00105 unsigned int result = 0;
00106 for (unsigned int i=start_bit; i<=stop_bit; i++)
00107 if (_channels[i])
00108 result++;
00109
00110 return result;
00111 }
00112
00113
00114
00115 unsigned int CombinedDigitalOutInterface::nbOfOutputs() const
00116 {
00117 return _channels.size();
00118 }
00119
00120
00121
00122 void CombinedDigitalOutInterface::refresh()
00123 {
00124 switch (_combine)
00125 {
00126 bool enable;
00127
00128 case OR:
00129 enable = false;
00130 for (unsigned int i=0; i<_channels.size(); i++)
00131 if (_channels[i]) enable = true;
00132
00133 if (enable)
00134 _digitalout->switchOn();
00135 else
00136 _digitalout->switchOff();
00137 break;
00138
00139 case AND:
00140 enable = true;
00141 for (unsigned int i=0; i<_channels.size(); i++)
00142 if (!_channels[i]) enable = false;
00143
00144 if (enable)
00145 _digitalout->switchOn();
00146 else
00147 _digitalout->switchOff();
00148 break;
00149 }
00150 }
00151
00152 #endif