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