From 1fcd320aca1ca0d13288af87e2e9cd082d33ca83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lucas=20Ple=C3=9F?= Date: Fri, 2 Mar 2012 22:09:43 +0100 Subject: [PATCH] added missing files --- .../de/ctdo/bunti/dao/BuntiDevicesDAO.java | 11 +++ .../ctdo/bunti/dao/BuntiDevicesDAOImpl.java | 78 +++++++++++++++ .../src/main/java/de/ctdo/bunti/dmx/DMX.java | 21 ++++ .../java/de/ctdo/bunti/dmx/DMXChannel.java | 13 +++ .../de/ctdo/bunti/model/BuntiDMXDevice.java | 99 +++++++++++++++++++ .../java/de/ctdo/bunti/model/BuntiDevice.java | 22 +++++ 6 files changed, 244 insertions(+) create mode 100644 bunti_server/src/main/java/de/ctdo/bunti/dao/BuntiDevicesDAO.java create mode 100644 bunti_server/src/main/java/de/ctdo/bunti/dao/BuntiDevicesDAOImpl.java create mode 100644 bunti_server/src/main/java/de/ctdo/bunti/dmx/DMX.java create mode 100644 bunti_server/src/main/java/de/ctdo/bunti/dmx/DMXChannel.java create mode 100644 bunti_server/src/main/java/de/ctdo/bunti/model/BuntiDMXDevice.java create mode 100644 bunti_server/src/main/java/de/ctdo/bunti/model/BuntiDevice.java diff --git a/bunti_server/src/main/java/de/ctdo/bunti/dao/BuntiDevicesDAO.java b/bunti_server/src/main/java/de/ctdo/bunti/dao/BuntiDevicesDAO.java new file mode 100644 index 0000000..c8d9388 --- /dev/null +++ b/bunti_server/src/main/java/de/ctdo/bunti/dao/BuntiDevicesDAO.java @@ -0,0 +1,11 @@ +package de.ctdo.bunti.dao; + +import java.util.List; + +import de.ctdo.bunti.model.*; + +public interface BuntiDevicesDAO { + + public List getAllDMXDevices(); + +} diff --git a/bunti_server/src/main/java/de/ctdo/bunti/dao/BuntiDevicesDAOImpl.java b/bunti_server/src/main/java/de/ctdo/bunti/dao/BuntiDevicesDAOImpl.java new file mode 100644 index 0000000..d737110 --- /dev/null +++ b/bunti_server/src/main/java/de/ctdo/bunti/dao/BuntiDevicesDAOImpl.java @@ -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 devices = new ArrayList(); + + 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 getAllDMXDevices() { + List liste = new ArrayList(); + for (BuntiDevice device : devices) { + if( device.getClass().equals(BuntiDMXDevice.class) ) { + liste.add((BuntiDMXDevice) device); + } + } + return liste; + } + +} diff --git a/bunti_server/src/main/java/de/ctdo/bunti/dmx/DMX.java b/bunti_server/src/main/java/de/ctdo/bunti/dmx/DMX.java new file mode 100644 index 0000000..5986b0c --- /dev/null +++ b/bunti_server/src/main/java/de/ctdo/bunti/dmx/DMX.java @@ -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); + } + +} diff --git a/bunti_server/src/main/java/de/ctdo/bunti/dmx/DMXChannel.java b/bunti_server/src/main/java/de/ctdo/bunti/dmx/DMXChannel.java new file mode 100644 index 0000000..15b0623 --- /dev/null +++ b/bunti_server/src/main/java/de/ctdo/bunti/dmx/DMXChannel.java @@ -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; + } +} diff --git a/bunti_server/src/main/java/de/ctdo/bunti/model/BuntiDMXDevice.java b/bunti_server/src/main/java/de/ctdo/bunti/model/BuntiDMXDevice.java new file mode 100644 index 0000000..8375ceb --- /dev/null +++ b/bunti_server/src/main/java/de/ctdo/bunti/model/BuntiDMXDevice.java @@ -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 dmxValues = new ArrayList(); + + 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); + } + } + +} diff --git a/bunti_server/src/main/java/de/ctdo/bunti/model/BuntiDevice.java b/bunti_server/src/main/java/de/ctdo/bunti/model/BuntiDevice.java new file mode 100644 index 0000000..b55c63f --- /dev/null +++ b/bunti_server/src/main/java/de/ctdo/bunti/model/BuntiDevice.java @@ -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; + } + + +}