Darien Figueroa / Mbed 2 deprecated repo3

Dependencies:   mbed MAX14720 MAX30205 USBDevice

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers DeviceController.cs Source File

DeviceController.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 HealthSensorPlatform.DeviceDescriptions;
00041 using RPCSupport.DeviceSupport;
00042 
00043 namespace Maxim.CustomControls
00044 {
00045     public class DeviceController
00046     {
00047         //Hid_BaseClass myHID;
00048         RegisterInfo[] infoArray;
00049         Byte deviceAddress;
00050         Device device;
00051         RPCSupport.RPCClient rpcClient;
00052 
00053         public Device Device
00054         {
00055             get
00056             {
00057                 return device;
00058             }
00059         }
00060 
00061         public event EventHandler<RegisterEventArgs> RegisterRead;
00062         public event EventHandler<RegisterEventArgs> RegisterWrite;
00063 
00064         public class RegisterEventArgs : EventArgs
00065         {
00066             public RegisterInfo reg { get; set; }
00067         }
00068 
00069         protected virtual void OnRegisterRead(RegisterEventArgs e)
00070         {
00071             EventHandler<RegisterEventArgs> handler = RegisterRead;
00072             if (handler != null)
00073             {
00074                 handler(this, e);
00075             }
00076         }
00077         protected virtual void OnRegisterWrite(RegisterEventArgs e)
00078         {
00079             EventHandler<RegisterEventArgs> handler = RegisterWrite;
00080             if (handler != null)
00081             {
00082                 handler(this, e);
00083             }
00084         }
00085 
00086         public void SetRegisterInfo(Device device)
00087         {
00088             this.device = device;
00089             this.infoArray = device.Info;
00090         }
00091         //public void SetHid(Hid_BaseClass hid) {
00092         //    myHID = hid;
00093         //}
00094         public void SetDeviceAddress(Byte address)
00095         {
00096             deviceAddress = address;
00097         }
00098         public RegisterInfo[] InfoArray
00099         {
00100             get
00101             {
00102                 return infoArray;
00103             }
00104         }
00105 
00106         public void ReadAll()
00107         {
00108             foreach (RegisterInfo reg in infoArray)
00109             {
00110                 ReadRegister(reg);
00111             }
00112         }
00113 
00114         public void WriteAll()
00115         {
00116             foreach (RegisterInfo reg in infoArray)
00117             {
00118                 WriteRegister(reg);
00119             }
00120         }
00121 
00122         public void ReadRegister(RegisterInfo reg)
00123         {
00124             rpcClient.ReadRegister(device.deviceDetails, reg);
00125             //RegisterEventArgs registerEventArgs = new RegisterEventArgs() { reg = reg };
00126             //OnRegisterRead(registerEventArgs);
00127         }
00128 
00129         public void WriteRegister(RegisterInfo reg)
00130         {
00131             rpcClient.WriteRegister(device.deviceDetails, reg);
00132             //RegisterEventArgs registerEventArgs = new RegisterEventArgs() { reg = reg };
00133             //OnRegisterWrite(registerEventArgs);
00134         }
00135 
00136         internal void SetInterface(RPCSupport.RPCClient rpcClient)
00137         {
00138             this.rpcClient = rpcClient;
00139         }
00140     }
00141 }