From 586420e75b25dc4cc4f075a530dfcc2603dcb897 Mon Sep 17 00:00:00 2001 From: Niclas Finne Date: Fri, 18 May 2012 15:54:52 +0200 Subject: [PATCH] Updated to use state change from Chip + added method to change only specified leds --- se/sics/mspsim/chip/Leds.java | 29 ++++++++++------------------- 1 file changed, 10 insertions(+), 19 deletions(-) diff --git a/se/sics/mspsim/chip/Leds.java b/se/sics/mspsim/chip/Leds.java index 8a13711..0ea51ed 100644 --- a/se/sics/mspsim/chip/Leds.java +++ b/se/sics/mspsim/chip/Leds.java @@ -44,7 +44,6 @@ package se.sics.mspsim.chip; import se.sics.mspsim.core.Chip; import se.sics.mspsim.core.MSP430Core; -import se.sics.mspsim.core.StateChangeListener; import se.sics.mspsim.util.Utils; public class Leds extends Chip { @@ -52,7 +51,6 @@ public class Leds extends Chip { private final int[] ledColors; private int leds; - private StateChangeListener stateListener; public Leds(MSP430Core cpu, int[] ledColors) { super("Leds", cpu); @@ -68,17 +66,25 @@ public class Leds extends Chip { public void setLeds(int leds) { if (this.leds != leds) { - int oldLeds = this.leds; this.leds = leds; - fireStateChanged(oldLeds, leds); + stateChanged(leds); if (DEBUG) log(ledColors.length <= 8 ? Utils.binary8(leds) : Utils.binary16(leds)); } } + public void setLeds(int leds, boolean on) { + if (on) { + setLeds(this.leds | leds); + } else { + setLeds(this.leds & ~leds); + } + } + public boolean isLedOn(int led) { return (leds & (1 << led)) != 0; } + public int getLedsColor(int led) { return ledColors[led]; } @@ -87,21 +93,6 @@ public class Leds extends Chip { return ledColors.length; } - private void fireStateChanged(int oldState, int newState) { - StateChangeListener listener = this.stateListener; - if (listener != null) { - listener.stateChanged(this, oldState, newState); - } - } - - public synchronized void addStateChangeListener(StateChangeListener listener) { - stateListener = StateChangeListener.Proxy.INSTANCE.add(stateListener, listener); - } - - public synchronized void removeStateChangeListener(StateChangeListener listener) { - stateListener = StateChangeListener.Proxy.INSTANCE.remove(stateListener, listener); - } - public int getModeMax() { return 0; }