Reorganise project to implement new loader system for local/remote implementations

This commit is contained in:
2015-06-24 16:48:16 +01:00
parent ae7b8b21c4
commit 55d51fdcd2
25 changed files with 421 additions and 484 deletions

View File

@@ -0,0 +1,60 @@
package com.github.boukefalos.tm1638.implementation;
import java.io.IOException;
import java.util.ArrayList;
import base.Duplex;
import base.Receiver;
import base.work.Listen;
import com.github.boukefalos.tm1638.AbstractTM1638;
import com.github.boukefalos.tm1638.exception.ArduinoException;
public class Remote extends AbstractTM1638 implements Receiver {
protected Duplex duplex;
protected ArrayList<Listen<Object>> listenList;
public Remote(Duplex duplex) {
this.duplex = duplex;
listenList = new ArrayList<Listen<Object>>();
duplex.register(this); // Server > [receive()]
}
public void start() {
duplex.start();
}
public void stop() {
duplex.stop();
}
public void exit() {
super.stop();
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 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");
}
}
}