always consuming button events

(bug fix: mote falls asleep during fast button clicks)
This commit is contained in:
fros4943 2007-04-02 14:14:26 +00:00
parent 5a96a9cdb7
commit 3d5298ab69
3 changed files with 15 additions and 8 deletions

View File

@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE. * 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" #include "lib/sensors.h"
@ -100,9 +100,9 @@ doInterfaceActionsBeforeTick(void)
if(timer_expired(&debouncetimer)) { if(timer_expired(&debouncetimer)) {
timer_set(&debouncetimer, CLOCK_SECOND / 10); timer_set(&debouncetimer, CLOCK_SECOND / 10);
sensors_changed(&button_sensor); sensors_changed(&button_sensor);
simButtonChanged = 0;
} }
} }
simButtonChanged = 0;
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
static void static void

View File

@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE. * 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; package se.sics.cooja.contikimote.interfaces;
@ -102,11 +102,11 @@ public class ContikiButton extends Button implements ContikiMoteInterface {
moteMem.setByteValueOf("simButtonIsDown", (byte) 0); moteMem.setByteValueOf("simButtonIsDown", (byte) 0);
if (moteMem.getByteValueOf("simButtonIsActive") == 1) { if (moteMem.getByteValueOf("simButtonIsActive") == 1) {
// moteMem.setByteValueOf("simButtonChanged", (byte) 1); moteMem.setByteValueOf("simButtonChanged", (byte) 1);
// If mote is inactive, wake it up // If mote is inactive, wake it up
// if (RAISES_EXTERNAL_INTERRUPT) if (RAISES_EXTERNAL_INTERRUPT)
// mote.setState(Mote.State.ACTIVE); mote.setState(Mote.State.ACTIVE);
setChanged(); setChanged();
notifyObservers(); notifyObservers();
@ -137,6 +137,12 @@ public class ContikiButton extends Button implements ContikiMoteInterface {
} }
public void doActionsAfterTick() { 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 a button is pressed and should be clicked, release it now
if (shouldBeReleased) { if (shouldBeReleased) {
// Make sure that the earlier press event has been handled by core // Make sure that the earlier press event has been handled by core

View File

@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE. * 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; package se.sics.cooja.plugins;
@ -103,7 +103,8 @@ public abstract class Visualizer2D extends VisPlugin {
private class ButtonClickMoteMenuAction implements MoteMenuAction { private class ButtonClickMoteMenuAction implements MoteMenuAction {
public boolean isEnabled(Mote mote) { public boolean isEnabled(Mote mote) {
return mote.getInterfaces().getButton() != null; return mote.getInterfaces().getButton() != null
&& !mote.getInterfaces().getButton().isPressed();
} }
public String getDescription(Mote mote) { public String getDescription(Mote mote) {
return "Click button on " + mote; return "Click button on " + mote;