From 4773db55efd597f27bd583f15ccfe0b9e81da187 Mon Sep 17 00:00:00 2001 From: Rik Veenboer Date: Tue, 1 Sep 2015 13:19:54 +0100 Subject: [PATCH] Replace tabs with spaces --- .../boukefalos/tm1638/AbstractTM1638.java | 362 +++++++++--------- .../com/github/boukefalos/tm1638/Loader.java | 34 +- .../com/github/boukefalos/tm1638/Server.java | 86 ++--- .../com/github/boukefalos/tm1638/TM1638.java | 36 +- .../tm1638/implementation/Local.java | 54 +-- .../tm1638/implementation/Remote.java | 71 ++-- src/test/java/test/TestLocal.java | 58 +-- .../java/test/TestRemoteImplementation.java | 38 +- src/test/java/test/TestTcpImplementation.java | 36 +- src/test/java/test/TestUdpImplementation.java | 30 +- 10 files changed, 398 insertions(+), 407 deletions(-) diff --git a/src/main/java/com/github/boukefalos/tm1638/AbstractTM1638.java b/src/main/java/com/github/boukefalos/tm1638/AbstractTM1638.java index 3d71b44..20449fe 100644 --- a/src/main/java/com/github/boukefalos/tm1638/AbstractTM1638.java +++ b/src/main/java/com/github/boukefalos/tm1638/AbstractTM1638.java @@ -3,7 +3,6 @@ package com.github.boukefalos.tm1638; import java.io.ByteArrayOutputStream; import java.io.IOException; -import tm1638.Tm1638.Buttons; import tm1638.Tm1638.ClearDisplayDigit; import tm1638.Tm1638.Color; import tm1638.Tm1638.Command; @@ -11,7 +10,6 @@ import tm1638.Tm1638.Command.Type; import tm1638.Tm1638.Construct; import tm1638.Tm1638.Message; import tm1638.Tm1638.Ping; -import tm1638.Tm1638.Pong; import tm1638.Tm1638.SetDisplay; import tm1638.Tm1638.SetDisplayDigit; import tm1638.Tm1638.SetDisplayToNumber; @@ -20,204 +18,216 @@ import tm1638.Tm1638.SetDisplayToString.Builder; import tm1638.Tm1638.SetLED; import tm1638.Tm1638.SetLEDs; import tm1638.Tm1638.SetupDisplay; -import tm1638.Tm1638.Text; +import base.work.Listen; import com.github.boukefalos.arduino.AbstractArduino; import com.google.protobuf.ByteString; public abstract class AbstractTM1638 extends AbstractArduino implements TM1638 { - public void input(Message message) { - System.out.println(message); - switch (message.getType()) { - case PONG: - input(message.getPong()); - break; - case TEXT: - input(message.getText()); - break; - case BUTTONS: - input(message.getButtons()); - break; - } - } + public void input(Message message) { + //System.out.println(message); + Object object; + switch (message.getType()) { + case PONG: + object = message.getPong(); + break; + case TEXT: + object = message.getText(); + break; + case BUTTONS: + object = message.getButtons(); + break; + default: + return; + } + for (Listen listen : listenList) { + listen.add(object); + } + } - public void input(Pong pong) {} - public void input(Text text) {} - public void input(Buttons buttons) {} + public void input(String input) { + for (Listen listen : listenList) { + listen.add(input); + } + } - public void command(Command command) { - ByteArrayOutputStream output = new ByteArrayOutputStream(BUFFER_SIZE); - try { - command.writeDelimitedTo(output); - byte[] buffer = output.toByteArray(); - send(buffer); - } catch (IOException e) { - logger.error("Failed to send command"); - } - } + public void command(Command command) { + //System.out.println(command.toString()); + //System.out.println(command.toString().length()); + ByteArrayOutputStream output = new ByteArrayOutputStream(BUFFER_SIZE); + try { + command.writeDelimitedTo(output); + byte[] buffer = output.toByteArray(); + //System.out.println("[" + new String(buffer).trim() + "]"); + //System.out.println(buffer.length); + send(buffer); + } catch (IOException e) { + logger.error("Failed to send command"); + } + } - public void ping(int id) { - command(Command.newBuilder() - .setType(Type.PING) - .setPing(Ping.newBuilder() - .setId(id)).build()); - } + public void ping(int id) { + command(Command.newBuilder() + .setType(Type.PING) + .setPing(Ping.newBuilder() + .setId(id)).build()); + } - public void construct(int dataPin, int clockPin, int strobePin) { - command(Command.newBuilder() - .setType(Type.CONSTRUCT) - .setConstruct( - Construct.newBuilder() - .setDataPin(dataPin) - .setClockPin(clockPin) - .setStrobePin(strobePin).build()).build()); - } + public void construct(int dataPin, int clockPin, int strobePin) { + command(Command.newBuilder() + .setType(Type.CONSTRUCT) + .setConstruct( + Construct.newBuilder() + .setDataPin(dataPin) + .setClockPin(clockPin) + .setStrobePin(strobePin).build()).build()); + } - public void clearDisplay() { - command(Command.newBuilder() - .setType(Type.CLEAR_DISPLAY).build()); - } + public void clearDisplay() { + command(Command.newBuilder() + .setType(Type.CLEAR_DISPLAY).build()); + } - public void clearDisplayDigit(int pos, boolean dot) { - command(Command.newBuilder() - .setType(Type.CLEAR_DISPLAY_DIGIT) - .setClearDisplayDigit( - ClearDisplayDigit.newBuilder() - .setPos(pos) - .setDot(dot).build()).build()); - } + public void clearDisplayDigit(int pos, boolean dot) { + command(Command.newBuilder() + .setType(Type.CLEAR_DISPLAY_DIGIT) + .setClearDisplayDigit( + ClearDisplayDigit.newBuilder() + .setPos(pos) + .setDot(dot).build()).build()); + } - public void setDisplay(byte[] values) { - command(Command.newBuilder() - .setType(Type.SET_DISPLAY) - .setSetDisplay( - SetDisplay.newBuilder() - .setValues(ByteString.copyFrom(values)).build()).build()); - } + public void setDisplay(byte[] values) { + command(Command.newBuilder() + .setType(Type.SET_DISPLAY) + .setSetDisplay( + SetDisplay.newBuilder() + .setValues(ByteString.copyFrom(values)).build()).build()); + } - public void setDisplayDigit(int digit, int pos, boolean dot) { - setDisplayDigit(digit, pos, dot, null); - } + public void setDisplayDigit(int digit, int pos, boolean dot) { + setDisplayDigit(digit, pos, dot, null); + } - public void setDisplayDigit(int digit, int pos, boolean dot, byte[] font) { - tm1638.Tm1638.SetDisplayDigit.Builder builder = SetDisplayDigit.newBuilder() - .setDigit(digit) - .setPos(pos) - .setDot(dot); - boolean has_font = font != null; - builder.setHasFont(has_font); - if (has_font) { - builder.setFont(ByteString.copyFrom(font)); - } - command(Command.newBuilder() - .setType(Type.SET_DISPLAY_DIGIT) - .setSetDisplayDigit(builder.build()).build()); - } + public void setDisplayDigit(int digit, int pos, boolean dot, byte[] font) { + tm1638.Tm1638.SetDisplayDigit.Builder builder = SetDisplayDigit.newBuilder() + .setDigit(digit) + .setPos(pos) + .setDot(dot); + boolean has_font = font != null; + builder.setHasFont(has_font); + if (has_font) { + builder.setFont(ByteString.copyFrom(font)); + } + command(Command.newBuilder() + .setType(Type.SET_DISPLAY_DIGIT) + .setSetDisplayDigit(builder.build()).build()); + } - public void setDisplayToBinNumber(int number, int dots) { - setDisplayToBinNumber(number, dots, null); - } + public void setDisplayToBinNumber(int number, int dots) { + setDisplayToBinNumber(number, dots, null); + } - public void setDisplayToBinNumber(int number, int dots, byte[] font) { - command(Command.newBuilder() - .setType(Type.SET_DISPLAY_TO_BIN_NUMBER) - .setSetDisplayToNumber( - SetDisplayToNumber.newBuilder() - .setNumber(number) - .setDots(dots) - .setFont(ByteString.copyFrom(font)).build()).build()); - } + public void setDisplayToBinNumber(int number, int dots, byte[] font) { + command(Command.newBuilder() + .setType(Type.SET_DISPLAY_TO_BIN_NUMBER) + .setSetDisplayToNumber( + SetDisplayToNumber.newBuilder() + .setNumber(number) + .setDots(dots) + .setFont(ByteString.copyFrom(font)).build()).build()); + } - public void setDisplayToDecNumber(int number, int dots, boolean leadingZeros) { - setDisplayToDecNumber(number, dots, leadingZeros, null); - } + public void setDisplayToDecNumber(int number, int dots, boolean leadingZeros) { + setDisplayToDecNumber(number, dots, leadingZeros, null); + } - public void setDisplayToDecNumber(int number, int dots, boolean leadingZeros, byte[] font) { - tm1638.Tm1638.SetDisplayToNumber.Builder builder = SetDisplayToNumber.newBuilder() - .setNumber(number) - .setDots(dots) - .setLeadingZeros(leadingZeros); - boolean has_font = font != null; - builder.setHasFont(has_font); - if (has_font) { - builder.setFont(ByteString.copyFrom(font)); - } - command(Command.newBuilder() - .setType(Type.SET_DISPLAY_TO_DEC_NUMBER) - .setSetDisplayToNumber(builder.build()).build()); - } + public void setDisplayToDecNumber(int number, int dots, boolean leadingZeros, byte[] font) { + tm1638.Tm1638.SetDisplayToNumber.Builder builder = SetDisplayToNumber.newBuilder() + .setNumber(number) + .setDots(dots) + .setLeadingZeros(leadingZeros); + boolean has_font = font != null; + builder.setHasFont(has_font); + if (has_font) { + builder.setFont(ByteString.copyFrom(font)); + } + command(Command.newBuilder() + .setType(Type.SET_DISPLAY_TO_DEC_NUMBER) + .setSetDisplayToNumber(builder.build()).build()); + } - public void setDisplayToHexNumber(int number, int dots, boolean leadingZeros) { - setDisplayToHexNumber(number, dots, leadingZeros, null); - } + public void setDisplayToHexNumber(int number, int dots, boolean leadingZeros) { + setDisplayToHexNumber(number, dots, leadingZeros, null); + } - public void setDisplayToHexNumber(int number, int dots, boolean leadingZeros, byte[] font) { - tm1638.Tm1638.SetDisplayToNumber.Builder builder = SetDisplayToNumber.newBuilder() - .setNumber(number) - .setDots(dots) - .setLeadingZeros(leadingZeros); - boolean has_font = font != null; - builder.setHasFont(has_font); - if (has_font) { - builder.setFont(ByteString.copyFrom(font)); - } - command(Command.newBuilder() - .setType(Type.SET_DISPLAY_TO_HEX_NUMBER) - .setSetDisplayToNumber( - builder.build()).build()); - } + public void setDisplayToHexNumber(int number, int dots, boolean leadingZeros, byte[] font) { + tm1638.Tm1638.SetDisplayToNumber.Builder builder = SetDisplayToNumber.newBuilder() + .setNumber(number) + .setDots(dots) + .setLeadingZeros(leadingZeros); + boolean has_font = font != null; + builder.setHasFont(has_font); + if (has_font) { + builder.setFont(ByteString.copyFrom(font)); + } + command(Command.newBuilder() + .setType(Type.SET_DISPLAY_TO_HEX_NUMBER) + .setSetDisplayToNumber( + builder.build()).build()); + } - public void setDisplayToError() { - command(Command.newBuilder() - .setType(Type.SET_DISPLAY_TO_ERROR).build()); - } + public void setDisplayToError() { + command(Command.newBuilder() + .setType(Type.SET_DISPLAY_TO_ERROR).build()); + } - public void setDisplayToString(String string, int dots, int pos) { - setDisplayToString(string, dots, pos, null); - } + public void setDisplayToString(String string, int dots, int pos) { + setDisplayToString(string, dots, pos, null); + } - public void setDisplayToString(String string, int dots, int pos, byte[] font) { - Builder builder = SetDisplayToString.newBuilder() - .setString(string) - .setDots(dots) - .setPos(pos); - boolean has_font = font != null; - builder.setHasFont(has_font); - if (has_font) { - builder.setFont(ByteString.copyFrom(font)); - } - if (has_font) { - builder.setFont(ByteString.copyFrom(font)); - } - command(Command.newBuilder() - .setType(Type.SET_DISPLAY_TO_STRING) - .setSetDisplayToString( - builder.build()).build()); - } + public void setDisplayToString(String string, int dots, int pos, byte[] font) { + Builder builder = SetDisplayToString.newBuilder() + .setString(string) + .setDots(dots) + .setPos(pos); + boolean has_font = font != null; + builder.setHasFont(has_font); + if (has_font) { + builder.setFont(ByteString.copyFrom(font)); + } + if (has_font) { + builder.setFont(ByteString.copyFrom(font)); + } + command(Command.newBuilder() + .setType(Type.SET_DISPLAY_TO_STRING) + .setSetDisplayToString( + builder.build()).build()); + } - public void setLED(Color color, int pos) { - command(Command.newBuilder() - .setType(Type.SET_LED) - .setSetLED( - SetLED.newBuilder() - .setColor(color) - .setPos(pos).build()).build()); - } + public void setLED(Color color, int pos) { + command(Command.newBuilder() + .setType(Type.SET_LED) + .setSetLED( + SetLED.newBuilder() + .setColor(color) + .setPos(pos).build()).build()); + } - public void setLEDs(int led) { - command(Command.newBuilder() - .setType(Type.SET_LEDS) - .setSetLEDs( - SetLEDs.newBuilder() - .setLed(led).build()).build()); - } + public void setLEDs(int led) { + command(Command.newBuilder() + .setType(Type.SET_LEDS) + .setSetLEDs( + SetLEDs.newBuilder() + .setLed(led).build()).build()); + } - public void setupDisplay(boolean active, int intensity) { - command(Command.newBuilder() - .setType(Type.SETUP_DISPLAY) - .setSetupDisplay( - SetupDisplay.newBuilder() - .setActive(active) - .setIntensity(intensity).build()).build()); - } + public void setupDisplay(boolean active, int intensity) { + command(Command.newBuilder() + .setType(Type.SETUP_DISPLAY) + .setSetupDisplay( + SetupDisplay.newBuilder() + .setActive(active) + .setIntensity(intensity).build()).build()); + } } diff --git a/src/main/java/com/github/boukefalos/tm1638/Loader.java b/src/main/java/com/github/boukefalos/tm1638/Loader.java index fe248d9..5de85aa 100644 --- a/src/main/java/com/github/boukefalos/tm1638/Loader.java +++ b/src/main/java/com/github/boukefalos/tm1638/Loader.java @@ -13,28 +13,28 @@ import com.github.boukefalos.tm1638.implementation.Local; import com.github.boukefalos.tm1638.implementation.Remote; public class Loader extends com.github.boukefalos.arduino.Loader { - protected static final String PROPERTIES_FILE = "TM1638.properties"; + protected static final String PROPERTIES_FILE = "TM1638.properties"; public Loader(Properties properties) throws LoaderException { - super(Local.class, Remote.class, Server.class, properties); - pico.addComponent(ParsingPort.getInstance(Message.class)); - } + super(Local.class, Remote.class, Server.class, properties); + pico.addComponent(ParsingPort.getInstance(Message.class)); + } - public TM1638 getTM1638() throws ArduinoException { - try { - return pico.getComponent(TM1638.class); - } catch (PicoCompositionException e) { - logger.error("", e); - throw new ArduinoException("Failed to load"); - } + public TM1638 getTM1638() throws ArduinoException { + try { + return pico.getComponent(TM1638.class); + } catch (PicoCompositionException e) { + logger.error("", e); + throw new ArduinoException("Failed to load"); + } } public Server getServer() throws ArduinoException { - try { - return pico.getComponent(Server.class); - } catch (PicoCompositionException e) { - logger.error("", e); - throw new ArduinoException("Failed to load"); - } + try { + return pico.getComponent(Server.class); + } catch (PicoCompositionException e) { + logger.error("", e); + throw new ArduinoException("Failed to load"); + } } } diff --git a/src/main/java/com/github/boukefalos/tm1638/Server.java b/src/main/java/com/github/boukefalos/tm1638/Server.java index 496e156..392f520 100644 --- a/src/main/java/com/github/boukefalos/tm1638/Server.java +++ b/src/main/java/com/github/boukefalos/tm1638/Server.java @@ -14,48 +14,48 @@ import com.github.boukefalos.arduino.exception.ArduinoException; public class Server extends com.github.boukefalos.arduino.Server { protected TM1638 tm1638; - public Server(TM1638 tm1638, Duplex duplex, boolean direct) { - super(tm1638, duplex, direct); - this.tm1638 = tm1638; - } + public Server(TM1638 tm1638, Duplex duplex, boolean direct) { + super(tm1638, duplex, direct); + this.tm1638 = tm1638; + } - public void receive(byte[] buffer) { - // Client > [Server] > Arduino - if (direct) { - try { - tm1638.send(buffer); - } catch (ArduinoException e) { - logger.error("", e); - } - } else { - ByteArrayInputStream input = new ByteArrayInputStream(buffer); - try { - Command command = Command.parseDelimitedFrom(input); - logger.debug("Command type = " + command.getType().name()); - switch (command.getType()) { - case PING: - Ping ping = command.getPing(); - tm1638.ping(ping.getId()); - break; - case SET_LED: - SetLED setLED = command.getSetLED(); - logger.debug("Color = " + setLED.getColor().name()); - switch (setLED.getColor()) { - case RED: - tm1638.setLED(Color.RED, 1); - case GREEN: - tm1638.setLED(Color.GREEN, 1); - default: - break; - } - break; - default: - break; - } - } catch (IOException e) { - logger.error("Failed to parse input"); - return; - } - } - } + public void receive(byte[] buffer) { + // Client > [Server] > Arduino + if (direct) { + try { + tm1638.send(buffer); + } catch (ArduinoException e) { + logger.error("", e); + } + } else { + ByteArrayInputStream input = new ByteArrayInputStream(buffer); + try { + Command command = Command.parseDelimitedFrom(input); + logger.debug("Command type = " + command.getType().name()); + switch (command.getType()) { + case PING: + Ping ping = command.getPing(); + tm1638.ping(ping.getId()); + break; + case SET_LED: + SetLED setLED = command.getSetLED(); + logger.debug("Color = " + setLED.getColor().name()); + switch (setLED.getColor()) { + case RED: + tm1638.setLED(Color.RED, 1); + case GREEN: + tm1638.setLED(Color.GREEN, 1); + default: + break; + } + break; + default: + break; + } + } catch (IOException e) { + logger.error("Failed to parse input"); + return; + } + } + } } \ No newline at end of file diff --git a/src/main/java/com/github/boukefalos/tm1638/TM1638.java b/src/main/java/com/github/boukefalos/tm1638/TM1638.java index 51b636e..1b5204f 100644 --- a/src/main/java/com/github/boukefalos/tm1638/TM1638.java +++ b/src/main/java/com/github/boukefalos/tm1638/TM1638.java @@ -4,23 +4,23 @@ import tm1638.Tm1638.Color; import com.github.boukefalos.arduino.Arduino; -public interface TM1638 extends Arduino { +public interface TM1638 extends Arduino { public void ping(int i); - public void construct(int dataPin, int clockPin, int strobePin); - public void clearDisplay(); - public void clearDisplayDigit(int pos, boolean dot); - public void setDisplay(byte[] values); - public void setDisplayDigit(int digit, int pos, boolean dot); - public void setDisplayDigit(int digit, int pos, boolean dot, byte[] font); - public void setDisplayToBinNumber(int number, int dots, byte[] font); - public void setDisplayToDecNumber(int number, int dots, boolean leadingZeros); - public void setDisplayToDecNumber(int number, int dots, boolean leadingZeros, byte[] font); - public void setDisplayToHexNumber(int number, int dots, boolean leadingZeros); - public void setDisplayToHexNumber(int number, int dots, boolean leadingZeros, byte[] font); - public void setDisplayToError(); - public void setDisplayToString(String string, int dots, int pos); - public void setDisplayToString(String string, int dots, int pos, byte[] font); - public void setLED(Color color, int pos); - public void setLEDs(int led); - public void setupDisplay(boolean active, int intensity); + public void construct(int dataPin, int clockPin, int strobePin); + public void clearDisplay(); + public void clearDisplayDigit(int pos, boolean dot); + public void setDisplay(byte[] values); + public void setDisplayDigit(int digit, int pos, boolean dot); + public void setDisplayDigit(int digit, int pos, boolean dot, byte[] font); + public void setDisplayToBinNumber(int number, int dots, byte[] font); + public void setDisplayToDecNumber(int number, int dots, boolean leadingZeros); + public void setDisplayToDecNumber(int number, int dots, boolean leadingZeros, byte[] font); + public void setDisplayToHexNumber(int number, int dots, boolean leadingZeros); + public void setDisplayToHexNumber(int number, int dots, boolean leadingZeros, byte[] font); + public void setDisplayToError(); + public void setDisplayToString(String string, int dots, int pos); + public void setDisplayToString(String string, int dots, int pos, byte[] font); + public void setLED(Color color, int pos); + public void setLEDs(int led); + public void setupDisplay(boolean active, int intensity); } \ No newline at end of file diff --git a/src/main/java/com/github/boukefalos/tm1638/implementation/Local.java b/src/main/java/com/github/boukefalos/tm1638/implementation/Local.java index 80dd384..ee69594 100644 --- a/src/main/java/com/github/boukefalos/tm1638/implementation/Local.java +++ b/src/main/java/com/github/boukefalos/tm1638/implementation/Local.java @@ -2,10 +2,8 @@ package com.github.boukefalos.tm1638.implementation; import java.io.IOException; import java.io.OutputStream; -import java.util.ArrayList; import tm1638.Tm1638.Message; -import base.work.Listen; import com.github.boukefalos.arduino.exception.ArduinoException; import com.github.boukefalos.arduino.port.ParsingPort; @@ -13,40 +11,28 @@ import com.github.boukefalos.arduino.port.Port; import com.github.boukefalos.tm1638.AbstractTM1638; public class Local extends AbstractTM1638 { - protected Port arduino; - protected OutputStream outputStream; - protected ArrayList> listenList; + protected Port arduino; + protected OutputStream outputStream; - public Local() throws ArduinoException { - this(ParsingPort.getInstance(Message.class)); - } + public Local() throws ArduinoException { + this(ParsingPort.getInstance(Message.class)); + } - public Local(Port arduino) throws ArduinoException { - this.arduino = arduino; - outputStream = arduino.getOutputStream(); - listenList = new ArrayList>(); - arduino.register(this); - } + public Local(Port arduino) throws ArduinoException { + this.arduino = arduino; + outputStream = arduino.getOutputStream(); + arduino.register(this); + } - public void register(Listen listen) { - listenList.add(listen); - } + public void stop() { + arduino.close(); + } - public void remove(Listen listen) { - listenList.remove(listen); - } - - public void stop() { - arduino.close(); - } - - public void send(byte[] buffer) throws ArduinoException { - try { - outputStream.write(buffer); - outputStream.flush(); - sleep(100); - } catch (IOException e) { - throw new ArduinoException("Failed to write to arduino"); - } - } + public void send(byte[] buffer) throws ArduinoException { + try { + outputStream.write(buffer); + } catch (IOException e) { + throw new ArduinoException("Failed to write to arduino"); + } + } } diff --git a/src/main/java/com/github/boukefalos/tm1638/implementation/Remote.java b/src/main/java/com/github/boukefalos/tm1638/implementation/Remote.java index 679d2b8..acfeb8d 100644 --- a/src/main/java/com/github/boukefalos/tm1638/implementation/Remote.java +++ b/src/main/java/com/github/boukefalos/tm1638/implementation/Remote.java @@ -11,50 +11,41 @@ import com.github.boukefalos.arduino.exception.ArduinoException; import com.github.boukefalos.tm1638.AbstractTM1638; public class Remote extends AbstractTM1638 implements Receiver { - protected Duplex duplex; - protected ArrayList> listenList; + protected Duplex duplex; - public Remote(Duplex duplex) { - this.duplex = duplex; - listenList = new ArrayList>(); - duplex.register(this); // Server > [receive()] - } + public Remote(Duplex duplex) { + this.duplex = duplex; + listenList = new ArrayList>(); + duplex.register(this); // Server > [receive()] + } - public void start() { - duplex.start(); - } + public void start() { + duplex.start(); + } - public void stop() { - duplex.stop(); - } + public void stop() { + duplex.stop(); + } - public void exit() { - super.stop(); - duplex.exit(); - } + public void exit() { + super.stop(); + duplex.exit(); + } - public void register(Listen listen) { - listenList.add(listen); - } + public void receive(byte[] buffer) { + // Arduino > Server > [Client] + // Should give option to decode here? + for (Listen listen : listenList) { + listen.add(buffer); + } + } - public void remove(Listen listen) { - listenList.remove(listen); - } - - public void receive(byte[] buffer) { - // Arduino > Server > [Client] - // Should give option to decode here? - for (Listen listen : listenList) { - listen.add(buffer); - } - } - - public void send(byte[] buffer) throws ArduinoException { - // [Client] > Server > Arduino - try { - duplex.send(buffer); - } catch (IOException e) { - throw new ArduinoException("Failed to send"); - } - } + public void send(byte[] buffer) throws ArduinoException { + // [Client] > Server > Arduino + try { + duplex.send(buffer); + } catch (IOException e) { + throw new ArduinoException("Failed to send"); + } + } } \ No newline at end of file diff --git a/src/test/java/test/TestLocal.java b/src/test/java/test/TestLocal.java index 8e04cc8..032516c 100644 --- a/src/test/java/test/TestLocal.java +++ b/src/test/java/test/TestLocal.java @@ -2,44 +2,48 @@ package test; import base.work.Listen; +import com.github.boukefalos.arduino.port.StringPort; import com.github.boukefalos.tm1638.TM1638; import com.github.boukefalos.tm1638.implementation.Local; public class TestLocal extends Listen { - public static void main(String[] args) throws Exception { - TM1638 TM1638 = new Local(); + public static void main(String[] args) throws Exception { + TM1638 TM1638 = new Local(StringPort.getInstance()); main(TM1638); - } + } - public static void main(TM1638 TM1638) throws InterruptedException { - TM1638.register(new TestLocal()); - TM1638.start(); + public void input(String input) { + System.out.println("> " + input); + } - /*TM1638.construct(8, 9, 7); - TM1638.setupDisplay(true, 1); - TM1638.setLEDs(0xff00);*/ + public static void main(TM1638 TM1638) throws Exception { + TM1638.register(new TestLocal()); + TM1638.start(); - // Light up all the green LEDs - TM1638.setLEDs(0x00ff); - Thread.sleep(2000); - //TM1638.setLEDs(0x0000); + TM1638.construct(8, 9, 7); + TM1638.setupDisplay(true, 1); + TM1638.setDisplayToString("Rik", 2, 0); + Thread.sleep(1000); - // Light up all the red LEDs - TM1638.setLEDs(0xff00); - Thread.sleep(2000); - TM1638.setLEDs(0x0000); + TM1638.setDisplayToDecNumber(123, 0, false); + + Thread.sleep(1000); + // Light up all the green LEDs + TM1638.setLEDs(0x00ff); + Thread.sleep(1000); + TM1638.setLEDs(0x0000); + + // Light up all the red LEDs + TM1638.setLEDs(0xff00); + Thread.sleep(1000); + TM1638.setLEDs(0x0000); int i = 0; - while (i < 10000) { + while (i < 10000) { //TM1638.setLED(i % 2 == 0 ? Color.GREEN : Color.RED, i % 8); - //Thread.sleep(500); - TM1638.ping(i++); - Thread.sleep(1000); + //Thread.sleep(500); + TM1638.ping(i++); + Thread.sleep(1000); } - } - - public TestLocal() { - super(); - start(); - } + } } diff --git a/src/test/java/test/TestRemoteImplementation.java b/src/test/java/test/TestRemoteImplementation.java index 49c8eea..f29c6c0 100644 --- a/src/test/java/test/TestRemoteImplementation.java +++ b/src/test/java/test/TestRemoteImplementation.java @@ -10,30 +10,30 @@ import com.github.boukefalos.tm1638.Server; import com.github.boukefalos.tm1638.TM1638; public class TestRemoteImplementation extends TestLocal { - protected TM1638 tm1638; + protected TM1638 tm1638; - public TestRemoteImplementation(Loader loader) throws ArduinoException { - tm1638 = loader.getTM1638(); - //tm1638.register(this); - } + public TestRemoteImplementation(Loader loader) throws ArduinoException { + tm1638 = loader.getTM1638(); + //tm1638.register(this); + } public void activate() throws ActivateException { - tm1638.start(); + tm1638.start(); super.activate(); } - public static void main(Properties localProperties, Properties remoteProperties) throws Exception { - Loader localLoader = new Loader(localProperties); - Loader remoteLoader = new Loader(remoteProperties); + public static void main(Properties localProperties, Properties remoteProperties) throws Exception { + Loader localLoader = new Loader(localProperties); + Loader remoteLoader = new Loader(remoteProperties); - try { - Server server = localLoader.getServer(); - TM1638 TM1638 = remoteLoader.getTM1638(); - server.start(); - main(TM1638); - } catch (ArduinoException e) { - e.printStackTrace(); - return; - } - } + try { + Server server = localLoader.getServer(); + TM1638 TM1638 = remoteLoader.getTM1638(); + server.start(); + main(TM1638); + } catch (ArduinoException e) { + e.printStackTrace(); + return; + } + } } diff --git a/src/test/java/test/TestTcpImplementation.java b/src/test/java/test/TestTcpImplementation.java index e72ed31..cdbad15 100644 --- a/src/test/java/test/TestTcpImplementation.java +++ b/src/test/java/test/TestTcpImplementation.java @@ -5,24 +5,24 @@ import java.util.Properties; import com.github.boukefalos.arduino.exception.ArduinoException; public class TestTcpImplementation { - public static void main(String[] args) throws Exception { - Properties localProperties = new Properties(); - localProperties.setProperty("implementation", "local"); - localProperties.setProperty("server", "true"); - localProperties.setProperty("server.direct", "false"); - localProperties.setProperty("server.port", "8883"); - localProperties.setProperty("server.protocol", "tcp"); + public static void main(String[] args) throws Exception { + Properties localProperties = new Properties(); + localProperties.setProperty("implementation", "local"); + localProperties.setProperty("server", "true"); + localProperties.setProperty("server.direct", "false"); + localProperties.setProperty("server.port", "8883"); + localProperties.setProperty("server.protocol", "tcp"); - Properties remoteProperties = new Properties(); - remoteProperties.setProperty("implementation", "remote"); - remoteProperties.setProperty("protocol", "tcp"); - remoteProperties.setProperty("remote.host", "localhost"); - remoteProperties.setProperty("remote.port", "8883"); + Properties remoteProperties = new Properties(); + remoteProperties.setProperty("implementation", "remote"); + remoteProperties.setProperty("protocol", "tcp"); + remoteProperties.setProperty("remote.host", "localhost"); + remoteProperties.setProperty("remote.port", "8883"); - try { - TestRemoteImplementation.main(localProperties, remoteProperties); - } catch (ArduinoException e) { - System.err.println(e.getMessage()); - } - } + try { + TestRemoteImplementation.main(localProperties, remoteProperties); + } catch (ArduinoException e) { + System.err.println(e.getMessage()); + } + } } \ No newline at end of file diff --git a/src/test/java/test/TestUdpImplementation.java b/src/test/java/test/TestUdpImplementation.java index fa4d4d3..c070915 100644 --- a/src/test/java/test/TestUdpImplementation.java +++ b/src/test/java/test/TestUdpImplementation.java @@ -3,21 +3,21 @@ package test; import java.util.Properties; public class TestUdpImplementation { - public static void main(String[] args) throws Exception { - Properties localProperties = new Properties(); - localProperties.setProperty("implementation", "local"); - localProperties.setProperty("protocol", "udp"); - localProperties.setProperty("server", "true"); - localProperties.setProperty("server.direct", "false"); - localProperties.setProperty("server.port", "8883"); - localProperties.setProperty("server.protocol", "udp"); + public static void main(String[] args) throws Exception { + Properties localProperties = new Properties(); + localProperties.setProperty("implementation", "local"); + localProperties.setProperty("protocol", "udp"); + localProperties.setProperty("server", "true"); + localProperties.setProperty("server.direct", "false"); + localProperties.setProperty("server.port", "8883"); + localProperties.setProperty("server.protocol", "udp"); - Properties remoteProperties = new Properties(); - remoteProperties.setProperty("implementation", "remote"); - remoteProperties.setProperty("protocol", "udp"); - remoteProperties.setProperty("remote.host", "localhost"); - remoteProperties.setProperty("remote.port", "8883"); + Properties remoteProperties = new Properties(); + remoteProperties.setProperty("implementation", "remote"); + remoteProperties.setProperty("protocol", "udp"); + remoteProperties.setProperty("remote.host", "localhost"); + remoteProperties.setProperty("remote.port", "8883"); - TestRemoteImplementation.main(localProperties, remoteProperties); - } + TestRemoteImplementation.main(localProperties, remoteProperties); + } }