Darien Figueroa / Mbed OS Final_Program

Dependencies:   USBDevice

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers LinePointCollection.java Source File

LinePointCollection.java

00001 /*******************************************************************************
00002  * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved.
00003  * <p>
00004  * Permission is hereby granted, free of charge, to any person obtaining a
00005  * copy of this software and associated documentation files (the "Software"),
00006  * to deal in the Software without restriction, including without limitation
00007  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
00008  * and/or sell copies of the Software, and to permit persons to whom the
00009  * Software is furnished to do so, subject to the following conditions:
00010  * <p>
00011  * The above copyright notice and this permission notice shall be included
00012  * in all copies or substantial portions of the Software.
00013  * <p>
00014  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
00015  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00016  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
00017  * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
00018  * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
00019  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
00020  * OTHER DEALINGS IN THE SOFTWARE.
00021  * <p>
00022  * Except as contained in this notice, the name of Maxim Integrated
00023  * Products, Inc. shall not be used except as stated in the Maxim Integrated
00024  * Products, Inc. Branding Policy.
00025  * <p>
00026  * The mere transfer of this software does not imply any licenses
00027  * of trade secrets, proprietary technology, copyrights, patents,
00028  * trademarks, maskwork rights, or any other form of intellectual
00029  * property whatsoever. Maxim Integrated Products, Inc. retains all
00030  * ownership rights.
00031  * ******************************************************************************
00032  */
00033 package graphing;
00034 
00035 import java.util.ArrayList;
00036 import java.util.List;
00037 
00038 /**
00039  * Contains a list of points, the list will only hold a max number of
00040  * points before the old value is deleted and new values are shifted in
00041  */
00042 public class LinePointCollection {
00043     /// list of points in this collection
00044     List<LinePoint> points;
00045     /// the list of points has a max count
00046     int maxCount;
00047     /// color used to render the points and connecting lines
00048     int color;
00049     /// the updated calculated max of all Y values in the list
00050     float runningMaxY;
00051     /// the updated calculated min of all Y values in the list
00052     float runningMinY;
00053 
00054     float pointDroppedOff;
00055 
00056     /**
00057      * Constructor used to specify the color of the line and tbe max number of points in this collection
00058      * @param _color Color to use when rendering this collection
00059      * @param _maxCount Max number of points held before deleting old points and "shifting" in new
00060      */
00061     public LinePointCollection(int _color, int _maxCount) {
00062         color = _color;
00063         maxCount = _maxCount;
00064         points = new ArrayList<>();
00065         pointDroppedOff = 0;
00066     }
00067 
00068     /**
00069      * Accessor to get the list of points
00070      * @return Return the list of points in this collection
00071      */
00072     public List<LinePoint> getPoints() {
00073         return points;
00074     }
00075 
00076     public float getDroppedPointY() {
00077         return pointDroppedOff;
00078     }
00079 
00080     /**
00081      * Accessor to get the color of this collection
00082      * @return Color that is used in this collection
00083      */
00084     public int getColor() {
00085         return color;
00086     }
00087 
00088     /**
00089      * Calculate the max and min Y extremes for the current cached points
00090      */
00091     private void calculateExtremes() {
00092         runningMaxY = Float.MIN_VALUE;
00093         runningMinY = Float.MAX_VALUE;
00094         for (LinePoint point : points) {
00095             if (point.y > runningMaxY) runningMaxY = point.y;
00096             if (point.y < runningMinY) runningMinY = point.y;
00097         }
00098     }
00099 
00100     /**
00101      * Accessor to get the min Y value
00102      * @return Smallest Y value in the list of points
00103      */
00104     public float getRunningMinY() {
00105         return runningMinY;
00106     }
00107 
00108     /**
00109      * Accessor to get the max Y value
00110      * @return Largest Y Value in the list of points
00111      */
00112     public float getRunningMaxY() {
00113         return runningMaxY;
00114     }
00115 
00116     /**
00117      * Get the max number of points that will be contained in this collection
00118      * @return Return the max count
00119      */
00120     public float getMaxCount() {
00121         return maxCount;
00122     }
00123 
00124     /**
00125      * Add a Y point value in this collection...
00126      * note currently we only care about the Y value,
00127      * the x running values are programically calculated
00128      * @param y The Y value to use for this point
00129      */
00130     public void addpoint(float y) {
00131         LinePoint point = new LinePoint();
00132         point.x = 0;
00133         point.y = y;
00134         points.add(point);
00135         if (points.size() > maxCount) {
00136             // get the point removed for plotting first point
00137             pointDroppedOff = points.get(0).rawY;
00138             points.remove(0);
00139         }
00140         calculateExtremes();
00141     }
00142 }