Library for MAXREFDES131 OneWire GridEYE sensor interface

Dependents:   MAXREFDES131_Qt_Demo MAXREFDES130_131_Demo

Committer:
j3
Date:
Mon Sep 26 15:08:17 2016 -0700
Revision:
12:4b7ac3b21d91
Parent:
11:6fde9f875d0c
Fix include paths

Who changed what in which revision?

UserRevisionLine numberNew contents of line
j3 1:9e457e35e2e3 1 /**********************************************************************
j3 1:9e457e35e2e3 2 * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved.
j3 1:9e457e35e2e3 3 *
j3 1:9e457e35e2e3 4 * Permission is hereby granted, free of charge, to any person obtaining a
j3 1:9e457e35e2e3 5 * copy of this software and associated documentation files (the "Software"),
j3 1:9e457e35e2e3 6 * to deal in the Software without restriction, including without limitation
j3 1:9e457e35e2e3 7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
j3 1:9e457e35e2e3 8 * and/or sell copies of the Software, and to permit persons to whom the
j3 1:9e457e35e2e3 9 * Software is furnished to do so, subject to the following conditions:
j3 1:9e457e35e2e3 10 *
j3 1:9e457e35e2e3 11 * The above copyright notice and this permission notice shall be included
j3 1:9e457e35e2e3 12 * in all copies or substantial portions of the Software.
j3 1:9e457e35e2e3 13 *
j3 1:9e457e35e2e3 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
j3 1:9e457e35e2e3 15 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
j3 1:9e457e35e2e3 16 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
j3 1:9e457e35e2e3 17 * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
j3 1:9e457e35e2e3 18 * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
j3 1:9e457e35e2e3 19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
j3 1:9e457e35e2e3 20 * OTHER DEALINGS IN THE SOFTWARE.
j3 1:9e457e35e2e3 21 *
j3 1:9e457e35e2e3 22 * Except as contained in this notice, the name of Maxim Integrated
j3 1:9e457e35e2e3 23 * Products, Inc. shall not be used except as stated in the Maxim Integrated
j3 1:9e457e35e2e3 24 * Products, Inc. Branding Policy.
j3 1:9e457e35e2e3 25 *
j3 1:9e457e35e2e3 26 * The mere transfer of this software does not imply any licenses
j3 1:9e457e35e2e3 27 * of trade secrets, proprietary technology, copyrights, patents,
j3 1:9e457e35e2e3 28 * trademarks, maskwork rights, or any other form of intellectual
j3 1:9e457e35e2e3 29 * property whatsoever. Maxim Integrated Products, Inc. retains all
j3 1:9e457e35e2e3 30 * ownership rights.
j3 1:9e457e35e2e3 31 **********************************************************************/
j3 1:9e457e35e2e3 32
j3 1:9e457e35e2e3 33
j3 12:4b7ac3b21d91 34 #include "OWGridEye.h"
j3 1:9e457e35e2e3 35
j3 1:9e457e35e2e3 36
j3 1:9e457e35e2e3 37 //*********************************************************************
j3 2:b10e7a2961ab 38 OWGridEye::OWGridEye(RandomAccessRomIterator & selector)
j3 2:b10e7a2961ab 39 : m_switch(selector), m_i2c_bridge(selector)
j3 1:9e457e35e2e3 40 {
j3 1:9e457e35e2e3 41 }
j3 1:9e457e35e2e3 42
j3 1:9e457e35e2e3 43
j3 1:9e457e35e2e3 44 //*********************************************************************
j3 1:9e457e35e2e3 45 OWGridEye::CmdResult OWGridEye::disconnectGridEye(void)
j3 1:9e457e35e2e3 46 {
j3 1:9e457e35e2e3 47 OWGridEye::CmdResult result = OWGridEye::OpFailure;
j3 1:9e457e35e2e3 48 uint8_t pio_state;
j3 1:9e457e35e2e3 49
j3 9:cb964c629580 50 DS2413::CmdResult sw_result = m_switch.pioAccessReadChB(pio_state);
j3 2:b10e7a2961ab 51 if(sw_result == DS2413::Success)
j3 1:9e457e35e2e3 52 {
j3 1:9e457e35e2e3 53 //if high take low, falling edge puts bridge and sensor to sleep
j3 1:9e457e35e2e3 54 if(pio_state)
j3 1:9e457e35e2e3 55 {
j3 9:cb964c629580 56 sw_result = m_switch.pioAccessWriteChB(0);
j3 2:b10e7a2961ab 57 if(sw_result == DS2413::Success)
j3 1:9e457e35e2e3 58 {
j3 1:9e457e35e2e3 59 result = OWGridEye::Success;
j3 1:9e457e35e2e3 60 }
j3 1:9e457e35e2e3 61 }
j3 1:9e457e35e2e3 62 else
j3 1:9e457e35e2e3 63 {
j3 1:9e457e35e2e3 64 //if low, take high, then low to get falling edge
j3 9:cb964c629580 65 sw_result = m_switch.pioAccessWriteChB(1);
j3 2:b10e7a2961ab 66 if(sw_result == DS2413::Success)
j3 1:9e457e35e2e3 67 {
j3 9:cb964c629580 68 sw_result = m_switch.pioAccessWriteChB(0);
j3 2:b10e7a2961ab 69 if(sw_result == DS2413::Success)
j3 1:9e457e35e2e3 70 {
j3 1:9e457e35e2e3 71 result = OWGridEye::Success;
j3 1:9e457e35e2e3 72 }
j3 1:9e457e35e2e3 73 }
j3 1:9e457e35e2e3 74 }
j3 1:9e457e35e2e3 75 }
j3 1:9e457e35e2e3 76
j3 1:9e457e35e2e3 77 return result;
j3 1:9e457e35e2e3 78 }
j3 1:9e457e35e2e3 79
j3 1:9e457e35e2e3 80
j3 1:9e457e35e2e3 81 //*********************************************************************
j3 1:9e457e35e2e3 82 OWGridEye::CmdResult OWGridEye::connectGridEye(void)
j3 1:9e457e35e2e3 83 {
j3 1:9e457e35e2e3 84 OWGridEye::CmdResult result = OWGridEye::OpFailure;
j3 1:9e457e35e2e3 85
j3 9:cb964c629580 86 DS2413::CmdResult sw_result = m_switch.pioAccessWriteChB(1);
j3 2:b10e7a2961ab 87 if(sw_result == DS2413::Success)
j3 1:9e457e35e2e3 88 {
j3 1:9e457e35e2e3 89 result = OWGridEye::Success;
j3 1:9e457e35e2e3 90 }
j3 1:9e457e35e2e3 91
j3 1:9e457e35e2e3 92 return result;
j3 1:9e457e35e2e3 93 }
j3 1:9e457e35e2e3 94
j3 1:9e457e35e2e3 95
j3 1:9e457e35e2e3 96 //*********************************************************************
j3 1:9e457e35e2e3 97 OWGridEye::CmdResult OWGridEye::connectOWbus(void)
j3 1:9e457e35e2e3 98 {
j3 1:9e457e35e2e3 99 OWGridEye::CmdResult result = OWGridEye::OpFailure;
j3 1:9e457e35e2e3 100
j3 9:cb964c629580 101 DS2413::CmdResult sw_result = m_switch.pioAccessWriteChA(0);
j3 2:b10e7a2961ab 102 if(sw_result == DS2413::Success)
j3 1:9e457e35e2e3 103 {
j3 1:9e457e35e2e3 104 result = OWGridEye::Success;
j3 1:9e457e35e2e3 105 }
j3 1:9e457e35e2e3 106
j3 1:9e457e35e2e3 107 return result;
j3 1:9e457e35e2e3 108 }
j3 1:9e457e35e2e3 109
j3 1:9e457e35e2e3 110
j3 1:9e457e35e2e3 111 //*********************************************************************
j3 1:9e457e35e2e3 112 OWGridEye::CmdResult OWGridEye::disconnectOWbus(void)
j3 1:9e457e35e2e3 113 {
j3 1:9e457e35e2e3 114 OWGridEye::CmdResult result = OWGridEye::OpFailure;
j3 1:9e457e35e2e3 115
j3 9:cb964c629580 116 DS2413::CmdResult sw_result = m_switch.pioAccessWriteChA(1);
j3 2:b10e7a2961ab 117 if(sw_result == DS2413::Success)
j3 1:9e457e35e2e3 118 {
j3 1:9e457e35e2e3 119 result = OWGridEye::Success;
j3 1:9e457e35e2e3 120 }
j3 1:9e457e35e2e3 121
j3 1:9e457e35e2e3 122 return result;
j3 1:9e457e35e2e3 123 }
j3 1:9e457e35e2e3 124
j3 1:9e457e35e2e3 125
j3 1:9e457e35e2e3 126 //*********************************************************************
j3 1:9e457e35e2e3 127 OWGridEye::CmdResult OWGridEye::gridEyeAccess(bool readWrite, GridEyeRegister regAdrs, uint8_t numBytes, uint8_t * dataBuf)
j3 1:9e457e35e2e3 128 {
j3 1:9e457e35e2e3 129 OWGridEye::CmdResult gridEye_result = OWGridEye::OpFailure;
j3 2:b10e7a2961ab 130 DS28E17::CmdResult i2c_cmd_result = DS28E17::OperationFailure;
j3 1:9e457e35e2e3 131
j3 2:b10e7a2961ab 132 uint8_t read_pointer = regAdrs;
j3 2:b10e7a2961ab 133 uint8_t status, wr_status;
j3 1:9e457e35e2e3 134
j3 2:b10e7a2961ab 135 if(readWrite)
j3 1:9e457e35e2e3 136 {
j3 11:6fde9f875d0c 137 i2c_cmd_result = m_i2c_bridge.writeReadDataWithStop((OWGridEye::I2C_ADRS << 1),
j3 2:b10e7a2961ab 138 1, &read_pointer, numBytes,
j3 2:b10e7a2961ab 139 status, wr_status, dataBuf);
j3 2:b10e7a2961ab 140 }
j3 2:b10e7a2961ab 141 else
j3 2:b10e7a2961ab 142 {
j3 11:6fde9f875d0c 143 i2c_cmd_result = m_i2c_bridge.writeDataWithStop((OWGridEye::I2C_ADRS << 1),
j3 2:b10e7a2961ab 144 numBytes, dataBuf, status,
j3 2:b10e7a2961ab 145 wr_status);
j3 2:b10e7a2961ab 146 }
j3 2:b10e7a2961ab 147
j3 2:b10e7a2961ab 148 if(i2c_cmd_result == DS28E17::Success)
j3 2:b10e7a2961ab 149 {
j3 2:b10e7a2961ab 150 gridEye_result = OWGridEye::Success;
j3 1:9e457e35e2e3 151 }
j3 1:9e457e35e2e3 152
j3 1:9e457e35e2e3 153 return gridEye_result;
j3 1:9e457e35e2e3 154 }
j3 4:6be732966106 155
j3 4:6be732966106 156
j3 4:6be732966106 157 //*********************************************************************
j3 4:6be732966106 158 OWGridEye::CmdResult OWGridEye::gridEyeGetThermistor(int16_t & thermTemp)
j3 4:6be732966106 159 {
j3 4:6be732966106 160 OWGridEye::CmdResult result;
j3 4:6be732966106 161 uint8_t data[2];
j3 4:6be732966106 162
j3 4:6be732966106 163 result = this->gridEyeAccess(1, OWGridEye::THERMISTOR_LOW, 2, data);
j3 4:6be732966106 164 if(result == OWGridEye::Success)
j3 4:6be732966106 165 {
j3 4:6be732966106 166 thermTemp = shAMG_PUB_TMP_ConvThermistor(data);
j3 4:6be732966106 167 }
j3 4:6be732966106 168
j3 4:6be732966106 169 return result;
j3 4:6be732966106 170 }
j3 4:6be732966106 171
j3 4:6be732966106 172
j3 4:6be732966106 173 //*********************************************************************
j3 4:6be732966106 174 OWGridEye::CmdResult OWGridEye::gridEyeGetPixelTemperature(uint8_t pixelAdrs, int16_t & pixelTemp)
j3 4:6be732966106 175 {
j3 4:6be732966106 176 OWGridEye::CmdResult result;
j3 4:6be732966106 177 uint8_t data[2];
j3 4:6be732966106 178
j3 4:6be732966106 179 result = this->gridEyeAccess(1, (GridEyeRegister) pixelAdrs, 2, data);
j3 4:6be732966106 180 if(result == OWGridEye::Success)
j3 4:6be732966106 181 {
j3 4:6be732966106 182 pixelTemp = shAMG_PUB_TMP_ConvTemperature(data);
j3 4:6be732966106 183 }
j3 4:6be732966106 184
j3 4:6be732966106 185 return result;
j3 4:6be732966106 186 }
j3 4:6be732966106 187
j3 4:6be732966106 188
j3 4:6be732966106 189 //*********************************************************************
j3 4:6be732966106 190 OWGridEye::CmdResult OWGridEye::gridEyeGetFrameTemperature(int16_t * frameTemp)
j3 4:6be732966106 191 {
j3 4:6be732966106 192 OWGridEye::CmdResult result;
j3 4:6be732966106 193 uint8_t data[128];
j3 4:6be732966106 194
j3 4:6be732966106 195 result = this->gridEyeAccess(1,(GridEyeRegister) OWGridEye::PIXEL_BASE_ADRS, 128, data);
j3 4:6be732966106 196 if(result == OWGridEye::Success)
j3 4:6be732966106 197 {
j3 4:6be732966106 198 vAMG_PUB_TMP_ConvTemperature64(data, frameTemp);
j3 4:6be732966106 199 }
j3 4:6be732966106 200
j3 4:6be732966106 201 return result;
j3 4:6be732966106 202 }