Bad water controller

This commit is contained in:
Imbus 2024-11-03 17:17:52 +01:00
parent 764cfbd0fa
commit b0210cbfbd

View file

@ -5,14 +5,74 @@ import wash.io.WashingIO;
public class WaterController extends ActorThread<WashingMessage> { public class WaterController extends ActorThread<WashingMessage> {
// TODO: add attributes WashingMessage.Order o;
WashingMessage m;
WashingIO io;
public WaterController(WashingIO io) { public WaterController(WashingIO io) {
// TODO this.io = io;
} }
@Override @Override
public void run() { public void run() {
// TODO
boolean firstRun = true;
while (true) {
try {
WashingMessage n = receiveWithTimeout(60000 / Settings.SPEEDUP);
if (n != null) {
if (o != null && o != n.order())
firstRun = true;
m = n;
o = m.order();
}
if (o != null) {
switch (o) {
case WATER_DRAIN -> {
if (io.getWaterLevel() > 0.0) {
io.fill(false);
io.drain(true);
}
else {
//io.drain(false);
if (firstRun)
//sendAck();
firstRun = false;
}
}
case WATER_FILL -> {
if (io.getWaterLevel() < 10.0) {
io.drain(false);
io.fill(true);
} else {
io.fill(false);
if (firstRun)
//sendAck();
firstRun = false;
}
}
case WATER_IDLE -> {
io.drain(false);
io.fill(false);
}
}
}
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
// if m is null, it means a minute passed and no message was received
}
}
public void sendAck() {
m.sendAck(this);
} }
} }