diff --git a/wash/src/wash/control/Settings.java b/wash/src/wash/control/Settings.java index c5bd535..733582c 100644 --- a/wash/src/wash/control/Settings.java +++ b/wash/src/wash/control/Settings.java @@ -1,6 +1,6 @@ package wash.control; -interface Settings { +public interface Settings { // simulation speed-up factor: 50 means the simulation is 50 times faster than // real time. Modify this as you wish. int SPEEDUP = 50; diff --git a/wash/src/wash/control/Wash.java b/wash/src/wash/control/Wash.java index 086ed44..3e3ee2a 100644 --- a/wash/src/wash/control/Wash.java +++ b/wash/src/wash/control/Wash.java @@ -2,6 +2,7 @@ package wash.control; import actor.ActorThread; import wash.io.WashingIO; +import wash.program.*; import wash.simulation.WashingSimulator; public class Wash { @@ -29,9 +30,9 @@ public class Wash { // if the user presses button 0, and a program has been started, stop it switch (n) { - case 0 -> t = new WashingProgram0(io, temp, water, spin); + case 0 -> t = new WashingProgramN(io, temp, water, spin); case 1 -> t = new WashingProgram1(io, temp, water, spin); - case 2 -> t = new WashingProgram1(io, temp, water, spin); + case 2 -> t = new WashingProgram2(io, temp, water, spin); case 3 -> t = new WashingProgram3(io, temp, water, spin); default -> { System.out.println("Invalid program number"); diff --git a/wash/src/wash/control/WashingMessage.java b/wash/src/wash/control/WashingMessage.java index 2fe4dd1..31cafde 100644 --- a/wash/src/wash/control/WashingMessage.java +++ b/wash/src/wash/control/WashingMessage.java @@ -22,7 +22,9 @@ public final class WashingMessage { WATER_IDLE, WATER_FILL, WATER_DRAIN, - ACKNOWLEDGMENT + ACKNOWLEDGMENT, + /** No operation, allows for prettier switch statements */ + NOOP } // Who sent the message diff --git a/wash/src/wash/control/WashingProgram3.java b/wash/src/wash/control/WashingProgram3.java deleted file mode 100644 index d4e24b8..0000000 --- a/wash/src/wash/control/WashingProgram3.java +++ /dev/null @@ -1,79 +0,0 @@ -package wash.control; - -import actor.ActorThread; -import wash.io.WashingIO; - -import static wash.control.WashingMessage.Order.*; - -/** - * Program 3 for washing machine. This also serves as an example of how washing - * programs can be structured. - * - * This short program stops all regulation of temperature and water levels, - * stops the barrel from spinning, and drains the machine of water. - * - * It can be used after an emergency stop (program 0) or a power failure. - */ -public class WashingProgram3 extends ActorThread { - - private WashingIO io; - private ActorThread temp; - private ActorThread water; - private ActorThread spin; - - public WashingProgram3(WashingIO io, - ActorThread temp, - ActorThread water, - ActorThread spin) - { - this.io = io; - this.temp = temp; - this.water = water; - this.spin = spin; - } - - @Override - public void run() { - try { - System.out.println("washing program 3 started"); - - // Switch off heating - temp.send(new WashingMessage(this, TEMP_IDLE)); - - // Wait for temperature controller to acknowledge - WashingMessage ack1 = receive(); - System.out.println("got " + ack1); - - // Drain barrel, which may take some time. To ensure the barrel - // is drained before we continue, an acknowledgment is required. - water.send(new WashingMessage(this, WATER_DRAIN)); - WashingMessage ack2 = receive(); // wait for acknowledgment - System.out.println("got " + ack2); - - // Now that the barrel is drained, we can turn off water regulation. - water.send(new WashingMessage(this, WATER_IDLE)); - WashingMessage ack3 = receive(); // wait for acknowledgment - System.out.println("got " + ack3); - - // Switch off spin. We expect an acknowledgment, to ensure - // the hatch isn't opened while the barrel is spinning. - spin.send(new WashingMessage(this, SPIN_OFF)); - WashingMessage ack4 = receive(); // wait for acknowledgment - System.out.println("got " + ack4); - - // Unlock hatch - io.lock(false); - - System.out.println("washing program 3 finished"); - } catch (InterruptedException e) { - - // If we end up here, it means the program was interrupt()'ed: - // set all controllers to idle - - temp.send(new WashingMessage(this, TEMP_IDLE)); - water.send(new WashingMessage(this, WATER_IDLE)); - spin.send(new WashingMessage(this, SPIN_OFF)); - System.out.println("washing program terminated"); - } - } -}