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 = Bela_setBit(clearDataOut, channel);
186 setDataOut = Bela_clearBit(setDataOut, channel);
188 setDataOut = Bela_setBit(setDataOut, channel);
189 clearDataOut = Bela_clearBit(clearDataOut, channel);
199 messageRate = Bela_clearBit(messageRate, channel);
200 signalRate = Bela_clearBit(signalRate, channel);
201 modeInput = Bela_clearBit(modeInput, channel);
202 modeOutput = Bela_clearBit(modeOutput, channel);
203 clearDataOut = Bela_clearBit(clearDataOut, channel);
204 setDataOut = Bela_clearBit(setDataOut, channel);
220 messageRate = Bela_changeBit(messageRate, channel, isMessageRate);
221 signalRate = Bela_changeBit(signalRate, channel, !isMessageRate);
222 if(direction == OUTPUT){
223 modeOutput = Bela_setBit(modeOutput, channel);
224 modeInput = Bela_clearBit(modeInput, channel);
226 modeInput = Bela_setBit(modeInput, channel);
227 modeOutput = Bela_clearBit(modeOutput, channel);
230 rt_printf(
"Bela digital: channel %d is set as %s at %s rate\n", channel,
234 void setVerbose(
bool isVerbose);
237 bool callbackEnabled;
238 void* callbackArguments[16];
239 void (*stateChangedCallback)(
bool value,
unsigned int delay,
void* arg);
240 uint32_t clearDataOut;
244 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:218
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