[Major] GpioBridge is now a singleton

This commit is contained in:
Robert von Burg 2016-02-05 22:19:00 +01:00
parent 4d5a58f8e5
commit 5121a179f5
2 changed files with 12 additions and 2 deletions

View File

@ -19,7 +19,17 @@ public class GpioBridge {
private Thread thread;
private volatile boolean run;
public GpioBridge() {
private static final GpioBridge instance;
static {
instance = new GpioBridge();
}
public static GpioBridge getInstance() {
return instance;
}
private GpioBridge() {
this.cache = new HashMap<>();
this.listeners = Collections.synchronizedMap(new HashMap<>());
}

View File

@ -25,7 +25,7 @@ public class GpioBridgeTest {
Thread.currentThread().setPriority(Thread.MAX_PRIORITY);
GpioBridge gpioBridge = new GpioBridge();
GpioBridge gpioBridge = GpioBridge.getInstance();
System.out.println("Preparing pins...");
greenBtn = gpioBridge.getGpio(Pin.P8_07, Direction.IN).setLabel("Green");