From c869104e8326537badc05ff8432f0373c24b3749 Mon Sep 17 00:00:00 2001 From: fros4943 Date: Sat, 14 Nov 2009 11:09:41 +0000 Subject: [PATCH] bug fix: schedule button events from simulation thread --- .../contikimote/interfaces/ContikiButton.java | 22 ++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/tools/cooja/java/se/sics/cooja/contikimote/interfaces/ContikiButton.java b/tools/cooja/java/se/sics/cooja/contikimote/interfaces/ContikiButton.java index 6443a4937..06b5caa8d 100644 --- a/tools/cooja/java/se/sics/cooja/contikimote/interfaces/ContikiButton.java +++ b/tools/cooja/java/se/sics/cooja/contikimote/interfaces/ContikiButton.java @@ -26,7 +26,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: ContikiButton.java,v 1.14 2009/10/27 10:11:17 fros4943 Exp $ + * $Id: ContikiButton.java,v 1.15 2009/11/14 11:09:41 fros4943 Exp $ */ package se.sics.cooja.contikimote.interfaces; @@ -108,16 +108,28 @@ public class ContikiButton extends Button implements ContikiMoteInterface { * Clicks button: Presses and immediately releases button. */ public void clickButton() { - mote.getSimulation().scheduleEvent(pressButtonEvent, mote.getSimulation().getSimulationTime()); - mote.getSimulation().scheduleEvent(releaseButtonEvent, mote.getSimulation().getSimulationTime() + Simulation.MILLISECOND); + mote.getSimulation().invokeSimulationThread(new Runnable() { + public void run() { + mote.getSimulation().scheduleEvent(pressButtonEvent, mote.getSimulation().getSimulationTime()); + mote.getSimulation().scheduleEvent(releaseButtonEvent, mote.getSimulation().getSimulationTime() + Simulation.MILLISECOND); + } + }); } public void pressButton() { - mote.getSimulation().scheduleEvent(pressButtonEvent, mote.getSimulation().getSimulationTime()); + mote.getSimulation().invokeSimulationThread(new Runnable() { + public void run() { + mote.getSimulation().scheduleEvent(pressButtonEvent, mote.getSimulation().getSimulationTime()); + } + }); } public void releaseButton() { - mote.getSimulation().scheduleEvent(releaseButtonEvent, mote.getSimulation().getSimulationTime()); + mote.getSimulation().invokeSimulationThread(new Runnable() { + public void run() { + mote.getSimulation().scheduleEvent(releaseButtonEvent, mote.getSimulation().getSimulationTime()); + } + }); } private void doReleaseButton() {