From e38ec028e365e96cae5a6dc4802086086742ee20 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Mon, 21 Oct 2013 23:57:04 +0200 Subject: [PATCH] minidmx, display connection state in the gui --- .../sematrix/output/MiniDmxDevice.java | 14 +++++++++++++ .../output/minidmx/MiniDmxSerial.java | 21 +++++++++++++------ 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/neophob/sematrix/output/MiniDmxDevice.java b/src/main/java/com/neophob/sematrix/output/MiniDmxDevice.java index 0f9d3514..4f13cd65 100644 --- a/src/main/java/com/neophob/sematrix/output/MiniDmxDevice.java +++ b/src/main/java/com/neophob/sematrix/output/MiniDmxDevice.java @@ -91,4 +91,18 @@ public boolean isConnected() { return this.initialized; } + @Override + public boolean isSupportConnectionState() { + return true; + } + + + @Override + public String getConnectionStatus(){ + if (initialized) { + return "Connected on port "+miniDmx.getSerialPortName(); + } + return "Not connected!"; + } + } diff --git a/src/main/java/com/neophob/sematrix/output/minidmx/MiniDmxSerial.java b/src/main/java/com/neophob/sematrix/output/minidmx/MiniDmxSerial.java index 59da3ca4..12d4d0c6 100644 --- a/src/main/java/com/neophob/sematrix/output/minidmx/MiniDmxSerial.java +++ b/src/main/java/com/neophob/sematrix/output/minidmx/MiniDmxSerial.java @@ -203,6 +203,8 @@ public static MiniDmxPayloadEnum getDmxPayload(int payloadSize) throws IllegalAr /** map to store checksum of image. */ private long lastDataMap; + private String serialPortName=""; + /** * Create a new instance to communicate with the rainbowduino. * @@ -245,7 +247,6 @@ public MiniDmxSerial(PApplet app, String portName, int targetBuffersize, int bau lastDataMap = 0L; - String serialPortName=""; this.miniDmxPayload = MiniDmxPayloadEnum.getDmxPayload(targetBuffersize); LOG.log(Level.INFO, "MiniDMX payload size: {0}, padding bytes: {1}, baudrate: {2}", new Object[] { this.miniDmxPayload.payloadSize, @@ -363,7 +364,7 @@ public boolean ping() { r.nextBytes(data); //just send a frame - return sendFrame(data); + return sendFrame(data)>0; } @@ -376,7 +377,7 @@ public boolean ping() { * @param colorFormat the color format * @return true if send was successful */ - public boolean sendRgbFrame(int[] data, ColorFormat colorFormat) { + public int sendRgbFrame(int[] data, ColorFormat colorFormat) { return sendFrame(OutputHelper.convertBufferTo24bit(data, colorFormat)); } @@ -419,7 +420,7 @@ private boolean didFrameChange(byte data[]) { * @return true if send was successful * @throws IllegalArgumentException the illegal argument exception */ - public boolean sendFrame(byte data[]) throws IllegalArgumentException { + public int sendFrame(byte data[]) throws IllegalArgumentException { //respect the padding! int sourceDataLength = miniDmxPayload.getPayloadSize()-miniDmxPayload.paddingBytes; @@ -438,14 +439,14 @@ public boolean sendFrame(byte data[]) throws IllegalArgumentException { //send frame only if needed if (didFrameChange(data)) { if (sendSerialData(cmdfull)) { - return true; + return cmdfull.length; } else { //in case of an error, make sure we send it the next time! lastDataMap=0L; } } - return false; + return -1; } @@ -583,5 +584,13 @@ public long getAckErrors() { return ackErrors; } + /** + * + * @return + */ + public String getSerialPortName() { + return serialPortName; + } + }