clean up
This commit is contained in:
parent
d5084b1290
commit
99ae75b88f
|
@ -2,6 +2,7 @@ package de.ctdo.bunti.dao;
|
|||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
|
@ -28,7 +29,6 @@ public class BuntiDevicesDAOImpl implements BuntiDevicesDAO {
|
|||
devices.add(new Par56Spot(deviceID++, 11, "Par56 Lampe 3"));
|
||||
devices.add(new Par56Spot(deviceID++, 16, "Par56 Lampe 4"));
|
||||
devices.add(new Strobe1500(deviceID++, 21, "Stroboskop 1"));
|
||||
|
||||
devices.add(new Par56Spot(deviceID++, 508, "Par56 Lampe 5"));
|
||||
logger.debug("added dummy devices in DAO");
|
||||
}
|
||||
|
@ -36,13 +36,18 @@ public class BuntiDevicesDAOImpl implements BuntiDevicesDAO {
|
|||
|
||||
@Override
|
||||
public final Collection<BuntiDMXDevice> getAllDMXDevices() {
|
||||
List<BuntiDMXDevice> liste = new ArrayList<BuntiDMXDevice>();
|
||||
List<BuntiDMXDevice> list = new ArrayList<BuntiDMXDevice>();
|
||||
for (BuntiDevice device : devices) {
|
||||
if( device instanceof BuntiDMXDevice ) {
|
||||
liste.add((BuntiDMXDevice) device);
|
||||
list.add((BuntiDMXDevice) device);
|
||||
}
|
||||
}
|
||||
return liste;
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Collection<BuntiDevice> getAllDevices() {
|
||||
return Collections.unmodifiableCollection(devices);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,18 +1,20 @@
|
|||
package de.ctdo.bunti.model;
|
||||
|
||||
import de.ctdo.bunti.dmx.DMX;
|
||||
import de.ctdo.bunti.dmx.DMXChannel;
|
||||
import de.ctdo.bunti.dmx.DMXChannels;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import de.ctdo.bunti.dmx.*;
|
||||
|
||||
public abstract class BuntiDMXDevice extends BuntiDevice {
|
||||
private int startAddress;
|
||||
private long lastSendOut;
|
||||
private DMXChannels dmxChannels = new DMXChannels();
|
||||
private final DMXChannels dmxChannels = new DMXChannels();
|
||||
|
||||
public BuntiDMXDevice(int deviceId, int startAddress, String name) {
|
||||
super(deviceId,name);
|
||||
super(deviceId, name);
|
||||
this.startAddress = startAddress;
|
||||
}
|
||||
|
||||
|
@ -34,13 +36,14 @@ public abstract class BuntiDMXDevice extends BuntiDevice {
|
|||
|
||||
/**
|
||||
* Set channel value by given channel name.
|
||||
*
|
||||
* @param name The channel name to change the value.
|
||||
* @param value The channel value to set.
|
||||
* @return True on success, otherwise false
|
||||
*/
|
||||
protected final boolean setChannelValueByName(String name, int value) {
|
||||
DMXChannel dx = dmxChannels.getChannelByName(name);
|
||||
if(dx != null) {
|
||||
if (dx != null) {
|
||||
dx.setValue(DMX.sanitizeDMXValue(value));
|
||||
lastChangedNow();
|
||||
return true;
|
||||
|
@ -50,24 +53,29 @@ public abstract class BuntiDMXDevice extends BuntiDevice {
|
|||
|
||||
/**
|
||||
* Returns the channel value identified by channel name.
|
||||
*
|
||||
* @param name The channel name to get the value from.
|
||||
* @return The desired channel value.
|
||||
*/
|
||||
protected final int getChannelValueByName(String name) {
|
||||
DMXChannel dx = dmxChannels.getChannelByName(name);
|
||||
if(dx != null) {
|
||||
if (dx != null) {
|
||||
return dx.getValue();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public Map<Integer,Integer> getChannelData() {
|
||||
Map<Integer,Integer> map = new HashMap<Integer, Integer>();
|
||||
/**
|
||||
* Collect the DMX Channel Data with correct DMX512 calculated offsets
|
||||
* @return The channel data with startaddress+offset of every channel
|
||||
*/
|
||||
public Map<Integer, Integer> getChannelData() {
|
||||
Map<Integer, Integer> map = new HashMap<Integer, Integer>();
|
||||
|
||||
for (DMXChannel channel : dmxChannels.getAllChannels()) {
|
||||
int index = channel.getOffset() + startAddress + DMX.DMX_STARTADDRESS_OFFSET;
|
||||
|
||||
if(index >= DMX.DMX_CHANNELS_MIN && index <= DMX.DMX_CHANNELS_MAX){
|
||||
if (index >= DMX.DMX_CHANNELS_MIN && index <= DMX.DMX_CHANNELS_MAX) {
|
||||
map.put(index, channel.getValue());
|
||||
}
|
||||
}
|
||||
|
@ -82,7 +90,7 @@ public abstract class BuntiDMXDevice extends BuntiDevice {
|
|||
try {
|
||||
int value = Integer.parseInt(opt.getValue().toString());
|
||||
|
||||
if(!setChannelValueByName(opt.getKey(), value)) {
|
||||
if (!setChannelValueByName(opt.getKey(), value)) {
|
||||
return false;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
|
@ -92,7 +100,13 @@ public abstract class BuntiDMXDevice extends BuntiDevice {
|
|||
return true;
|
||||
}
|
||||
|
||||
public final boolean addChannel(DMXChannel channel){
|
||||
/**
|
||||
* Add a channel to this DMX Device
|
||||
* used internally by subclasses to define their structure
|
||||
* @param channel DMXChannel to add (name and offset)
|
||||
* @return True on success, false otherwise.
|
||||
*/
|
||||
public final boolean addChannel(DMXChannel channel) {
|
||||
return dmxChannels.addChannel(channel);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@ public abstract class BuntiDevice {
|
|||
}
|
||||
|
||||
public BuntiDevice(int deviceId, String deviceName) {
|
||||
this(deviceId,deviceName,System.currentTimeMillis());
|
||||
this(deviceId, deviceName, System.currentTimeMillis());
|
||||
}
|
||||
|
||||
public final int getDeviceId() {
|
||||
|
@ -49,6 +49,7 @@ public abstract class BuntiDevice {
|
|||
|
||||
/**
|
||||
* The the internal options corresponding to the given Key Value Map
|
||||
*
|
||||
* @param options The options Map.
|
||||
* @return True on success. False otherwise.
|
||||
*/
|
||||
|
|
|
@ -2,7 +2,7 @@ package de.ctdo.bunti.model;
|
|||
|
||||
import java.util.Map;
|
||||
|
||||
public class BuntiSwitchingDevice extends BuntiDevice {
|
||||
public abstract class BuntiSwitchingDevice extends BuntiDevice {
|
||||
|
||||
|
||||
public BuntiSwitchingDevice(int deviceId, String deviceName, long lastChanged) {
|
||||
|
@ -13,17 +13,6 @@ public class BuntiSwitchingDevice extends BuntiDevice {
|
|||
super(deviceId, deviceName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void switchOff() {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void switchOn() {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public final boolean setValuesFromOptions(Map<String, Object> options) {
|
||||
|
@ -31,6 +20,4 @@ public class BuntiSwitchingDevice extends BuntiDevice {
|
|||
return false;
|
||||
}
|
||||
|
||||
// zum Beispiel Lampel, also nen Hostname und HTTP Krams hier rein
|
||||
|
||||
}
|
||||
|
|
|
@ -24,18 +24,23 @@ public class Par56Spot extends BuntiDMXDevice {
|
|||
public final void setColorRed(int value) {
|
||||
setChannelValueByName(CHANNEL_RED, value);
|
||||
}
|
||||
|
||||
public final void setColorGreen(int value) {
|
||||
setChannelValueByName(CHANNEL_GREEN, value);
|
||||
}
|
||||
|
||||
public final void setColorBlue(int value) {
|
||||
setChannelValueByName(CHANNEL_BLUE, value);
|
||||
}
|
||||
|
||||
public final int getColorRed() {
|
||||
return getChannelValueByName(CHANNEL_RED);
|
||||
}
|
||||
|
||||
public final int getColorGreen() {
|
||||
return getChannelValueByName(CHANNEL_GREEN);
|
||||
}
|
||||
|
||||
public final int getColorBlue() {
|
||||
return getChannelValueByName(CHANNEL_BLUE);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue