repo time
Dependencies: mbed MAX14720 MAX30205 USBDevice
src/main/java/graphing/LinePointCollection.java@20:6d2af70c92ab, 2021-04-06 (annotated)
- Committer:
- darienf
- Date:
- Tue Apr 06 06:41:40 2021 +0000
- Revision:
- 20:6d2af70c92ab
another repo
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
darienf | 20:6d2af70c92ab | 1 | /******************************************************************************* |
darienf | 20:6d2af70c92ab | 2 | * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. |
darienf | 20:6d2af70c92ab | 3 | * <p> |
darienf | 20:6d2af70c92ab | 4 | * Permission is hereby granted, free of charge, to any person obtaining a |
darienf | 20:6d2af70c92ab | 5 | * copy of this software and associated documentation files (the "Software"), |
darienf | 20:6d2af70c92ab | 6 | * to deal in the Software without restriction, including without limitation |
darienf | 20:6d2af70c92ab | 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
darienf | 20:6d2af70c92ab | 8 | * and/or sell copies of the Software, and to permit persons to whom the |
darienf | 20:6d2af70c92ab | 9 | * Software is furnished to do so, subject to the following conditions: |
darienf | 20:6d2af70c92ab | 10 | * <p> |
darienf | 20:6d2af70c92ab | 11 | * The above copyright notice and this permission notice shall be included |
darienf | 20:6d2af70c92ab | 12 | * in all copies or substantial portions of the Software. |
darienf | 20:6d2af70c92ab | 13 | * <p> |
darienf | 20:6d2af70c92ab | 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
darienf | 20:6d2af70c92ab | 15 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
darienf | 20:6d2af70c92ab | 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
darienf | 20:6d2af70c92ab | 17 | * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES |
darienf | 20:6d2af70c92ab | 18 | * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
darienf | 20:6d2af70c92ab | 19 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
darienf | 20:6d2af70c92ab | 20 | * OTHER DEALINGS IN THE SOFTWARE. |
darienf | 20:6d2af70c92ab | 21 | * <p> |
darienf | 20:6d2af70c92ab | 22 | * Except as contained in this notice, the name of Maxim Integrated |
darienf | 20:6d2af70c92ab | 23 | * Products, Inc. shall not be used except as stated in the Maxim Integrated |
darienf | 20:6d2af70c92ab | 24 | * Products, Inc. Branding Policy. |
darienf | 20:6d2af70c92ab | 25 | * <p> |
darienf | 20:6d2af70c92ab | 26 | * The mere transfer of this software does not imply any licenses |
darienf | 20:6d2af70c92ab | 27 | * of trade secrets, proprietary technology, copyrights, patents, |
darienf | 20:6d2af70c92ab | 28 | * trademarks, maskwork rights, or any other form of intellectual |
darienf | 20:6d2af70c92ab | 29 | * property whatsoever. Maxim Integrated Products, Inc. retains all |
darienf | 20:6d2af70c92ab | 30 | * ownership rights. |
darienf | 20:6d2af70c92ab | 31 | * ****************************************************************************** |
darienf | 20:6d2af70c92ab | 32 | */ |
darienf | 20:6d2af70c92ab | 33 | package graphing; |
darienf | 20:6d2af70c92ab | 34 | |
darienf | 20:6d2af70c92ab | 35 | import java.util.ArrayList; |
darienf | 20:6d2af70c92ab | 36 | import java.util.List; |
darienf | 20:6d2af70c92ab | 37 | |
darienf | 20:6d2af70c92ab | 38 | /** |
darienf | 20:6d2af70c92ab | 39 | * Contains a list of points, the list will only hold a max number of |
darienf | 20:6d2af70c92ab | 40 | * points before the old value is deleted and new values are shifted in |
darienf | 20:6d2af70c92ab | 41 | */ |
darienf | 20:6d2af70c92ab | 42 | public class LinePointCollection { |
darienf | 20:6d2af70c92ab | 43 | /// list of points in this collection |
darienf | 20:6d2af70c92ab | 44 | List<LinePoint> points; |
darienf | 20:6d2af70c92ab | 45 | /// the list of points has a max count |
darienf | 20:6d2af70c92ab | 46 | int maxCount; |
darienf | 20:6d2af70c92ab | 47 | /// color used to render the points and connecting lines |
darienf | 20:6d2af70c92ab | 48 | int color; |
darienf | 20:6d2af70c92ab | 49 | /// the updated calculated max of all Y values in the list |
darienf | 20:6d2af70c92ab | 50 | float runningMaxY; |
darienf | 20:6d2af70c92ab | 51 | /// the updated calculated min of all Y values in the list |
darienf | 20:6d2af70c92ab | 52 | float runningMinY; |
darienf | 20:6d2af70c92ab | 53 | |
darienf | 20:6d2af70c92ab | 54 | float pointDroppedOff; |
darienf | 20:6d2af70c92ab | 55 | |
darienf | 20:6d2af70c92ab | 56 | /** |
darienf | 20:6d2af70c92ab | 57 | * Constructor used to specify the color of the line and tbe max number of points in this collection |
darienf | 20:6d2af70c92ab | 58 | * @param _color Color to use when rendering this collection |
darienf | 20:6d2af70c92ab | 59 | * @param _maxCount Max number of points held before deleting old points and "shifting" in new |
darienf | 20:6d2af70c92ab | 60 | */ |
darienf | 20:6d2af70c92ab | 61 | public LinePointCollection(int _color, int _maxCount) { |
darienf | 20:6d2af70c92ab | 62 | color = _color; |
darienf | 20:6d2af70c92ab | 63 | maxCount = _maxCount; |
darienf | 20:6d2af70c92ab | 64 | points = new ArrayList<>(); |
darienf | 20:6d2af70c92ab | 65 | pointDroppedOff = 0; |
darienf | 20:6d2af70c92ab | 66 | } |
darienf | 20:6d2af70c92ab | 67 | |
darienf | 20:6d2af70c92ab | 68 | /** |
darienf | 20:6d2af70c92ab | 69 | * Accessor to get the list of points |
darienf | 20:6d2af70c92ab | 70 | * @return Return the list of points in this collection |
darienf | 20:6d2af70c92ab | 71 | */ |
darienf | 20:6d2af70c92ab | 72 | public List<LinePoint> getPoints() { |
darienf | 20:6d2af70c92ab | 73 | return points; |
darienf | 20:6d2af70c92ab | 74 | } |
darienf | 20:6d2af70c92ab | 75 | |
darienf | 20:6d2af70c92ab | 76 | public float getDroppedPointY() { |
darienf | 20:6d2af70c92ab | 77 | return pointDroppedOff; |
darienf | 20:6d2af70c92ab | 78 | } |
darienf | 20:6d2af70c92ab | 79 | |
darienf | 20:6d2af70c92ab | 80 | /** |
darienf | 20:6d2af70c92ab | 81 | * Accessor to get the color of this collection |
darienf | 20:6d2af70c92ab | 82 | * @return Color that is used in this collection |
darienf | 20:6d2af70c92ab | 83 | */ |
darienf | 20:6d2af70c92ab | 84 | public int getColor() { |
darienf | 20:6d2af70c92ab | 85 | return color; |
darienf | 20:6d2af70c92ab | 86 | } |
darienf | 20:6d2af70c92ab | 87 | |
darienf | 20:6d2af70c92ab | 88 | /** |
darienf | 20:6d2af70c92ab | 89 | * Calculate the max and min Y extremes for the current cached points |
darienf | 20:6d2af70c92ab | 90 | */ |
darienf | 20:6d2af70c92ab | 91 | private void calculateExtremes() { |
darienf | 20:6d2af70c92ab | 92 | runningMaxY = Float.MIN_VALUE; |
darienf | 20:6d2af70c92ab | 93 | runningMinY = Float.MAX_VALUE; |
darienf | 20:6d2af70c92ab | 94 | for (LinePoint point : points) { |
darienf | 20:6d2af70c92ab | 95 | if (point.y > runningMaxY) runningMaxY = point.y; |
darienf | 20:6d2af70c92ab | 96 | if (point.y < runningMinY) runningMinY = point.y; |
darienf | 20:6d2af70c92ab | 97 | } |
darienf | 20:6d2af70c92ab | 98 | } |
darienf | 20:6d2af70c92ab | 99 | |
darienf | 20:6d2af70c92ab | 100 | /** |
darienf | 20:6d2af70c92ab | 101 | * Accessor to get the min Y value |
darienf | 20:6d2af70c92ab | 102 | * @return Smallest Y value in the list of points |
darienf | 20:6d2af70c92ab | 103 | */ |
darienf | 20:6d2af70c92ab | 104 | public float getRunningMinY() { |
darienf | 20:6d2af70c92ab | 105 | return runningMinY; |
darienf | 20:6d2af70c92ab | 106 | } |
darienf | 20:6d2af70c92ab | 107 | |
darienf | 20:6d2af70c92ab | 108 | /** |
darienf | 20:6d2af70c92ab | 109 | * Accessor to get the max Y value |
darienf | 20:6d2af70c92ab | 110 | * @return Largest Y Value in the list of points |
darienf | 20:6d2af70c92ab | 111 | */ |
darienf | 20:6d2af70c92ab | 112 | public float getRunningMaxY() { |
darienf | 20:6d2af70c92ab | 113 | return runningMaxY; |
darienf | 20:6d2af70c92ab | 114 | } |
darienf | 20:6d2af70c92ab | 115 | |
darienf | 20:6d2af70c92ab | 116 | /** |
darienf | 20:6d2af70c92ab | 117 | * Get the max number of points that will be contained in this collection |
darienf | 20:6d2af70c92ab | 118 | * @return Return the max count |
darienf | 20:6d2af70c92ab | 119 | */ |
darienf | 20:6d2af70c92ab | 120 | public float getMaxCount() { |
darienf | 20:6d2af70c92ab | 121 | return maxCount; |
darienf | 20:6d2af70c92ab | 122 | } |
darienf | 20:6d2af70c92ab | 123 | |
darienf | 20:6d2af70c92ab | 124 | /** |
darienf | 20:6d2af70c92ab | 125 | * Add a Y point value in this collection... |
darienf | 20:6d2af70c92ab | 126 | * note currently we only care about the Y value, |
darienf | 20:6d2af70c92ab | 127 | * the x running values are programically calculated |
darienf | 20:6d2af70c92ab | 128 | * @param y The Y value to use for this point |
darienf | 20:6d2af70c92ab | 129 | */ |
darienf | 20:6d2af70c92ab | 130 | public void addpoint(float y) { |
darienf | 20:6d2af70c92ab | 131 | LinePoint point = new LinePoint(); |
darienf | 20:6d2af70c92ab | 132 | point.x = 0; |
darienf | 20:6d2af70c92ab | 133 | point.y = y; |
darienf | 20:6d2af70c92ab | 134 | points.add(point); |
darienf | 20:6d2af70c92ab | 135 | if (points.size() > maxCount) { |
darienf | 20:6d2af70c92ab | 136 | // get the point removed for plotting first point |
darienf | 20:6d2af70c92ab | 137 | pointDroppedOff = points.get(0).rawY; |
darienf | 20:6d2af70c92ab | 138 | points.remove(0); |
darienf | 20:6d2af70c92ab | 139 | } |
darienf | 20:6d2af70c92ab | 140 | calculateExtremes(); |
darienf | 20:6d2af70c92ab | 141 | } |
darienf | 20:6d2af70c92ab | 142 | } |