From ee655cf8c434787c8c604ebdca935a50775cf762 Mon Sep 17 00:00:00 2001 From: fros4943 Date: Tue, 28 Oct 2008 15:36:25 +0000 Subject: [PATCH] using new energy interface --- .../java/se/sics/cooja/plugins/VisBattery.java | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/tools/cooja/java/se/sics/cooja/plugins/VisBattery.java b/tools/cooja/java/se/sics/cooja/plugins/VisBattery.java index 8950fe69b..736ebf342 100644 --- a/tools/cooja/java/se/sics/cooja/plugins/VisBattery.java +++ b/tools/cooja/java/se/sics/cooja/plugins/VisBattery.java @@ -26,7 +26,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: VisBattery.java,v 1.4 2007/01/09 09:49:24 fros4943 Exp $ + * $Id: VisBattery.java,v 1.5 2008/10/28 15:36:25 fros4943 Exp $ */ package se.sics.cooja.plugins; @@ -43,9 +43,9 @@ import se.sics.cooja.interfaces.Battery; * different colors. The mote is painted in a grayscale where white is max * energy and black is no energy left. If a mote has no battery interface or * infinite energy, it is painted blue. If a mote is dead it is painted red. - * + * * A VisBattery observers both the simulation and all mote batteries. - * + * * @author Fredrik Osterlind */ @ClassDescription("Battery Visualizer") @@ -61,7 +61,7 @@ public class VisBattery extends Visualizer2D { /** * Creates a new battery visualizer. - * + * * @param simulationToVisualize * Simulation to visualize */ @@ -93,8 +93,9 @@ public class VisBattery extends Visualizer2D { } public Color[] getColorOf(Mote mote) { - if (mote.getState() == Mote.State.DEAD) + if (mote.getState() == Mote.State.DEAD) { return new Color[]{Color.RED}; + } Battery battery = mote.getInterfaces().getBattery(); if (battery == null) { @@ -105,13 +106,13 @@ public class VisBattery extends Visualizer2D { return new Color[]{Color.BLUE}; } - double currentEnergy = battery.getCurrentEnergy(); + double currentEnergy = battery.getEnergyLeftRatio(); if (currentEnergy < 0.0) { return new Color[]{Color.RED}; } - int grayValue = (int) (255 * (currentEnergy / battery.getInitialEnergy())); + int grayValue = (int) (255 * currentEnergy); return new Color[]{new Color(grayValue, grayValue, grayValue)}; }