12 #ifndef xtChannels_hpp
13 #define xtChannels_hpp
21 template<
int _numChannels>
99 template<
int numChannels>
102 for(
size_t i =0; i< numChannels; ++i)
104 m_channels[i] =
false;
105 m_inputOnly[i] =
false;
109 template<
int numChannels>
112 if(chNo > numChannels - 1)
return -1;
114 if(m_inputOnly[chNo])
116 m_channels[chNo] =
false;
120 m_channels[chNo] =
true;
125 template<
int numChannels>
128 if(chNo > numChannels - 1)
return -1;
130 m_inputOnly[chNo] =
true;
135 template<
int numChannels>
138 if(chNo > numChannels - 1)
return -1;
140 m_channels[chNo] =
false;
145 template<
int numChannels>
148 for(
size_t i=0;i<numChannels; ++i) m_channels[i] =
false;
153 template<
int numChannels>
156 for(
size_t i =0; i < numRegisters; ++i)
160 for(
size_t j=0; j < 4; ++j)
162 if(!m_inputOnly[i*4 + j])
165 if(m_channels[i*4+j])
167 registers[i] += (1 << j);
177 template<
int numChannels>
180 for(
size_t i =0; i < numRegisters; ++i)
182 m_channels[i*4] = ((registers[i] & 1) > 0);
183 m_channels[i*4+1] = ((registers[i] & 2) > 0) ;
184 m_channels[i*4+2] = ((registers[i] & 4) > 0);
185 m_channels[i*4+3] = ((registers[i] & 8) > 0);
192 template<
int numChannels>
195 if(chNo > numChannels - 1)
return -1;
197 return m_channels[chNo];
Utility class for managing Acromag xt12XX digital I/O channels.
bool m_inputOnly[numChannels]
Control which channels can not be set to output.
int setRegisters(uint16_t registers[numRegisters])
Set registers based on current channel states.
int setChannel(size_t chNo)
Set a channel to true.
static constexpr int numRegisters
The number of registers needed for the number of channels.
int channel(size_t chNo)
Gets the current state of a channel.
bool m_channels[numChannels]
The state of the channels.
int clearAll()
Clear all channels.
int setInputOnly(size_t chNo)
Set a channel to be input only.
int clearChannel(size_t chNo)
Set a channel to false.
static constexpr int numChannels
The number of channels controlled by the device.
int readRegisters(uint16_t registers[numRegisters])
Read channel states from the registers.
xtChannels< 16 > xt1121Channels
Instantiaion of xtChannels for the 16-channel xt1121.