added missing files

This commit is contained in:
Lucas Pleß 2012-03-02 22:09:43 +01:00
parent 6609d1a44b
commit 1fcd320aca
6 changed files with 244 additions and 0 deletions

View File

@ -0,0 +1,11 @@
package de.ctdo.bunti.dao;
import java.util.List;
import de.ctdo.bunti.model.*;
public interface BuntiDevicesDAO {
public List<BuntiDMXDevice> getAllDMXDevices();
}

View File

@ -0,0 +1,78 @@
package de.ctdo.bunti.dao;
import java.util.ArrayList;
import java.util.List;
import de.ctdo.bunti.dmx.DMXChannel;
import de.ctdo.bunti.model.BuntiDMXDevice;
import de.ctdo.bunti.model.BuntiDevice;
public class BuntiDevicesDAOImpl implements BuntiDevicesDAO {
List<BuntiDevice> devices = new ArrayList<BuntiDevice>();
public BuntiDevicesDAOImpl() {
addDummyDevices();
}
private void addDummyDevices() {
BuntiDMXDevice d1 = new BuntiDMXDevice();
d1.setDeviceID(1);
d1.setDeviceName("Par65 Lampe 1");
d1.setStartAddress(1);
d1.addChannel(new DMXChannel(0, "mode"));
d1.addChannel(new DMXChannel(1, "red"));
d1.addChannel(new DMXChannel(2, "green"));
d1.addChannel(new DMXChannel(3, "blue"));
d1.addChannel(new DMXChannel(4, "speed"));
devices.add(d1);
d1 = new BuntiDMXDevice();
d1.setDeviceID(6);
d1.setDeviceName("Par65 Lampe 2");
d1.setStartAddress(1);
d1.addChannel(new DMXChannel(0, "mode"));
d1.addChannel(new DMXChannel(1, "red"));
d1.addChannel(new DMXChannel(2, "green"));
d1.addChannel(new DMXChannel(3, "blue"));
d1.addChannel(new DMXChannel(4, "speed"));
devices.add(d1);
d1 = new BuntiDMXDevice();
d1.setDeviceID(11);
d1.setDeviceName("Par65 Lampe 4");
d1.setStartAddress(1);
d1.addChannel(new DMXChannel(0, "mode"));
d1.addChannel(new DMXChannel(1, "red"));
d1.addChannel(new DMXChannel(2, "green"));
d1.addChannel(new DMXChannel(3, "blue"));
d1.addChannel(new DMXChannel(4, "speed"));
devices.add(d1);
d1 = new BuntiDMXDevice();
d1.setDeviceID(16);
d1.setDeviceName("Par65 Lampe 4");
d1.setStartAddress(1);
d1.addChannel(new DMXChannel(0, "mode"));
d1.addChannel(new DMXChannel(1, "red"));
d1.addChannel(new DMXChannel(2, "green"));
d1.addChannel(new DMXChannel(3, "blue"));
d1.addChannel(new DMXChannel(4, "speed"));
devices.add(d1);
}
@Override
public List<BuntiDMXDevice> getAllDMXDevices() {
List<BuntiDMXDevice> liste = new ArrayList<BuntiDMXDevice>();
for (BuntiDevice device : devices) {
if( device.getClass().equals(BuntiDMXDevice.class) ) {
liste.add((BuntiDMXDevice) device);
}
}
return liste;
}
}

View File

@ -0,0 +1,21 @@
package de.ctdo.bunti.dmx;
public class DMX {
public static int DMX_CHANNELS_MAX = 511;
public static int DMX_CHANNELS_MIN = 0;
public static int DMX_CHANNEL_VALUE_MAX = 255;
public static int DMX_CHANNEL_VALUE_MIN = 0;
public static int sanitizeDMXValue(int value) {
if(value < DMX_CHANNEL_VALUE_MIN) value = DMX_CHANNEL_VALUE_MIN;
if(value > DMX_CHANNEL_VALUE_MAX) value = DMX_CHANNEL_VALUE_MAX;
return value;
}
public static boolean checkChannelBoundaries(int channel) {
return (channel >= DMX_CHANNELS_MIN && channel <= DMX_CHANNELS_MAX);
}
}

View File

@ -0,0 +1,13 @@
package de.ctdo.bunti.dmx;
public class DMXChannel {
public int offset;
public String description;
public int value;
public DMXChannel(int offset, String description) {
this.description = description;
this.offset = offset;
this.value = 0;
}
}

View File

@ -0,0 +1,99 @@
package de.ctdo.bunti.model;
import java.util.*;
import de.ctdo.bunti.dmx.*;
public class BuntiDMXDevice extends BuntiDevice {
int startAddress;
List<DMXChannel> dmxValues = new ArrayList<DMXChannel>();
public DMXChannel getDMXChannelByName(String channel) {
for (DMXChannel dx : dmxValues) {
if(channel.equals(dx.description)) {
return dx;
}
}
return null;
}
public DMXChannel getDMXChannelByOffset(int offset) {
for (DMXChannel dx : dmxValues) {
if(offset == dx.offset) {
return dx;
}
}
return null;
}
// public DMXChannel getDMXChannelByAddress(int address) {
// int offset = address - startAddress;
// return getDMXChannelByOffset(offset);
// }
public void setChannelValueByName(String name, int value) {
DMXChannel dx = getDMXChannelByName(name);
if(dx != null) {
dx.value = DMX.sanitizeDMXValue(value);
}
}
// 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 getChannelValueByName(String name) {
DMXChannel dx = getDMXChannelByName(name);
if(dx != null) {
return dx.value;
}
return 0;
}
// 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;
// }
public int getStartAddress() {
return startAddress;
}
public void setStartAddress(int startAddress) {
this.startAddress = startAddress;
}
public void addChannel(DMXChannel channel) {
dmxValues.add(channel);
}
public void removeChannel(int offset) {
DMXChannel dx = getDMXChannelByOffset(offset);
if(dx != null) {
dmxValues.remove(offset);
}
}
}

View File

@ -0,0 +1,22 @@
package de.ctdo.bunti.model;
public class BuntiDevice {
int deviceID;
String deviceName;
public int getDeviceID() {
return deviceID;
}
public void setDeviceID(int deviceID) {
this.deviceID = deviceID;
}
public String getDeviceName() {
return deviceName;
}
public void setDeviceName(String deviceName) {
this.deviceName = deviceName;
}
}