extended controller and created a test web gui

extended BuntiDevice with a picture Path
This commit is contained in:
Lucas Pleß 2012-03-14 00:57:00 +01:00
parent 9c54e5d73c
commit 71421bd559
12 changed files with 165 additions and 111 deletions

View File

@ -123,6 +123,13 @@
<version>4.10</version>
</dependency>
<dependency>
<groupId>org.easymock</groupId>
<artifactId>easymock</artifactId>
<version>3.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-server</artifactId>

View File

@ -31,11 +31,11 @@ public class ByteUtils {
this.data = data;
}
public static final int byteToUint(byte b) {
public static int byteToUint(byte b) {
return (b < 0 ? BYTE_OVERFLOW + b : b);
}
public static final byte uintToByte(int i) {
public static byte uintToByte(int i) {
return (byte)(i & BYTE_MAX);
}

View File

@ -119,8 +119,8 @@ public class ArtDmxPacket extends ArtNetPacket {
/**
* Sets universe and subnet into data array. Needed because subnet and universe are both 4 bit and share one byte
* @param subnetID
* @param universeID
* @param subnetID The ArtNet Subnet ID from 0 to 3
* @param universeID The ArtNet Universe ID from 0 to 3
*/
private void setUniverse(int subnetID, int universeID) {
getData().setInt16LE(subnetID << HALF_BYTE | universeID, OFFSET_UNIVERSE);

View File

@ -45,6 +45,7 @@ public class DMXMixerImpl implements DMXMixer, ApplicationListener<DeviceChanged
}
if (hasDataChanged) {
LOGGER.debug("sending DMX Data");
artNetSender.sendDMXData(dmxMap, artNetDeviceAddress);
hasDataChanged = false;
}

View File

@ -10,6 +10,7 @@ import java.util.Map;
public abstract class BuntiDevice {
private int deviceId;
private String deviceName;
private String picture;
public BuntiDevice(int deviceId, String deviceName) {
this.deviceId = deviceId;
@ -54,6 +55,22 @@ public abstract class BuntiDevice {
this.deviceName = deviceName;
}
/**
* Get the relative URL to the picture of this device
* @return the relative URL to the picture
*/
public final String getPicture() {
return picture;
}
/**
* Get the relative URL to the picture of this device
* @param picture The relative URL to the picture
*/
public final void setPicture(String picture) {
this.picture = picture;
}
/**
* Switch this device off.
*/
@ -72,4 +89,5 @@ public abstract class BuntiDevice {
*/
public abstract boolean setValuesFromOptions(Map<String, Object> options);
}

View File

@ -21,45 +21,45 @@ public class Par56Spot extends BuntiDMXDevice {
addChannel(new DMXChannel(offset, CHANNEL_SPEED));
}
public final void setColorRed(int value) {
public final void setRed(int value) {
setChannelValueByName(CHANNEL_RED, value);
}
public final void setColorGreen(int value) {
public final void setGreen(int value) {
setChannelValueByName(CHANNEL_GREEN, value);
}
public final void setColorBlue(int value) {
public final void setBlue(int value) {
setChannelValueByName(CHANNEL_BLUE, value);
}
public final int getColorRed() {
public final int getRed() {
return getChannelValueByName(CHANNEL_RED);
}
public final int getColorGreen() {
public final int getGreen() {
return getChannelValueByName(CHANNEL_GREEN);
}
public final int getColorBlue() {
public final int getBlue() {
return getChannelValueByName(CHANNEL_BLUE);
}
@Override
public final void switchOff() {
setChannelValueByName(CHANNEL_MODE, DMX.DMX_CHANNEL_VALUE_MIN);
setColorRed(DMX.DMX_CHANNEL_VALUE_MIN);
setColorGreen(DMX.DMX_CHANNEL_VALUE_MIN);
setColorBlue(DMX.DMX_CHANNEL_VALUE_MIN);
setRed(DMX.DMX_CHANNEL_VALUE_MIN);
setGreen(DMX.DMX_CHANNEL_VALUE_MIN);
setBlue(DMX.DMX_CHANNEL_VALUE_MIN);
setChannelValueByName(CHANNEL_SPEED, DMX.DMX_CHANNEL_VALUE_MIN);
}
@Override
public final void switchOn() {
setChannelValueByName(CHANNEL_MODE, DMX.DMX_CHANNEL_VALUE_MIN);
setColorRed(DMX.DMX_CHANNEL_VALUE_MAX);
setColorGreen(DMX.DMX_CHANNEL_VALUE_MAX);
setColorBlue(DMX.DMX_CHANNEL_VALUE_MAX);
setRed(DMX.DMX_CHANNEL_VALUE_MAX);
setGreen(DMX.DMX_CHANNEL_VALUE_MAX);
setBlue(DMX.DMX_CHANNEL_VALUE_MAX);
setChannelValueByName(CHANNEL_SPEED, DMX.DMX_CHANNEL_VALUE_MIN);
}
@ -71,11 +71,11 @@ public class Par56Spot extends BuntiDMXDevice {
sb.append(", ");
sb.append(getDeviceName());
sb.append(" [");
sb.append(getColorRed());
sb.append(getRed());
sb.append(",");
sb.append(getColorGreen());
sb.append(getGreen());
sb.append(",");
sb.append(getColorBlue());
sb.append(getBlue());
sb.append("]");
return sb.toString();
}

View File

@ -30,18 +30,6 @@ public class RestController {
this.controller = controller;
}
@RequestMapping(value = "/devices2", method = RequestMethod.GET)
public @ResponseBody DeviceUpdate testGet() {
DeviceUpdate update = new DeviceUpdate();
update.setDeviceId(23);
Map<String, Object> options = new HashMap<String, Object>();
options.put("red", 111);
options.put("green", 2);
options.put("blue", 33);
update.setOptions(options);
return update;
}
@RequestMapping(value = "/devices", method = RequestMethod.GET)
public @ResponseBody Collection<BuntiDevice> getAll() {
LOGGER.info("handle GET /devices request");
@ -54,37 +42,26 @@ public class RestController {
return controller.getDeviceById(id);
}
@RequestMapping(value = "/devices/{id}", method = RequestMethod.PUT)
public String setDeviceById(@PathVariable("id") int id, @RequestBody Map<String, Object> update) {
@RequestMapping(value = "/devices/{id}", method = RequestMethod.POST)
public @ResponseBody BuntiDevice setDeviceById(@PathVariable("id") int id, @RequestBody DeviceUpdate update) {
LOGGER.info("handle PUT /devices/" + id + " request update=" + update.toString() );
controller.updateDeviceData(id, update);
return "redirect:devices/" + id;
controller.updateDeviceData(id, update.getOptions());
return controller.getDeviceById(id);
}
@RequestMapping(value = "/devices", method = RequestMethod.PUT)
public String setDevices(@RequestBody ArrayList<DeviceUpdate> updates) {
@RequestMapping(value = "/devices", method = RequestMethod.POST)
public String setDevices(@RequestBody DeviceUpdates updates) {
LOGGER.info("handle PUT /devices" + " request update=" + updates.toString() );
for (DeviceUpdate update: updates) {
for (DeviceUpdate update: updates.getUpdates()) {
LOGGER.info("Update deviceId=" + update.getDeviceId());
controller.updateDeviceData(update.getDeviceId(), update.getOptions());
}
return "redirect:devices";
}
@RequestMapping(value = "/devices2", method = RequestMethod.PUT)
public String setDevices2(@RequestBody DeviceUpdate update) {
LOGGER.info("handle PUT /devices" + " request update=" + update.toString() );
LOGGER.info("Update deviceId=" + update.getDeviceId());
controller.updateDeviceData(update.getDeviceId(), update.getOptions());
return "redirect:devices";
return "bla";
}
}

View File

@ -1,10 +1,29 @@
package de.ctdo.bunti.webmodel;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
public class DeviceUpdates {
private long timeStamp = 0;
private List<DeviceUpdate> updates = new ArrayList<DeviceUpdate>();
public List<DeviceUpdate> getUpdates() {
return updates;
}
public void setUpdates(List<DeviceUpdate> updates) {
this.updates = updates;
}
public long getTimeStamp() {
return timeStamp;
}
public void setTimeStamp(long timeStamp) {
this.timeStamp = timeStamp;
}
}

View File

@ -12,7 +12,7 @@
</appender>
<logger name="org.springframework">
<level value="debug" />
<level value="info" />
</logger>

View File

@ -14,36 +14,57 @@
<script type="text/javascript" src="<c:url value="/resources/js/jquery-ui-1.8.18.custom.min.js" />"></script>
<script type="text/javascript">
var ws;
var dmxData;
$(document).ready(
function() {
var dataChanged = false;
var par56eins = $.parseJSON('{"deviceId":1, "options": {"red":0,"blue":0,"green":0} }');
function sendData(data) {
$.ajax({
type: 'POST',
url: "/control/devices/1",
contentType: "application/json",
dataType: "json",
data: JSON.stringify(data)
});
}
var senden = function sendOutAllDevices() {
if(dataChanged) {
dataChanged = false;
sendData(par56eins);
}
};
// vielleicht baut man lieber was mit setTimeout und setzt das jeweils neu wenn man daten ändert
// das könnte den Browser entlasten, sofern den das 200ms Aufrufen überhaupt stört :D
window.setInterval(senden, 200);
$("#slider1").slider({ min: 0, max: 255, slide: function(event, ui) {
par56eins.options.red = ui.value;
dataChanged = true;
} });
$("#slider2").slider({ min: 0, max: 255, slide: function(event, ui) {
par56eins.options.green = ui.value;
dataChanged = true;
} });
$("#slider3").slider({ min: 0, max: 255, slide: function(event, ui) {
par56eins.options.blue = ui.value;
dataChanged = true;
} });
$("#buttonLampe1").click(function() {
$.getJSON('/devices/1', function(data) {
$.getJSON('/control/devices/1', function(data) {
alert("data: " + data.deviceId + " " + data.colorRed );
$("#messages").append("type: " + data.type + " name=" + data.deviceName + "<br/>" );
});
});
});
});
}
);
</script>
</head>
@ -51,16 +72,16 @@
<h1>Bunti Steuerung</h1>
<div class="demo">
<div id="slider1" style="width: 300px"></div>
<div id="slider2" style="width: 300px; margin-top: 10px"></div>
<div id="slider3" style="width: 300px; margin-top: 10px"></div>
</div>
<input type="button" value="Get Device 1" id="buttonLampe1" />
<div id="messages"></div>
<input type="button" value="Update Lampe 1" id="buttonLampe1" />
</body>
</html>

View File

@ -142,4 +142,15 @@ public class BuntiDMXDeviceTest {
assertEquals(DEVICEID, dut.getDeviceId());
}
@Test
public void testGetPicture() throws Exception {
dut.setPicture("urltopicture");
assertEquals("urltopicture", dut.getPicture());
}
@Test
public void testGetType() throws Exception {
assertEquals("Par56Spot", dut.getType());
}
}

View File

@ -15,55 +15,55 @@ public class Par56SpotTest {
@Test
public void testColorRed() throws Exception {
dut.setColorRed(0);
assertEquals(0,dut.getColorRed());
dut.setColorRed(128);
assertEquals(128,dut.getColorRed());
dut.setColorRed(255);
assertEquals(255,dut.getColorRed());
dut.setRed(0);
assertEquals(0,dut.getRed());
dut.setRed(128);
assertEquals(128,dut.getRed());
dut.setRed(255);
assertEquals(255,dut.getRed());
}
@Test
public void testColorGreen() throws Exception {
dut.setColorGreen(0);
assertEquals(0,dut.getColorGreen());
dut.setColorGreen(128);
assertEquals(128,dut.getColorGreen());
dut.setColorGreen(255);
assertEquals(255,dut.getColorGreen());
dut.setGreen(0);
assertEquals(0,dut.getGreen());
dut.setGreen(128);
assertEquals(128,dut.getGreen());
dut.setGreen(255);
assertEquals(255,dut.getGreen());
}
@Test
public void testColorBlue() throws Exception {
dut.setColorBlue(0);
assertEquals(0,dut.getColorBlue());
dut.setColorBlue(128);
assertEquals(128,dut.getColorBlue());
dut.setColorBlue(255);
assertEquals(255,dut.getColorBlue());
dut.setBlue(0);
assertEquals(0,dut.getBlue());
dut.setBlue(128);
assertEquals(128,dut.getBlue());
dut.setBlue(255);
assertEquals(255,dut.getBlue());
}
@Test
public void testSwitchOff() throws Exception {
dut.switchOff();
assertEquals(0,dut.getColorRed());
assertEquals(0,dut.getColorGreen());
assertEquals(0,dut.getColorBlue());
assertEquals(0,dut.getRed());
assertEquals(0,dut.getGreen());
assertEquals(0,dut.getBlue());
}
@Test
public void testSwitchOn() throws Exception {
dut.switchOn();
assertEquals(255,dut.getColorRed());
assertEquals(255,dut.getColorGreen());
assertEquals(255,dut.getColorBlue());
assertEquals(255,dut.getRed());
assertEquals(255,dut.getGreen());
assertEquals(255,dut.getBlue());
}
@Test
public void testToString() throws Exception {
dut.setColorRed(123);
dut.setColorGreen(111);
dut.setColorBlue(42);
dut.setRed(123);
dut.setGreen(111);
dut.setBlue(42);
assertEquals("Par56Spot 23, device [123,111,42]", dut.toString());
}
}