8 #ifndef DIGITALCHANNELMANAGER_H_ 9 #define DIGITALCHANNELMANAGER_H_ 50 void setCallback(
void (*newCallback)(
bool,
unsigned int,
void*)){
51 stateChangedCallback = newCallback;
52 if(newCallback != NULL){
53 callbackEnabled =
true;
55 callbackEnabled =
false;
69 callbackArguments[channel] = arg;
83 if(callbackEnabled ==
false){
87 static uint16_t lastDigitalInputValues = 0;
88 for (
unsigned int frame = 0; frame < length; ++frame) {
89 uint32_t inWord = array[frame];
90 uint16_t direction = inWord & 0Xffff;
91 uint16_t inputValues = (inWord >> 16);
98 inputValues &= direction;
99 uint16_t changed = inputValues ^ lastDigitalInputValues;
101 changed &= messageRate;
104 for(
int n = 0; n < 16; ++n){
105 if(changed & (1 << n)){
106 stateChangedCallback(inputValues & (1 << n), frame, callbackArguments[n]);
110 lastDigitalInputValues = inputValues;
127 uint32_t orWord = ((setDataOut << 16) | modeInput);
128 uint32_t andWord = ~((clearDataOut << 16) | modeOutput);
130 for (
unsigned int frame = 0; frame < length; ++frame) {
131 outWord = array[frame];
132 outWord = outWord | orWord;
133 outWord = outWord & andWord;
134 array[frame] = outWord;
144 return (
bool)((1 << channel) & signalRate);
154 return (
bool)((1 << channel) & messageRate);
164 return (
bool)((1 << channel) & modeInput);
174 return (
bool)((1 << channel) & modeOutput);
185 clearDataOut = setBit(clearDataOut, channel);
186 setDataOut = clearBit(setDataOut, channel);
188 setDataOut = setBit(setDataOut, channel);
189 clearDataOut = clearBit(clearDataOut, channel);
199 messageRate = clearBit(messageRate, channel);
200 signalRate = clearBit(signalRate, channel);
201 modeInput = clearBit(modeInput, channel);
202 modeOutput = clearBit(modeOutput, channel);
203 clearDataOut = clearBit(clearDataOut, channel);
204 setDataOut = clearBit(setDataOut, channel);
219 messageRate = changeBit(messageRate, channel, isMessageRate);
220 signalRate = changeBit(signalRate, channel, !isMessageRate);
221 if(direction == OUTPUT){
222 modeOutput = setBit(modeOutput, channel);
223 modeInput = clearBit(modeInput, channel);
225 modeInput = setBit(modeInput, channel);
226 modeOutput = clearBit(modeOutput, channel);
228 rt_printf(
"Bela digital: channel %d is set as %s at %s rate\n", channel,
234 bool callbackEnabled;
235 void* callbackArguments[16];
236 void (*stateChangedCallback)(
bool value,
unsigned int delay,
void* arg);
237 uint32_t clearDataOut;
241 uint16_t messageRate;
void processOutput(uint32_t *array, unsigned int length)
Definition: DigitalChannelManager.h:126
Definition: DigitalChannelManager.h:34
bool isMessageRate(unsigned int channel)
Definition: DigitalChannelManager.h:153
bool isOutput(unsigned int channel)
Definition: DigitalChannelManager.h:173
bool isSignalRate(unsigned int channel)
Definition: DigitalChannelManager.h:143
bool isInput(unsigned int channel)
Definition: DigitalChannelManager.h:163
void setValue(unsigned int channel, bool value)
Definition: DigitalChannelManager.h:183
void manage(unsigned int channel, bool direction, bool isMessageRate)
Definition: DigitalChannelManager.h:217
void unmanage(unsigned int channel)
Definition: DigitalChannelManager.h:198
void processInput(uint32_t *array, unsigned int length)
Definition: DigitalChannelManager.h:82
void setCallbackArgument(unsigned int channel, void *arg)
Definition: DigitalChannelManager.h:68
void setCallback(void(*newCallback)(bool, unsigned int, void *))
Definition: DigitalChannelManager.h:50