Replace tabs with spaces
This commit is contained in:
@@ -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,36 +18,48 @@ 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);
|
||||||
|
Object object;
|
||||||
switch (message.getType()) {
|
switch (message.getType()) {
|
||||||
case PONG:
|
case PONG:
|
||||||
input(message.getPong());
|
object = message.getPong();
|
||||||
break;
|
break;
|
||||||
case TEXT:
|
case TEXT:
|
||||||
input(message.getText());
|
object = message.getText();
|
||||||
break;
|
break;
|
||||||
case BUTTONS:
|
case BUTTONS:
|
||||||
input(message.getButtons());
|
object = message.getButtons();
|
||||||
break;
|
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) {
|
||||||
|
//System.out.println(command.toString());
|
||||||
|
//System.out.println(command.toString().length());
|
||||||
ByteArrayOutputStream output = new ByteArrayOutputStream(BUFFER_SIZE);
|
ByteArrayOutputStream output = new ByteArrayOutputStream(BUFFER_SIZE);
|
||||||
try {
|
try {
|
||||||
command.writeDelimitedTo(output);
|
command.writeDelimitedTo(output);
|
||||||
byte[] buffer = output.toByteArray();
|
byte[] buffer = output.toByteArray();
|
||||||
|
//System.out.println("[" + new String(buffer).trim() + "]");
|
||||||
|
//System.out.println(buffer.length);
|
||||||
send(buffer);
|
send(buffer);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
logger.error("Failed to send command");
|
logger.error("Failed to send command");
|
||||||
|
|||||||
@@ -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;
|
||||||
@@ -15,7 +13,6 @@ 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));
|
||||||
@@ -24,18 +21,9 @@ public class Local extends AbstractTM1638 {
|
|||||||
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) {
|
|
||||||
listenList.add(listen);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void remove(Listen<Object> listen) {
|
|
||||||
listenList.remove(listen);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void stop() {
|
public void stop() {
|
||||||
arduino.close();
|
arduino.close();
|
||||||
}
|
}
|
||||||
@@ -43,8 +31,6 @@ public class Local extends AbstractTM1638 {
|
|||||||
public void send(byte[] buffer) throws ArduinoException {
|
public void send(byte[] buffer) throws ArduinoException {
|
||||||
try {
|
try {
|
||||||
outputStream.write(buffer);
|
outputStream.write(buffer);
|
||||||
outputStream.flush();
|
|
||||||
sleep(100);
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new ArduinoException("Failed to write to arduino");
|
throw new ArduinoException("Failed to write to arduino");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,7 +12,6 @@ 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;
|
||||||
@@ -33,14 +32,6 @@ public class Remote extends AbstractTM1638 implements Receiver {
|
|||||||
duplex.exit();
|
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) {
|
public void receive(byte[] buffer) {
|
||||||
// Arduino > Server > [Client]
|
// Arduino > Server > [Client]
|
||||||
// Should give option to decode here?
|
// Should give option to decode here?
|
||||||
|
|||||||
@@ -2,31 +2,40 @@ 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) {
|
||||||
|
System.out.println("> " + input);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(TM1638 TM1638) throws Exception {
|
||||||
TM1638.register(new TestLocal());
|
TM1638.register(new TestLocal());
|
||||||
TM1638.start();
|
TM1638.start();
|
||||||
|
|
||||||
/*TM1638.construct(8, 9, 7);
|
TM1638.construct(8, 9, 7);
|
||||||
TM1638.setupDisplay(true, 1);
|
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
|
// Light up all the green LEDs
|
||||||
TM1638.setLEDs(0x00ff);
|
TM1638.setLEDs(0x00ff);
|
||||||
Thread.sleep(2000);
|
Thread.sleep(1000);
|
||||||
//TM1638.setLEDs(0x0000);
|
TM1638.setLEDs(0x0000);
|
||||||
|
|
||||||
// Light up all the red LEDs
|
// Light up all the red LEDs
|
||||||
TM1638.setLEDs(0xff00);
|
TM1638.setLEDs(0xff00);
|
||||||
Thread.sleep(2000);
|
Thread.sleep(1000);
|
||||||
TM1638.setLEDs(0x0000);
|
TM1638.setLEDs(0x0000);
|
||||||
|
|
||||||
int i = 0;
|
int i = 0;
|
||||||
@@ -37,9 +46,4 @@ public class TestLocal extends Listen<Object> {
|
|||||||
Thread.sleep(1000);
|
Thread.sleep(1000);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public TestLocal() {
|
|
||||||
super();
|
|
||||||
start();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user