diff --git a/se/sics/mspsim/chip/Button.java b/se/sics/mspsim/chip/Button.java index 746b7d2..04334e7 100644 --- a/se/sics/mspsim/chip/Button.java +++ b/se/sics/mspsim/chip/Button.java @@ -44,87 +44,93 @@ import java.awt.event.ActionListener; public class Button extends Chip implements ActionListener { public enum Btn_Typ { - HighOpen, NoOpen - } + HighOpen, NoOpen + } - private final IOPort port; - private final int pin; - private final boolean polarity; - private boolean isPressed; - private Btn_Typ btnTyp = Btn_Typ.NoOpen; - private javax.swing.Timer waittimer; + private final IOPort port; + private final int pin; + private final boolean polarity; + private boolean isPressed; + private Btn_Typ btnTyp = Btn_Typ.NoOpen; + private javax.swing.Timer waittimer; - public Button(String id, MSP430Core cpu, IOPort port, int pin, boolean polarity) { - super(id, cpu); - this.port = port; - this.pin = pin; - this.polarity = polarity; - this.isPressed = false; - if (this.polarity == false) { - SetState(); - } - } + public Button(String id, MSP430Core cpu, IOPort port, int pin, boolean polarity) { + super(id, cpu); + this.port = port; + this.pin = pin; + this.polarity = polarity; + this.isPressed = false; + if (this.polarity == false) { + SetState(); + } + } - public Button(String id, MSP430Core cpu, IOPort port, int pin, - boolean polarity, Btn_Typ btnTyp) { - this(id,cpu,port,pin,polarity); - this.btnTyp = btnTyp; - waittimer = new javax.swing.Timer(3000, this); - waittimer.stop(); - waittimer.setRepeats(false); - } - - public boolean isPressed() { - return isPressed; - } + public Button(String id, MSP430Core cpu, IOPort port, int pin, + boolean polarity, Btn_Typ btnTyp) { + this(id,cpu,port,pin,polarity); + this.btnTyp = btnTyp; + waittimer = new javax.swing.Timer(3000, this); + waittimer.stop(); + waittimer.setRepeats(false); + } - public void setPressed(boolean isPressed) { - if (this.isPressed != isPressed) { - this.isPressed = isPressed; - boolean isHigh = isPressed ^ (!polarity); - boolean Ren = ((this.port.getRegister(PortReg.REN) & (1 << this.pin)) != 0); - boolean Up_Down = ((this.port.getRegister(PortReg.OUT) & (1 << this.pin)) != 0); - boolean PullUp = Up_Down & Ren; - // if potential open, then wait 3 seconds to change - if (isHigh && (btnTyp == Btn_Typ.HighOpen) && !PullUp) { - waittimer.restart(); - } else { - waittimer.stop(); - SetState(); - } - } - } - - public void actionPerformed(ActionEvent e) { - waittimer.stop(); - SetState(); - } + public boolean isPressed() { + return isPressed; + } - public void SetState() { - boolean isHigh = this.isPressed ^ (!this.polarity); - stateChanged(this.isPressed ? 1 : 0); - if (DEBUG) - log(this.isPressed ? "pressed" : "released"); - port.setPinState(pin, isHigh ? IOPort.PinState.HI : IOPort.PinState.LOW); - } + public boolean isPullUp() { + boolean Ren = ((this.port.getRegister(PortReg.REN) & (1 << this.pin)) != 0); + boolean Up_Down = ((this.port.getRegister(PortReg.OUT) & (1 << this.pin)) != 0); + return Up_Down & Ren; + } - @Override - public int getConfiguration(int parameter) { - return 0; - } - @Override - public int getModeMax() { - return 0; - } + public void setPressed(boolean isPressed) { + if (this.isPressed != isPressed) { + this.isPressed = isPressed; + boolean isHigh = isPressed ^ (!polarity); + boolean Ren = ((this.port.getRegister(PortReg.REN) & (1 << this.pin)) != 0); + // if potential open, then wait 3 seconds to change + if (isHigh && (btnTyp == Btn_Typ.HighOpen) && !Ren) { + waittimer.restart(); + } else { + waittimer.stop(); + SetState(); + } + } + } - @Override - public String info() { - return " Button is " + (isPressed ? "pressed" : "not pressed"); - } - - @Override - public void notifyReset() { - SetState(); - } + public void actionPerformed(ActionEvent e) { + waittimer.stop(); + SetState(); + } + + public void SetState() { + boolean isHigh = this.isPressed ^ (!this.polarity); + stateChanged(this.isPressed ? 1 : 0); + if((btnTyp==Btn_Typ.HighOpen)&!isPullUp()) isHigh=false; + if (DEBUG) + log(this.isPressed ? "pressed" : "released"); + port.setPinState(pin, isHigh ? IOPort.PinState.HI : IOPort.PinState.LOW); + } + + @Override + public int getConfiguration(int parameter) { + return 0; + } + + @Override + public int getModeMax() { + return 0; + } + + @Override + public String info() { + return " Button is " + (isPressed ? "pressed" : "not pressed"); + } + + @Override + public void notifyReset() { + SetState(); + } } diff --git a/se/sics/mspsim/platform/MSPEXP430F5438/Exp5438Gui.java b/se/sics/mspsim/platform/MSPEXP430F5438/Exp5438Gui.java index 7fb8b76..e555819 100644 --- a/se/sics/mspsim/platform/MSPEXP430F5438/Exp5438Gui.java +++ b/se/sics/mspsim/platform/MSPEXP430F5438/Exp5438Gui.java @@ -80,7 +80,7 @@ public class Exp5438Gui extends AbstractNodeGUI { }; public Exp5438Gui(Exp5438Node node) { - super("MSPSIM fork by Prof. Rüdiger Heintz 0.4.22", "images/MSP-EXP430F5438.jpg"); + super("MSPSIM fork by Prof. Rüdiger Heintz 0.4.23", "images/MSP-EXP430F5438.jpg"); this.node = node; Action scaleDownAction = new AbstractAction() { private static final long serialVersionUID = 1L;