Factor out all general jlibarduino code

This commit is contained in:
2015-06-25 15:58:30 +01:00
parent 55d51fdcd2
commit 0e8f953f0f
12 changed files with 65 additions and 279 deletions

View File

@@ -7,42 +7,16 @@ import tm1638.Tm1638.Color;
import tm1638.Tm1638.Command;
import tm1638.Tm1638.Ping;
import tm1638.Tm1638.SetLed;
import base.Control;
import base.Duplex;
import base.Receiver;
import base.exception.worker.ActivateException;
import base.exception.worker.DeactivateException;
import base.work.Listen;
import com.github.boukefalos.tm1638.exception.ArduinoException;
public class Server extends Listen<Object> implements Control, Receiver {
protected static final boolean DIRECT = false;
import com.github.boukefalos.arduino.exception.ArduinoException;
public class Server extends com.github.boukefalos.arduino.Server {
protected TM1638 tm1638;
protected Duplex duplex;
protected boolean direct;
public Server(TM1638 tm1638, Duplex duplex) {
this(tm1638, duplex, DIRECT);
}
public Server(TM1638 tm1638, Duplex duplex, boolean direct) {
super(tm1638, duplex, direct);
this.tm1638 = tm1638;
this.duplex = duplex;
this.direct = direct;
tm1638.register(this); // Arduino > [input()]
duplex.register(this); // Client > [receive()]
}
public void activate() throws ActivateException {
duplex.start();
super.activate();
}
public void deactivate() throws DeactivateException {
duplex.stop();
super.deactivate();
}
public void receive(byte[] buffer) {
@@ -84,13 +58,4 @@ public class Server extends Listen<Object> implements Control, Receiver {
}
}
}
public void input(byte[] buffer) {
// Arduino > [Server] > Client
try {
duplex.send(buffer);
} catch (IOException e) {
logger.error("", e);
}
}
}