From 3d5298ab69ee65a97403d69271679313427291f7 Mon Sep 17 00:00:00 2001 From: fros4943 Date: Mon, 2 Apr 2007 14:14:26 +0000 Subject: [PATCH] always consuming button events (bug fix: mote falls asleep during fast button clicks) --- platform/cooja/dev/button-sensor.c | 4 ++-- .../contikimote/interfaces/ContikiButton.java | 14 ++++++++++---- .../java/se/sics/cooja/plugins/Visualizer2D.java | 5 +++-- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/platform/cooja/dev/button-sensor.c b/platform/cooja/dev/button-sensor.c index c8e2a3948..e2b9c0cfc 100644 --- a/platform/cooja/dev/button-sensor.c +++ b/platform/cooja/dev/button-sensor.c @@ -26,7 +26,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: button-sensor.c,v 1.3 2007/03/22 20:37:34 fros4943 Exp $ + * $Id: button-sensor.c,v 1.4 2007/04/02 14:14:28 fros4943 Exp $ */ #include "lib/sensors.h" @@ -100,9 +100,9 @@ doInterfaceActionsBeforeTick(void) if(timer_expired(&debouncetimer)) { timer_set(&debouncetimer, CLOCK_SECOND / 10); sensors_changed(&button_sensor); - simButtonChanged = 0; } } + simButtonChanged = 0; } /*---------------------------------------------------------------------------*/ static void 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 a28f345f7..0894a9f84 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.5 2007/01/09 10:05:19 fros4943 Exp $ + * $Id: ContikiButton.java,v 1.6 2007/04/02 14:14:28 fros4943 Exp $ */ package se.sics.cooja.contikimote.interfaces; @@ -102,11 +102,11 @@ public class ContikiButton extends Button implements ContikiMoteInterface { moteMem.setByteValueOf("simButtonIsDown", (byte) 0); if (moteMem.getByteValueOf("simButtonIsActive") == 1) { -// moteMem.setByteValueOf("simButtonChanged", (byte) 1); + moteMem.setByteValueOf("simButtonChanged", (byte) 1); // If mote is inactive, wake it up -// if (RAISES_EXTERNAL_INTERRUPT) -// mote.setState(Mote.State.ACTIVE); + if (RAISES_EXTERNAL_INTERRUPT) + mote.setState(Mote.State.ACTIVE); setChanged(); notifyObservers(); @@ -137,6 +137,12 @@ public class ContikiButton extends Button implements ContikiMoteInterface { } public void doActionsAfterTick() { + // Make sure a mote never falls asleep with unhandled button events + if (moteMem.getByteValueOf("simButtonChanged") == 1 + && RAISES_EXTERNAL_INTERRUPT) { + mote.setState(Mote.State.ACTIVE); + } + // If a button is pressed and should be clicked, release it now if (shouldBeReleased) { // Make sure that the earlier press event has been handled by core diff --git a/tools/cooja/java/se/sics/cooja/plugins/Visualizer2D.java b/tools/cooja/java/se/sics/cooja/plugins/Visualizer2D.java index 929657bd9..a38f8bc27 100644 --- a/tools/cooja/java/se/sics/cooja/plugins/Visualizer2D.java +++ b/tools/cooja/java/se/sics/cooja/plugins/Visualizer2D.java @@ -26,7 +26,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: Visualizer2D.java,v 1.8 2007/03/23 20:48:29 fros4943 Exp $ + * $Id: Visualizer2D.java,v 1.9 2007/04/02 14:14:26 fros4943 Exp $ */ package se.sics.cooja.plugins; @@ -103,7 +103,8 @@ public abstract class Visualizer2D extends VisPlugin { private class ButtonClickMoteMenuAction implements MoteMenuAction { public boolean isEnabled(Mote mote) { - return mote.getInterfaces().getButton() != null; + return mote.getInterfaces().getButton() != null + && !mote.getInterfaces().getButton().isPressed(); } public String getDescription(Mote mote) { return "Click button on " + mote;