From 22410c419f342d7a8a986905ea6414e93353b7a6 Mon Sep 17 00:00:00 2001 From: Imbus <> Date: Thu, 7 Nov 2024 22:25:54 +0100 Subject: [PATCH] Wash --- wash/src/wash/control/Wash.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/wash/src/wash/control/Wash.java b/wash/src/wash/control/Wash.java index 4c29e4a..0f0f4bf 100644 --- a/wash/src/wash/control/Wash.java +++ b/wash/src/wash/control/Wash.java @@ -20,17 +20,19 @@ public class Wash { water.start(); spin.start(); - ActorThread t = null; + // Instantiated to avoid nullchecking in the interrupt inside the loop + ActorThread t = new EmptyProgram(); outer: while (true) { int n = io.awaitButton(); + t.interrupt(); // Immediately abort previous action, t != null here System.out.println("user selected program " + n); // if the user presses buttons 1-3, start a washing program // if the user presses button 0, and a program has been started, stop it switch (n) { - case 0 -> t = new WashingProgramN(io, temp, water, spin); + case 0 -> t = new WashingProgramStop(io, temp, water, spin); case 1 -> 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);