repo time

Dependencies:   mbed MAX14720 MAX30205 USBDevice

Committer:
darienf
Date:
Tue Apr 06 06:41:40 2021 +0000
Revision:
20:6d2af70c92ab
another repo

Who changed what in which revision?

UserRevisionLine numberNew contents of line
darienf 20:6d2af70c92ab 1 using System;
darienf 20:6d2af70c92ab 2 using System.Collections.Generic;
darienf 20:6d2af70c92ab 3 using System.Linq;
darienf 20:6d2af70c92ab 4 using System.Text;
darienf 20:6d2af70c92ab 5 using System.ComponentModel;
darienf 20:6d2af70c92ab 6 using System.Collections;
darienf 20:6d2af70c92ab 7
darienf 20:6d2af70c92ab 8 namespace HealthSensorPlatform
darienf 20:6d2af70c92ab 9 {
darienf 20:6d2af70c92ab 10 class Streaming
darienf 20:6d2af70c92ab 11 {
darienf 20:6d2af70c92ab 12 BackgroundWorker _testWorker;
darienf 20:6d2af70c92ab 13
darienf 20:6d2af70c92ab 14 public ArrayList ArrayListRed = new ArrayList();
darienf 20:6d2af70c92ab 15 public ArrayList ArrayListIR = new ArrayList();
darienf 20:6d2af70c92ab 16 public ArrayList ArrayListGreen = new ArrayList();
darienf 20:6d2af70c92ab 17 public event EventHandler<PartialArrayIntAvailableEventArgs> PartialArrayIntAvailable;
darienf 20:6d2af70c92ab 18
darienf 20:6d2af70c92ab 19 public void Init()
darienf 20:6d2af70c92ab 20 {
darienf 20:6d2af70c92ab 21 _testWorker = new BackgroundWorker();
darienf 20:6d2af70c92ab 22 _testWorker.WorkerSupportsCancellation = true;
darienf 20:6d2af70c92ab 23 _testWorker.ProgressChanged += new ProgressChangedEventHandler(_testWorker_ProgressChanged);
darienf 20:6d2af70c92ab 24 _testWorker.DoWork += new DoWorkEventHandler(_testWorker_DoWork);
darienf 20:6d2af70c92ab 25 _testWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(_testWorker_RunWorkerCompleted);
darienf 20:6d2af70c92ab 26 _testWorker.WorkerReportsProgress = true;
darienf 20:6d2af70c92ab 27 }
darienf 20:6d2af70c92ab 28
darienf 20:6d2af70c92ab 29 protected virtual void OnPartialArrayIntAvailable(PartialArrayIntAvailableEventArgs e)
darienf 20:6d2af70c92ab 30 {
darienf 20:6d2af70c92ab 31 EventHandler<PartialArrayIntAvailableEventArgs> handler = PartialArrayIntAvailable;
darienf 20:6d2af70c92ab 32 if (handler != null)
darienf 20:6d2af70c92ab 33 {
darienf 20:6d2af70c92ab 34 handler(this, e);
darienf 20:6d2af70c92ab 35 }
darienf 20:6d2af70c92ab 36 }
darienf 20:6d2af70c92ab 37
darienf 20:6d2af70c92ab 38 public void Start()
darienf 20:6d2af70c92ab 39 {
darienf 20:6d2af70c92ab 40 ArrayListRed.Clear();
darienf 20:6d2af70c92ab 41 ArrayListIR.Clear();
darienf 20:6d2af70c92ab 42 ArrayListGreen.Clear();
darienf 20:6d2af70c92ab 43 _testWorker.RunWorkerAsync();
darienf 20:6d2af70c92ab 44 }
darienf 20:6d2af70c92ab 45 public void Stop()
darienf 20:6d2af70c92ab 46 {
darienf 20:6d2af70c92ab 47 _testWorker.CancelAsync();
darienf 20:6d2af70c92ab 48 }
darienf 20:6d2af70c92ab 49 void _testWorker_ProgressChanged(object sender, ProgressChangedEventArgs e)
darienf 20:6d2af70c92ab 50 {
darienf 20:6d2af70c92ab 51 var data = (System.Tuple<int, int, int[], int[], int[]>)(e.UserState);
darienf 20:6d2af70c92ab 52 int reportID = data.Item1;
darienf 20:6d2af70c92ab 53 int sampleNumberOffset = data.Item2;
darienf 20:6d2af70c92ab 54 int[] list1_Red___or_X = data.Item3;
darienf 20:6d2af70c92ab 55 int[] list2_IR____or_Y = data.Item4;
darienf 20:6d2af70c92ab 56 int[] list3_Green_or_Z = data.Item5;
darienf 20:6d2af70c92ab 57
darienf 20:6d2af70c92ab 58 for (int index = 0; index < list1_Red___or_X.Length; index++)
darienf 20:6d2af70c92ab 59 {
darienf 20:6d2af70c92ab 60 ArrayListRed.Add(list1_Red___or_X[index]);
darienf 20:6d2af70c92ab 61 }
darienf 20:6d2af70c92ab 62 for (int index = 0; index < list2_IR____or_Y.Length; index++)
darienf 20:6d2af70c92ab 63 {
darienf 20:6d2af70c92ab 64 ArrayListIR.Add(list2_IR____or_Y[index]);
darienf 20:6d2af70c92ab 65 }
darienf 20:6d2af70c92ab 66 for (int index = 0; index < list3_Green_or_Z.Length; index++)
darienf 20:6d2af70c92ab 67 {
darienf 20:6d2af70c92ab 68 ArrayListGreen.Add(list3_Green_or_Z[index]);
darienf 20:6d2af70c92ab 69 }
darienf 20:6d2af70c92ab 70
darienf 20:6d2af70c92ab 71 // https://jira.maxim-ic.com/browse/OS24EVK-59 matlab: PartialArrayIntAvailable based on PartialDataBufferAvailable of r14194 (broken)
darienf 20:6d2af70c92ab 72 // https://jira.maxim-ic.com/browse/OS24EVK-59 matlab: What about using System.Array<int> instead of System.Collections.ArrayList?
darienf 20:6d2af70c92ab 73 // https://jira.maxim-ic.com/browse/OS24EVK-59 matlab: Changed PartialDataBufferAvailableEventArgs and FinalDataBufferAvailableEventArgs to use int[] rawRedData, int[] rawIRData, int[] rawGreenData
darienf 20:6d2af70c92ab 74 // int[] RawRedData replaces ArrayList ArrayListRed
darienf 20:6d2af70c92ab 75 // example: https://jira.maxim-ic.com/browse/OS24EVK-59 standard event handler: Fire the PartialArrayIntAvailable event
darienf 20:6d2af70c92ab 76 OnPartialArrayIntAvailable(new PartialArrayIntAvailableEventArgs()
darienf 20:6d2af70c92ab 77 {
darienf 20:6d2af70c92ab 78 sampleNumberOffset = sampleNumberOffset,
darienf 20:6d2af70c92ab 79 rawRedData = (int[])ArrayListRed.ToArray(typeof(int)),
darienf 20:6d2af70c92ab 80 rawIRData = (int[])ArrayListIR.ToArray(typeof(int)),
darienf 20:6d2af70c92ab 81 rawGreenData = (int[])ArrayListGreen.ToArray(typeof(int))
darienf 20:6d2af70c92ab 82 });
darienf 20:6d2af70c92ab 83 }
darienf 20:6d2af70c92ab 84 private void _testWorker_DoWork(object sender, DoWorkEventArgs e)
darienf 20:6d2af70c92ab 85 {
darienf 20:6d2af70c92ab 86 while (true)
darienf 20:6d2af70c92ab 87 {
darienf 20:6d2af70c92ab 88 if (_testWorker.CancellationPending)
darienf 20:6d2af70c92ab 89 {
darienf 20:6d2af70c92ab 90 return;
darienf 20:6d2af70c92ab 91 }
darienf 20:6d2af70c92ab 92 }
darienf 20:6d2af70c92ab 93 }
darienf 20:6d2af70c92ab 94 void _testWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
darienf 20:6d2af70c92ab 95 {
darienf 20:6d2af70c92ab 96 }
darienf 20:6d2af70c92ab 97 }
darienf 20:6d2af70c92ab 98 }