From 4f288256e88404d45af45bf255c4f0fbd0ba37b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lucas=20Ple=C3=9F?= Date: Mon, 26 Mar 2012 23:02:42 +0200 Subject: [PATCH] moved model classes to their packages --- .../bunti/{ => dmx}/model/BuntiDMXDevice.java | 7 +- .../ctdo/bunti/{ => dmx}/model/Par56Spot.java | 3 +- .../bunti/{ => dmx}/model/Strobe1500.java | 3 +- .../de/ctdo/bunti/ethersex/model/Lampel.java | 61 +++++++++++++ src/main/java/de/ctdo/bunti/model/Lampel.java | 89 ------------------- 5 files changed, 67 insertions(+), 96 deletions(-) rename src/main/java/de/ctdo/bunti/{ => dmx}/model/BuntiDMXDevice.java (94%) rename src/main/java/de/ctdo/bunti/{ => dmx}/model/Par56Spot.java (97%) rename src/main/java/de/ctdo/bunti/{ => dmx}/model/Strobe1500.java (97%) create mode 100644 src/main/java/de/ctdo/bunti/ethersex/model/Lampel.java delete mode 100644 src/main/java/de/ctdo/bunti/model/Lampel.java diff --git a/src/main/java/de/ctdo/bunti/model/BuntiDMXDevice.java b/src/main/java/de/ctdo/bunti/dmx/model/BuntiDMXDevice.java similarity index 94% rename from src/main/java/de/ctdo/bunti/model/BuntiDMXDevice.java rename to src/main/java/de/ctdo/bunti/dmx/model/BuntiDMXDevice.java index 0a281fb..8daf9d9 100644 --- a/src/main/java/de/ctdo/bunti/model/BuntiDMXDevice.java +++ b/src/main/java/de/ctdo/bunti/dmx/model/BuntiDMXDevice.java @@ -1,8 +1,9 @@ -package de.ctdo.bunti.model; +package de.ctdo.bunti.dmx.model; import de.ctdo.bunti.dmx.DMX; import de.ctdo.bunti.dmx.model.DMXChannel; import de.ctdo.bunti.dmx.DMXChannels; +import de.ctdo.bunti.model.BuntiDevice; import org.codehaus.jackson.annotate.JsonIgnore; import org.hibernate.annotations.Entity; @@ -49,7 +50,7 @@ public abstract class BuntiDMXDevice extends BuntiDevice { * @param value The channel value to set. * @return True on success, otherwise false */ - protected final boolean setChannelValueByName(String name, int value) { + public final boolean setChannelValueByName(String name, int value) { DMXChannel dx = dmxChannels.getChannelByName(name); if (dx != null) { dx.setValue(DMX.sanitizeDMXValue(value)); @@ -66,7 +67,7 @@ public abstract class BuntiDMXDevice extends BuntiDevice { */ @JsonIgnore @Transient - protected final int getChannelValueByName(String name) { + public final int getChannelValueByName(String name) { DMXChannel dx = dmxChannels.getChannelByName(name); if (dx != null) { return dx.getValue(); diff --git a/src/main/java/de/ctdo/bunti/model/Par56Spot.java b/src/main/java/de/ctdo/bunti/dmx/model/Par56Spot.java similarity index 97% rename from src/main/java/de/ctdo/bunti/model/Par56Spot.java rename to src/main/java/de/ctdo/bunti/dmx/model/Par56Spot.java index b5b7f69..c732b4f 100644 --- a/src/main/java/de/ctdo/bunti/model/Par56Spot.java +++ b/src/main/java/de/ctdo/bunti/dmx/model/Par56Spot.java @@ -1,7 +1,6 @@ -package de.ctdo.bunti.model; +package de.ctdo.bunti.dmx.model; import de.ctdo.bunti.dmx.DMX; -import de.ctdo.bunti.dmx.model.DMXChannel; import org.codehaus.jackson.annotate.JsonIgnore; import javax.persistence.Entity; diff --git a/src/main/java/de/ctdo/bunti/model/Strobe1500.java b/src/main/java/de/ctdo/bunti/dmx/model/Strobe1500.java similarity index 97% rename from src/main/java/de/ctdo/bunti/model/Strobe1500.java rename to src/main/java/de/ctdo/bunti/dmx/model/Strobe1500.java index 4cbb134..7eabdad 100644 --- a/src/main/java/de/ctdo/bunti/model/Strobe1500.java +++ b/src/main/java/de/ctdo/bunti/dmx/model/Strobe1500.java @@ -1,7 +1,6 @@ -package de.ctdo.bunti.model; +package de.ctdo.bunti.dmx.model; import de.ctdo.bunti.dmx.DMX; -import de.ctdo.bunti.dmx.model.DMXChannel; import org.codehaus.jackson.annotate.JsonIgnore; import javax.persistence.Entity; diff --git a/src/main/java/de/ctdo/bunti/ethersex/model/Lampel.java b/src/main/java/de/ctdo/bunti/ethersex/model/Lampel.java new file mode 100644 index 0000000..6e2b338 --- /dev/null +++ b/src/main/java/de/ctdo/bunti/ethersex/model/Lampel.java @@ -0,0 +1,61 @@ +package de.ctdo.bunti.ethersex.model; + +import de.ctdo.bunti.dmx.DMX; +import de.ctdo.bunti.dmx.model.DMXChannel; +import de.ctdo.bunti.model.BuntiDevice; +import org.codehaus.jackson.annotate.JsonIgnore; + +import javax.persistence.Entity; +import javax.persistence.Transient; +import java.util.HashMap; +import java.util.Map; + +@Entity +public class Lampel extends BuntiEthersexDevice { + private static final String PORTC = "2"; // TODO: rausfinden welche PortNummer das ist + public static final int LAMPEL_OFF = 0x00; + public static final int LAMPEL_RED = 0x80; // TODO: rausfinden ob die Reihenfolge stimmt + public static final int LAMPEL_YELLOW = 0x40; + public static final int LAMPEL_GREEN = 0x20; + + public Lampel() { + addPort(PORTC); + } + + + @Transient + public int getLampelState() { + return getPortByName(PORTC); + } + + public void setLampelState(int value) { + setPortByName(PORTC, value); + } + + + @Override + public final void switchOff() { + setPortByName(PORTC, LAMPEL_OFF); + } + + @Override + public final void switchOn() { + setPortByName(PORTC, LAMPEL_GREEN | LAMPEL_RED | LAMPEL_YELLOW ); + } + + + + @Override + public final String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("Lampel "); + sb.append(getId()); + sb.append(", "); + sb.append(getDeviceName()); + sb.append(" ["); + sb.append(getPortByName(PORTC)); + sb.append("]"); + return sb.toString(); + } + +} diff --git a/src/main/java/de/ctdo/bunti/model/Lampel.java b/src/main/java/de/ctdo/bunti/model/Lampel.java deleted file mode 100644 index 8080986..0000000 --- a/src/main/java/de/ctdo/bunti/model/Lampel.java +++ /dev/null @@ -1,89 +0,0 @@ -package de.ctdo.bunti.model; - -import de.ctdo.bunti.dmx.DMX; -import de.ctdo.bunti.dmx.model.DMXChannel; -import org.codehaus.jackson.annotate.JsonIgnore; - -import javax.persistence.Entity; -import javax.persistence.Transient; -import java.util.HashMap; -import java.util.Map; - -@Entity -public class Lampel extends BuntiDevice { - - private static final String CHANNEL_RED = "red"; - private static final String CHANNEL_GREEN = "green"; - private static final String CHANNEL_YELLOW = "yellow"; - private static final Map values = new HashMap(); - - @Override - public final void switchOff() { - setValueByName(CHANNEL_GREEN, false); - setValueByName(CHANNEL_YELLOW, false); - setValueByName(CHANNEL_RED, false); - } - - @Override - public final void switchOn() { - setValueByName(CHANNEL_GREEN, true); - setValueByName(CHANNEL_YELLOW, true); - setValueByName(CHANNEL_RED, true); - } - - protected final boolean setValueByName(String name, boolean value) { - if (values.containsKey(name)) { - values.put(name, value); - return true; - } - return false; - } - - @Transient - protected final boolean getValueByName(String name) { - if (values.containsKey(name)) { - return values.get(name); - } - return false; - } - - @Override - public boolean setValuesFromOptions(Map options) { - for (Map.Entry opt : options.entrySet()) { - try { - Boolean value = Boolean.parseBoolean(opt.getValue().toString()); - - if (!setValueByName(opt.getKey(), value)) { - return false; - } - } catch (Exception e) { - return false; - } - } - return true; - } - - @Override - public Map getOptions() { - return null; - } - - - @Override - public final String toString() { - StringBuilder sb = new StringBuilder(); - sb.append("Lampel "); - sb.append(getId()); - sb.append(", "); - sb.append(getDeviceName()); - sb.append(" ["); - sb.append(getValueByName(CHANNEL_RED)); - sb.append(","); - sb.append(getValueByName(CHANNEL_YELLOW)); - sb.append(","); - sb.append(getValueByName(CHANNEL_GREEN)); - sb.append("]"); - return sb.toString(); - } - -}