Replace tabs with spaces

This commit is contained in:
2015-09-01 13:19:54 +01:00
parent 0f33f2a429
commit 4773db55ef
10 changed files with 398 additions and 407 deletions

View File

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

View File

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

View File

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

View File

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

View File

@@ -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<Listen<Object>> 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<Listen<Object>>();
arduino.register(this);
}
public Local(Port arduino) throws ArduinoException {
this.arduino = arduino;
outputStream = arduino.getOutputStream();
arduino.register(this);
}
public void register(Listen<Object> listen) {
listenList.add(listen);
}
public void stop() {
arduino.close();
}
public void remove(Listen<Object> 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");
}
}
}

View File

@@ -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<Listen<Object>> listenList;
protected Duplex duplex;
public Remote(Duplex duplex) {
this.duplex = duplex;
listenList = new ArrayList<Listen<Object>>();
duplex.register(this); // Server > [receive()]
}
public Remote(Duplex duplex) {
this.duplex = duplex;
listenList = new ArrayList<Listen<Object>>();
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<Object> listen) {
listenList.add(listen);
}
public void receive(byte[] buffer) {
// Arduino > Server > [Client]
// Should give option to decode here?
for (Listen<Object> listen : listenList) {
listen.add(buffer);
}
}
public void remove(Listen<Object> listen) {
listenList.remove(listen);
}
public void receive(byte[] buffer) {
// Arduino > Server > [Client]
// Should give option to decode here?
for (Listen<Object> 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");
}
}
}

View File

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

View File

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

View File

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

View File

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