removes control IO from the Well class, creates threaded IOControl class

This commit is contained in:
Patrick McDonagh
2017-02-10 10:26:45 -06:00
parent 419f42cf17
commit 062771a1e9
4 changed files with 72 additions and 79 deletions

View File

@@ -12,9 +12,7 @@ public class POC implements Runnable{
protected Well thisWell;
private int simLoops;
private Thread t;
private DigitalIn startBtn, stopBtn;
private DigitalOut led2, led3, led4, led5;
private DigitalOut runIndicator;
private boolean ioEnabled;
@@ -25,14 +23,7 @@ public class POC implements Runnable{
// thisWell.printTapers();
this.simLoops = simLoops;
// IO
startBtn = new DigitalIn(8);
stopBtn = new DigitalIn(9);
led2 = new DigitalOut(2, 0);
led3 = new DigitalOut(3, 0);
led4 = new DigitalOut(4, 0);
led5 = new DigitalOut(5, 0);
runIndicator = new DigitalOut(6,0);
}
@@ -41,25 +32,9 @@ public class POC implements Runnable{
if (this.ioEnabled) {
thisWell = new Well(wellName, simFileName,99, 99, 7);
// IO
startBtn = new DigitalIn(8);
stopBtn = new DigitalIn(9);
led2 = new DigitalOut(2, 0);
led3 = new DigitalOut(3, 0);
led4 = new DigitalOut(4, 0);
led5 = new DigitalOut(5, 0);
runIndicator = new DigitalOut(6,0);
} else {
thisWell = new Well(wellName, simFileName,99, 99, 99);
// IO
startBtn = new DigitalIn(99);
stopBtn = new DigitalIn(99);
led2 = new DigitalOut(99, 0);
led3 = new DigitalOut(99, 0);
led4 = new DigitalOut(99, 0);
led5 = new DigitalOut(99, 0);
runIndicator = new DigitalOut(99,0);
}
thisWell.parseJSONFile(wellSetupJsonFile);
@@ -67,40 +42,21 @@ public class POC implements Runnable{
this.simLoops = simLoops;
}
public void allOutputsOff(){
led2.write(0,true);
led3.write(0,true);
led4.write(0,true);
led5.write(0,true);
}
public void run(){
new Thread(new CLScanner(this)).start();
int led2out, led3out, led4out,led5out;
double pos;
if(ioEnabled){
new Thread(new IOControl(this)).start();
}
long sleepMilliseconds = (long) (thisWell.getDt() * 1000);
thisWell.setupFluidRatio(0.50, 0.50, 1.12);
thisWell.checkSafeties();
while (true) {
while (thisWell.getRunStatus() == Well.RUNSTATUS_RUNNING || thisWell.getRunStatus() == Well.RUNSTATUS_STARTING) {
for (int i = 0; i <= thisWell.sim.getLastFilledIndex(); i++) {
if (startBtn.read() == 1) thisWell.start("startbutton");
if (stopBtn.read() == 1) thisWell.stop("stopbutton");
if (startBtn.read() == 1 && stopBtn.read() == 1) {
System.exit(0);
}
thisWell.eval(i);
pos = thisWell.getCurrentSurfacePosition();
led2.write(pos > 20.0 ? 1 : 0);
led3.write(pos > 40.0 ? 1 : 0);
led4.write(pos > 60.0 ? 1 : 0);
led5.write(pos > 80.0 ? 1 : 0);
runIndicator.write(thisWell.getRunStatus()==Well.RUNSTATUS_RUNNING ? 1 : 0);
try {
Thread.sleep(sleepMilliseconds);
} catch (InterruptedException e) {
@@ -108,17 +64,6 @@ public class POC implements Runnable{
}
}
}
if (startBtn.read() == 1) thisWell.start("startbutton");
if (stopBtn.read() == 1) thisWell.stop("stopbutton");
if (startBtn.read() == 1 && stopBtn.read() == 1) {
System.exit(0);
}
led2.write(0);
led3.write(0);
led4.write(0);
led5.write(0);
}
}