Merge branch 'master' of gitolite@git.ctdo.de:bunti

Conflicts:
	bunti_server/src/main/java/de/ctdo/dmx/DMXMixer.java
This commit is contained in:
Lucas Pleß 2012-03-02 01:01:44 +01:00
commit 0bd6c5acf7
1 changed files with 0 additions and 103 deletions

View File

@ -1,103 +0,0 @@
package de.ctdo.dmx;
import java.net.SocketException;
import java.util.ArrayList;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import artnet4j.ArtNet;
import artnet4j.ArtNetException;
import artnet4j.ArtNetNode;
import artnet4j.packets.ArtDmxPacket;
public class DMXMixer {
final int TICKS_BETWEEN_DMX_SEND = 20;
final int DMX_MIN_CHANNEL = 0;
final int DMX_MAX_CHANNEL = 512;
final String ARTNET_DEVICE_ADDRESS = "192.168.0.90";
Logger logger = LoggerFactory.getLogger(DMXMixer.class);
int[] dmx512databuffer = new int[512];
static int sequenceID = 0;
ArtNet artnet = new ArtNet();
ArtNetNode firstNodeFound = null;
ArtDmxPacket artnetDmxPacket = null;
long ticksLastBufferFlush = 0;
protected final List<DMXDataChangedListener> listeners = new ArrayList<DMXDataChangedListener>();
public void addListener(DMXDataChangedListener l) {
synchronized (listeners) {
listeners.add(l);
}
}
public void removeListener(DMXDataChangedListener l) {
synchronized (listeners) {
listeners.remove(l);
}
}
public DMXMixer() {
artnetDmxPacket = new ArtDmxPacket();
artnetDmxPacket.setUniverse(0, 0);
try {
artnet.start();
}
catch (ArtNetException e) {
logger.error("ArtNetException... " + e.toString());
}
catch (SocketException e) {
logger.error("SocketException... " + e.toString());
}
}
private void sendOutDMXBuffer() {
byte[] arr = new byte[dmx512databuffer.length];
for (int i = 0; i < dmx512databuffer.length; i++) {
arr[i] = (byte)dmx512databuffer[i];
}
artnetDmxPacket.setSequenceID(sequenceID % 255);
artnetDmxPacket.setDMX(arr, arr.length);
artnet.unicastPacket(artnetDmxPacket, ARTNET_DEVICE_ADDRESS);
sequenceID++;
ticksLastBufferFlush = System.currentTimeMillis();
}
public void sendOutDMXBufferIfNeeded() {
if(ticksLastBufferFlush + TICKS_BETWEEN_DMX_SEND < System.currentTimeMillis()) {
sendOutDMXBuffer();
}
}
public void setDMX512Channel(int channel, int value) {
if(channel < DMX_MIN_CHANNEL || channel > DMX_MAX_CHANNEL) {
return;
}
if(value < 0) value = 0;
if(value > 255) value = 255;
dmx512databuffer[channel-1] = value;
sendOutDMXBufferIfNeeded();
for (DMXDataChangedListener l : this.listeners) {
l.DMXDataChanged(dmx512databuffer);
}
}
}