Bela
Real-time, ultra-low-latency audio and sensor processing system for BeagleBone Black
 All Classes Files Functions Variables Typedefs Macros Groups
Public Member Functions | List of all members
DigitalChannelManager Class Reference

#include <DigitalChannelManager.h>

Public Member Functions

void setCallback (void(*newCallback)(bool, unsigned int, void *))
 
void setCallbackArgument (unsigned int channel, void *arg)
 
void processInput (uint32_t *array, unsigned int length)
 
void processOutput (uint32_t *array, unsigned int length)
 
bool isSignalRate (unsigned int channel)
 
bool isMessageRate (unsigned int channel)
 
bool isInput (unsigned int channel)
 
bool isOutput (unsigned int channel)
 
void setValue (unsigned int channel, bool value)
 
void unmanage (unsigned int channel)
 
void manage (unsigned int channel, bool direction, bool isMessageRate)
 
void setVerbose (bool isVerbose)
 

Detailed Description

This class manages the digital channels.

Each channel can be set as either signal or message rate. When set as message rate: inputs are parsed when calling processInput() and a callback is invoked when they change state, outputs are set via calls to setValue() and then written to the output array when calling processOutput().

When set at signal rate: the DigitalChannelManager only sets the pin direction.

Throughout the class we keep track of message/signal rate and input/output in separate variables, so that we always know if a channel is managed by the DigitalChannelManager or not. This way, managed and unmanaged channels can be freely mixed in the code.

For the reasons above, isSignalRate(channel) is not the same as !isMessageRate(channel) and isInput(channel) is not the same as !isOutput(channel)

Member Function Documentation

void DigitalChannelManager::setCallback ( void(*)(bool, unsigned int, void *)  newCallback)
inline

Set the callback.

The callback will be called when one of the managed message-rate input bits changes state. The callback's signature is void (stateChangedCallback)(bool value, unsigned int delay, void arg) where value is the new value of the channel, delay is the sample in the most recent block when the status changed, and arg is an additional argument passed to the callback, which can be set for each channel using setCallbackArgument()

void DigitalChannelManager::setCallbackArgument ( unsigned int  channel,
void *  arg 
)
inline

Sets the argument for the callback.

Typically an argument will allow the callback to identify the channel that changed state.

Parameters
channelis the channel for which the argument is set
argis the argument that will be passed to the callback for that channel
void DigitalChannelManager::processInput ( uint32_t *  array,
unsigned int  length 
)
inline

Process the input signals.

Parses the input array and looks for state changes in the bits managed as message-rate inputs and invokes the appropriate callbacks.

Parameters
arraythe array of input values
lengththe length of the array
void DigitalChannelManager::processOutput ( uint32_t *  array,
unsigned int  length 
)
inline

Process the output signals.

Processes the output array and appropriately sets the bits managed as message-rate outputs. Bits marked as input and unmanaged bits are left alone.

It also updates the channel directions.

Parameters
arraythe array of input values
lengththe length of the array
bool DigitalChannelManager::isSignalRate ( unsigned int  channel)
inline

Inquires if the channel is managed as signal-rate.

Parameters
channelthe channel which is inquired.
bool DigitalChannelManager::isMessageRate ( unsigned int  channel)
inline

Inquires if the channel is managed as message-rate.

Parameters
channelthe channel which is inquired.
Returns
true if the channel is managed at message-rate, false otherwise
bool DigitalChannelManager::isInput ( unsigned int  channel)
inline

Inquires if the channel is managed as input.

Parameters
channelthe channel which is inquired.
Returns
true if the channel is managed as input, false otherwise
bool DigitalChannelManager::isOutput ( unsigned int  channel)
inline

Inquires if the channel is managed as output.

Parameters
channelthe channel which is inquired.
Returns
true if the channel is managed as output, false otherwise
void DigitalChannelManager::setValue ( unsigned int  channel,
bool  value 
)
inline

Sets the output value for a channel.

Parameters
channelthe channel to set.
valuethe value to set.
void DigitalChannelManager::unmanage ( unsigned int  channel)
inline

Stops managing a channel.

Parameters
channelthe channel number
void DigitalChannelManager::manage ( unsigned int  channel,
bool  direction,
bool  isMessageRate 
)
inline

Manages a channel.

Starts managing a channel with given direction and rate. It can be called repeatedly on a given channel to change direction and/or rate.

Parameters
channelthe channel to manage.
direction
isMessageRatewhether the channel should be managed at audio rate (false) or message rate (true)

The documentation for this class was generated from the following file: