moved model classes to their packages

This commit is contained in:
Lucas Pleß 2012-03-26 23:02:42 +02:00
parent 41bfcd33c3
commit 4f288256e8
5 changed files with 67 additions and 96 deletions

View File

@ -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.DMX;
import de.ctdo.bunti.dmx.model.DMXChannel; import de.ctdo.bunti.dmx.model.DMXChannel;
import de.ctdo.bunti.dmx.DMXChannels; import de.ctdo.bunti.dmx.DMXChannels;
import de.ctdo.bunti.model.BuntiDevice;
import org.codehaus.jackson.annotate.JsonIgnore; import org.codehaus.jackson.annotate.JsonIgnore;
import org.hibernate.annotations.Entity; import org.hibernate.annotations.Entity;
@ -49,7 +50,7 @@ public abstract class BuntiDMXDevice extends BuntiDevice {
* @param value The channel value to set. * @param value The channel value to set.
* @return True on success, otherwise false * @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); DMXChannel dx = dmxChannels.getChannelByName(name);
if (dx != null) { if (dx != null) {
dx.setValue(DMX.sanitizeDMXValue(value)); dx.setValue(DMX.sanitizeDMXValue(value));
@ -66,7 +67,7 @@ public abstract class BuntiDMXDevice extends BuntiDevice {
*/ */
@JsonIgnore @JsonIgnore
@Transient @Transient
protected final int getChannelValueByName(String name) { public final int getChannelValueByName(String name) {
DMXChannel dx = dmxChannels.getChannelByName(name); DMXChannel dx = dmxChannels.getChannelByName(name);
if (dx != null) { if (dx != null) {
return dx.getValue(); return dx.getValue();

View File

@ -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.DMX;
import de.ctdo.bunti.dmx.model.DMXChannel;
import org.codehaus.jackson.annotate.JsonIgnore; import org.codehaus.jackson.annotate.JsonIgnore;
import javax.persistence.Entity; import javax.persistence.Entity;

View File

@ -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.DMX;
import de.ctdo.bunti.dmx.model.DMXChannel;
import org.codehaus.jackson.annotate.JsonIgnore; import org.codehaus.jackson.annotate.JsonIgnore;
import javax.persistence.Entity; import javax.persistence.Entity;

View File

@ -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();
}
}

View File

@ -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<String, Boolean> values = new HashMap<String, Boolean>();
@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<String, Object> options) {
for (Map.Entry<String, Object> 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<String, Object> 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();
}
}