SkyButton: Reduce dependency on SkyMote

Placed call to setButton() in implementation-specific functions
doPressButton() and doReleaseButton() as in ContikiButton.
This commit is contained in:
Enrico Joerns 2014-10-31 00:39:43 +01:00
parent d99708ba08
commit 82d30ef2e3

View file

@ -31,17 +31,14 @@
package org.contikios.cooja.mspmote.interfaces; package org.contikios.cooja.mspmote.interfaces;
import java.util.Collection; import java.util.Collection;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.jdom.Element;
import org.contikios.cooja.ClassDescription; import org.contikios.cooja.ClassDescription;
import org.contikios.cooja.Mote; import org.contikios.cooja.Mote;
import org.contikios.cooja.MoteTimeEvent;
import org.contikios.cooja.Simulation; import org.contikios.cooja.Simulation;
import org.contikios.cooja.interfaces.Button; import org.contikios.cooja.interfaces.Button;
import org.contikios.cooja.mspmote.MspMoteTimeEvent;
import org.contikios.cooja.mspmote.SkyMote; import org.contikios.cooja.mspmote.SkyMote;
import org.jdom.Element;
@ClassDescription("Button") @ClassDescription("Button")
public class SkyButton extends Button { public class SkyButton extends Button {
@ -50,21 +47,21 @@ public class SkyButton extends Button {
private SkyMote skyMote; private SkyMote skyMote;
private Simulation sim; private Simulation sim;
private MspMoteTimeEvent pressButtonEvent; private MoteTimeEvent pressButtonEvent;
private MspMoteTimeEvent releaseButtonEvent; private MoteTimeEvent releaseButtonEvent;
public SkyButton(Mote mote) { public SkyButton(Mote mote) {
skyMote = (SkyMote) mote; skyMote = (SkyMote) mote;
sim = mote.getSimulation(); sim = mote.getSimulation();
pressButtonEvent = new MspMoteTimeEvent((SkyMote)mote, 0) { pressButtonEvent = new MoteTimeEvent(mote, 0) {
public void execute(long t) { public void execute(long t) {
skyMote.skyNode.setButton(true); doPressButton();
} }
}; };
releaseButtonEvent = new MspMoteTimeEvent((SkyMote)mote, 0) { releaseButtonEvent = new MoteTimeEvent(mote, 0) {
public void execute(long t) { public void execute(long t) {
skyMote.skyNode.setButton(false); doReleaseButton();
} }
}; };
} }
@ -86,6 +83,10 @@ public class SkyButton extends Button {
}); });
} }
public void doPressButton() {
skyMote.skyNode.setButton(true);
}
public void releaseButton() { public void releaseButton() {
sim.invokeSimulationThread(new Runnable() { sim.invokeSimulationThread(new Runnable() {
public void run() { public void run() {
@ -94,6 +95,10 @@ public class SkyButton extends Button {
}); });
} }
public void doReleaseButton() {
skyMote.skyNode.setButton(false);
}
public boolean isPressed() { public boolean isPressed() {
/* Not implemented */ /* Not implemented */
return false; return false;