163 lines
3.1 KiB
Java
163 lines
3.1 KiB
Java
package de.ctdo.bunti.model;
|
|
|
|
import java.util.*;
|
|
import java.util.Map.Entry;
|
|
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
import de.ctdo.bunti.dmx.*;
|
|
|
|
public abstract class BuntiDMXDevice extends BuntiDevice {
|
|
Logger logger = LoggerFactory.getLogger(getClass());
|
|
int startAddress;
|
|
long lastSendOut;
|
|
DMXChannels dmxChannels = new DMXChannels();
|
|
|
|
public int getStartAddress() {
|
|
return startAddress+1;
|
|
}
|
|
|
|
public long getLastSendOut() {
|
|
return lastSendOut;
|
|
}
|
|
|
|
public void setSendOutNow() {
|
|
this.lastSendOut = System.currentTimeMillis();
|
|
}
|
|
|
|
|
|
/**
|
|
* set the DMX Start Address (1 to 512)
|
|
* @param startAddress
|
|
*/
|
|
public void setStartAddress(int startAddress) {
|
|
this.startAddress = startAddress-1;
|
|
}
|
|
|
|
|
|
public void addChannel(DMXChannel channel) {
|
|
//dmxChannels.add(channel);
|
|
dmxChannels.addChannel(channel);
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setChannelValueByName(String name, int value) {
|
|
DMXChannel dx = dmxChannels.getChannelByName(name);
|
|
if(dx != null) {
|
|
dx.setValue(DMX.sanitizeDMXValue(value));
|
|
}
|
|
lastChangedNow();
|
|
}
|
|
|
|
public int getChannelValueByName(String name) {
|
|
DMXChannel dx = dmxChannels.getChannelByName(name);
|
|
if(dx != null) {
|
|
return dx.getValue();
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
* Merge the DMX values from this device into a global DMX512 Data Array
|
|
* @param dmxData
|
|
* @return
|
|
*/
|
|
public boolean mergeDMXData(int[] dmxData) {
|
|
|
|
if(dmxData == null) {
|
|
return false;
|
|
}
|
|
|
|
for (DMXChannel channel : dmxChannels.getAllChannels()) {
|
|
int index = channel.getOffset() + startAddress;
|
|
|
|
if(index >= DMX.DMX_CHANNEL_VALUE_MIN && index <= DMX.DMX_CHANNELS_MAX){
|
|
dmxData[index] = channel.getValue();
|
|
} else {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
@Override
|
|
public void switchOff() {
|
|
|
|
}
|
|
|
|
@Override
|
|
public void switchOn() {
|
|
|
|
}
|
|
|
|
|
|
@Override
|
|
public boolean setValuesFromOptions(Map<String, Object> options) {
|
|
|
|
for (Entry<String, Object> opt : options.entrySet()) {
|
|
|
|
DMXChannel channel = dmxChannels.getChannelByName(opt.getKey());
|
|
|
|
if(channel != null) {
|
|
try {
|
|
int value = Integer.parseInt(opt.getValue().toString());
|
|
|
|
setChannelValueByName(channel.getName(), value);
|
|
|
|
} catch (Exception e) {
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
|
|
|
|
|
|
// public void setChannelValueByOffset(int offsetChannel, int value) {
|
|
// DMXChannel dx = getDMXChannelByOffset(offsetChannel);
|
|
// if(dx != null) {
|
|
// dx.value = DMX.sanitizeDMXValue(value);
|
|
// }
|
|
//}
|
|
|
|
//public void setChannelValueByAddress(int address, int value) {
|
|
// DMXChannel dx = getDMXChannelByAddress(address);
|
|
// if(dx != null) {
|
|
// dx.value = DMX.sanitizeDMXValue(value);
|
|
// }
|
|
//}
|
|
|
|
//public int getChannelValueByOffset(int offsetChannel) {
|
|
// DMXChannel dx = getDMXChannelByOffset(offsetChannel)
|
|
// if(dx != null) {
|
|
// return dx.value;
|
|
// }
|
|
// return 0;
|
|
//}
|
|
|
|
//public int getChannelValueByAddress(int address) {
|
|
// DMXChannel dx = getDMXChannelByAddress(address);
|
|
// if(dx != null) {
|
|
// return dx.value;
|
|
// }
|
|
// return 0;
|
|
//}
|
|
|
|
@Override
|
|
public String toString() {
|
|
return "BuntiDMXDevice " + getDeviceID() + ", " + getDeviceName();
|
|
}
|
|
|
|
|
|
|
|
}
|