Darien Figueroa / Mbed OS Final_Program

Dependencies:   USBDevice

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers MAX30101.cs Source File

MAX30101.cs

00001 /*******************************************************************************
00002 * Copyright (C) 2016 Maxim Integrated Products, Inc., All rights Reserved.
00003 * 
00004 * This software is protected by copyright laws of the United States and
00005 * of foreign countries. This material may also be protected by patent laws
00006 * and technology transfer regulations of the United States and of foreign
00007 * countries. This software is furnished under a license agreement and/or a
00008 * nondisclosure agreement and may only be used or reproduced in accordance
00009 * with the terms of those agreements. Dissemination of this information to
00010 * any party or parties not specified in the license agreement and/or
00011 * nondisclosure agreement is expressly prohibited.
00012 *
00013 * The above copyright notice and this permission notice shall be included
00014 * in all copies or substantial portions of the Software.
00015 *
00016 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
00017 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00018 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
00019 * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
00020 * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
00021 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
00022 * OTHER DEALINGS IN THE SOFTWARE.
00023 *
00024 * Except as contained in this notice, the name of Maxim Integrated
00025 * Products, Inc. shall not be used except as stated in the Maxim Integrated
00026 * Products, Inc. Branding Policy.
00027 *
00028 * The mere transfer of this software does not imply any licenses
00029 * of trade secrets, proprietary technology, copyrights, patents,
00030 * trademarks, maskwork rights, or any other form of intellectual
00031 * property whatsoever. Maxim Integrated Products, Inc. retains all
00032 * ownership rights.
00033 *******************************************************************************
00034 */
00035 
00036 using System;
00037 using System.Collections.Generic;
00038 using System.Linq;
00039 using System.Text;
00040 using System.Threading;
00041 
00042 namespace RPCSupport.Devices
00043 {
00044     /* Optical */
00045     public class MAX30101 : ClientDevice
00046     {
00047         public const string CLASSNAME = "MAX30101";
00048         int slaveAddress;
00049         public MAX30101(RPCClient client, int slaveAddress)
00050             : base(client)
00051         {
00052             this.slaveAddress = slaveAddress;
00053         }
00054         public byte ReadReg(byte addr)
00055         {
00056             string reply = Call(CLASSNAME, "ReadReg", addr.ToString("X2"));
00057             return client.pipeline.StringToByte(reply);
00058         }
00059         public void WriteReg(byte addr, byte data)
00060         {
00061             Call(CLASSNAME, "WriteReg", addr.ToString("X2"), data.ToString("X2"));
00062         }
00063 
00064         private void InitStreaming()
00065         {
00066             client.pipeline.Discard();
00067             client.streaming.Init(client.pipeline);
00068             client.streaming.Start();
00069             //Call(CLASSNAME, "StreamTest");
00070             //CallNoReply(CLASSNAME, "StreamTest");
00071         }
00072 
00073         public void StopStreaming()
00074         {
00075             StopStreaming(true);
00076         }
00077 
00078         public void StopStreaming(bool connected)
00079         {
00080             if (connected)
00081                 client.pipeline.SendSingleByte(' ');
00082 
00083             client.streaming.Stop();
00084 
00085             if (connected)
00086             {
00087                 client.pipeline.Discard();
00088                 Thread.Sleep(500);
00089                 client.pipeline.Discard();
00090             }
00091         }
00092 
00093         public void SpO2mode_init(byte fifo_waterlevel_mark, byte sample_avg, byte sample_rate, byte pulse_width,
00094                                                                         byte red_led_current, byte ir_led_current, byte accelRateParameter)
00095         {
00096             InitStreaming();
00097             CallNoReply(CLASSNAME, "SpO2mode_init", 
00098                 fifo_waterlevel_mark.ToString("X2"), 
00099                 sample_avg.ToString("X2"),
00100                 sample_rate.ToString("X2"),
00101                 pulse_width.ToString("X2"),
00102                 red_led_current.ToString("X2"),
00103                 ir_led_current.ToString("X2"),
00104                 accelRateParameter.ToString("X2")
00105                 );
00106         }
00107 
00108         public void HRmode_init(byte fifo_waterlevel_mark, byte sample_avg, byte sample_rate, byte pulse_width, 
00109                                                                         byte red_led_current,byte accelRateParameter)
00110         {
00111             InitStreaming();
00112             CallNoReply(CLASSNAME, "HRmode_init",
00113                 fifo_waterlevel_mark.ToString("X2"),
00114                 sample_avg.ToString("X2"),
00115                 sample_rate.ToString("X2"),
00116                 pulse_width.ToString("X2"),
00117                 red_led_current.ToString("X2"),
00118                 accelRateParameter.ToString("X2")
00119                 );
00120         }
00121 
00122         public void Multimode_init(byte fifo_waterlevel_mark, byte sample_avg, byte sample_rate, byte pulse_width,
00123                                             byte red_led_current, byte ir_led_current, byte green_led_current,
00124                                             byte slot_1, byte slot_2, byte slot_3, byte slot_4, byte accelRateParameter)
00125         {
00126             InitStreaming();
00127             CallNoReply(CLASSNAME, "Multimode_init",
00128                 fifo_waterlevel_mark.ToString("X2"),
00129                 sample_avg.ToString("X2"),
00130                 sample_rate.ToString("X2"),
00131                 pulse_width.ToString("X2"),
00132                 red_led_current.ToString("X2"),
00133                 ir_led_current.ToString("X2"),
00134                 green_led_current.ToString("X2"),
00135                 slot_1.ToString("X2"),
00136                 slot_2.ToString("X2"),
00137                 slot_3.ToString("X2"),
00138                 slot_4.ToString("X2"),
00139                 accelRateParameter.ToString("X2")
00140                 );
00141         }
00142 
00143         public void SpO2mode_stop()
00144         {
00145             SpO2mode_stop(true);
00146         }
00147 
00148         public void SpO2mode_stop(bool connected)
00149         {
00150             StopStreaming(connected);
00151 
00152             if (connected)
00153             {
00154                 Call(CLASSNAME, "SpO2mode_stop");
00155                 System.Threading.Thread.Sleep(250);
00156                 client.pipeline.Discard();
00157             }
00158         }
00159 
00160         public void HRmode_stop()
00161         {
00162             HRmode_stop(true);
00163         }
00164 
00165         public void HRmode_stop(bool connected)
00166         {
00167             StopStreaming(connected);
00168 
00169             if (connected)
00170             {
00171                 Call(CLASSNAME, "HRmode_stop");
00172                 System.Threading.Thread.Sleep(250);
00173                 client.pipeline.Discard();
00174             }
00175         }
00176 
00177         public void Multimode_stop()
00178         {
00179             Multimode_stop(true);
00180         }
00181 
00182         public void Multimode_stop(bool connected)
00183         {
00184             StopStreaming(connected);
00185 
00186             if (connected)
00187             {
00188                 Call(CLASSNAME, "Multimode_stop");
00189                 System.Threading.Thread.Sleep(250);
00190                 client.pipeline.Discard();
00191             }
00192         }
00193 
00194     }
00195 }
00196 
00197