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,36 +18,48 @@ 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);
//System.out.println(message);
Object object;
switch (message.getType()) {
case PONG:
input(message.getPong());
object = message.getPong();
break;
case TEXT:
input(message.getText());
object = message.getText();
break;
case BUTTONS:
input(message.getButtons());
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) {
//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");

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;
@@ -15,7 +13,6 @@ import com.github.boukefalos.tm1638.AbstractTM1638;
public class Local extends AbstractTM1638 {
protected Port arduino;
protected OutputStream outputStream;
protected ArrayList<Listen<Object>> listenList;
public Local() throws ArduinoException {
this(ParsingPort.getInstance(Message.class));
@@ -24,18 +21,9 @@ public class Local extends AbstractTM1638 {
public Local(Port arduino) throws ArduinoException {
this.arduino = arduino;
outputStream = arduino.getOutputStream();
listenList = new ArrayList<Listen<Object>>();
arduino.register(this);
}
public void register(Listen<Object> listen) {
listenList.add(listen);
}
public void remove(Listen<Object> listen) {
listenList.remove(listen);
}
public void stop() {
arduino.close();
}
@@ -43,8 +31,6 @@ public class Local extends AbstractTM1638 {
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

@@ -12,7 +12,6 @@ import com.github.boukefalos.tm1638.AbstractTM1638;
public class Remote extends AbstractTM1638 implements Receiver {
protected Duplex duplex;
protected ArrayList<Listen<Object>> listenList;
public Remote(Duplex duplex) {
this.duplex = duplex;
@@ -33,14 +32,6 @@ public class Remote extends AbstractTM1638 implements Receiver {
duplex.exit();
}
public void register(Listen<Object> listen) {
listenList.add(listen);
}
public void remove(Listen<Object> listen) {
listenList.remove(listen);
}
public void receive(byte[] buffer) {
// Arduino > Server > [Client]
// Should give option to decode here?

View File

@@ -2,31 +2,40 @@ 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();
TM1638 TM1638 = new Local(StringPort.getInstance());
main(TM1638);
}
public static void main(TM1638 TM1638) throws InterruptedException {
public void input(String input) {
System.out.println("> " + input);
}
public static void main(TM1638 TM1638) throws Exception {
TM1638.register(new TestLocal());
TM1638.start();
/*TM1638.construct(8, 9, 7);
TM1638.construct(8, 9, 7);
TM1638.setupDisplay(true, 1);
TM1638.setLEDs(0xff00);*/
TM1638.setDisplayToString("Rik", 2, 0);
Thread.sleep(1000);
TM1638.setDisplayToDecNumber(123, 0, false);
Thread.sleep(1000);
// Light up all the green LEDs
TM1638.setLEDs(0x00ff);
Thread.sleep(2000);
//TM1638.setLEDs(0x0000);
Thread.sleep(1000);
TM1638.setLEDs(0x0000);
// Light up all the red LEDs
TM1638.setLEDs(0xff00);
Thread.sleep(2000);
Thread.sleep(1000);
TM1638.setLEDs(0x0000);
int i = 0;
@@ -37,9 +46,4 @@ public class TestLocal extends Listen<Object> {
Thread.sleep(1000);
}
}
public TestLocal() {
super();
start();
}
}