This is the latest working repository used in our demo video for the Maxim to display temperature readings on Bluetooth

Dependencies:   USBDevice

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?

UserRevisionLine numberNew contents of line
darienf 3:36de8b9e4b1a 1 /*******************************************************************************
darienf 3:36de8b9e4b1a 2 * Copyright (C) 2016 Maxim Integrated Products, Inc., All rights Reserved.
darienf 3:36de8b9e4b1a 3 *
darienf 3:36de8b9e4b1a 4 * This software is protected by copyright laws of the United States and
darienf 3:36de8b9e4b1a 5 * of foreign countries. This material may also be protected by patent laws
darienf 3:36de8b9e4b1a 6 * and technology transfer regulations of the United States and of foreign
darienf 3:36de8b9e4b1a 7 * countries. This software is furnished under a license agreement and/or a
darienf 3:36de8b9e4b1a 8 * nondisclosure agreement and may only be used or reproduced in accordance
darienf 3:36de8b9e4b1a 9 * with the terms of those agreements. Dissemination of this information to
darienf 3:36de8b9e4b1a 10 * any party or parties not specified in the license agreement and/or
darienf 3:36de8b9e4b1a 11 * nondisclosure agreement is expressly prohibited.
darienf 3:36de8b9e4b1a 12 *
darienf 3:36de8b9e4b1a 13 * The above copyright notice and this permission notice shall be included
darienf 3:36de8b9e4b1a 14 * in all copies or substantial portions of the Software.
darienf 3:36de8b9e4b1a 15 *
darienf 3:36de8b9e4b1a 16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
darienf 3:36de8b9e4b1a 17 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
darienf 3:36de8b9e4b1a 18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
darienf 3:36de8b9e4b1a 19 * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
darienf 3:36de8b9e4b1a 20 * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
darienf 3:36de8b9e4b1a 21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
darienf 3:36de8b9e4b1a 22 * OTHER DEALINGS IN THE SOFTWARE.
darienf 3:36de8b9e4b1a 23 *
darienf 3:36de8b9e4b1a 24 * Except as contained in this notice, the name of Maxim Integrated
darienf 3:36de8b9e4b1a 25 * Products, Inc. shall not be used except as stated in the Maxim Integrated
darienf 3:36de8b9e4b1a 26 * Products, Inc. Branding Policy.
darienf 3:36de8b9e4b1a 27 *
darienf 3:36de8b9e4b1a 28 * The mere transfer of this software does not imply any licenses
darienf 3:36de8b9e4b1a 29 * of trade secrets, proprietary technology, copyrights, patents,
darienf 3:36de8b9e4b1a 30 * trademarks, maskwork rights, or any other form of intellectual
darienf 3:36de8b9e4b1a 31 * property whatsoever. Maxim Integrated Products, Inc. retains all
darienf 3:36de8b9e4b1a 32 * ownership rights.
darienf 3:36de8b9e4b1a 33 *******************************************************************************
darienf 3:36de8b9e4b1a 34 */
darienf 3:36de8b9e4b1a 35
darienf 3:36de8b9e4b1a 36 using System;
darienf 3:36de8b9e4b1a 37 using System.Collections.Generic;
darienf 3:36de8b9e4b1a 38 using System.Linq;
darienf 3:36de8b9e4b1a 39 using System.Text;
darienf 3:36de8b9e4b1a 40 using System.Windows.Forms;
darienf 3:36de8b9e4b1a 41 using RPCSupport;
darienf 3:36de8b9e4b1a 42 using RPCSupport.Devices;
darienf 3:36de8b9e4b1a 43
darienf 3:36de8b9e4b1a 44 namespace HealthSensorPlatform
darienf 3:36de8b9e4b1a 45 {
darienf 3:36de8b9e4b1a 46 class RegisterField : IRegisterFieldView
darienf 3:36de8b9e4b1a 47 {
darienf 3:36de8b9e4b1a 48 /// <summary>
darienf 3:36de8b9e4b1a 49 /// Device which is connected to this RegisterField
darienf 3:36de8b9e4b1a 50 /// </summary>
darienf 3:36de8b9e4b1a 51 public IRegisterDevice Device;
darienf 3:36de8b9e4b1a 52 /// <summary>
darienf 3:36de8b9e4b1a 53 /// Bit name in data sheet
darienf 3:36de8b9e4b1a 54 /// </summary>
darienf 3:36de8b9e4b1a 55 public string Name;
darienf 3:36de8b9e4b1a 56 /// <summary>
darienf 3:36de8b9e4b1a 57 /// Register number
darienf 3:36de8b9e4b1a 58 /// </summary>
darienf 3:36de8b9e4b1a 59 public int Register;
darienf 3:36de8b9e4b1a 60 /// <summary>
darienf 3:36de8b9e4b1a 61 /// LSB Bit index number of bit field
darienf 3:36de8b9e4b1a 62 /// </summary>
darienf 3:36de8b9e4b1a 63 public int Index;
darienf 3:36de8b9e4b1a 64 /// <summary>
darienf 3:36de8b9e4b1a 65 /// Length of bit field
darienf 3:36de8b9e4b1a 66 /// </summary>
darienf 3:36de8b9e4b1a 67 public int Width;
darienf 3:36de8b9e4b1a 68 /// <summary>
darienf 3:36de8b9e4b1a 69 /// Description array of field settings
darienf 3:36de8b9e4b1a 70 /// </summary>
darienf 3:36de8b9e4b1a 71 public string[] Descriptions;
darienf 3:36de8b9e4b1a 72 /// <summary>
darienf 3:36de8b9e4b1a 73 /// Control associated with bit field
darienf 3:36de8b9e4b1a 74 /// </summary>
darienf 3:36de8b9e4b1a 75 Control control;
darienf 3:36de8b9e4b1a 76 public Control Control
darienf 3:36de8b9e4b1a 77 {
darienf 3:36de8b9e4b1a 78 get
darienf 3:36de8b9e4b1a 79 {
darienf 3:36de8b9e4b1a 80 return control;
darienf 3:36de8b9e4b1a 81 }
darienf 3:36de8b9e4b1a 82 set
darienf 3:36de8b9e4b1a 83 {
darienf 3:36de8b9e4b1a 84 control = value;
darienf 3:36de8b9e4b1a 85 if (control.GetType() == typeof(MaximStyle.MaximComboBox))
darienf 3:36de8b9e4b1a 86 {
darienf 3:36de8b9e4b1a 87 MaximStyle.MaximComboBox cb = (MaximStyle.MaximComboBox)control;
darienf 3:36de8b9e4b1a 88 cb.Items.Clear();
darienf 3:36de8b9e4b1a 89 foreach (string s in Descriptions)
darienf 3:36de8b9e4b1a 90 {
darienf 3:36de8b9e4b1a 91 cb.Items.Add(s);
darienf 3:36de8b9e4b1a 92 }
darienf 3:36de8b9e4b1a 93 }
darienf 3:36de8b9e4b1a 94 }
darienf 3:36de8b9e4b1a 95 }
darienf 3:36de8b9e4b1a 96
darienf 3:36de8b9e4b1a 97 /// <summary>
darienf 3:36de8b9e4b1a 98 /// Label (Text) associated with register field
darienf 3:36de8b9e4b1a 99 /// </summary>
darienf 3:36de8b9e4b1a 100 Label label;
darienf 3:36de8b9e4b1a 101 public Label Label
darienf 3:36de8b9e4b1a 102 {
darienf 3:36de8b9e4b1a 103 set
darienf 3:36de8b9e4b1a 104 {
darienf 3:36de8b9e4b1a 105 LabelDescription = value.Text;
darienf 3:36de8b9e4b1a 106 label = value;
darienf 3:36de8b9e4b1a 107 }
darienf 3:36de8b9e4b1a 108
darienf 3:36de8b9e4b1a 109 get
darienf 3:36de8b9e4b1a 110 {
darienf 3:36de8b9e4b1a 111 return label;
darienf 3:36de8b9e4b1a 112 }
darienf 3:36de8b9e4b1a 113 }
darienf 3:36de8b9e4b1a 114
darienf 3:36de8b9e4b1a 115 /// <summary>
darienf 3:36de8b9e4b1a 116 /// Text value of label
darienf 3:36de8b9e4b1a 117 /// </summary>
darienf 3:36de8b9e4b1a 118 public string LabelDescription;
darienf 3:36de8b9e4b1a 119
darienf 3:36de8b9e4b1a 120 /// <summary>
darienf 3:36de8b9e4b1a 121 /// Automatically update register field
darienf 3:36de8b9e4b1a 122 /// </summary>
darienf 3:36de8b9e4b1a 123 public bool AutoUpdate = true;
darienf 3:36de8b9e4b1a 124
darienf 3:36de8b9e4b1a 125 /// <summary>
darienf 3:36de8b9e4b1a 126 /// Read register field value
darienf 3:36de8b9e4b1a 127 /// </summary>
darienf 3:36de8b9e4b1a 128 /// <returns></returns>
darienf 3:36de8b9e4b1a 129 public int ReadField()
darienf 3:36de8b9e4b1a 130 {
darienf 3:36de8b9e4b1a 131 int registerData;
darienf 3:36de8b9e4b1a 132
darienf 3:36de8b9e4b1a 133 registerData = Device.ReadReg((byte)Register);
darienf 3:36de8b9e4b1a 134
darienf 3:36de8b9e4b1a 135 return (registerData >> Index) & ((1 << Width) - 1);
darienf 3:36de8b9e4b1a 136 }
darienf 3:36de8b9e4b1a 137
darienf 3:36de8b9e4b1a 138 /// <summary>
darienf 3:36de8b9e4b1a 139 /// Write register field value
darienf 3:36de8b9e4b1a 140 /// </summary>
darienf 3:36de8b9e4b1a 141 /// <param name="data">value to write to field</param>
darienf 3:36de8b9e4b1a 142 public void WriteField(int data)
darienf 3:36de8b9e4b1a 143 {
darienf 3:36de8b9e4b1a 144 int registerData;
darienf 3:36de8b9e4b1a 145
darienf 3:36de8b9e4b1a 146 registerData = Device.ReadReg((byte)Register);
darienf 3:36de8b9e4b1a 147 registerData &= ~(((1 << Width) - 1) << Index); // Mask and Clear Bits
darienf 3:36de8b9e4b1a 148 registerData |= data << Index; // Set Bits
darienf 3:36de8b9e4b1a 149
darienf 3:36de8b9e4b1a 150 Device.WriteReg((byte)Register, registerData);
darienf 3:36de8b9e4b1a 151 }
darienf 3:36de8b9e4b1a 152
darienf 3:36de8b9e4b1a 153 }
darienf 3:36de8b9e4b1a 154 }