// (Re)Initialize the specified mode.
// The mode parameter should be a value from enum DMXMode.
void DMXSerialClass::init(int mode, int dmxModePin)
{
// initialize global variables
_dmxMode = DMXNone;
_dmxModePin = dmxModePin;
_dmxRecvState = STARTUP; // initial state
_dmxChannel = 0;
_dmxDataPtr = _dmxData;
_dmxLastPacket = millis(); // remember current (relative) time in msecs.
_dmxMaxChannel = DMXSERIAL_MAX; // The default in Receiver mode is reading all possible 512 channels.
_dmxDataLastPtr = _dmxData + _dmxMaxChannel;
// initialize the DMX buffer
// memset(_dmxData, 0, sizeof(_dmxData));
for (int n = 0; n < DMXSERIAL_MAX+1; n++)
_dmxData[n] = 0;
// now start
_dmxMode = (DMXMode)mode;
if ((_dmxMode == DMXController) || (_dmxMode == DMXReceiver) || (_dmxMode == DMXProbe)) {
// a valid mode was given
// Setup external mode signal
pinMode(_dmxModePin, OUTPUT); // enables the pin for output to control data direction
digitalWrite(_dmxModePin, DmxModeIn); // data in direction, to avoid problems on the DMX line for now.
if (_dmxMode == DMXController) {
digitalWrite(_dmxModePin, DmxModeOut); // data Out direction
_dmxMaxChannel = 32; // The default in Controller mode is sending 32 channels.
_DMXStartSending();
} else if (_dmxMode == DMXReceiver) {
// Setup Hardware
_DMXStartReceiving();
// } else if (_dmxMode == DMXProbe) {
// // don't setup the Hardware now
} // if
} // if
} // init()
|