repo time
Dependencies: mbed MAX14720 MAX30205 USBDevice
HspGuiSourceV301/HSPGui/CustomControls/OpticalView.cs@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 | * |
darienf | 20:6d2af70c92ab | 4 | * This software is protected by copyright laws of the United States and |
darienf | 20:6d2af70c92ab | 5 | * of foreign countries. This material may also be protected by patent laws |
darienf | 20:6d2af70c92ab | 6 | * and technology transfer regulations of the United States and of foreign |
darienf | 20:6d2af70c92ab | 7 | * countries. This software is furnished under a license agreement and/or a |
darienf | 20:6d2af70c92ab | 8 | * nondisclosure agreement and may only be used or reproduced in accordance |
darienf | 20:6d2af70c92ab | 9 | * with the terms of those agreements. Dissemination of this information to |
darienf | 20:6d2af70c92ab | 10 | * any party or parties not specified in the license agreement and/or |
darienf | 20:6d2af70c92ab | 11 | * nondisclosure agreement is expressly prohibited. |
darienf | 20:6d2af70c92ab | 12 | * |
darienf | 20:6d2af70c92ab | 13 | * The above copyright notice and this permission notice shall be included |
darienf | 20:6d2af70c92ab | 14 | * in all copies or substantial portions of the Software. |
darienf | 20:6d2af70c92ab | 15 | * |
darienf | 20:6d2af70c92ab | 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
darienf | 20:6d2af70c92ab | 17 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
darienf | 20:6d2af70c92ab | 18 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
darienf | 20:6d2af70c92ab | 19 | * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES |
darienf | 20:6d2af70c92ab | 20 | * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
darienf | 20:6d2af70c92ab | 21 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
darienf | 20:6d2af70c92ab | 22 | * OTHER DEALINGS IN THE SOFTWARE. |
darienf | 20:6d2af70c92ab | 23 | * |
darienf | 20:6d2af70c92ab | 24 | * Except as contained in this notice, the name of Maxim Integrated |
darienf | 20:6d2af70c92ab | 25 | * Products, Inc. shall not be used except as stated in the Maxim Integrated |
darienf | 20:6d2af70c92ab | 26 | * Products, Inc. Branding Policy. |
darienf | 20:6d2af70c92ab | 27 | * |
darienf | 20:6d2af70c92ab | 28 | * The mere transfer of this software does not imply any licenses |
darienf | 20:6d2af70c92ab | 29 | * of trade secrets, proprietary technology, copyrights, patents, |
darienf | 20:6d2af70c92ab | 30 | * trademarks, maskwork rights, or any other form of intellectual |
darienf | 20:6d2af70c92ab | 31 | * property whatsoever. Maxim Integrated Products, Inc. retains all |
darienf | 20:6d2af70c92ab | 32 | * ownership rights. |
darienf | 20:6d2af70c92ab | 33 | ******************************************************************************* |
darienf | 20:6d2af70c92ab | 34 | */ |
darienf | 20:6d2af70c92ab | 35 | |
darienf | 20:6d2af70c92ab | 36 | #define USE_MEDICALCHARTHELPER |
darienf | 20:6d2af70c92ab | 37 | //#define CES_DEMO |
darienf | 20:6d2af70c92ab | 38 | |
darienf | 20:6d2af70c92ab | 39 | using System; |
darienf | 20:6d2af70c92ab | 40 | using System.Collections.Generic; |
darienf | 20:6d2af70c92ab | 41 | using System.Collections; |
darienf | 20:6d2af70c92ab | 42 | using System.ComponentModel; |
darienf | 20:6d2af70c92ab | 43 | using System.Drawing; |
darienf | 20:6d2af70c92ab | 44 | using System.Data; |
darienf | 20:6d2af70c92ab | 45 | using System.Linq; |
darienf | 20:6d2af70c92ab | 46 | using System.Text; |
darienf | 20:6d2af70c92ab | 47 | using System.Windows.Forms; |
darienf | 20:6d2af70c92ab | 48 | using RPCSupport.Streaming; |
darienf | 20:6d2af70c92ab | 49 | using Maxim.Charting; |
darienf | 20:6d2af70c92ab | 50 | using System.Threading; |
darienf | 20:6d2af70c92ab | 51 | using HealthSensorPlatform.View; |
darienf | 20:6d2af70c92ab | 52 | |
darienf | 20:6d2af70c92ab | 53 | using System.Windows.Forms.DataVisualization.Charting; |
darienf | 20:6d2af70c92ab | 54 | |
darienf | 20:6d2af70c92ab | 55 | // DEBUG |
darienf | 20:6d2af70c92ab | 56 | using System.IO; |
darienf | 20:6d2af70c92ab | 57 | |
darienf | 20:6d2af70c92ab | 58 | namespace HealthSensorPlatform.CustomControls |
darienf | 20:6d2af70c92ab | 59 | { |
darienf | 20:6d2af70c92ab | 60 | public partial class OpticalView : UserControl, IDeviceView, IOpticalAlgorithmView |
darienf | 20:6d2af70c92ab | 61 | { |
darienf | 20:6d2af70c92ab | 62 | /* Constant Fields */ |
darienf | 20:6d2af70c92ab | 63 | static string StartString = "Start Monitor"; |
darienf | 20:6d2af70c92ab | 64 | static string StopString = "Stop Monitor"; |
darienf | 20:6d2af70c92ab | 65 | |
darienf | 20:6d2af70c92ab | 66 | const int ChartTime = 4; // 4 seconds |
darienf | 20:6d2af70c92ab | 67 | |
darienf | 20:6d2af70c92ab | 68 | /* Fields */ |
darienf | 20:6d2af70c92ab | 69 | private bool connected = false; |
darienf | 20:6d2af70c92ab | 70 | private bool streaming = false; |
darienf | 20:6d2af70c92ab | 71 | |
darienf | 20:6d2af70c92ab | 72 | private RPCSupport.RPCClient rpcClient; |
darienf | 20:6d2af70c92ab | 73 | //private MedicalChartHelper medicalChartLED; |
darienf | 20:6d2af70c92ab | 74 | //private MedicalChartHelper medicalChartAccel; |
darienf | 20:6d2af70c92ab | 75 | private AutoScaleCalculator fifo1Calc; |
darienf | 20:6d2af70c92ab | 76 | private AutoScaleCalculator fifo2Calc; |
darienf | 20:6d2af70c92ab | 77 | private AutoScaleCalculator fifo3Calc; |
darienf | 20:6d2af70c92ab | 78 | |
darienf | 20:6d2af70c92ab | 79 | eStreamMode streamMode; |
darienf | 20:6d2af70c92ab | 80 | byte fifo_waterlevel_mark = 0x0f; |
darienf | 20:6d2af70c92ab | 81 | byte sample_avg; |
darienf | 20:6d2af70c92ab | 82 | byte sample_rate; |
darienf | 20:6d2af70c92ab | 83 | byte pulse_width; |
darienf | 20:6d2af70c92ab | 84 | byte red_led_current; |
darienf | 20:6d2af70c92ab | 85 | byte ir_led_current; |
darienf | 20:6d2af70c92ab | 86 | byte green_led_current; |
darienf | 20:6d2af70c92ab | 87 | byte slot_1; |
darienf | 20:6d2af70c92ab | 88 | byte slot_2; |
darienf | 20:6d2af70c92ab | 89 | byte slot_3; |
darienf | 20:6d2af70c92ab | 90 | byte slot_4; |
darienf | 20:6d2af70c92ab | 91 | |
darienf | 20:6d2af70c92ab | 92 | // Heart Rate Sensor |
darienf | 20:6d2af70c92ab | 93 | int points; // Number of x-axis points for a plot |
darienf | 20:6d2af70c92ab | 94 | int sampleRate; // Human readable sample rate |
darienf | 20:6d2af70c92ab | 95 | int sampleAverage; // Human readable number of average points |
darienf | 20:6d2af70c92ab | 96 | // LIS2HD |
darienf | 20:6d2af70c92ab | 97 | int sampleRateAccel; |
darienf | 20:6d2af70c92ab | 98 | int pointsAccel; |
darienf | 20:6d2af70c92ab | 99 | |
darienf | 20:6d2af70c92ab | 100 | EventHandler<PartialArrayIntAvailableEventArgs> appendChart; // Allows event to be unregistered |
darienf | 20:6d2af70c92ab | 101 | |
darienf | 20:6d2af70c92ab | 102 | Dictionary<string, MedianFilter> intervalDict = new Dictionary<string, MedianFilter>(); |
darienf | 20:6d2af70c92ab | 103 | Dictionary<string, AutoScaleCalculator> chartScaleDict = new Dictionary<string, AutoScaleCalculator>(); |
darienf | 20:6d2af70c92ab | 104 | |
darienf | 20:6d2af70c92ab | 105 | List<Control> streamingControls = new List<Control>(); |
darienf | 20:6d2af70c92ab | 106 | |
darienf | 20:6d2af70c92ab | 107 | #if CES_DEMO |
darienf | 20:6d2af70c92ab | 108 | // Algorithm Data |
darienf | 20:6d2af70c92ab | 109 | Queue red; |
darienf | 20:6d2af70c92ab | 110 | Queue ir; |
darienf | 20:6d2af70c92ab | 111 | Queue led; |
darienf | 20:6d2af70c92ab | 112 | // struct to run algorithms |
darienf | 20:6d2af70c92ab | 113 | AlgorithmMobileBU.AlgorithmConfiguration config; |
darienf | 20:6d2af70c92ab | 114 | AlgorithmMobileBU.AlgorithmOutput output; |
darienf | 20:6d2af70c92ab | 115 | int algoCounter = 0; |
darienf | 20:6d2af70c92ab | 116 | #endif |
darienf | 20:6d2af70c92ab | 117 | |
darienf | 20:6d2af70c92ab | 118 | // DEBUG |
darienf | 20:6d2af70c92ab | 119 | //StreamWriter file = new StreamWriter("hsp_output_data.csv"); |
darienf | 20:6d2af70c92ab | 120 | |
darienf | 20:6d2af70c92ab | 121 | /* Constructors */ |
darienf | 20:6d2af70c92ab | 122 | public OpticalView() |
darienf | 20:6d2af70c92ab | 123 | { |
darienf | 20:6d2af70c92ab | 124 | InitializeComponent(); |
darienf | 20:6d2af70c92ab | 125 | |
darienf | 20:6d2af70c92ab | 126 | OpticalSensorInitControls(); |
darienf | 20:6d2af70c92ab | 127 | |
darienf | 20:6d2af70c92ab | 128 | cboSampleRate.SelectedIndexChanged += new EventHandler(cboSRPWLed_SelectedIndexChanged); |
darienf | 20:6d2af70c92ab | 129 | cboPulseWidth.SelectedIndexChanged += new EventHandler(cboSRPWLed_SelectedIndexChanged); |
darienf | 20:6d2af70c92ab | 130 | cboRedLED.SelectedIndexChanged += new EventHandler(cboSRPWLed_SelectedIndexChanged); |
darienf | 20:6d2af70c92ab | 131 | cboIRLED.SelectedIndexChanged += new EventHandler(cboSRPWLed_SelectedIndexChanged); |
darienf | 20:6d2af70c92ab | 132 | cboGreenLED.SelectedIndexChanged += new EventHandler(cboSRPWLed_SelectedIndexChanged); |
darienf | 20:6d2af70c92ab | 133 | |
darienf | 20:6d2af70c92ab | 134 | cboSampleRate.SelectedIndexChanged += new EventHandler(cboSampleRate_SelectedIndexChanged); |
darienf | 20:6d2af70c92ab | 135 | cboSampleAvg.SelectedIndexChanged += new EventHandler(cboSampleRate_SelectedIndexChanged); |
darienf | 20:6d2af70c92ab | 136 | |
darienf | 20:6d2af70c92ab | 137 | streamingControls.AddRange(new Control[] { panel1, maximGroupBoxSettings, maximGroupBoxLEDcurrents, maximGroupBoxLEDTimingSlots, btnDefaults }); |
darienf | 20:6d2af70c92ab | 138 | #if CES_DEMO |
darienf | 20:6d2af70c92ab | 139 | // Algorithm |
darienf | 20:6d2af70c92ab | 140 | red = new Queue(); |
darienf | 20:6d2af70c92ab | 141 | ir = new Queue(); |
darienf | 20:6d2af70c92ab | 142 | led = new Queue(); |
darienf | 20:6d2af70c92ab | 143 | |
darienf | 20:6d2af70c92ab | 144 | config = new AlgorithmMobileBU.AlgorithmConfiguration(); |
darienf | 20:6d2af70c92ab | 145 | output = new AlgorithmMobileBU.AlgorithmOutput(); |
darienf | 20:6d2af70c92ab | 146 | |
darienf | 20:6d2af70c92ab | 147 | config.snrNoFingerThreshold = -9; |
darienf | 20:6d2af70c92ab | 148 | config.acLowPerfusionThreshold = 950; |
darienf | 20:6d2af70c92ab | 149 | config.isAGC = 0; |
darienf | 20:6d2af70c92ab | 150 | |
darienf | 20:6d2af70c92ab | 151 | //updateAlgorithm(); |
darienf | 20:6d2af70c92ab | 152 | lblHeartRate.Visible = true; |
darienf | 20:6d2af70c92ab | 153 | lblHeartRateText.Visible = true; |
darienf | 20:6d2af70c92ab | 154 | #endif |
darienf | 20:6d2af70c92ab | 155 | } |
darienf | 20:6d2af70c92ab | 156 | |
darienf | 20:6d2af70c92ab | 157 | /* Delegates */ |
darienf | 20:6d2af70c92ab | 158 | //public delegate void StreamingStartStopEventHandler(StreamingStartStopEventArgs e); |
darienf | 20:6d2af70c92ab | 159 | |
darienf | 20:6d2af70c92ab | 160 | /* Events */ |
darienf | 20:6d2af70c92ab | 161 | //public event StreamingStartStopEventHandler StreamingStartStop; |
darienf | 20:6d2af70c92ab | 162 | public event EventHandler<StreamingStartStopEventArgs> StreamingStartStop; |
darienf | 20:6d2af70c92ab | 163 | |
darienf | 20:6d2af70c92ab | 164 | /* Enums */ |
darienf | 20:6d2af70c92ab | 165 | public enum eStreamMode |
darienf | 20:6d2af70c92ab | 166 | { |
darienf | 20:6d2af70c92ab | 167 | eHR, |
darienf | 20:6d2af70c92ab | 168 | eSPO2, |
darienf | 20:6d2af70c92ab | 169 | eMulti |
darienf | 20:6d2af70c92ab | 170 | } |
darienf | 20:6d2af70c92ab | 171 | |
darienf | 20:6d2af70c92ab | 172 | /* Properties */ |
darienf | 20:6d2af70c92ab | 173 | public RPCSupport.RPCClient RPCClient |
darienf | 20:6d2af70c92ab | 174 | { |
darienf | 20:6d2af70c92ab | 175 | set |
darienf | 20:6d2af70c92ab | 176 | { |
darienf | 20:6d2af70c92ab | 177 | rpcClient = value; |
darienf | 20:6d2af70c92ab | 178 | appendChart = new EventHandler<PartialArrayIntAvailableEventArgs>(On_AppendChart); |
darienf | 20:6d2af70c92ab | 179 | rpcClient.streaming.PartialArrayIntAvailable += appendChart; |
darienf | 20:6d2af70c92ab | 180 | } |
darienf | 20:6d2af70c92ab | 181 | } |
darienf | 20:6d2af70c92ab | 182 | |
darienf | 20:6d2af70c92ab | 183 | public bool Connected |
darienf | 20:6d2af70c92ab | 184 | { |
darienf | 20:6d2af70c92ab | 185 | get |
darienf | 20:6d2af70c92ab | 186 | { |
darienf | 20:6d2af70c92ab | 187 | return connected; |
darienf | 20:6d2af70c92ab | 188 | } |
darienf | 20:6d2af70c92ab | 189 | set |
darienf | 20:6d2af70c92ab | 190 | { |
darienf | 20:6d2af70c92ab | 191 | connected = value; |
darienf | 20:6d2af70c92ab | 192 | if (connected == false) |
darienf | 20:6d2af70c92ab | 193 | if (btnMonitoring.Text == StopString) |
darienf | 20:6d2af70c92ab | 194 | streamingStartStop(); |
darienf | 20:6d2af70c92ab | 195 | } |
darienf | 20:6d2af70c92ab | 196 | } |
darienf | 20:6d2af70c92ab | 197 | |
darienf | 20:6d2af70c92ab | 198 | public int AccelSampleRate |
darienf | 20:6d2af70c92ab | 199 | { |
darienf | 20:6d2af70c92ab | 200 | get |
darienf | 20:6d2af70c92ab | 201 | { |
darienf | 20:6d2af70c92ab | 202 | return sampleRateAccel; |
darienf | 20:6d2af70c92ab | 203 | } |
darienf | 20:6d2af70c92ab | 204 | } |
darienf | 20:6d2af70c92ab | 205 | |
darienf | 20:6d2af70c92ab | 206 | public int OpticalSampleRate |
darienf | 20:6d2af70c92ab | 207 | { |
darienf | 20:6d2af70c92ab | 208 | get |
darienf | 20:6d2af70c92ab | 209 | { |
darienf | 20:6d2af70c92ab | 210 | return sampleRate / sampleAverage; |
darienf | 20:6d2af70c92ab | 211 | } |
darienf | 20:6d2af70c92ab | 212 | } |
darienf | 20:6d2af70c92ab | 213 | |
darienf | 20:6d2af70c92ab | 214 | public eStreamMode ModeConfiguration |
darienf | 20:6d2af70c92ab | 215 | { |
darienf | 20:6d2af70c92ab | 216 | get |
darienf | 20:6d2af70c92ab | 217 | { |
darienf | 20:6d2af70c92ab | 218 | return streamMode; |
darienf | 20:6d2af70c92ab | 219 | } |
darienf | 20:6d2af70c92ab | 220 | } |
darienf | 20:6d2af70c92ab | 221 | |
darienf | 20:6d2af70c92ab | 222 | /* Methods */ |
darienf | 20:6d2af70c92ab | 223 | |
darienf | 20:6d2af70c92ab | 224 | // Clean up streaming |
darienf | 20:6d2af70c92ab | 225 | public void Close() |
darienf | 20:6d2af70c92ab | 226 | { |
darienf | 20:6d2af70c92ab | 227 | rpcClient.streaming.PartialArrayIntAvailable -= appendChart; // Stop event from firing |
darienf | 20:6d2af70c92ab | 228 | // Disable streaming if enabled |
darienf | 20:6d2af70c92ab | 229 | if (btnMonitoring.Text == StopString) |
darienf | 20:6d2af70c92ab | 230 | streamingStartStop(); |
darienf | 20:6d2af70c92ab | 231 | } |
darienf | 20:6d2af70c92ab | 232 | |
darienf | 20:6d2af70c92ab | 233 | public void DisplayAlgorithmResult(double heartRateBPM, bool heartRateBPMValid, double heartRateBPMSignalStrength, |
darienf | 20:6d2af70c92ab | 234 | double spO2Percent, bool spO2PercentValid, double spO2PercentSignalStrength) |
darienf | 20:6d2af70c92ab | 235 | { |
darienf | 20:6d2af70c92ab | 236 | // 100Hz only - TODO |
darienf | 20:6d2af70c92ab | 237 | if (OpticalSampleRate != 100) |
darienf | 20:6d2af70c92ab | 238 | return; |
darienf | 20:6d2af70c92ab | 239 | |
darienf | 20:6d2af70c92ab | 240 | if (heartRateBPMValid) |
darienf | 20:6d2af70c92ab | 241 | { |
darienf | 20:6d2af70c92ab | 242 | lblHeartRate.ForeColor = SystemColors.ControlText; |
darienf | 20:6d2af70c92ab | 243 | lblHeartRate.Text = string.Format("{0}", heartRateBPM * (sampleRate / 100.0)); // 100.0 for default sample rate |
darienf | 20:6d2af70c92ab | 244 | } |
darienf | 20:6d2af70c92ab | 245 | else |
darienf | 20:6d2af70c92ab | 246 | { |
darienf | 20:6d2af70c92ab | 247 | lblHeartRate.ForeColor = Color.Gray; |
darienf | 20:6d2af70c92ab | 248 | } |
darienf | 20:6d2af70c92ab | 249 | |
darienf | 20:6d2af70c92ab | 250 | if (spO2PercentValid) |
darienf | 20:6d2af70c92ab | 251 | { |
darienf | 20:6d2af70c92ab | 252 | lblSpO2.ForeColor = SystemColors.ControlText; |
darienf | 20:6d2af70c92ab | 253 | lblSpO2.Text = string.Format("{0:0.0}", spO2Percent); |
darienf | 20:6d2af70c92ab | 254 | } |
darienf | 20:6d2af70c92ab | 255 | else |
darienf | 20:6d2af70c92ab | 256 | { |
darienf | 20:6d2af70c92ab | 257 | lblSpO2.ForeColor = Color.Gray; |
darienf | 20:6d2af70c92ab | 258 | } |
darienf | 20:6d2af70c92ab | 259 | } |
darienf | 20:6d2af70c92ab | 260 | |
darienf | 20:6d2af70c92ab | 261 | public void DisplayAlgorithmReset() |
darienf | 20:6d2af70c92ab | 262 | { |
darienf | 20:6d2af70c92ab | 263 | lblHeartRate.Text = "----"; |
darienf | 20:6d2af70c92ab | 264 | lblHeartRate.ForeColor = Color.Gray; |
darienf | 20:6d2af70c92ab | 265 | |
darienf | 20:6d2af70c92ab | 266 | lblSpO2.Text = "----"; |
darienf | 20:6d2af70c92ab | 267 | lblSpO2.ForeColor = Color.Gray; |
darienf | 20:6d2af70c92ab | 268 | } |
darienf | 20:6d2af70c92ab | 269 | |
darienf | 20:6d2af70c92ab | 270 | System.Windows.Forms.Timer timer = new System.Windows.Forms.Timer(); |
darienf | 20:6d2af70c92ab | 271 | void InitGraphs() |
darienf | 20:6d2af70c92ab | 272 | { |
darienf | 20:6d2af70c92ab | 273 | /* |
darienf | 20:6d2af70c92ab | 274 | medicalChartLED = new MedicalChartHelper(chartLED, |
darienf | 20:6d2af70c92ab | 275 | "ChartArea1Red", "SeriesRed", "Red ADC Code", |
darienf | 20:6d2af70c92ab | 276 | "ChartArea2IR", "SeriesIR", "IR ADC Code", |
darienf | 20:6d2af70c92ab | 277 | "ChartArea3Green", "SeriesGreen", "Green ADC Code", |
darienf | 20:6d2af70c92ab | 278 | MedicalChartHelper.DataFormats.FormatUnsigned); |
darienf | 20:6d2af70c92ab | 279 | medicalChartLED._plotPoints = 200; |
darienf | 20:6d2af70c92ab | 280 | medicalChartAccel = new MedicalChartHelper(chartAccel, |
darienf | 20:6d2af70c92ab | 281 | "ChartArea4AccelX", "SeriesAccelX", "Accelerometer X", |
darienf | 20:6d2af70c92ab | 282 | "ChartArea5AccelY", "SeriesAccelY", "Accelerometer Y", |
darienf | 20:6d2af70c92ab | 283 | "ChartArea6AccelZ", "SeriesAccelZ", "Accelerometer Z", |
darienf | 20:6d2af70c92ab | 284 | MedicalChartHelper.DataFormats.Format16bit2sComplement); |
darienf | 20:6d2af70c92ab | 285 | */ |
darienf | 20:6d2af70c92ab | 286 | |
darienf | 20:6d2af70c92ab | 287 | MedianFilter fifo1 = new MedianFilter(10); |
darienf | 20:6d2af70c92ab | 288 | MedianFilter fifo2 = new MedianFilter(10); |
darienf | 20:6d2af70c92ab | 289 | MedianFilter fifo3 = new MedianFilter(10); |
darienf | 20:6d2af70c92ab | 290 | MedianFilter accelx = new MedianFilter(10); |
darienf | 20:6d2af70c92ab | 291 | MedianFilter accely = new MedianFilter(10); |
darienf | 20:6d2af70c92ab | 292 | MedianFilter accelz = new MedianFilter(10); |
darienf | 20:6d2af70c92ab | 293 | |
darienf | 20:6d2af70c92ab | 294 | intervalDict.Add("ChartArea1Red", fifo1); |
darienf | 20:6d2af70c92ab | 295 | intervalDict.Add("ChartArea2IR", fifo2); |
darienf | 20:6d2af70c92ab | 296 | intervalDict.Add("ChartArea3Green", fifo3); |
darienf | 20:6d2af70c92ab | 297 | |
darienf | 20:6d2af70c92ab | 298 | intervalDict.Add("ChartArea4AccelX", accelx); |
darienf | 20:6d2af70c92ab | 299 | intervalDict.Add("ChartArea5AccelY", accely); |
darienf | 20:6d2af70c92ab | 300 | intervalDict.Add("ChartArea6AccelZ", accelz); |
darienf | 20:6d2af70c92ab | 301 | |
darienf | 20:6d2af70c92ab | 302 | fifo1Calc = new AutoScaleCalculator(0, 90000); |
darienf | 20:6d2af70c92ab | 303 | fifo1Calc.Minimum = 0; |
darienf | 20:6d2af70c92ab | 304 | fifo1Calc.Maximum = Math.Pow(2, 18); |
darienf | 20:6d2af70c92ab | 305 | fifo1Calc.Intervals = 5; |
darienf | 20:6d2af70c92ab | 306 | fifo1Calc.MinimumRange = 200; |
darienf | 20:6d2af70c92ab | 307 | fifo1Calc.ScaleTrigger = 0.8; |
darienf | 20:6d2af70c92ab | 308 | fifo1Calc.RescaleTargetRange = 0.25; |
darienf | 20:6d2af70c92ab | 309 | chartScaleDict.Add("ChartArea1Red", fifo1Calc); |
darienf | 20:6d2af70c92ab | 310 | |
darienf | 20:6d2af70c92ab | 311 | fifo2Calc = new AutoScaleCalculator(0, 90000); |
darienf | 20:6d2af70c92ab | 312 | fifo2Calc.Minimum = 0; |
darienf | 20:6d2af70c92ab | 313 | fifo2Calc.Maximum = Math.Pow(2, 18); |
darienf | 20:6d2af70c92ab | 314 | fifo2Calc.Intervals = 5; |
darienf | 20:6d2af70c92ab | 315 | fifo2Calc.MinimumRange = 200; |
darienf | 20:6d2af70c92ab | 316 | fifo2Calc.ScaleTrigger = 0.8; |
darienf | 20:6d2af70c92ab | 317 | fifo2Calc.RescaleTargetRange = 0.25; |
darienf | 20:6d2af70c92ab | 318 | chartScaleDict.Add("ChartArea2IR", fifo2Calc); |
darienf | 20:6d2af70c92ab | 319 | |
darienf | 20:6d2af70c92ab | 320 | fifo3Calc = new AutoScaleCalculator(0, 90000); |
darienf | 20:6d2af70c92ab | 321 | fifo3Calc.Minimum = 0; |
darienf | 20:6d2af70c92ab | 322 | fifo3Calc.Maximum = Math.Pow(2, 18); |
darienf | 20:6d2af70c92ab | 323 | fifo3Calc.Intervals = 5; |
darienf | 20:6d2af70c92ab | 324 | fifo3Calc.MinimumRange = 200; |
darienf | 20:6d2af70c92ab | 325 | fifo3Calc.ScaleTrigger = 0.8; |
darienf | 20:6d2af70c92ab | 326 | fifo3Calc.RescaleTargetRange = 0.25; |
darienf | 20:6d2af70c92ab | 327 | chartScaleDict.Add("ChartArea3Green", fifo2Calc); |
darienf | 20:6d2af70c92ab | 328 | |
darienf | 20:6d2af70c92ab | 329 | AutoScaleCalculator accelXCalc = new AutoScaleCalculator(-10000, 10000); |
darienf | 20:6d2af70c92ab | 330 | accelXCalc.Minimum = -32768; |
darienf | 20:6d2af70c92ab | 331 | accelXCalc.Maximum = 32767; |
darienf | 20:6d2af70c92ab | 332 | accelXCalc.Intervals = 5; |
darienf | 20:6d2af70c92ab | 333 | accelXCalc.MinimumRange = 500; |
darienf | 20:6d2af70c92ab | 334 | accelXCalc.ScaleTrigger = 0.8; |
darienf | 20:6d2af70c92ab | 335 | accelXCalc.RescaleTargetRange = 0.25; |
darienf | 20:6d2af70c92ab | 336 | chartScaleDict.Add("ChartArea4AccelX", accelXCalc); |
darienf | 20:6d2af70c92ab | 337 | |
darienf | 20:6d2af70c92ab | 338 | AutoScaleCalculator accelYCalc = new AutoScaleCalculator(-10000, 10000); |
darienf | 20:6d2af70c92ab | 339 | accelYCalc.Minimum = -32768; |
darienf | 20:6d2af70c92ab | 340 | accelYCalc.Maximum = 32767; |
darienf | 20:6d2af70c92ab | 341 | accelYCalc.Intervals = 5; |
darienf | 20:6d2af70c92ab | 342 | accelYCalc.MinimumRange = 500; |
darienf | 20:6d2af70c92ab | 343 | accelYCalc.ScaleTrigger = 0.8; |
darienf | 20:6d2af70c92ab | 344 | accelYCalc.RescaleTargetRange = 0.25; |
darienf | 20:6d2af70c92ab | 345 | chartScaleDict.Add("ChartArea5AccelY", accelYCalc); |
darienf | 20:6d2af70c92ab | 346 | |
darienf | 20:6d2af70c92ab | 347 | AutoScaleCalculator accelZCalc = new AutoScaleCalculator(-10000, 10000); |
darienf | 20:6d2af70c92ab | 348 | accelZCalc.Minimum = -32768; |
darienf | 20:6d2af70c92ab | 349 | accelZCalc.Maximum = 32767; |
darienf | 20:6d2af70c92ab | 350 | accelZCalc.Intervals = 5; |
darienf | 20:6d2af70c92ab | 351 | accelZCalc.MinimumRange = 500; |
darienf | 20:6d2af70c92ab | 352 | accelZCalc.ScaleTrigger = 0.8; |
darienf | 20:6d2af70c92ab | 353 | accelZCalc.RescaleTargetRange = 0.25; |
darienf | 20:6d2af70c92ab | 354 | chartScaleDict.Add("ChartArea6AccelZ", accelZCalc); |
darienf | 20:6d2af70c92ab | 355 | |
darienf | 20:6d2af70c92ab | 356 | /* |
darienf | 20:6d2af70c92ab | 357 | Random rand = new Random(); |
darienf | 20:6d2af70c92ab | 358 | int[] data1 = new int[10]; |
darienf | 20:6d2af70c92ab | 359 | int[] data2 = new int[10]; |
darienf | 20:6d2af70c92ab | 360 | int[] data3 = new int[10]; |
darienf | 20:6d2af70c92ab | 361 | double[] data1_ = new double[10]; |
darienf | 20:6d2af70c92ab | 362 | double[] data2_ = new double[10]; |
darienf | 20:6d2af70c92ab | 363 | double[] data3_ = new double[10]; |
darienf | 20:6d2af70c92ab | 364 | for (int i = 0; i < data1.Length; i++) |
darienf | 20:6d2af70c92ab | 365 | { |
darienf | 20:6d2af70c92ab | 366 | data1[i] = rand.Next(10); |
darienf | 20:6d2af70c92ab | 367 | data2[i] = rand.Next(10); |
darienf | 20:6d2af70c92ab | 368 | data3[i] = rand.Next(10); |
darienf | 20:6d2af70c92ab | 369 | data1_[i] = rand.NextDouble() * 10; |
darienf | 20:6d2af70c92ab | 370 | data2_[i] = rand.NextDouble() * 10; |
darienf | 20:6d2af70c92ab | 371 | data3_[i] = rand.NextDouble() * 10; |
darienf | 20:6d2af70c92ab | 372 | } |
darienf | 20:6d2af70c92ab | 373 | */ |
darienf | 20:6d2af70c92ab | 374 | |
darienf | 20:6d2af70c92ab | 375 | /* |
darienf | 20:6d2af70c92ab | 376 | int[] dummyData = new int[] { 0 }; |
darienf | 20:6d2af70c92ab | 377 | medicalChartLED.AppendDataChartArea1(dummyData, 0, 0); |
darienf | 20:6d2af70c92ab | 378 | medicalChartLED.AppendDataChartArea2(dummyData, 0, 0); |
darienf | 20:6d2af70c92ab | 379 | medicalChartLED.AppendDataChartArea3(dummyData, 0, 0); |
darienf | 20:6d2af70c92ab | 380 | //medicalChartAccel._xCount1++; |
darienf | 20:6d2af70c92ab | 381 | //medicalChartAccel._xCount2++; |
darienf | 20:6d2af70c92ab | 382 | //medicalChartAccel._xCount3++; |
darienf | 20:6d2af70c92ab | 383 | medicalChartAccel.AppendDataChartArea1(dummyData, 0, 0); |
darienf | 20:6d2af70c92ab | 384 | medicalChartAccel.AppendDataChartArea2(dummyData, 0, 0); |
darienf | 20:6d2af70c92ab | 385 | medicalChartAccel.AppendDataChartArea3(dummyData, 0, 0); |
darienf | 20:6d2af70c92ab | 386 | */ |
darienf | 20:6d2af70c92ab | 387 | |
darienf | 20:6d2af70c92ab | 388 | setupGraphs(); |
darienf | 20:6d2af70c92ab | 389 | |
darienf | 20:6d2af70c92ab | 390 | chartLED.ChartAreas["ChartArea3Green"].Visible = false; |
darienf | 20:6d2af70c92ab | 391 | timer.Interval = 50; |
darienf | 20:6d2af70c92ab | 392 | //timer.Tick += new EventHandler(timer_Tick); |
darienf | 20:6d2af70c92ab | 393 | } |
darienf | 20:6d2af70c92ab | 394 | |
darienf | 20:6d2af70c92ab | 395 | void setupGraphs() |
darienf | 20:6d2af70c92ab | 396 | { |
darienf | 20:6d2af70c92ab | 397 | chartLED.SuspendLayout(); |
darienf | 20:6d2af70c92ab | 398 | chartAccel.SuspendLayout(); |
darienf | 20:6d2af70c92ab | 399 | |
darienf | 20:6d2af70c92ab | 400 | /* Initialize Empty Chart Grid */ |
darienf | 20:6d2af70c92ab | 401 | chartLED.Series["SeriesRed"].Points.Clear(); |
darienf | 20:6d2af70c92ab | 402 | chartLED.Series["SeriesIR"].Points.Clear(); |
darienf | 20:6d2af70c92ab | 403 | chartLED.Series["SeriesGreen"].Points.Clear(); |
darienf | 20:6d2af70c92ab | 404 | |
darienf | 20:6d2af70c92ab | 405 | chartAccel.Series["SeriesAccelX"].Points.Clear(); |
darienf | 20:6d2af70c92ab | 406 | chartAccel.Series["SeriesAccelY"].Points.Clear(); |
darienf | 20:6d2af70c92ab | 407 | chartAccel.Series["SeriesAccelZ"].Points.Clear(); |
darienf | 20:6d2af70c92ab | 408 | |
darienf | 20:6d2af70c92ab | 409 | // Clear labels |
darienf | 20:6d2af70c92ab | 410 | chartLED.ChartAreas["ChartArea1Red"].AxisX.CustomLabels.Clear(); |
darienf | 20:6d2af70c92ab | 411 | chartLED.ChartAreas["ChartArea2IR"].AxisX.CustomLabels.Clear(); |
darienf | 20:6d2af70c92ab | 412 | chartLED.ChartAreas["ChartArea3Green"].AxisX.CustomLabels.Clear(); |
darienf | 20:6d2af70c92ab | 413 | chartAccel.ChartAreas["ChartArea4AccelX"].AxisX.CustomLabels.Clear(); |
darienf | 20:6d2af70c92ab | 414 | chartAccel.ChartAreas["ChartArea5AccelY"].AxisX.CustomLabels.Clear(); |
darienf | 20:6d2af70c92ab | 415 | chartAccel.ChartAreas["ChartArea6AccelZ"].AxisX.CustomLabels.Clear(); |
darienf | 20:6d2af70c92ab | 416 | |
darienf | 20:6d2af70c92ab | 417 | chartLED.Series["SeriesRed"].Points.Add(0); |
darienf | 20:6d2af70c92ab | 418 | chartLED.Series["SeriesIR"].Points.Add(0); |
darienf | 20:6d2af70c92ab | 419 | chartLED.Series["SeriesGreen"].Points.Add(0); |
darienf | 20:6d2af70c92ab | 420 | |
darienf | 20:6d2af70c92ab | 421 | chartAccel.Series["SeriesAccelX"].Points.Add(0); |
darienf | 20:6d2af70c92ab | 422 | chartAccel.Series["SeriesAccelY"].Points.Add(0); |
darienf | 20:6d2af70c92ab | 423 | chartAccel.Series["SeriesAccelZ"].Points.Add(0); |
darienf | 20:6d2af70c92ab | 424 | |
darienf | 20:6d2af70c92ab | 425 | // Initialize Plots for OS24 |
darienf | 20:6d2af70c92ab | 426 | chartLED.ChartAreas["ChartArea1Red"].AxisX.Interval = points / ChartTime; |
darienf | 20:6d2af70c92ab | 427 | chartLED.ChartAreas["ChartArea2IR"].AxisX.Interval = points / ChartTime; |
darienf | 20:6d2af70c92ab | 428 | chartLED.ChartAreas["ChartArea3Green"].AxisX.Interval = points / ChartTime; |
darienf | 20:6d2af70c92ab | 429 | chartLED.ChartAreas["ChartArea1Red"].AxisX.Maximum = points; |
darienf | 20:6d2af70c92ab | 430 | chartLED.ChartAreas["ChartArea2IR"].AxisX.Maximum = points; |
darienf | 20:6d2af70c92ab | 431 | chartLED.ChartAreas["ChartArea3Green"].AxisX.Maximum = points; |
darienf | 20:6d2af70c92ab | 432 | chartLED.ChartAreas["ChartArea1Red"].AxisY.Maximum = 90000; |
darienf | 20:6d2af70c92ab | 433 | chartLED.ChartAreas["ChartArea1Red"].AxisY.Minimum = 0; |
darienf | 20:6d2af70c92ab | 434 | chartLED.ChartAreas["ChartArea2IR"].AxisY.Maximum = 90000; |
darienf | 20:6d2af70c92ab | 435 | chartLED.ChartAreas["ChartArea2IR"].AxisY.Minimum = 0; |
darienf | 20:6d2af70c92ab | 436 | chartLED.ChartAreas["ChartArea3Green"].AxisY.Maximum = 90000; |
darienf | 20:6d2af70c92ab | 437 | chartLED.ChartAreas["ChartArea3Green"].AxisY.Minimum = 0; |
darienf | 20:6d2af70c92ab | 438 | |
darienf | 20:6d2af70c92ab | 439 | // Initialize Plots for LIS2HD |
darienf | 20:6d2af70c92ab | 440 | sampleRateAccel = sampleRate; |
darienf | 20:6d2af70c92ab | 441 | //pointsAccel = (sampleRateAccel / sampleAverage) * ChartTime; |
darienf | 20:6d2af70c92ab | 442 | pointsAccel = (sampleRateAccel) * ChartTime; |
darienf | 20:6d2af70c92ab | 443 | chartAccel.ChartAreas["ChartArea4AccelX"].AxisX.Interval = pointsAccel / ChartTime; |
darienf | 20:6d2af70c92ab | 444 | chartAccel.ChartAreas["ChartArea5AccelY"].AxisX.Interval = pointsAccel / ChartTime; |
darienf | 20:6d2af70c92ab | 445 | chartAccel.ChartAreas["ChartArea6AccelZ"].AxisX.Interval = pointsAccel / ChartTime; |
darienf | 20:6d2af70c92ab | 446 | chartAccel.ChartAreas["ChartArea4AccelX"].AxisX.Maximum = pointsAccel; |
darienf | 20:6d2af70c92ab | 447 | chartAccel.ChartAreas["ChartArea5AccelY"].AxisX.Maximum = pointsAccel; |
darienf | 20:6d2af70c92ab | 448 | chartAccel.ChartAreas["ChartArea6AccelZ"].AxisX.Maximum = pointsAccel; |
darienf | 20:6d2af70c92ab | 449 | chartAccel.ChartAreas["ChartArea4AccelX"].AxisY.Minimum = -10000; |
darienf | 20:6d2af70c92ab | 450 | chartAccel.ChartAreas["ChartArea5AccelY"].AxisY.Minimum = -10000; |
darienf | 20:6d2af70c92ab | 451 | chartAccel.ChartAreas["ChartArea6AccelZ"].AxisY.Minimum = -10000; |
darienf | 20:6d2af70c92ab | 452 | chartAccel.ChartAreas["ChartArea4AccelX"].AxisY.Maximum = 10000; |
darienf | 20:6d2af70c92ab | 453 | chartAccel.ChartAreas["ChartArea5AccelY"].AxisY.Maximum = 10000; |
darienf | 20:6d2af70c92ab | 454 | chartAccel.ChartAreas["ChartArea6AccelZ"].AxisY.Maximum = 10000; |
darienf | 20:6d2af70c92ab | 455 | |
darienf | 20:6d2af70c92ab | 456 | // Set X-axis labels in seconds |
darienf | 20:6d2af70c92ab | 457 | for (int i = 0; i < ChartTime + 1; i++) |
darienf | 20:6d2af70c92ab | 458 | { |
darienf | 20:6d2af70c92ab | 459 | chartLED.ChartAreas["ChartArea1Red"].AxisX.CustomLabels.Add( (sampleRate / sampleAverage) * (2 * i - 1) / 2, (sampleRate / sampleAverage) * (2 * i + 1) / 2, i.ToString()); |
darienf | 20:6d2af70c92ab | 460 | chartLED.ChartAreas["ChartArea2IR"].AxisX.CustomLabels.Add( (sampleRate / sampleAverage) * (2 * i - 1) / 2, (sampleRate / sampleAverage) * (2 * i + 1) / 2, i.ToString()); |
darienf | 20:6d2af70c92ab | 461 | chartLED.ChartAreas["ChartArea3Green"].AxisX.CustomLabels.Add( (sampleRate / sampleAverage) * (2 * i - 1) / 2, (sampleRate / sampleAverage) * (2 * i + 1) / 2, i.ToString()); |
darienf | 20:6d2af70c92ab | 462 | |
darienf | 20:6d2af70c92ab | 463 | chartAccel.ChartAreas["ChartArea4AccelX"].AxisX.CustomLabels.Add(sampleRateAccel * (2 * i - 1) / 2, sampleRateAccel * (2 * i + 1) / 2, i.ToString()); |
darienf | 20:6d2af70c92ab | 464 | chartAccel.ChartAreas["ChartArea5AccelY"].AxisX.CustomLabels.Add(sampleRateAccel * (2 * i - 1) / 2, sampleRateAccel * (2 * i + 1) / 2, i.ToString()); |
darienf | 20:6d2af70c92ab | 465 | chartAccel.ChartAreas["ChartArea6AccelZ"].AxisX.CustomLabels.Add(sampleRateAccel * (2 * i - 1) / 2, sampleRateAccel * (2 * i + 1) / 2, i.ToString()); |
darienf | 20:6d2af70c92ab | 466 | } |
darienf | 20:6d2af70c92ab | 467 | |
darienf | 20:6d2af70c92ab | 468 | chartLED.ResumeLayout(); |
darienf | 20:6d2af70c92ab | 469 | chartLED.Invalidate(); |
darienf | 20:6d2af70c92ab | 470 | chartAccel.ResumeLayout(); |
darienf | 20:6d2af70c92ab | 471 | chartAccel.Invalidate(); |
darienf | 20:6d2af70c92ab | 472 | } |
darienf | 20:6d2af70c92ab | 473 | |
darienf | 20:6d2af70c92ab | 474 | void timer_Tick(object sender, EventArgs e) |
darienf | 20:6d2af70c92ab | 475 | { |
darienf | 20:6d2af70c92ab | 476 | /*Single tmpData = dynamicData[0].Y; |
darienf | 20:6d2af70c92ab | 477 | for (int i = 0; i < dynamicData.Length - 1; i++) |
darienf | 20:6d2af70c92ab | 478 | { |
darienf | 20:6d2af70c92ab | 479 | dynamicData[i].Y = dynamicData[i + 1].Y; |
darienf | 20:6d2af70c92ab | 480 | } |
darienf | 20:6d2af70c92ab | 481 | dynamicData[dynamicData.Length - 1].Y = tmpData;*/ |
darienf | 20:6d2af70c92ab | 482 | |
darienf | 20:6d2af70c92ab | 483 | //PointF[] newData = GenerateDynamicData(100, 5); |
darienf | 20:6d2af70c92ab | 484 | //UpdateLedChart("SeriesRed", newData); |
darienf | 20:6d2af70c92ab | 485 | //UpdateLedChart("SeriesIR", newData); |
darienf | 20:6d2af70c92ab | 486 | //UpdateLedChart("SeriesGreen", newData); |
darienf | 20:6d2af70c92ab | 487 | } |
darienf | 20:6d2af70c92ab | 488 | |
darienf | 20:6d2af70c92ab | 489 | /*private void UpdateLedChart(string seriesName, PointF[] data) |
darienf | 20:6d2af70c92ab | 490 | { |
darienf | 20:6d2af70c92ab | 491 | int count; |
darienf | 20:6d2af70c92ab | 492 | |
darienf | 20:6d2af70c92ab | 493 | chartLED.SuspendLayout(); |
darienf | 20:6d2af70c92ab | 494 | //chartLED.Series[seriesName].Points.Clear(); |
darienf | 20:6d2af70c92ab | 495 | foreach (PointF pt in data) |
darienf | 20:6d2af70c92ab | 496 | { |
darienf | 20:6d2af70c92ab | 497 | //chartLED.Series[seriesName].Points.AddXY(pt.X, pt.Y); |
darienf | 20:6d2af70c92ab | 498 | chartLED.Series[seriesName].Points.Add(pt.Y); |
darienf | 20:6d2af70c92ab | 499 | } |
darienf | 20:6d2af70c92ab | 500 | |
darienf | 20:6d2af70c92ab | 501 | for (count = chartLED.Series[seriesName].Points.Count; |
darienf | 20:6d2af70c92ab | 502 | count > points; |
darienf | 20:6d2af70c92ab | 503 | count = chartLED.Series[seriesName].Points.Count) |
darienf | 20:6d2af70c92ab | 504 | { |
darienf | 20:6d2af70c92ab | 505 | chartLED.Series[seriesName].Points.RemoveAt(0); |
darienf | 20:6d2af70c92ab | 506 | } |
darienf | 20:6d2af70c92ab | 507 | chartLED.ResumeLayout(); |
darienf | 20:6d2af70c92ab | 508 | chartLED.Invalidate(); |
darienf | 20:6d2af70c92ab | 509 | }*/ |
darienf | 20:6d2af70c92ab | 510 | |
darienf | 20:6d2af70c92ab | 511 | private void UpdateXYZChart(string seriesName, int[] data) |
darienf | 20:6d2af70c92ab | 512 | { |
darienf | 20:6d2af70c92ab | 513 | int datapoint; |
darienf | 20:6d2af70c92ab | 514 | int count; |
darienf | 20:6d2af70c92ab | 515 | |
darienf | 20:6d2af70c92ab | 516 | chartAccel.SuspendLayout(); |
darienf | 20:6d2af70c92ab | 517 | //chartLED.Series[seriesName].Points.Clear(); |
darienf | 20:6d2af70c92ab | 518 | foreach (int val in data) |
darienf | 20:6d2af70c92ab | 519 | { |
darienf | 20:6d2af70c92ab | 520 | //chartLED.Series[seriesName].Points.AddXY(pt.X, pt.Y); |
darienf | 20:6d2af70c92ab | 521 | datapoint = val; |
darienf | 20:6d2af70c92ab | 522 | // Two's complement conversion |
darienf | 20:6d2af70c92ab | 523 | if (val > 0x8000) |
darienf | 20:6d2af70c92ab | 524 | { |
darienf | 20:6d2af70c92ab | 525 | datapoint = datapoint - 0x10000; |
darienf | 20:6d2af70c92ab | 526 | } |
darienf | 20:6d2af70c92ab | 527 | chartAccel.Series[seriesName].Points.Add(datapoint); |
darienf | 20:6d2af70c92ab | 528 | } |
darienf | 20:6d2af70c92ab | 529 | |
darienf | 20:6d2af70c92ab | 530 | for (count = chartAccel.Series[seriesName].Points.Count; |
darienf | 20:6d2af70c92ab | 531 | count > pointsAccel; |
darienf | 20:6d2af70c92ab | 532 | count = chartAccel.Series[seriesName].Points.Count) |
darienf | 20:6d2af70c92ab | 533 | { |
darienf | 20:6d2af70c92ab | 534 | chartAccel.Series[seriesName].Points.RemoveAt(0); |
darienf | 20:6d2af70c92ab | 535 | } |
darienf | 20:6d2af70c92ab | 536 | //chartAccel.ResetAutoValues(); |
darienf | 20:6d2af70c92ab | 537 | chartAccel.ResumeLayout(); |
darienf | 20:6d2af70c92ab | 538 | chartAccel.Invalidate(); |
darienf | 20:6d2af70c92ab | 539 | } |
darienf | 20:6d2af70c92ab | 540 | |
darienf | 20:6d2af70c92ab | 541 | private void UpdateLedChart(string seriesName, int[] data) |
darienf | 20:6d2af70c92ab | 542 | { |
darienf | 20:6d2af70c92ab | 543 | int[] dataPoints = new int[points]; |
darienf | 20:6d2af70c92ab | 544 | int j = 0; |
darienf | 20:6d2af70c92ab | 545 | int count; |
darienf | 20:6d2af70c92ab | 546 | |
darienf | 20:6d2af70c92ab | 547 | chartLED.SuspendLayout(); |
darienf | 20:6d2af70c92ab | 548 | //chartLED.Series[seriesName].Points.Clear(); |
darienf | 20:6d2af70c92ab | 549 | |
darienf | 20:6d2af70c92ab | 550 | // Update Chart with new data |
darienf | 20:6d2af70c92ab | 551 | if (data.Length > points) |
darienf | 20:6d2af70c92ab | 552 | j = data.Length - points; |
darienf | 20:6d2af70c92ab | 553 | |
darienf | 20:6d2af70c92ab | 554 | for (; j < data.Length; j++ ) |
darienf | 20:6d2af70c92ab | 555 | { |
darienf | 20:6d2af70c92ab | 556 | chartLED.Series[seriesName].Points.Add(data[j]); |
darienf | 20:6d2af70c92ab | 557 | #if CES_DEMO |
darienf | 20:6d2af70c92ab | 558 | if (seriesName.CompareTo("SeriesRed") == 0) |
darienf | 20:6d2af70c92ab | 559 | red.Enqueue(data[j]); |
darienf | 20:6d2af70c92ab | 560 | else if (seriesName.CompareTo("SeriesIR") == 0) |
darienf | 20:6d2af70c92ab | 561 | ir.Enqueue(data[j]); |
darienf | 20:6d2af70c92ab | 562 | else if (seriesName.CompareTo("SeriesGreen") == 0) |
darienf | 20:6d2af70c92ab | 563 | led.Enqueue(data[j]); |
darienf | 20:6d2af70c92ab | 564 | #endif |
darienf | 20:6d2af70c92ab | 565 | } |
darienf | 20:6d2af70c92ab | 566 | |
darienf | 20:6d2af70c92ab | 567 | for (count = chartLED.Series[seriesName].Points.Count; |
darienf | 20:6d2af70c92ab | 568 | count > points; |
darienf | 20:6d2af70c92ab | 569 | count = chartLED.Series[seriesName].Points.Count) |
darienf | 20:6d2af70c92ab | 570 | { |
darienf | 20:6d2af70c92ab | 571 | chartLED.Series[seriesName].Points.RemoveAt(0); |
darienf | 20:6d2af70c92ab | 572 | } |
darienf | 20:6d2af70c92ab | 573 | } |
darienf | 20:6d2af70c92ab | 574 | |
darienf | 20:6d2af70c92ab | 575 | private void UpdateLedChartScale(string chartName, string seriesName) |
darienf | 20:6d2af70c92ab | 576 | { |
darienf | 20:6d2af70c92ab | 577 | int min = Int32.MaxValue, max = 0; |
darienf | 20:6d2af70c92ab | 578 | int i, j; |
darienf | 20:6d2af70c92ab | 579 | int[] data = new int[points]; |
darienf | 20:6d2af70c92ab | 580 | int graphCount; |
darienf | 20:6d2af70c92ab | 581 | //int maxRound, minRound; |
darienf | 20:6d2af70c92ab | 582 | |
darienf | 20:6d2af70c92ab | 583 | graphCount = chartLED.Series[seriesName].Points.Count; |
darienf | 20:6d2af70c92ab | 584 | |
darienf | 20:6d2af70c92ab | 585 | for (j = 0; j < graphCount; j++ ) |
darienf | 20:6d2af70c92ab | 586 | { |
darienf | 20:6d2af70c92ab | 587 | data[j] = (int)chartLED.Series[seriesName].Points[j].YValues[0]; |
darienf | 20:6d2af70c92ab | 588 | } |
darienf | 20:6d2af70c92ab | 589 | |
darienf | 20:6d2af70c92ab | 590 | //if (data.Length < sampleRate) |
darienf | 20:6d2af70c92ab | 591 | // return; // not enough data to draw graph |
darienf | 20:6d2af70c92ab | 592 | /*else*/ |
darienf | 20:6d2af70c92ab | 593 | if (graphCount < (sampleRate / sampleAverage) * 2) // look back 2 seconds |
darienf | 20:6d2af70c92ab | 594 | { |
darienf | 20:6d2af70c92ab | 595 | i = 0; |
darienf | 20:6d2af70c92ab | 596 | } |
darienf | 20:6d2af70c92ab | 597 | else // look back 2 seconds |
darienf | 20:6d2af70c92ab | 598 | { |
darienf | 20:6d2af70c92ab | 599 | i = graphCount - (sampleRate / sampleAverage) * 2; |
darienf | 20:6d2af70c92ab | 600 | } |
darienf | 20:6d2af70c92ab | 601 | |
darienf | 20:6d2af70c92ab | 602 | min = data[i]; |
darienf | 20:6d2af70c92ab | 603 | max = data[i]; |
darienf | 20:6d2af70c92ab | 604 | for (; i < graphCount; i++ ) |
darienf | 20:6d2af70c92ab | 605 | { |
darienf | 20:6d2af70c92ab | 606 | if (data[i] < min && data[i] != 0) |
darienf | 20:6d2af70c92ab | 607 | min = data[i]; |
darienf | 20:6d2af70c92ab | 608 | else if (data[i] > max) |
darienf | 20:6d2af70c92ab | 609 | max = data[i]; |
darienf | 20:6d2af70c92ab | 610 | } |
darienf | 20:6d2af70c92ab | 611 | |
darienf | 20:6d2af70c92ab | 612 | /* |
darienf | 20:6d2af70c92ab | 613 | MedianFilter filter; |
darienf | 20:6d2af70c92ab | 614 | intervalDict.TryGetValue(chartName, out filter); |
darienf | 20:6d2af70c92ab | 615 | |
darienf | 20:6d2af70c92ab | 616 | var minMax = chartInterval(min, max, chartLED.ChartAreas[chartName].AxisY.Minimum, chartLED.ChartAreas[chartName].AxisY.Maximum, filter); |
darienf | 20:6d2af70c92ab | 617 | minRound = minMax.Item1; |
darienf | 20:6d2af70c92ab | 618 | maxRound = minMax.Item2; |
darienf | 20:6d2af70c92ab | 619 | |
darienf | 20:6d2af70c92ab | 620 | |
darienf | 20:6d2af70c92ab | 621 | |
darienf | 20:6d2af70c92ab | 622 | // For no finger on sensor |
darienf | 20:6d2af70c92ab | 623 | if (max < 500) |
darienf | 20:6d2af70c92ab | 624 | max = 500; |
darienf | 20:6d2af70c92ab | 625 | */ |
darienf | 20:6d2af70c92ab | 626 | |
darienf | 20:6d2af70c92ab | 627 | AutoScaleCalculator chartScale; |
darienf | 20:6d2af70c92ab | 628 | chartScaleDict.TryGetValue(chartName, out chartScale); |
darienf | 20:6d2af70c92ab | 629 | |
darienf | 20:6d2af70c92ab | 630 | var minMax = chartScale.Interval(min, max); |
darienf | 20:6d2af70c92ab | 631 | |
darienf | 20:6d2af70c92ab | 632 | // Round to nearest 100 with averaging |
darienf | 20:6d2af70c92ab | 633 | //chartLED.ChartAreas[chartName].AxisY.Maximum = (chartLED.ChartAreas[chartName].AxisY.Maximum + (max / 100 + 1) * 100)/2; |
darienf | 20:6d2af70c92ab | 634 | //chartLED.ChartAreas[chartName].AxisY.Maximum = (((int)chartLED.ChartAreas[chartName].AxisY.Maximum + max)/200 + 1) * 100; |
darienf | 20:6d2af70c92ab | 635 | //chartLED.ChartAreas[chartName].AxisY.Minimum = (chartLED.ChartAreas[chartName].AxisY.Minimum + (min / 100 - 1) * 100)/2; |
darienf | 20:6d2af70c92ab | 636 | //chartLED.ChartAreas[chartName].AxisY.Minimum = (((int)chartLED.ChartAreas[chartName].AxisY.Minimum + min)/200 - 1) * 100; |
darienf | 20:6d2af70c92ab | 637 | chartLED.ChartAreas[chartName].AxisY.Minimum = minMax.Item1; |
darienf | 20:6d2af70c92ab | 638 | chartLED.ChartAreas[chartName].AxisY.Maximum = minMax.Item2; |
darienf | 20:6d2af70c92ab | 639 | |
darienf | 20:6d2af70c92ab | 640 | chartLED.ResumeLayout(); |
darienf | 20:6d2af70c92ab | 641 | chartLED.Invalidate(); |
darienf | 20:6d2af70c92ab | 642 | } |
darienf | 20:6d2af70c92ab | 643 | |
darienf | 20:6d2af70c92ab | 644 | private void UpdateXYZChartScale(string chartName, string seriesName) |
darienf | 20:6d2af70c92ab | 645 | { |
darienf | 20:6d2af70c92ab | 646 | int min = Int32.MaxValue, max = Int32.MinValue; |
darienf | 20:6d2af70c92ab | 647 | int i, j; |
darienf | 20:6d2af70c92ab | 648 | int maxRound, minRound; |
darienf | 20:6d2af70c92ab | 649 | int graphCount; |
darienf | 20:6d2af70c92ab | 650 | |
darienf | 20:6d2af70c92ab | 651 | int[] data = new int[pointsAccel]; |
darienf | 20:6d2af70c92ab | 652 | |
darienf | 20:6d2af70c92ab | 653 | graphCount = chartAccel.Series[seriesName].Points.Count; |
darienf | 20:6d2af70c92ab | 654 | |
darienf | 20:6d2af70c92ab | 655 | // Save all points from plot to data[] |
darienf | 20:6d2af70c92ab | 656 | for (j = 0; j < graphCount; j++) |
darienf | 20:6d2af70c92ab | 657 | { |
darienf | 20:6d2af70c92ab | 658 | data[j] = (int)chartAccel.Series[seriesName].Points[j].YValues[0]; |
darienf | 20:6d2af70c92ab | 659 | } |
darienf | 20:6d2af70c92ab | 660 | |
darienf | 20:6d2af70c92ab | 661 | if (graphCount < (sampleRateAccel / sampleAverage) * 2) // look back 3 seconds |
darienf | 20:6d2af70c92ab | 662 | i = 0; |
darienf | 20:6d2af70c92ab | 663 | else |
darienf | 20:6d2af70c92ab | 664 | i = graphCount - (sampleRateAccel / sampleAverage) * 2; |
darienf | 20:6d2af70c92ab | 665 | |
darienf | 20:6d2af70c92ab | 666 | // Find min/max |
darienf | 20:6d2af70c92ab | 667 | min = data[i]; |
darienf | 20:6d2af70c92ab | 668 | max = data[i]; |
darienf | 20:6d2af70c92ab | 669 | for (; i < graphCount; i++) |
darienf | 20:6d2af70c92ab | 670 | { |
darienf | 20:6d2af70c92ab | 671 | if (data[i] < min) |
darienf | 20:6d2af70c92ab | 672 | min = data[i]; |
darienf | 20:6d2af70c92ab | 673 | else if (data[i] > max) |
darienf | 20:6d2af70c92ab | 674 | max = data[i]; |
darienf | 20:6d2af70c92ab | 675 | } |
darienf | 20:6d2af70c92ab | 676 | |
darienf | 20:6d2af70c92ab | 677 | /* |
darienf | 20:6d2af70c92ab | 678 | // Sane defaults |
darienf | 20:6d2af70c92ab | 679 | if (min == max) |
darienf | 20:6d2af70c92ab | 680 | { |
darienf | 20:6d2af70c92ab | 681 | min = 0; |
darienf | 20:6d2af70c92ab | 682 | max = 100; |
darienf | 20:6d2af70c92ab | 683 | } |
darienf | 20:6d2af70c92ab | 684 | |
darienf | 20:6d2af70c92ab | 685 | MedianFilter filter; |
darienf | 20:6d2af70c92ab | 686 | intervalDict.TryGetValue(chartName, out filter); |
darienf | 20:6d2af70c92ab | 687 | |
darienf | 20:6d2af70c92ab | 688 | var minMax = chartInterval(min, max, chartAccel.ChartAreas[chartName].AxisY.Minimum, chartAccel.ChartAreas[chartName].AxisY.Maximum, filter); |
darienf | 20:6d2af70c92ab | 689 | minRound = minMax.Item1; |
darienf | 20:6d2af70c92ab | 690 | maxRound = minMax.Item2; |
darienf | 20:6d2af70c92ab | 691 | |
darienf | 20:6d2af70c92ab | 692 | if (maxRound > 32768) |
darienf | 20:6d2af70c92ab | 693 | maxRound = 33000; |
darienf | 20:6d2af70c92ab | 694 | |
darienf | 20:6d2af70c92ab | 695 | if (minRound < -32768) |
darienf | 20:6d2af70c92ab | 696 | minRound = -33000; |
darienf | 20:6d2af70c92ab | 697 | */ |
darienf | 20:6d2af70c92ab | 698 | |
darienf | 20:6d2af70c92ab | 699 | AutoScaleCalculator chartScale; |
darienf | 20:6d2af70c92ab | 700 | chartScaleDict.TryGetValue(chartName, out chartScale); |
darienf | 20:6d2af70c92ab | 701 | |
darienf | 20:6d2af70c92ab | 702 | var minMax = chartScale.Interval(min, max); |
darienf | 20:6d2af70c92ab | 703 | minRound = (int)minMax.Item1; |
darienf | 20:6d2af70c92ab | 704 | maxRound = (int)minMax.Item2; |
darienf | 20:6d2af70c92ab | 705 | |
darienf | 20:6d2af70c92ab | 706 | // Set the Min and Max for Y Axis |
darienf | 20:6d2af70c92ab | 707 | //chartAccel.ChartAreas[chartName].AxisY.Maximum = (((int)chartAccel.ChartAreas[chartName].AxisY.Maximum + max) / 200 + 1) * 100; |
darienf | 20:6d2af70c92ab | 708 | //chartAccel.ChartAreas[chartName].AxisY.Minimum = (((int)chartAccel.ChartAreas[chartName].AxisY.Minimum + min) / 200 - 1) * 100; |
darienf | 20:6d2af70c92ab | 709 | chartAccel.ChartAreas[chartName].AxisY.Maximum = maxRound; |
darienf | 20:6d2af70c92ab | 710 | chartAccel.ChartAreas[chartName].AxisY.Minimum = minRound; |
darienf | 20:6d2af70c92ab | 711 | //System.Diagnostics.Debug.Print(chartName + " count: " + graphCount + " minRound: " + minRound + " maxRound: " + maxRound + " min: " + min + " max: " + max); |
darienf | 20:6d2af70c92ab | 712 | |
darienf | 20:6d2af70c92ab | 713 | chartAccel.ResumeLayout(); |
darienf | 20:6d2af70c92ab | 714 | chartAccel.Invalidate(); |
darienf | 20:6d2af70c92ab | 715 | } |
darienf | 20:6d2af70c92ab | 716 | |
darienf | 20:6d2af70c92ab | 717 | /*private PointF[] dynamicData; |
darienf | 20:6d2af70c92ab | 718 | private static PointF[] GenerateDynamicData(double amplitude, int sampleCount) |
darienf | 20:6d2af70c92ab | 719 | { |
darienf | 20:6d2af70c92ab | 720 | Random rnd = new Random(); |
darienf | 20:6d2af70c92ab | 721 | PointF[] points = new PointF[sampleCount]; |
darienf | 20:6d2af70c92ab | 722 | points[0] = new PointF(0, (Single)(amplitude * rnd.NextDouble())); |
darienf | 20:6d2af70c92ab | 723 | for (int i = 1; i < sampleCount; i++) |
darienf | 20:6d2af70c92ab | 724 | { |
darienf | 20:6d2af70c92ab | 725 | points[i] = new PointF(i, (Single)(points[i - 1].Y + (amplitude / 10 * (0.5 - rnd.NextDouble())))); |
darienf | 20:6d2af70c92ab | 726 | if (points[i].Y > amplitude) points[i].Y = (Single)amplitude; |
darienf | 20:6d2af70c92ab | 727 | } |
darienf | 20:6d2af70c92ab | 728 | return (points); |
darienf | 20:6d2af70c92ab | 729 | }*/ |
darienf | 20:6d2af70c92ab | 730 | |
darienf | 20:6d2af70c92ab | 731 | /// <summary> |
darienf | 20:6d2af70c92ab | 732 | /// Calculate rounded minimum and maximum for chart data |
darienf | 20:6d2af70c92ab | 733 | /// </summary> |
darienf | 20:6d2af70c92ab | 734 | /// <param name="minimum"></param> |
darienf | 20:6d2af70c92ab | 735 | /// <param name="maximum"></param> |
darienf | 20:6d2af70c92ab | 736 | /// <param name="chartInterval"></param> |
darienf | 20:6d2af70c92ab | 737 | /// <returns></returns> |
darienf | 20:6d2af70c92ab | 738 | private static Tuple<int, int> chartInterval(int minimum, int maximum, double chartMinimum, double chartMaximum, MedianFilter chartInterval) |
darienf | 20:6d2af70c92ab | 739 | { |
darienf | 20:6d2af70c92ab | 740 | int delta, interval, roundInterval, roundCenter; |
darienf | 20:6d2af70c92ab | 741 | double mag, magPower, magMostSigDigit; |
darienf | 20:6d2af70c92ab | 742 | int center; |
darienf | 20:6d2af70c92ab | 743 | |
darienf | 20:6d2af70c92ab | 744 | // 10% and 90% range |
darienf | 20:6d2af70c92ab | 745 | int chartRange = (int)(chartMaximum - chartMinimum); |
darienf | 20:6d2af70c92ab | 746 | int dataRange = maximum - minimum; |
darienf | 20:6d2af70c92ab | 747 | if (minimum < chartMinimum + chartRange * 0.10 || maximum > chartMaximum - chartRange * 0.10 |
darienf | 20:6d2af70c92ab | 748 | || dataRange > 0.9 * chartRange || dataRange < 0.1 * chartRange) |
darienf | 20:6d2af70c92ab | 749 | { |
darienf | 20:6d2af70c92ab | 750 | |
darienf | 20:6d2af70c92ab | 751 | delta = (int)((maximum - minimum)); |
darienf | 20:6d2af70c92ab | 752 | |
darienf | 20:6d2af70c92ab | 753 | interval = delta * (100 / 35) / 5; // delta * 4 = 25% * 4 = 100 (full chart scale) |
darienf | 20:6d2af70c92ab | 754 | center = minimum + (maximum - minimum) / 2; |
darienf | 20:6d2af70c92ab | 755 | |
darienf | 20:6d2af70c92ab | 756 | mag = Math.Floor(Math.Log10(interval)); |
darienf | 20:6d2af70c92ab | 757 | magPower = Math.Pow(10, mag); |
darienf | 20:6d2af70c92ab | 758 | |
darienf | 20:6d2af70c92ab | 759 | magMostSigDigit = (int)(interval / (double)magPower + 0.5); |
darienf | 20:6d2af70c92ab | 760 | |
darienf | 20:6d2af70c92ab | 761 | if (magMostSigDigit >= 5.0) |
darienf | 20:6d2af70c92ab | 762 | magMostSigDigit = 10; |
darienf | 20:6d2af70c92ab | 763 | else if (magMostSigDigit >= 2.0) |
darienf | 20:6d2af70c92ab | 764 | magMostSigDigit = 5; |
darienf | 20:6d2af70c92ab | 765 | else if (magMostSigDigit >= 1.0) |
darienf | 20:6d2af70c92ab | 766 | magMostSigDigit = 2; |
darienf | 20:6d2af70c92ab | 767 | |
darienf | 20:6d2af70c92ab | 768 | roundInterval = (int)(magMostSigDigit * magPower); |
darienf | 20:6d2af70c92ab | 769 | if (roundInterval < 100) |
darienf | 20:6d2af70c92ab | 770 | { |
darienf | 20:6d2af70c92ab | 771 | roundInterval = 100; |
darienf | 20:6d2af70c92ab | 772 | } |
darienf | 20:6d2af70c92ab | 773 | roundInterval = chartInterval.Filter(roundInterval); |
darienf | 20:6d2af70c92ab | 774 | |
darienf | 20:6d2af70c92ab | 775 | roundCenter = ((center + 100) / 200) * 200; |
darienf | 20:6d2af70c92ab | 776 | |
darienf | 20:6d2af70c92ab | 777 | int roundMin = (int)(roundCenter - roundInterval * 2.5); |
darienf | 20:6d2af70c92ab | 778 | int roundMax = (int)(roundCenter + roundInterval * 2.5); |
darienf | 20:6d2af70c92ab | 779 | if (roundInterval > 104858) |
darienf | 20:6d2af70c92ab | 780 | { |
darienf | 20:6d2af70c92ab | 781 | roundMin = 0; |
darienf | 20:6d2af70c92ab | 782 | roundMax = 550000; |
darienf | 20:6d2af70c92ab | 783 | } |
darienf | 20:6d2af70c92ab | 784 | /*else |
darienf | 20:6d2af70c92ab | 785 | { |
darienf | 20:6d2af70c92ab | 786 | if (roundMin < 0) // || roundMax > 524288) |
darienf | 20:6d2af70c92ab | 787 | { |
darienf | 20:6d2af70c92ab | 788 | roundMin = 0; |
darienf | 20:6d2af70c92ab | 789 | roundMax = roundInterval * 5; |
darienf | 20:6d2af70c92ab | 790 | } |
darienf | 20:6d2af70c92ab | 791 | }*/ |
darienf | 20:6d2af70c92ab | 792 | |
darienf | 20:6d2af70c92ab | 793 | return new Tuple<int, int>(roundMin, roundMax); |
darienf | 20:6d2af70c92ab | 794 | } |
darienf | 20:6d2af70c92ab | 795 | |
darienf | 20:6d2af70c92ab | 796 | return new Tuple<int, int>((int)chartMinimum, (int)chartMaximum); |
darienf | 20:6d2af70c92ab | 797 | } |
darienf | 20:6d2af70c92ab | 798 | |
darienf | 20:6d2af70c92ab | 799 | void OpticalSensorInitControls() |
darienf | 20:6d2af70c92ab | 800 | { |
darienf | 20:6d2af70c92ab | 801 | cboMode.Items.AddRange(new string[] { "HR","SPO2","LED" }); |
darienf | 20:6d2af70c92ab | 802 | cboSampleRate.Items.AddRange(new string[] { "50", "100", "200", "400" }); |
darienf | 20:6d2af70c92ab | 803 | cboSampleAvg.Items.AddRange(new string[] { "1", "2", "4", "8", "16", "32" }); |
darienf | 20:6d2af70c92ab | 804 | cboPulseWidth.Items.AddRange(new string[] { "69", "118", "215", "411" }); |
darienf | 20:6d2af70c92ab | 805 | cboADCFSrangenA.Items.AddRange(new string[] { "2048", "4096", "8192", "16384" }); |
darienf | 20:6d2af70c92ab | 806 | double slopeInt = 25.0 / 128.0; |
darienf | 20:6d2af70c92ab | 807 | for (int index = 0; index < 256; index++) |
darienf | 20:6d2af70c92ab | 808 | { |
darienf | 20:6d2af70c92ab | 809 | string str = index < 0x0F ? (0.2 * index).ToString() : (slopeInt * index + slopeInt).ToString(); |
darienf | 20:6d2af70c92ab | 810 | cboIRLED.Items.Add(str); |
darienf | 20:6d2af70c92ab | 811 | cboRedLED.Items.Add(str); |
darienf | 20:6d2af70c92ab | 812 | cboGreenLED.Items.Add(str); |
darienf | 20:6d2af70c92ab | 813 | cboPilotPA.Items.Add(str); |
darienf | 20:6d2af70c92ab | 814 | } |
darienf | 20:6d2af70c92ab | 815 | |
darienf | 20:6d2af70c92ab | 816 | OpticalSensorDefaults(); |
darienf | 20:6d2af70c92ab | 817 | calculateAvgCurrent(); |
darienf | 20:6d2af70c92ab | 818 | |
darienf | 20:6d2af70c92ab | 819 | InitGraphs(); |
darienf | 20:6d2af70c92ab | 820 | } |
darienf | 20:6d2af70c92ab | 821 | |
darienf | 20:6d2af70c92ab | 822 | public void OpticalSensorDefaults() |
darienf | 20:6d2af70c92ab | 823 | { |
darienf | 20:6d2af70c92ab | 824 | cboMode.SelectedItem = "SPO2"; |
darienf | 20:6d2af70c92ab | 825 | cboRedLED.SelectedItem = "10.15625"; |
darienf | 20:6d2af70c92ab | 826 | cboIRLED.SelectedItem = "10.15625"; |
darienf | 20:6d2af70c92ab | 827 | cboGreenLED.SelectedItem = "10.15625"; |
darienf | 20:6d2af70c92ab | 828 | cboSampleRate.SelectedItem = "100"; |
darienf | 20:6d2af70c92ab | 829 | cboPulseWidth.SelectedItem = "411"; |
darienf | 20:6d2af70c92ab | 830 | cboSampleAvg.SelectedItem = "1"; |
darienf | 20:6d2af70c92ab | 831 | cboADCFSrangenA.SelectedItem = "8192"; |
darienf | 20:6d2af70c92ab | 832 | |
darienf | 20:6d2af70c92ab | 833 | cboLEDslot1.SelectedIndex = 1; |
darienf | 20:6d2af70c92ab | 834 | cboLEDslot2.SelectedIndex = 2; |
darienf | 20:6d2af70c92ab | 835 | cboLEDslot3.SelectedIndex = 3; |
darienf | 20:6d2af70c92ab | 836 | cboLEDslot4.SelectedIndex = 0; |
darienf | 20:6d2af70c92ab | 837 | |
darienf | 20:6d2af70c92ab | 838 | // Used to generate the initial chart grid |
darienf | 20:6d2af70c92ab | 839 | sample_rate = (byte)cboSampleRate.SelectedIndex; |
darienf | 20:6d2af70c92ab | 840 | sample_avg = (byte)cboSampleAvg.SelectedIndex; |
darienf | 20:6d2af70c92ab | 841 | |
darienf | 20:6d2af70c92ab | 842 | sampleRate = (1 << sample_rate) * 50; // (1 << sample_rate) = 2^sample_rate |
darienf | 20:6d2af70c92ab | 843 | sampleAverage = (1 << sample_avg); // 2^sample_avg |
darienf | 20:6d2af70c92ab | 844 | points = (sampleRate / sampleAverage) * ChartTime; // 4 seconds, 2^sample_av |
darienf | 20:6d2af70c92ab | 845 | |
darienf | 20:6d2af70c92ab | 846 | sampleRateAccel = sampleRate; |
darienf | 20:6d2af70c92ab | 847 | pointsAccel = (sampleRateAccel / sampleAverage) * ChartTime; |
darienf | 20:6d2af70c92ab | 848 | } |
darienf | 20:6d2af70c92ab | 849 | |
darienf | 20:6d2af70c92ab | 850 | private void cbo_IndexChanged(object sender, EventArgs e) |
darienf | 20:6d2af70c92ab | 851 | { |
darienf | 20:6d2af70c92ab | 852 | if ((MaximStyle.MaximComboBox)sender == cboMode) |
darienf | 20:6d2af70c92ab | 853 | { |
darienf | 20:6d2af70c92ab | 854 | bool HRmode = (cboMode.Text == "HR"); |
darienf | 20:6d2af70c92ab | 855 | bool SPO2mode = (cboMode.Text == "SPO2"); |
darienf | 20:6d2af70c92ab | 856 | bool multiLEDmode = (cboMode.Text == "LED"); |
darienf | 20:6d2af70c92ab | 857 | //labelcboRedLED.Enabled = myMAX30101.valid_Red; |
darienf | 20:6d2af70c92ab | 858 | //cboRedLED.Enabled = myMAX30101.valid_Red; |
darienf | 20:6d2af70c92ab | 859 | bool valid_IR = (multiLEDmode || SPO2mode); |
darienf | 20:6d2af70c92ab | 860 | bool valid_Green = multiLEDmode; |
darienf | 20:6d2af70c92ab | 861 | bool valid_Red = multiLEDmode; |
darienf | 20:6d2af70c92ab | 862 | labelcboIRLED.Enabled = valid_IR; |
darienf | 20:6d2af70c92ab | 863 | cboIRLED.Enabled = valid_IR; |
darienf | 20:6d2af70c92ab | 864 | labelcboGreenLED.Enabled = valid_Green; |
darienf | 20:6d2af70c92ab | 865 | cboGreenLED.Enabled = valid_Green; |
darienf | 20:6d2af70c92ab | 866 | cboLEDslot1.Enabled = multiLEDmode; |
darienf | 20:6d2af70c92ab | 867 | cboLEDslot2.Enabled = multiLEDmode; |
darienf | 20:6d2af70c92ab | 868 | cboLEDslot3.Enabled = multiLEDmode; |
darienf | 20:6d2af70c92ab | 869 | cboLEDslot4.Enabled = multiLEDmode; |
darienf | 20:6d2af70c92ab | 870 | { |
darienf | 20:6d2af70c92ab | 871 | // Hide unused LED channel graphs |
darienf | 20:6d2af70c92ab | 872 | // | mode | ChartArea1Red | ChartArea2IR | ChartArea3Green | |
darienf | 20:6d2af70c92ab | 873 | // | LED | visible | visible | visible | MAX30101 only |
darienf | 20:6d2af70c92ab | 874 | // | SPO2 | visible | visible | hidden | |
darienf | 20:6d2af70c92ab | 875 | // | HR | visible | hidden | hidden | MAX30101: Red only. MAX30100: IR only. |
darienf | 20:6d2af70c92ab | 876 | valid_Red = true; |
darienf | 20:6d2af70c92ab | 877 | valid_IR = multiLEDmode || SPO2mode; |
darienf | 20:6d2af70c92ab | 878 | valid_Green = multiLEDmode; |
darienf | 20:6d2af70c92ab | 879 | |
darienf | 20:6d2af70c92ab | 880 | chartLED.ChartAreas["ChartArea1Red"].Visible = valid_Red; |
darienf | 20:6d2af70c92ab | 881 | chartLED.ChartAreas["ChartArea2IR"].Visible = valid_IR; |
darienf | 20:6d2af70c92ab | 882 | chartLED.ChartAreas["ChartArea3Green"].Visible = valid_Green; |
darienf | 20:6d2af70c92ab | 883 | } |
darienf | 20:6d2af70c92ab | 884 | } |
darienf | 20:6d2af70c92ab | 885 | } |
darienf | 20:6d2af70c92ab | 886 | |
darienf | 20:6d2af70c92ab | 887 | public void On_AppendChart(object sender, PartialArrayIntAvailableEventArgs e) |
darienf | 20:6d2af70c92ab | 888 | { |
darienf | 20:6d2af70c92ab | 889 | if (streaming) |
darienf | 20:6d2af70c92ab | 890 | { |
darienf | 20:6d2af70c92ab | 891 | if ((e.reportID & 0xF0) == PartialArrayIntAvailableEventArgs.PACKET_MAX30101) |
darienf | 20:6d2af70c92ab | 892 | { |
darienf | 20:6d2af70c92ab | 893 | if (e.array1.Length != 0) |
darienf | 20:6d2af70c92ab | 894 | { |
darienf | 20:6d2af70c92ab | 895 | UpdateLedChart("SeriesRed", e.array1); |
darienf | 20:6d2af70c92ab | 896 | UpdateLedChartScale("ChartArea1Red", "SeriesRed"); |
darienf | 20:6d2af70c92ab | 897 | } |
darienf | 20:6d2af70c92ab | 898 | if (e.array2.Length != 0) |
darienf | 20:6d2af70c92ab | 899 | { |
darienf | 20:6d2af70c92ab | 900 | UpdateLedChart("SeriesIR", e.array2); |
darienf | 20:6d2af70c92ab | 901 | UpdateLedChartScale("ChartArea2IR", "SeriesIR"); |
darienf | 20:6d2af70c92ab | 902 | } |
darienf | 20:6d2af70c92ab | 903 | if (e.array3.Length != 0) |
darienf | 20:6d2af70c92ab | 904 | { |
darienf | 20:6d2af70c92ab | 905 | UpdateLedChart("SeriesGreen", e.array3); |
darienf | 20:6d2af70c92ab | 906 | UpdateLedChartScale("ChartArea3Green", "SeriesGreen"); |
darienf | 20:6d2af70c92ab | 907 | } |
darienf | 20:6d2af70c92ab | 908 | } |
darienf | 20:6d2af70c92ab | 909 | if (e.reportID == PartialArrayIntAvailableEventArgs.PACKET_LIS2DH) |
darienf | 20:6d2af70c92ab | 910 | { |
darienf | 20:6d2af70c92ab | 911 | if (e.array1.Length != 0) |
darienf | 20:6d2af70c92ab | 912 | { |
darienf | 20:6d2af70c92ab | 913 | UpdateXYZChart("SeriesAccelX", e.array1); |
darienf | 20:6d2af70c92ab | 914 | UpdateXYZChartScale("ChartArea4AccelX", "SeriesAccelX"); |
darienf | 20:6d2af70c92ab | 915 | } |
darienf | 20:6d2af70c92ab | 916 | if (e.array2.Length != 0) |
darienf | 20:6d2af70c92ab | 917 | { |
darienf | 20:6d2af70c92ab | 918 | UpdateXYZChart("SeriesAccelY", e.array2); |
darienf | 20:6d2af70c92ab | 919 | UpdateXYZChartScale("ChartArea5AccelY", "SeriesAccelY"); |
darienf | 20:6d2af70c92ab | 920 | } |
darienf | 20:6d2af70c92ab | 921 | if (e.array3.Length != 0) |
darienf | 20:6d2af70c92ab | 922 | { |
darienf | 20:6d2af70c92ab | 923 | UpdateXYZChart("SeriesAccelZ", e.array3); |
darienf | 20:6d2af70c92ab | 924 | UpdateXYZChartScale("ChartArea6AccelZ", "SeriesAccelZ"); |
darienf | 20:6d2af70c92ab | 925 | } |
darienf | 20:6d2af70c92ab | 926 | |
darienf | 20:6d2af70c92ab | 927 | #if CES_DEMO |
darienf | 20:6d2af70c92ab | 928 | if (sampleRate == 100) |
darienf | 20:6d2af70c92ab | 929 | updateAlgorithm(); |
darienf | 20:6d2af70c92ab | 930 | #endif |
darienf | 20:6d2af70c92ab | 931 | } |
darienf | 20:6d2af70c92ab | 932 | } |
darienf | 20:6d2af70c92ab | 933 | } |
darienf | 20:6d2af70c92ab | 934 | |
darienf | 20:6d2af70c92ab | 935 | #if CES_DEMO |
darienf | 20:6d2af70c92ab | 936 | private void updateAlgorithm() |
darienf | 20:6d2af70c92ab | 937 | { |
darienf | 20:6d2af70c92ab | 938 | int rtn = 0; |
darienf | 20:6d2af70c92ab | 939 | |
darienf | 20:6d2af70c92ab | 940 | while (red.Count != 0 ) //&& ir.Couunt != 0 && led.Count != 0) |
darienf | 20:6d2af70c92ab | 941 | { |
darienf | 20:6d2af70c92ab | 942 | StringBuilder outputData = new StringBuilder(); |
darienf | 20:6d2af70c92ab | 943 | int redVal = (Int32)red.Dequeue(); // Always dequeue red, checked in while loop |
darienf | 20:6d2af70c92ab | 944 | int irVal = ir.Count > 0 ? (Int32)ir.Dequeue() : 1; |
darienf | 20:6d2af70c92ab | 945 | int ledVal = led.Count > 0 ? (Int32)led.Dequeue() : 1; |
darienf | 20:6d2af70c92ab | 946 | |
darienf | 20:6d2af70c92ab | 947 | switch (streamMode) |
darienf | 20:6d2af70c92ab | 948 | { |
darienf | 20:6d2af70c92ab | 949 | case eStreamMode.eSPO2: |
darienf | 20:6d2af70c92ab | 950 | rtn = AlgorithmMobileBU.runAlgorithm_win(irVal, redVal, 1, // ir, r, led |
darienf | 20:6d2af70c92ab | 951 | 25, sampleRate, ++algoCounter, |
darienf | 20:6d2af70c92ab | 952 | 0, 0, 0, ref config, ref output); |
darienf | 20:6d2af70c92ab | 953 | break; |
darienf | 20:6d2af70c92ab | 954 | case eStreamMode.eHR: // TODO: Not functioning |
darienf | 20:6d2af70c92ab | 955 | rtn = AlgorithmMobileBU.runAlgorithm_win(1, redVal, 1, // ir, r, led |
darienf | 20:6d2af70c92ab | 956 | 25, sampleRate, ++algoCounter, |
darienf | 20:6d2af70c92ab | 957 | 0, 0, 0, ref config, ref output); |
darienf | 20:6d2af70c92ab | 958 | break; |
darienf | 20:6d2af70c92ab | 959 | case eStreamMode.eMulti: |
darienf | 20:6d2af70c92ab | 960 | rtn = AlgorithmMobileBU.runAlgorithm_win(irVal, redVal, ledVal, // ir, r, led |
darienf | 20:6d2af70c92ab | 961 | 25, sampleRate, ++algoCounter, |
darienf | 20:6d2af70c92ab | 962 | 0, 0, 0, ref config, ref output); |
darienf | 20:6d2af70c92ab | 963 | break; |
darienf | 20:6d2af70c92ab | 964 | } |
darienf | 20:6d2af70c92ab | 965 | |
darienf | 20:6d2af70c92ab | 966 | //outputData.Append(DateTime.Now.ToString("HH:mm:ss.ffff")); |
darienf | 20:6d2af70c92ab | 967 | //outputData.Append(","); |
darienf | 20:6d2af70c92ab | 968 | //outputData.Append(irVal); |
darienf | 20:6d2af70c92ab | 969 | //outputData.Append(","); |
darienf | 20:6d2af70c92ab | 970 | //outputData.Append(redVal); |
darienf | 20:6d2af70c92ab | 971 | //outputData.Append(","); |
darienf | 20:6d2af70c92ab | 972 | //outputData.Append(0); // Can be green |
darienf | 20:6d2af70c92ab | 973 | //outputData.Append(","); |
darienf | 20:6d2af70c92ab | 974 | //outputData.Append(0); // Ax |
darienf | 20:6d2af70c92ab | 975 | //outputData.Append(","); |
darienf | 20:6d2af70c92ab | 976 | //outputData.Append(0); // Ay |
darienf | 20:6d2af70c92ab | 977 | //outputData.Append(","); |
darienf | 20:6d2af70c92ab | 978 | //outputData.Append(0); // Az |
darienf | 20:6d2af70c92ab | 979 | //outputData.Append(","); |
darienf | 20:6d2af70c92ab | 980 | |
darienf | 20:6d2af70c92ab | 981 | //file.WriteLine(outputData.ToString()); // Raw data output |
darienf | 20:6d2af70c92ab | 982 | } |
darienf | 20:6d2af70c92ab | 983 | |
darienf | 20:6d2af70c92ab | 984 | lblHeartRate.Text = Math.Round(output.hr).ToString(); //redIn.ToString(); |
darienf | 20:6d2af70c92ab | 985 | lblRespRate.Text = output.resp_rate.ToString("N"); |
darienf | 20:6d2af70c92ab | 986 | lblSpO2.Text = output.R == 0 ? "0" : (-45.060 * output.R * output.R + 30.354 * output.R + 94.845).ToString("N");//output.spo2.ToString("N"); |
darienf | 20:6d2af70c92ab | 987 | lblHeartRateVariation.Text = output.hrv.ToString("N"); |
darienf | 20:6d2af70c92ab | 988 | lblPulseInterval.Text = output.pulse_interval.ToString("N"); |
darienf | 20:6d2af70c92ab | 989 | } |
darienf | 20:6d2af70c92ab | 990 | |
darienf | 20:6d2af70c92ab | 991 | #endif |
darienf | 20:6d2af70c92ab | 992 | |
darienf | 20:6d2af70c92ab | 993 | private void OpticalView_Load(object sender, EventArgs e) |
darienf | 20:6d2af70c92ab | 994 | { |
darienf | 20:6d2af70c92ab | 995 | //OpticalSensorInitControls(); |
darienf | 20:6d2af70c92ab | 996 | //OpticalSensorDefaults(); |
darienf | 20:6d2af70c92ab | 997 | } |
darienf | 20:6d2af70c92ab | 998 | |
darienf | 20:6d2af70c92ab | 999 | private void streamingStartStop() |
darienf | 20:6d2af70c92ab | 1000 | { |
darienf | 20:6d2af70c92ab | 1001 | if (cboMode.Text == "HR") streamMode = eStreamMode.eHR; |
darienf | 20:6d2af70c92ab | 1002 | if (cboMode.Text == "SPO2") streamMode = eStreamMode.eSPO2; |
darienf | 20:6d2af70c92ab | 1003 | if (cboMode.Text == "LED") streamMode = eStreamMode.eMulti; |
darienf | 20:6d2af70c92ab | 1004 | |
darienf | 20:6d2af70c92ab | 1005 | if (Connected && btnMonitoring.Text == StartString) |
darienf | 20:6d2af70c92ab | 1006 | { |
darienf | 20:6d2af70c92ab | 1007 | streaming = true; |
darienf | 20:6d2af70c92ab | 1008 | sample_rate = (byte)cboSampleRate.SelectedIndex; |
darienf | 20:6d2af70c92ab | 1009 | sample_avg = (byte)cboSampleAvg.SelectedIndex; |
darienf | 20:6d2af70c92ab | 1010 | pulse_width = (byte)cboPulseWidth.SelectedIndex; |
darienf | 20:6d2af70c92ab | 1011 | red_led_current = (byte)cboRedLED.SelectedIndex; |
darienf | 20:6d2af70c92ab | 1012 | ir_led_current = (byte)cboIRLED.SelectedIndex; |
darienf | 20:6d2af70c92ab | 1013 | green_led_current = (byte)cboGreenLED.SelectedIndex; |
darienf | 20:6d2af70c92ab | 1014 | slot_1 = (byte)cboLEDslot1.SelectedIndex; |
darienf | 20:6d2af70c92ab | 1015 | slot_2 = (byte)cboLEDslot2.SelectedIndex; |
darienf | 20:6d2af70c92ab | 1016 | slot_3 = (byte)cboLEDslot3.SelectedIndex; |
darienf | 20:6d2af70c92ab | 1017 | slot_4 = (byte)cboLEDslot4.SelectedIndex; |
darienf | 20:6d2af70c92ab | 1018 | |
darienf | 20:6d2af70c92ab | 1019 | sampleRate = Int32.Parse((string)cboSampleRate.SelectedItem); |
darienf | 20:6d2af70c92ab | 1020 | sampleAverage = Int32.Parse((string)cboSampleAvg.SelectedItem); |
darienf | 20:6d2af70c92ab | 1021 | points = (sampleRate / sampleAverage ) * ChartTime; |
darienf | 20:6d2af70c92ab | 1022 | |
darienf | 20:6d2af70c92ab | 1023 | foreach (Control c in streamingControls) |
darienf | 20:6d2af70c92ab | 1024 | c.Enabled = false; |
darienf | 20:6d2af70c92ab | 1025 | |
darienf | 20:6d2af70c92ab | 1026 | #if CES_DEMO |
darienf | 20:6d2af70c92ab | 1027 | // For Algorithm |
darienf | 20:6d2af70c92ab | 1028 | sampleRate = (1 << sample_rate) * 50; // (1 << sample_rate) = 2^sample_rate |
darienf | 20:6d2af70c92ab | 1029 | sampleAverage = (1 << sample_avg); // 2^sample_avg |
darienf | 20:6d2af70c92ab | 1030 | points = (sampleRate / sampleAverage) * ChartTime; // 4 seconds, 2^sample_av |
darienf | 20:6d2af70c92ab | 1031 | |
darienf | 20:6d2af70c92ab | 1032 | sampleRateAccel = 10; // TODO, update with real value from Jerry |
darienf | 20:6d2af70c92ab | 1033 | pointsAccel = (sampleRateAccel / sampleAverage) * ChartTime; |
darienf | 20:6d2af70c92ab | 1034 | |
darienf | 20:6d2af70c92ab | 1035 | // Reset algorithm counter |
darienf | 20:6d2af70c92ab | 1036 | algoCounter = 0; |
darienf | 20:6d2af70c92ab | 1037 | |
darienf | 20:6d2af70c92ab | 1038 | if (sampleRate == 100) |
darienf | 20:6d2af70c92ab | 1039 | { |
darienf | 20:6d2af70c92ab | 1040 | lblHeartRateText.Enabled = true; |
darienf | 20:6d2af70c92ab | 1041 | lblHeartRate.Enabled = true; |
darienf | 20:6d2af70c92ab | 1042 | lblSpO2.Enabled = true; |
darienf | 20:6d2af70c92ab | 1043 | lblSpO2Text.Enabled = true; |
darienf | 20:6d2af70c92ab | 1044 | } |
darienf | 20:6d2af70c92ab | 1045 | else |
darienf | 20:6d2af70c92ab | 1046 | { |
darienf | 20:6d2af70c92ab | 1047 | lblHeartRateText.Enabled = false; |
darienf | 20:6d2af70c92ab | 1048 | lblHeartRate.Enabled = false; |
darienf | 20:6d2af70c92ab | 1049 | lblSpO2.Enabled = false; |
darienf | 20:6d2af70c92ab | 1050 | lblSpO2Text.Enabled = false; |
darienf | 20:6d2af70c92ab | 1051 | } |
darienf | 20:6d2af70c92ab | 1052 | #endif |
darienf | 20:6d2af70c92ab | 1053 | |
darienf | 20:6d2af70c92ab | 1054 | // Setup grid |
darienf | 20:6d2af70c92ab | 1055 | setupGraphs(); |
darienf | 20:6d2af70c92ab | 1056 | |
darienf | 20:6d2af70c92ab | 1057 | switch (streamMode) |
darienf | 20:6d2af70c92ab | 1058 | { |
darienf | 20:6d2af70c92ab | 1059 | case eStreamMode.eHR: |
darienf | 20:6d2af70c92ab | 1060 | rpcClient.MAX30101.HRmode_init(fifo_waterlevel_mark, sample_avg, sample_rate, pulse_width, |
darienf | 20:6d2af70c92ab | 1061 | red_led_current, (byte)(sample_rate + 4)); |
darienf | 20:6d2af70c92ab | 1062 | break; |
darienf | 20:6d2af70c92ab | 1063 | case eStreamMode.eMulti: |
darienf | 20:6d2af70c92ab | 1064 | rpcClient.MAX30101.Multimode_init(fifo_waterlevel_mark, sample_avg, sample_rate, pulse_width, |
darienf | 20:6d2af70c92ab | 1065 | red_led_current, ir_led_current, green_led_current, |
darienf | 20:6d2af70c92ab | 1066 | slot_1, slot_2, slot_3, slot_4, (byte)(sample_rate + 4)); |
darienf | 20:6d2af70c92ab | 1067 | break; |
darienf | 20:6d2af70c92ab | 1068 | case eStreamMode.eSPO2: |
darienf | 20:6d2af70c92ab | 1069 | rpcClient.MAX30101.SpO2mode_init(fifo_waterlevel_mark, sample_avg, sample_rate, pulse_width, |
darienf | 20:6d2af70c92ab | 1070 | red_led_current, ir_led_current, (byte)(sample_rate + 4)); |
darienf | 20:6d2af70c92ab | 1071 | break; |
darienf | 20:6d2af70c92ab | 1072 | } |
darienf | 20:6d2af70c92ab | 1073 | |
darienf | 20:6d2af70c92ab | 1074 | btnMonitoring.Text = StopString; |
darienf | 20:6d2af70c92ab | 1075 | |
darienf | 20:6d2af70c92ab | 1076 | if (StreamingStartStop != null) |
darienf | 20:6d2af70c92ab | 1077 | StreamingStartStop(this, new StreamingStartStopEventArgs() { state = true }); |
darienf | 20:6d2af70c92ab | 1078 | |
darienf | 20:6d2af70c92ab | 1079 | } |
darienf | 20:6d2af70c92ab | 1080 | else if (btnMonitoring.Text == StopString) |
darienf | 20:6d2af70c92ab | 1081 | { |
darienf | 20:6d2af70c92ab | 1082 | streaming = false; |
darienf | 20:6d2af70c92ab | 1083 | switch (streamMode) |
darienf | 20:6d2af70c92ab | 1084 | { |
darienf | 20:6d2af70c92ab | 1085 | case eStreamMode.eHR: |
darienf | 20:6d2af70c92ab | 1086 | rpcClient.MAX30101.HRmode_stop(connected); |
darienf | 20:6d2af70c92ab | 1087 | break; |
darienf | 20:6d2af70c92ab | 1088 | case eStreamMode.eMulti: |
darienf | 20:6d2af70c92ab | 1089 | rpcClient.MAX30101.Multimode_stop(connected); |
darienf | 20:6d2af70c92ab | 1090 | break; |
darienf | 20:6d2af70c92ab | 1091 | case eStreamMode.eSPO2: |
darienf | 20:6d2af70c92ab | 1092 | rpcClient.MAX30101.SpO2mode_stop(connected); |
darienf | 20:6d2af70c92ab | 1093 | break; |
darienf | 20:6d2af70c92ab | 1094 | } |
darienf | 20:6d2af70c92ab | 1095 | //rpcClient.MAX30101.StopStreaming(); |
darienf | 20:6d2af70c92ab | 1096 | btnMonitoring.Text = StartString; |
darienf | 20:6d2af70c92ab | 1097 | |
darienf | 20:6d2af70c92ab | 1098 | foreach (Control c in streamingControls) |
darienf | 20:6d2af70c92ab | 1099 | c.Enabled = true; |
darienf | 20:6d2af70c92ab | 1100 | |
darienf | 20:6d2af70c92ab | 1101 | if (StreamingStartStop != null) |
darienf | 20:6d2af70c92ab | 1102 | StreamingStartStop(this, new StreamingStartStopEventArgs() { state = false }); |
darienf | 20:6d2af70c92ab | 1103 | } |
darienf | 20:6d2af70c92ab | 1104 | } |
darienf | 20:6d2af70c92ab | 1105 | |
darienf | 20:6d2af70c92ab | 1106 | private void btnMonitoring_Click(object sender, EventArgs e) |
darienf | 20:6d2af70c92ab | 1107 | { |
darienf | 20:6d2af70c92ab | 1108 | //if (Connected) |
darienf | 20:6d2af70c92ab | 1109 | streamingStartStop(); |
darienf | 20:6d2af70c92ab | 1110 | } |
darienf | 20:6d2af70c92ab | 1111 | |
darienf | 20:6d2af70c92ab | 1112 | private void button1_Click(object sender, EventArgs e) |
darienf | 20:6d2af70c92ab | 1113 | { |
darienf | 20:6d2af70c92ab | 1114 | timer.Start(); |
darienf | 20:6d2af70c92ab | 1115 | } |
darienf | 20:6d2af70c92ab | 1116 | |
darienf | 20:6d2af70c92ab | 1117 | private void button1_Click_1(object sender, EventArgs e) |
darienf | 20:6d2af70c92ab | 1118 | { |
darienf | 20:6d2af70c92ab | 1119 | /* Debug*/ |
darienf | 20:6d2af70c92ab | 1120 | //int count = chartLED.Series["SeriesRed"].Points.Count; |
darienf | 20:6d2af70c92ab | 1121 | //int count2 = chartAccel.Series["SeriesAccelX"].Points.Count; |
darienf | 20:6d2af70c92ab | 1122 | UpdateXYZChartScale("ChartArea6AccelZ", "SeriesAccelZ"); |
darienf | 20:6d2af70c92ab | 1123 | } |
darienf | 20:6d2af70c92ab | 1124 | |
darienf | 20:6d2af70c92ab | 1125 | private void btnDefaults_Click(object sender, EventArgs e) |
darienf | 20:6d2af70c92ab | 1126 | { |
darienf | 20:6d2af70c92ab | 1127 | OpticalSensorDefaults(); |
darienf | 20:6d2af70c92ab | 1128 | } |
darienf | 20:6d2af70c92ab | 1129 | |
darienf | 20:6d2af70c92ab | 1130 | private void cboSRPWLed_SelectedIndexChanged(object sender, EventArgs e) |
darienf | 20:6d2af70c92ab | 1131 | { |
darienf | 20:6d2af70c92ab | 1132 | calculateAvgCurrent(); |
darienf | 20:6d2af70c92ab | 1133 | } |
darienf | 20:6d2af70c92ab | 1134 | |
darienf | 20:6d2af70c92ab | 1135 | private void calculateAvgCurrent() |
darienf | 20:6d2af70c92ab | 1136 | { |
darienf | 20:6d2af70c92ab | 1137 | double ratio = double.Parse(cboPulseWidth.Text) * 1e-6 * double.Parse(cboSampleRate.Text); |
darienf | 20:6d2af70c92ab | 1138 | string _noDataString = "---"; |
darienf | 20:6d2af70c92ab | 1139 | if (ratio <= 1) |
darienf | 20:6d2af70c92ab | 1140 | { |
darienf | 20:6d2af70c92ab | 1141 | lblAvgIRLEDcurrent.Text = String.Format("{0:0.00}", double.Parse(cboIRLED.Text) * ratio); |
darienf | 20:6d2af70c92ab | 1142 | lblAvgRedLEDcurrent.Text = String.Format("{0:0.00}", double.Parse(cboRedLED.Text) * ratio); |
darienf | 20:6d2af70c92ab | 1143 | // https://jira.maxim-ic.com/browse/OS24EVK-17 Green LED: Multi-LED Mode timeslice; FIFO Read Red, IR, Green |
darienf | 20:6d2af70c92ab | 1144 | lblAvgGreenLEDcurrent.Text = String.Format("{0:0.00}", double.Parse(cboGreenLED.Text) * ratio); |
darienf | 20:6d2af70c92ab | 1145 | // https://jira.maxim-ic.com/browse/OS24EVK-32 update lblAvgPilotPALEDcurrent from cboPilotPA similar to lblAvgGreenLEDcurrent |
darienf | 20:6d2af70c92ab | 1146 | //lblAvgPilotPALEDcurrent.Text = String.Format("{0:0.00}", double.Parse(cboPilotPA.Text) * ratio); |
darienf | 20:6d2af70c92ab | 1147 | } |
darienf | 20:6d2af70c92ab | 1148 | else |
darienf | 20:6d2af70c92ab | 1149 | { |
darienf | 20:6d2af70c92ab | 1150 | lblAvgIRLEDcurrent.Text = _noDataString; |
darienf | 20:6d2af70c92ab | 1151 | lblAvgRedLEDcurrent.Text = _noDataString; |
darienf | 20:6d2af70c92ab | 1152 | // https://jira.maxim-ic.com/browse/OS24EVK-17 Green LED: Multi-LED Mode timeslice; FIFO Read Red, IR, Green |
darienf | 20:6d2af70c92ab | 1153 | lblAvgGreenLEDcurrent.Text = _noDataString; |
darienf | 20:6d2af70c92ab | 1154 | // https://jira.maxim-ic.com/browse/OS24EVK-32 update lblAvgPilotPALEDcurrent from cboPilotPA similar to lblAvgGreenLEDcurrent |
darienf | 20:6d2af70c92ab | 1155 | lblAvgPilotPALEDcurrent.Text = _noDataString; |
darienf | 20:6d2af70c92ab | 1156 | } |
darienf | 20:6d2af70c92ab | 1157 | } |
darienf | 20:6d2af70c92ab | 1158 | |
darienf | 20:6d2af70c92ab | 1159 | void cboSampleRate_SelectedIndexChanged(object sender, EventArgs e) |
darienf | 20:6d2af70c92ab | 1160 | { |
darienf | 20:6d2af70c92ab | 1161 | if ((string)cboSampleRate.SelectedItem == "100" && (string)cboSampleAvg.SelectedItem == "1") |
darienf | 20:6d2af70c92ab | 1162 | grpAlgorithm.Enabled = true; |
darienf | 20:6d2af70c92ab | 1163 | else |
darienf | 20:6d2af70c92ab | 1164 | grpAlgorithm.Enabled = false; |
darienf | 20:6d2af70c92ab | 1165 | |
darienf | 20:6d2af70c92ab | 1166 | sampleRate = Int32.Parse((string)cboSampleRate.SelectedItem); |
darienf | 20:6d2af70c92ab | 1167 | sampleAverage = Int32.Parse((string)cboSampleAvg.SelectedItem); |
darienf | 20:6d2af70c92ab | 1168 | } |
darienf | 20:6d2af70c92ab | 1169 | |
darienf | 20:6d2af70c92ab | 1170 | public string SettingsString() |
darienf | 20:6d2af70c92ab | 1171 | { |
darienf | 20:6d2af70c92ab | 1172 | StringBuilder strBuilder = new StringBuilder(); |
darienf | 20:6d2af70c92ab | 1173 | |
darienf | 20:6d2af70c92ab | 1174 | strBuilder.Append("% "); |
darienf | 20:6d2af70c92ab | 1175 | strBuilder.Append("Mode = "); |
darienf | 20:6d2af70c92ab | 1176 | strBuilder.Append(cboMode.SelectedItem); |
darienf | 20:6d2af70c92ab | 1177 | strBuilder.Append(Environment.NewLine); |
darienf | 20:6d2af70c92ab | 1178 | |
darienf | 20:6d2af70c92ab | 1179 | strBuilder.Append("% "); |
darienf | 20:6d2af70c92ab | 1180 | strBuilder.Append("Sample Rate (Hz) = "); |
darienf | 20:6d2af70c92ab | 1181 | strBuilder.Append(cboSampleRate.SelectedItem); |
darienf | 20:6d2af70c92ab | 1182 | strBuilder.Append(" Sample Average = "); |
darienf | 20:6d2af70c92ab | 1183 | strBuilder.Append(cboSampleAvg.SelectedItem); |
darienf | 20:6d2af70c92ab | 1184 | strBuilder.Append(" Pulse Width (us) = "); |
darienf | 20:6d2af70c92ab | 1185 | strBuilder.Append(cboPulseWidth.SelectedItem); |
darienf | 20:6d2af70c92ab | 1186 | strBuilder.Append(" ADC Full Scale Range (nA) = "); |
darienf | 20:6d2af70c92ab | 1187 | strBuilder.Append(cboADCFSrangenA.SelectedItem); |
darienf | 20:6d2af70c92ab | 1188 | strBuilder.Append(Environment.NewLine); |
darienf | 20:6d2af70c92ab | 1189 | |
darienf | 20:6d2af70c92ab | 1190 | strBuilder.Append("% "); |
darienf | 20:6d2af70c92ab | 1191 | strBuilder.Append(" LED Red (mA) = "); |
darienf | 20:6d2af70c92ab | 1192 | strBuilder.Append(cboRedLED.SelectedItem); |
darienf | 20:6d2af70c92ab | 1193 | strBuilder.Append(" LED IR (mA) = "); |
darienf | 20:6d2af70c92ab | 1194 | strBuilder.Append(cboIRLED.SelectedItem); |
darienf | 20:6d2af70c92ab | 1195 | strBuilder.Append(" LED Green (mA) = "); |
darienf | 20:6d2af70c92ab | 1196 | strBuilder.Append(cboGreenLED.SelectedItem); |
darienf | 20:6d2af70c92ab | 1197 | strBuilder.Append(Environment.NewLine); |
darienf | 20:6d2af70c92ab | 1198 | |
darienf | 20:6d2af70c92ab | 1199 | strBuilder.Append("% "); |
darienf | 20:6d2af70c92ab | 1200 | strBuilder.Append("LED Slot 1 = "); |
darienf | 20:6d2af70c92ab | 1201 | strBuilder.Append(cboLEDslot1.SelectedIndex); |
darienf | 20:6d2af70c92ab | 1202 | strBuilder.Append(" LED Slot 2 = "); |
darienf | 20:6d2af70c92ab | 1203 | strBuilder.Append(cboLEDslot2.SelectedIndex); |
darienf | 20:6d2af70c92ab | 1204 | strBuilder.Append(" LED Slot 3 = "); |
darienf | 20:6d2af70c92ab | 1205 | strBuilder.Append(cboLEDslot3.SelectedIndex); |
darienf | 20:6d2af70c92ab | 1206 | strBuilder.Append(" LED Slot 4 = "); |
darienf | 20:6d2af70c92ab | 1207 | strBuilder.Append(cboLEDslot4.SelectedIndex); |
darienf | 20:6d2af70c92ab | 1208 | |
darienf | 20:6d2af70c92ab | 1209 | return strBuilder.ToString(); |
darienf | 20:6d2af70c92ab | 1210 | } |
darienf | 20:6d2af70c92ab | 1211 | |
darienf | 20:6d2af70c92ab | 1212 | public string AccelSettingString() |
darienf | 20:6d2af70c92ab | 1213 | { |
darienf | 20:6d2af70c92ab | 1214 | return "% Sample Rate (Hz) = " + AccelSampleRate; |
darienf | 20:6d2af70c92ab | 1215 | } |
darienf | 20:6d2af70c92ab | 1216 | |
darienf | 20:6d2af70c92ab | 1217 | public InitArgs.HRModeInitStart GetHRModeArgs() |
darienf | 20:6d2af70c92ab | 1218 | { |
darienf | 20:6d2af70c92ab | 1219 | InitArgs.HRModeInitStart args = new InitArgs.HRModeInitStart(); |
darienf | 20:6d2af70c92ab | 1220 | |
darienf | 20:6d2af70c92ab | 1221 | args.FifoWaterlevelMark = fifo_waterlevel_mark; |
darienf | 20:6d2af70c92ab | 1222 | args.SampleRate = (byte)cboSampleRate.SelectedIndex; |
darienf | 20:6d2af70c92ab | 1223 | args.SampleAverage = (byte)cboSampleAvg.SelectedIndex; |
darienf | 20:6d2af70c92ab | 1224 | args.PulseWidth = (byte)cboPulseWidth.SelectedIndex; |
darienf | 20:6d2af70c92ab | 1225 | args.RedLedCurrent = (byte)cboRedLED.SelectedIndex; |
darienf | 20:6d2af70c92ab | 1226 | |
darienf | 20:6d2af70c92ab | 1227 | return args; |
darienf | 20:6d2af70c92ab | 1228 | } |
darienf | 20:6d2af70c92ab | 1229 | |
darienf | 20:6d2af70c92ab | 1230 | public InitArgs.SpO2HRModeInitStart GetSpO2HRModeArgs() |
darienf | 20:6d2af70c92ab | 1231 | { |
darienf | 20:6d2af70c92ab | 1232 | InitArgs.SpO2HRModeInitStart args = new InitArgs.SpO2HRModeInitStart(); |
darienf | 20:6d2af70c92ab | 1233 | |
darienf | 20:6d2af70c92ab | 1234 | args.FifoWaterlevelMark = fifo_waterlevel_mark; |
darienf | 20:6d2af70c92ab | 1235 | args.SampleRate = (byte)cboSampleRate.SelectedIndex; |
darienf | 20:6d2af70c92ab | 1236 | args.SampleAverage = (byte)cboSampleAvg.SelectedIndex; |
darienf | 20:6d2af70c92ab | 1237 | args.PulseWidth = (byte)cboPulseWidth.SelectedIndex; |
darienf | 20:6d2af70c92ab | 1238 | args.RedLedCurrent = (byte)cboRedLED.SelectedIndex; |
darienf | 20:6d2af70c92ab | 1239 | args.IRLedCurrent = (byte)cboIRLED.SelectedIndex; |
darienf | 20:6d2af70c92ab | 1240 | |
darienf | 20:6d2af70c92ab | 1241 | return args; |
darienf | 20:6d2af70c92ab | 1242 | } |
darienf | 20:6d2af70c92ab | 1243 | |
darienf | 20:6d2af70c92ab | 1244 | public InitArgs.MultiModeInitStart GetMultiModeArgs() |
darienf | 20:6d2af70c92ab | 1245 | { |
darienf | 20:6d2af70c92ab | 1246 | InitArgs.MultiModeInitStart args = new InitArgs.MultiModeInitStart(); |
darienf | 20:6d2af70c92ab | 1247 | |
darienf | 20:6d2af70c92ab | 1248 | args.FifoWaterlevelMark = fifo_waterlevel_mark; |
darienf | 20:6d2af70c92ab | 1249 | args.SampleRate = (byte)cboSampleRate.SelectedIndex; |
darienf | 20:6d2af70c92ab | 1250 | args.SampleAverage = (byte)cboSampleAvg.SelectedIndex; |
darienf | 20:6d2af70c92ab | 1251 | args.PulseWidth = (byte)cboPulseWidth.SelectedIndex; |
darienf | 20:6d2af70c92ab | 1252 | args.RedLedCurrent = (byte)cboRedLED.SelectedIndex; |
darienf | 20:6d2af70c92ab | 1253 | args.IRLedCurrent = (byte)cboIRLED.SelectedIndex; |
darienf | 20:6d2af70c92ab | 1254 | args.GreenLedCurrent = (byte)cboGreenLED.SelectedIndex; |
darienf | 20:6d2af70c92ab | 1255 | args.Slot1 = (byte)cboLEDslot1.SelectedIndex; |
darienf | 20:6d2af70c92ab | 1256 | args.Slot2 = (byte)cboLEDslot2.SelectedIndex; |
darienf | 20:6d2af70c92ab | 1257 | args.Slot3 = (byte)cboLEDslot3.SelectedIndex; |
darienf | 20:6d2af70c92ab | 1258 | args.Slot4 = (byte)cboLEDslot4.SelectedIndex; |
darienf | 20:6d2af70c92ab | 1259 | |
darienf | 20:6d2af70c92ab | 1260 | return args; |
darienf | 20:6d2af70c92ab | 1261 | } |
darienf | 20:6d2af70c92ab | 1262 | |
darienf | 20:6d2af70c92ab | 1263 | public void SetHRModeArgs(InitArgs.HRModeInitStart args) |
darienf | 20:6d2af70c92ab | 1264 | { |
darienf | 20:6d2af70c92ab | 1265 | cboSampleRate.SelectedIndex = args.SampleRate; |
darienf | 20:6d2af70c92ab | 1266 | cboSampleAvg.SelectedIndex = args.SampleAverage; |
darienf | 20:6d2af70c92ab | 1267 | cboPulseWidth.SelectedIndex = args.PulseWidth; |
darienf | 20:6d2af70c92ab | 1268 | cboRedLED.SelectedIndex = args.RedLedCurrent; |
darienf | 20:6d2af70c92ab | 1269 | } |
darienf | 20:6d2af70c92ab | 1270 | |
darienf | 20:6d2af70c92ab | 1271 | public void SetSpO2HRModeArgs(InitArgs.SpO2HRModeInitStart args) |
darienf | 20:6d2af70c92ab | 1272 | { |
darienf | 20:6d2af70c92ab | 1273 | cboSampleRate.SelectedIndex = args.SampleRate; |
darienf | 20:6d2af70c92ab | 1274 | cboSampleAvg.SelectedIndex = args.SampleAverage; |
darienf | 20:6d2af70c92ab | 1275 | cboPulseWidth.SelectedIndex = args.PulseWidth; |
darienf | 20:6d2af70c92ab | 1276 | cboRedLED.SelectedIndex = args.RedLedCurrent; |
darienf | 20:6d2af70c92ab | 1277 | cboIRLED.SelectedIndex = args.IRLedCurrent; |
darienf | 20:6d2af70c92ab | 1278 | } |
darienf | 20:6d2af70c92ab | 1279 | |
darienf | 20:6d2af70c92ab | 1280 | public void SetMultiModeArgs(InitArgs.MultiModeInitStart args) |
darienf | 20:6d2af70c92ab | 1281 | { |
darienf | 20:6d2af70c92ab | 1282 | cboSampleRate.SelectedIndex = args.SampleRate; |
darienf | 20:6d2af70c92ab | 1283 | cboSampleAvg.SelectedIndex = args.SampleAverage; |
darienf | 20:6d2af70c92ab | 1284 | cboPulseWidth.SelectedIndex = args.PulseWidth; |
darienf | 20:6d2af70c92ab | 1285 | cboRedLED.SelectedIndex = args.RedLedCurrent; |
darienf | 20:6d2af70c92ab | 1286 | cboIRLED.SelectedIndex = args.IRLedCurrent; |
darienf | 20:6d2af70c92ab | 1287 | cboGreenLED.SelectedIndex = args.GreenLedCurrent; |
darienf | 20:6d2af70c92ab | 1288 | cboLEDslot1.SelectedIndex = args.Slot1; |
darienf | 20:6d2af70c92ab | 1289 | cboLEDslot2.SelectedIndex = args.Slot2; |
darienf | 20:6d2af70c92ab | 1290 | cboLEDslot3.SelectedIndex = args.Slot3; |
darienf | 20:6d2af70c92ab | 1291 | cboLEDslot4.SelectedIndex = args.Slot4; |
darienf | 20:6d2af70c92ab | 1292 | } |
darienf | 20:6d2af70c92ab | 1293 | |
darienf | 20:6d2af70c92ab | 1294 | class MedianFilter |
darienf | 20:6d2af70c92ab | 1295 | { |
darienf | 20:6d2af70c92ab | 1296 | Queue<int> items; |
darienf | 20:6d2af70c92ab | 1297 | int depth; |
darienf | 20:6d2af70c92ab | 1298 | |
darienf | 20:6d2af70c92ab | 1299 | public MedianFilter(int depth) |
darienf | 20:6d2af70c92ab | 1300 | { |
darienf | 20:6d2af70c92ab | 1301 | items = new Queue<int>(depth + 1); |
darienf | 20:6d2af70c92ab | 1302 | this.depth = depth; |
darienf | 20:6d2af70c92ab | 1303 | } |
darienf | 20:6d2af70c92ab | 1304 | |
darienf | 20:6d2af70c92ab | 1305 | public int Filter(int current) |
darienf | 20:6d2af70c92ab | 1306 | { |
darienf | 20:6d2af70c92ab | 1307 | int last; |
darienf | 20:6d2af70c92ab | 1308 | |
darienf | 20:6d2af70c92ab | 1309 | items.Enqueue(current); |
darienf | 20:6d2af70c92ab | 1310 | if (items.Count > depth) |
darienf | 20:6d2af70c92ab | 1311 | { |
darienf | 20:6d2af70c92ab | 1312 | items.Dequeue(); |
darienf | 20:6d2af70c92ab | 1313 | } |
darienf | 20:6d2af70c92ab | 1314 | |
darienf | 20:6d2af70c92ab | 1315 | last = items.Peek(); |
darienf | 20:6d2af70c92ab | 1316 | |
darienf | 20:6d2af70c92ab | 1317 | if (items.Count < depth) |
darienf | 20:6d2af70c92ab | 1318 | { |
darienf | 20:6d2af70c92ab | 1319 | return current; |
darienf | 20:6d2af70c92ab | 1320 | } |
darienf | 20:6d2af70c92ab | 1321 | else |
darienf | 20:6d2af70c92ab | 1322 | { |
darienf | 20:6d2af70c92ab | 1323 | int count; |
darienf | 20:6d2af70c92ab | 1324 | int[] arrayItems = items.ToArray(); |
darienf | 20:6d2af70c92ab | 1325 | int maxCount = 0; |
darienf | 20:6d2af70c92ab | 1326 | int maxKey = 0; |
darienf | 20:6d2af70c92ab | 1327 | |
darienf | 20:6d2af70c92ab | 1328 | Dictionary<int, int> valueOccurance = new Dictionary<int, int>(); |
darienf | 20:6d2af70c92ab | 1329 | |
darienf | 20:6d2af70c92ab | 1330 | for (int i = 0; i < arrayItems.Length; i++) |
darienf | 20:6d2af70c92ab | 1331 | { |
darienf | 20:6d2af70c92ab | 1332 | bool exists = valueOccurance.TryGetValue(arrayItems[i], out count); |
darienf | 20:6d2af70c92ab | 1333 | if (exists) |
darienf | 20:6d2af70c92ab | 1334 | { |
darienf | 20:6d2af70c92ab | 1335 | count++; |
darienf | 20:6d2af70c92ab | 1336 | valueOccurance.Remove(arrayItems[i]); |
darienf | 20:6d2af70c92ab | 1337 | valueOccurance.Add(arrayItems[i], count); |
darienf | 20:6d2af70c92ab | 1338 | } |
darienf | 20:6d2af70c92ab | 1339 | else |
darienf | 20:6d2af70c92ab | 1340 | { |
darienf | 20:6d2af70c92ab | 1341 | valueOccurance.Add(arrayItems[i], 1); |
darienf | 20:6d2af70c92ab | 1342 | } |
darienf | 20:6d2af70c92ab | 1343 | } |
darienf | 20:6d2af70c92ab | 1344 | |
darienf | 20:6d2af70c92ab | 1345 | foreach (KeyValuePair<int, int> item in valueOccurance) |
darienf | 20:6d2af70c92ab | 1346 | { |
darienf | 20:6d2af70c92ab | 1347 | if (item.Key > maxCount) |
darienf | 20:6d2af70c92ab | 1348 | { |
darienf | 20:6d2af70c92ab | 1349 | maxKey = item.Key; |
darienf | 20:6d2af70c92ab | 1350 | } |
darienf | 20:6d2af70c92ab | 1351 | } |
darienf | 20:6d2af70c92ab | 1352 | |
darienf | 20:6d2af70c92ab | 1353 | return maxKey; |
darienf | 20:6d2af70c92ab | 1354 | } |
darienf | 20:6d2af70c92ab | 1355 | |
darienf | 20:6d2af70c92ab | 1356 | } |
darienf | 20:6d2af70c92ab | 1357 | } |
darienf | 20:6d2af70c92ab | 1358 | |
darienf | 20:6d2af70c92ab | 1359 | /* |
darienf | 20:6d2af70c92ab | 1360 | public class StreamingStartStopEventArgs : EventArgs |
darienf | 20:6d2af70c92ab | 1361 | { |
darienf | 20:6d2af70c92ab | 1362 | public bool state { get; set; } |
darienf | 20:6d2af70c92ab | 1363 | }*/ |
darienf | 20:6d2af70c92ab | 1364 | |
darienf | 20:6d2af70c92ab | 1365 | } |
darienf | 20:6d2af70c92ab | 1366 | } |