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.ByteArrayOutputStream;
import java.io.IOException; import java.io.IOException;
import tm1638.Tm1638.Buttons;
import tm1638.Tm1638.ClearDisplayDigit; import tm1638.Tm1638.ClearDisplayDigit;
import tm1638.Tm1638.Color; import tm1638.Tm1638.Color;
import tm1638.Tm1638.Command; import tm1638.Tm1638.Command;
@@ -11,7 +10,6 @@ import tm1638.Tm1638.Command.Type;
import tm1638.Tm1638.Construct; import tm1638.Tm1638.Construct;
import tm1638.Tm1638.Message; import tm1638.Tm1638.Message;
import tm1638.Tm1638.Ping; import tm1638.Tm1638.Ping;
import tm1638.Tm1638.Pong;
import tm1638.Tm1638.SetDisplay; import tm1638.Tm1638.SetDisplay;
import tm1638.Tm1638.SetDisplayDigit; import tm1638.Tm1638.SetDisplayDigit;
import tm1638.Tm1638.SetDisplayToNumber; import tm1638.Tm1638.SetDisplayToNumber;
@@ -20,204 +18,216 @@ import tm1638.Tm1638.SetDisplayToString.Builder;
import tm1638.Tm1638.SetLED; import tm1638.Tm1638.SetLED;
import tm1638.Tm1638.SetLEDs; import tm1638.Tm1638.SetLEDs;
import tm1638.Tm1638.SetupDisplay; import tm1638.Tm1638.SetupDisplay;
import tm1638.Tm1638.Text; import base.work.Listen;
import com.github.boukefalos.arduino.AbstractArduino; import com.github.boukefalos.arduino.AbstractArduino;
import com.google.protobuf.ByteString; import com.google.protobuf.ByteString;
public abstract class AbstractTM1638 extends AbstractArduino implements TM1638 { public abstract class AbstractTM1638 extends AbstractArduino implements TM1638 {
public void input(Message message) { public void input(Message message) {
System.out.println(message); //System.out.println(message);
switch (message.getType()) { Object object;
case PONG: switch (message.getType()) {
input(message.getPong()); case PONG:
break; object = message.getPong();
case TEXT: break;
input(message.getText()); case TEXT:
break; object = message.getText();
case BUTTONS: break;
input(message.getButtons()); case BUTTONS:
break; object = message.getButtons();
} break;
} default:
return;
}
for (Listen<Object> listen : listenList) {
listen.add(object);
}
}
public void input(Pong pong) {} public void input(String input) {
public void input(Text text) {} for (Listen<Object> listen : listenList) {
public void input(Buttons buttons) {} listen.add(input);
}
}
public void command(Command command) { public void command(Command command) {
ByteArrayOutputStream output = new ByteArrayOutputStream(BUFFER_SIZE); //System.out.println(command.toString());
try { //System.out.println(command.toString().length());
command.writeDelimitedTo(output); ByteArrayOutputStream output = new ByteArrayOutputStream(BUFFER_SIZE);
byte[] buffer = output.toByteArray(); try {
send(buffer); command.writeDelimitedTo(output);
} catch (IOException e) { byte[] buffer = output.toByteArray();
logger.error("Failed to send command"); //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) { public void ping(int id) {
command(Command.newBuilder() command(Command.newBuilder()
.setType(Type.PING) .setType(Type.PING)
.setPing(Ping.newBuilder() .setPing(Ping.newBuilder()
.setId(id)).build()); .setId(id)).build());
} }
public void construct(int dataPin, int clockPin, int strobePin) { public void construct(int dataPin, int clockPin, int strobePin) {
command(Command.newBuilder() command(Command.newBuilder()
.setType(Type.CONSTRUCT) .setType(Type.CONSTRUCT)
.setConstruct( .setConstruct(
Construct.newBuilder() Construct.newBuilder()
.setDataPin(dataPin) .setDataPin(dataPin)
.setClockPin(clockPin) .setClockPin(clockPin)
.setStrobePin(strobePin).build()).build()); .setStrobePin(strobePin).build()).build());
} }
public void clearDisplay() { public void clearDisplay() {
command(Command.newBuilder() command(Command.newBuilder()
.setType(Type.CLEAR_DISPLAY).build()); .setType(Type.CLEAR_DISPLAY).build());
} }
public void clearDisplayDigit(int pos, boolean dot) { public void clearDisplayDigit(int pos, boolean dot) {
command(Command.newBuilder() command(Command.newBuilder()
.setType(Type.CLEAR_DISPLAY_DIGIT) .setType(Type.CLEAR_DISPLAY_DIGIT)
.setClearDisplayDigit( .setClearDisplayDigit(
ClearDisplayDigit.newBuilder() ClearDisplayDigit.newBuilder()
.setPos(pos) .setPos(pos)
.setDot(dot).build()).build()); .setDot(dot).build()).build());
} }
public void setDisplay(byte[] values) { public void setDisplay(byte[] values) {
command(Command.newBuilder() command(Command.newBuilder()
.setType(Type.SET_DISPLAY) .setType(Type.SET_DISPLAY)
.setSetDisplay( .setSetDisplay(
SetDisplay.newBuilder() SetDisplay.newBuilder()
.setValues(ByteString.copyFrom(values)).build()).build()); .setValues(ByteString.copyFrom(values)).build()).build());
} }
public void setDisplayDigit(int digit, int pos, boolean dot) { public void setDisplayDigit(int digit, int pos, boolean dot) {
setDisplayDigit(digit, pos, dot, null); setDisplayDigit(digit, pos, dot, null);
} }
public void setDisplayDigit(int digit, int pos, boolean dot, byte[] font) { public void setDisplayDigit(int digit, int pos, boolean dot, byte[] font) {
tm1638.Tm1638.SetDisplayDigit.Builder builder = SetDisplayDigit.newBuilder() tm1638.Tm1638.SetDisplayDigit.Builder builder = SetDisplayDigit.newBuilder()
.setDigit(digit) .setDigit(digit)
.setPos(pos) .setPos(pos)
.setDot(dot); .setDot(dot);
boolean has_font = font != null; boolean has_font = font != null;
builder.setHasFont(has_font); builder.setHasFont(has_font);
if (has_font) { if (has_font) {
builder.setFont(ByteString.copyFrom(font)); builder.setFont(ByteString.copyFrom(font));
} }
command(Command.newBuilder() command(Command.newBuilder()
.setType(Type.SET_DISPLAY_DIGIT) .setType(Type.SET_DISPLAY_DIGIT)
.setSetDisplayDigit(builder.build()).build()); .setSetDisplayDigit(builder.build()).build());
} }
public void setDisplayToBinNumber(int number, int dots) { public void setDisplayToBinNumber(int number, int dots) {
setDisplayToBinNumber(number, dots, null); setDisplayToBinNumber(number, dots, null);
} }
public void setDisplayToBinNumber(int number, int dots, byte[] font) { public void setDisplayToBinNumber(int number, int dots, byte[] font) {
command(Command.newBuilder() command(Command.newBuilder()
.setType(Type.SET_DISPLAY_TO_BIN_NUMBER) .setType(Type.SET_DISPLAY_TO_BIN_NUMBER)
.setSetDisplayToNumber( .setSetDisplayToNumber(
SetDisplayToNumber.newBuilder() SetDisplayToNumber.newBuilder()
.setNumber(number) .setNumber(number)
.setDots(dots) .setDots(dots)
.setFont(ByteString.copyFrom(font)).build()).build()); .setFont(ByteString.copyFrom(font)).build()).build());
} }
public void setDisplayToDecNumber(int number, int dots, boolean leadingZeros) { public void setDisplayToDecNumber(int number, int dots, boolean leadingZeros) {
setDisplayToDecNumber(number, dots, leadingZeros, null); setDisplayToDecNumber(number, dots, leadingZeros, null);
} }
public void setDisplayToDecNumber(int number, int dots, boolean leadingZeros, byte[] font) { public void setDisplayToDecNumber(int number, int dots, boolean leadingZeros, byte[] font) {
tm1638.Tm1638.SetDisplayToNumber.Builder builder = SetDisplayToNumber.newBuilder() tm1638.Tm1638.SetDisplayToNumber.Builder builder = SetDisplayToNumber.newBuilder()
.setNumber(number) .setNumber(number)
.setDots(dots) .setDots(dots)
.setLeadingZeros(leadingZeros); .setLeadingZeros(leadingZeros);
boolean has_font = font != null; boolean has_font = font != null;
builder.setHasFont(has_font); builder.setHasFont(has_font);
if (has_font) { if (has_font) {
builder.setFont(ByteString.copyFrom(font)); builder.setFont(ByteString.copyFrom(font));
} }
command(Command.newBuilder() command(Command.newBuilder()
.setType(Type.SET_DISPLAY_TO_DEC_NUMBER) .setType(Type.SET_DISPLAY_TO_DEC_NUMBER)
.setSetDisplayToNumber(builder.build()).build()); .setSetDisplayToNumber(builder.build()).build());
} }
public void setDisplayToHexNumber(int number, int dots, boolean leadingZeros) { public void setDisplayToHexNumber(int number, int dots, boolean leadingZeros) {
setDisplayToHexNumber(number, dots, leadingZeros, null); setDisplayToHexNumber(number, dots, leadingZeros, null);
} }
public void setDisplayToHexNumber(int number, int dots, boolean leadingZeros, byte[] font) { public void setDisplayToHexNumber(int number, int dots, boolean leadingZeros, byte[] font) {
tm1638.Tm1638.SetDisplayToNumber.Builder builder = SetDisplayToNumber.newBuilder() tm1638.Tm1638.SetDisplayToNumber.Builder builder = SetDisplayToNumber.newBuilder()
.setNumber(number) .setNumber(number)
.setDots(dots) .setDots(dots)
.setLeadingZeros(leadingZeros); .setLeadingZeros(leadingZeros);
boolean has_font = font != null; boolean has_font = font != null;
builder.setHasFont(has_font); builder.setHasFont(has_font);
if (has_font) { if (has_font) {
builder.setFont(ByteString.copyFrom(font)); builder.setFont(ByteString.copyFrom(font));
} }
command(Command.newBuilder() command(Command.newBuilder()
.setType(Type.SET_DISPLAY_TO_HEX_NUMBER) .setType(Type.SET_DISPLAY_TO_HEX_NUMBER)
.setSetDisplayToNumber( .setSetDisplayToNumber(
builder.build()).build()); builder.build()).build());
} }
public void setDisplayToError() { public void setDisplayToError() {
command(Command.newBuilder() command(Command.newBuilder()
.setType(Type.SET_DISPLAY_TO_ERROR).build()); .setType(Type.SET_DISPLAY_TO_ERROR).build());
} }
public void setDisplayToString(String string, int dots, int pos) { public void setDisplayToString(String string, int dots, int pos) {
setDisplayToString(string, dots, pos, null); setDisplayToString(string, dots, pos, null);
} }
public void setDisplayToString(String string, int dots, int pos, byte[] font) { public void setDisplayToString(String string, int dots, int pos, byte[] font) {
Builder builder = SetDisplayToString.newBuilder() Builder builder = SetDisplayToString.newBuilder()
.setString(string) .setString(string)
.setDots(dots) .setDots(dots)
.setPos(pos); .setPos(pos);
boolean has_font = font != null; boolean has_font = font != null;
builder.setHasFont(has_font); builder.setHasFont(has_font);
if (has_font) { if (has_font) {
builder.setFont(ByteString.copyFrom(font)); builder.setFont(ByteString.copyFrom(font));
} }
if (has_font) { if (has_font) {
builder.setFont(ByteString.copyFrom(font)); builder.setFont(ByteString.copyFrom(font));
} }
command(Command.newBuilder() command(Command.newBuilder()
.setType(Type.SET_DISPLAY_TO_STRING) .setType(Type.SET_DISPLAY_TO_STRING)
.setSetDisplayToString( .setSetDisplayToString(
builder.build()).build()); builder.build()).build());
} }
public void setLED(Color color, int pos) { public void setLED(Color color, int pos) {
command(Command.newBuilder() command(Command.newBuilder()
.setType(Type.SET_LED) .setType(Type.SET_LED)
.setSetLED( .setSetLED(
SetLED.newBuilder() SetLED.newBuilder()
.setColor(color) .setColor(color)
.setPos(pos).build()).build()); .setPos(pos).build()).build());
} }
public void setLEDs(int led) { public void setLEDs(int led) {
command(Command.newBuilder() command(Command.newBuilder()
.setType(Type.SET_LEDS) .setType(Type.SET_LEDS)
.setSetLEDs( .setSetLEDs(
SetLEDs.newBuilder() SetLEDs.newBuilder()
.setLed(led).build()).build()); .setLed(led).build()).build());
} }
public void setupDisplay(boolean active, int intensity) { public void setupDisplay(boolean active, int intensity) {
command(Command.newBuilder() command(Command.newBuilder()
.setType(Type.SETUP_DISPLAY) .setType(Type.SETUP_DISPLAY)
.setSetupDisplay( .setSetupDisplay(
SetupDisplay.newBuilder() SetupDisplay.newBuilder()
.setActive(active) .setActive(active)
.setIntensity(intensity).build()).build()); .setIntensity(intensity).build()).build());
} }
} }

View File

@@ -13,28 +13,28 @@ import com.github.boukefalos.tm1638.implementation.Local;
import com.github.boukefalos.tm1638.implementation.Remote; import com.github.boukefalos.tm1638.implementation.Remote;
public class Loader extends com.github.boukefalos.arduino.Loader { 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 { public Loader(Properties properties) throws LoaderException {
super(Local.class, Remote.class, Server.class, properties); super(Local.class, Remote.class, Server.class, properties);
pico.addComponent(ParsingPort.getInstance(Message.class)); pico.addComponent(ParsingPort.getInstance(Message.class));
} }
public TM1638 getTM1638() throws ArduinoException { public TM1638 getTM1638() throws ArduinoException {
try { try {
return pico.getComponent(TM1638.class); return pico.getComponent(TM1638.class);
} catch (PicoCompositionException e) { } catch (PicoCompositionException e) {
logger.error("", e); logger.error("", e);
throw new ArduinoException("Failed to load"); throw new ArduinoException("Failed to load");
} }
} }
public Server getServer() throws ArduinoException { public Server getServer() throws ArduinoException {
try { try {
return pico.getComponent(Server.class); return pico.getComponent(Server.class);
} catch (PicoCompositionException e) { } catch (PicoCompositionException e) {
logger.error("", e); logger.error("", e);
throw new ArduinoException("Failed to load"); 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 { public class Server extends com.github.boukefalos.arduino.Server {
protected TM1638 tm1638; protected TM1638 tm1638;
public Server(TM1638 tm1638, Duplex duplex, boolean direct) { public Server(TM1638 tm1638, Duplex duplex, boolean direct) {
super(tm1638, duplex, direct); super(tm1638, duplex, direct);
this.tm1638 = tm1638; this.tm1638 = tm1638;
} }
public void receive(byte[] buffer) { public void receive(byte[] buffer) {
// Client > [Server] > Arduino // Client > [Server] > Arduino
if (direct) { if (direct) {
try { try {
tm1638.send(buffer); tm1638.send(buffer);
} catch (ArduinoException e) { } catch (ArduinoException e) {
logger.error("", e); logger.error("", e);
} }
} else { } else {
ByteArrayInputStream input = new ByteArrayInputStream(buffer); ByteArrayInputStream input = new ByteArrayInputStream(buffer);
try { try {
Command command = Command.parseDelimitedFrom(input); Command command = Command.parseDelimitedFrom(input);
logger.debug("Command type = " + command.getType().name()); logger.debug("Command type = " + command.getType().name());
switch (command.getType()) { switch (command.getType()) {
case PING: case PING:
Ping ping = command.getPing(); Ping ping = command.getPing();
tm1638.ping(ping.getId()); tm1638.ping(ping.getId());
break; break;
case SET_LED: case SET_LED:
SetLED setLED = command.getSetLED(); SetLED setLED = command.getSetLED();
logger.debug("Color = " + setLED.getColor().name()); logger.debug("Color = " + setLED.getColor().name());
switch (setLED.getColor()) { switch (setLED.getColor()) {
case RED: case RED:
tm1638.setLED(Color.RED, 1); tm1638.setLED(Color.RED, 1);
case GREEN: case GREEN:
tm1638.setLED(Color.GREEN, 1); tm1638.setLED(Color.GREEN, 1);
default: default:
break; break;
} }
break; break;
default: default:
break; break;
} }
} catch (IOException e) { } catch (IOException e) {
logger.error("Failed to parse input"); logger.error("Failed to parse input");
return; return;
} }
} }
} }
} }

View File

@@ -4,23 +4,23 @@ import tm1638.Tm1638.Color;
import com.github.boukefalos.arduino.Arduino; import com.github.boukefalos.arduino.Arduino;
public interface TM1638 extends Arduino { public interface TM1638 extends Arduino {
public void ping(int i); public void ping(int i);
public void construct(int dataPin, int clockPin, int strobePin); public void construct(int dataPin, int clockPin, int strobePin);
public void clearDisplay(); public void clearDisplay();
public void clearDisplayDigit(int pos, boolean dot); public void clearDisplayDigit(int pos, boolean dot);
public void setDisplay(byte[] values); public void setDisplay(byte[] values);
public void setDisplayDigit(int digit, int pos, boolean dot); public void setDisplayDigit(int digit, int pos, boolean dot);
public void setDisplayDigit(int digit, int pos, boolean dot, byte[] font); public void setDisplayDigit(int digit, int pos, boolean dot, byte[] font);
public void setDisplayToBinNumber(int number, int dots, 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);
public void setDisplayToDecNumber(int number, int dots, boolean leadingZeros, byte[] font); 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);
public void setDisplayToHexNumber(int number, int dots, boolean leadingZeros, byte[] font); public void setDisplayToHexNumber(int number, int dots, boolean leadingZeros, byte[] font);
public void setDisplayToError(); public void setDisplayToError();
public void setDisplayToString(String string, int dots, int pos); public void setDisplayToString(String string, int dots, int pos);
public void setDisplayToString(String string, int dots, int pos, byte[] font); public void setDisplayToString(String string, int dots, int pos, byte[] font);
public void setLED(Color color, int pos); public void setLED(Color color, int pos);
public void setLEDs(int led); public void setLEDs(int led);
public void setupDisplay(boolean active, int intensity); 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.IOException;
import java.io.OutputStream; import java.io.OutputStream;
import java.util.ArrayList;
import tm1638.Tm1638.Message; import tm1638.Tm1638.Message;
import base.work.Listen;
import com.github.boukefalos.arduino.exception.ArduinoException; import com.github.boukefalos.arduino.exception.ArduinoException;
import com.github.boukefalos.arduino.port.ParsingPort; import com.github.boukefalos.arduino.port.ParsingPort;
@@ -13,40 +11,28 @@ import com.github.boukefalos.arduino.port.Port;
import com.github.boukefalos.tm1638.AbstractTM1638; import com.github.boukefalos.tm1638.AbstractTM1638;
public class Local extends AbstractTM1638 { public class Local extends AbstractTM1638 {
protected Port arduino; protected Port arduino;
protected OutputStream outputStream; protected OutputStream outputStream;
protected ArrayList<Listen<Object>> listenList;
public Local() throws ArduinoException { public Local() throws ArduinoException {
this(ParsingPort.getInstance(Message.class)); this(ParsingPort.getInstance(Message.class));
} }
public Local(Port arduino) throws ArduinoException { public Local(Port arduino) throws ArduinoException {
this.arduino = arduino; this.arduino = arduino;
outputStream = arduino.getOutputStream(); outputStream = arduino.getOutputStream();
listenList = new ArrayList<Listen<Object>>(); arduino.register(this);
arduino.register(this); }
}
public void register(Listen<Object> listen) { public void stop() {
listenList.add(listen); arduino.close();
} }
public void remove(Listen<Object> listen) { public void send(byte[] buffer) throws ArduinoException {
listenList.remove(listen); try {
} outputStream.write(buffer);
} catch (IOException e) {
public void stop() { throw new ArduinoException("Failed to write to arduino");
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");
}
}
} }

View File

@@ -11,50 +11,41 @@ import com.github.boukefalos.arduino.exception.ArduinoException;
import com.github.boukefalos.tm1638.AbstractTM1638; import com.github.boukefalos.tm1638.AbstractTM1638;
public class Remote extends AbstractTM1638 implements Receiver { public class Remote extends AbstractTM1638 implements Receiver {
protected Duplex duplex; protected Duplex duplex;
protected ArrayList<Listen<Object>> listenList;
public Remote(Duplex duplex) { public Remote(Duplex duplex) {
this.duplex = duplex; this.duplex = duplex;
listenList = new ArrayList<Listen<Object>>(); listenList = new ArrayList<Listen<Object>>();
duplex.register(this); // Server > [receive()] duplex.register(this); // Server > [receive()]
} }
public void start() { public void start() {
duplex.start(); duplex.start();
} }
public void stop() { public void stop() {
duplex.stop(); duplex.stop();
} }
public void exit() { public void exit() {
super.stop(); super.stop();
duplex.exit(); duplex.exit();
} }
public void register(Listen<Object> listen) { public void receive(byte[] buffer) {
listenList.add(listen); // Arduino > Server > [Client]
} // Should give option to decode here?
for (Listen<Object> listen : listenList) {
listen.add(buffer);
}
}
public void remove(Listen<Object> listen) { public void send(byte[] buffer) throws ArduinoException {
listenList.remove(listen); // [Client] > Server > Arduino
} try {
duplex.send(buffer);
public void receive(byte[] buffer) { } catch (IOException e) {
// Arduino > Server > [Client] throw new ArduinoException("Failed to send");
// 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");
}
}
} }

View File

@@ -2,44 +2,48 @@ package test;
import base.work.Listen; import base.work.Listen;
import com.github.boukefalos.arduino.port.StringPort;
import com.github.boukefalos.tm1638.TM1638; import com.github.boukefalos.tm1638.TM1638;
import com.github.boukefalos.tm1638.implementation.Local; import com.github.boukefalos.tm1638.implementation.Local;
public class TestLocal extends Listen<Object> { public class TestLocal extends Listen<Object> {
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
TM1638 TM1638 = new Local(); TM1638 TM1638 = new Local(StringPort.getInstance());
main(TM1638); main(TM1638);
} }
public static void main(TM1638 TM1638) throws InterruptedException { public void input(String input) {
TM1638.register(new TestLocal()); System.out.println("> " + input);
TM1638.start(); }
/*TM1638.construct(8, 9, 7); public static void main(TM1638 TM1638) throws Exception {
TM1638.setupDisplay(true, 1); TM1638.register(new TestLocal());
TM1638.setLEDs(0xff00);*/ TM1638.start();
// Light up all the green LEDs TM1638.construct(8, 9, 7);
TM1638.setLEDs(0x00ff); TM1638.setupDisplay(true, 1);
Thread.sleep(2000); TM1638.setDisplayToString("Rik", 2, 0);
//TM1638.setLEDs(0x0000); Thread.sleep(1000);
// Light up all the red LEDs TM1638.setDisplayToDecNumber(123, 0, false);
TM1638.setLEDs(0xff00);
Thread.sleep(2000); Thread.sleep(1000);
TM1638.setLEDs(0x0000); // 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; int i = 0;
while (i < 10000) { while (i < 10000) {
//TM1638.setLED(i % 2 == 0 ? Color.GREEN : Color.RED, i % 8); //TM1638.setLED(i % 2 == 0 ? Color.GREEN : Color.RED, i % 8);
//Thread.sleep(500); //Thread.sleep(500);
TM1638.ping(i++); TM1638.ping(i++);
Thread.sleep(1000); 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; import com.github.boukefalos.tm1638.TM1638;
public class TestRemoteImplementation extends TestLocal { public class TestRemoteImplementation extends TestLocal {
protected TM1638 tm1638; protected TM1638 tm1638;
public TestRemoteImplementation(Loader loader) throws ArduinoException { public TestRemoteImplementation(Loader loader) throws ArduinoException {
tm1638 = loader.getTM1638(); tm1638 = loader.getTM1638();
//tm1638.register(this); //tm1638.register(this);
} }
public void activate() throws ActivateException { public void activate() throws ActivateException {
tm1638.start(); tm1638.start();
super.activate(); super.activate();
} }
public static void main(Properties localProperties, Properties remoteProperties) throws Exception { public static void main(Properties localProperties, Properties remoteProperties) throws Exception {
Loader localLoader = new Loader(localProperties); Loader localLoader = new Loader(localProperties);
Loader remoteLoader = new Loader(remoteProperties); Loader remoteLoader = new Loader(remoteProperties);
try { try {
Server server = localLoader.getServer(); Server server = localLoader.getServer();
TM1638 TM1638 = remoteLoader.getTM1638(); TM1638 TM1638 = remoteLoader.getTM1638();
server.start(); server.start();
main(TM1638); main(TM1638);
} catch (ArduinoException e) { } catch (ArduinoException e) {
e.printStackTrace(); e.printStackTrace();
return; return;
} }
} }
} }

View File

@@ -5,24 +5,24 @@ import java.util.Properties;
import com.github.boukefalos.arduino.exception.ArduinoException; import com.github.boukefalos.arduino.exception.ArduinoException;
public class TestTcpImplementation { public class TestTcpImplementation {
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
Properties localProperties = new Properties(); Properties localProperties = new Properties();
localProperties.setProperty("implementation", "local"); localProperties.setProperty("implementation", "local");
localProperties.setProperty("server", "true"); localProperties.setProperty("server", "true");
localProperties.setProperty("server.direct", "false"); localProperties.setProperty("server.direct", "false");
localProperties.setProperty("server.port", "8883"); localProperties.setProperty("server.port", "8883");
localProperties.setProperty("server.protocol", "tcp"); localProperties.setProperty("server.protocol", "tcp");
Properties remoteProperties = new Properties(); Properties remoteProperties = new Properties();
remoteProperties.setProperty("implementation", "remote"); remoteProperties.setProperty("implementation", "remote");
remoteProperties.setProperty("protocol", "tcp"); remoteProperties.setProperty("protocol", "tcp");
remoteProperties.setProperty("remote.host", "localhost"); remoteProperties.setProperty("remote.host", "localhost");
remoteProperties.setProperty("remote.port", "8883"); remoteProperties.setProperty("remote.port", "8883");
try { try {
TestRemoteImplementation.main(localProperties, remoteProperties); TestRemoteImplementation.main(localProperties, remoteProperties);
} catch (ArduinoException e) { } catch (ArduinoException e) {
System.err.println(e.getMessage()); System.err.println(e.getMessage());
} }
} }
} }

View File

@@ -3,21 +3,21 @@ package test;
import java.util.Properties; import java.util.Properties;
public class TestUdpImplementation { public class TestUdpImplementation {
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
Properties localProperties = new Properties(); Properties localProperties = new Properties();
localProperties.setProperty("implementation", "local"); localProperties.setProperty("implementation", "local");
localProperties.setProperty("protocol", "udp"); localProperties.setProperty("protocol", "udp");
localProperties.setProperty("server", "true"); localProperties.setProperty("server", "true");
localProperties.setProperty("server.direct", "false"); localProperties.setProperty("server.direct", "false");
localProperties.setProperty("server.port", "8883"); localProperties.setProperty("server.port", "8883");
localProperties.setProperty("server.protocol", "udp"); localProperties.setProperty("server.protocol", "udp");
Properties remoteProperties = new Properties(); Properties remoteProperties = new Properties();
remoteProperties.setProperty("implementation", "remote"); remoteProperties.setProperty("implementation", "remote");
remoteProperties.setProperty("protocol", "udp"); remoteProperties.setProperty("protocol", "udp");
remoteProperties.setProperty("remote.host", "localhost"); remoteProperties.setProperty("remote.host", "localhost");
remoteProperties.setProperty("remote.port", "8883"); remoteProperties.setProperty("remote.port", "8883");
TestRemoteImplementation.main(localProperties, remoteProperties); TestRemoteImplementation.main(localProperties, remoteProperties);
} }
} }