Rohan Gurav
/
Sean_AdiSense1000_V21
ADISense1000 Version 2.1 code base
Fork of AdiSense1000_V21 by
main.cpp@15:78f3f517417f, 2017-12-05 (annotated)
- Committer:
- kevin1990
- Date:
- Tue Dec 05 19:07:05 2017 +0000
- Revision:
- 15:78f3f517417f
- Parent:
- 14:81f059dc75d0
- Child:
- 23:2adb6216b001
v1.0_RC2 Release
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
kevin1990 | 15:78f3f517417f | 1 | /* |
kevin1990 | 15:78f3f517417f | 2 | ****************************************************************************** |
kevin1990 | 15:78f3f517417f | 3 | * file: main.cpp |
kevin1990 | 15:78f3f517417f | 4 | *----------------------------------------------------------------------------- |
kevin1990 | 15:78f3f517417f | 5 | * |
kevin1990 | 15:78f3f517417f | 6 | Copyright (c) 2017 Emutex Ltd. / Analog Devices, Inc. |
kevin1990 | 15:78f3f517417f | 7 | |
kevin1990 | 15:78f3f517417f | 8 | All rights reserved. |
kevin1990 | 15:78f3f517417f | 9 | |
kevin1990 | 15:78f3f517417f | 10 | Redistribution and use in source and binary forms, with or without modification, |
kevin1990 | 15:78f3f517417f | 11 | are permitted provided that the following conditions are met: |
kevin1990 | 15:78f3f517417f | 12 | - Redistributions of source code must retain the above copyright notice, |
kevin1990 | 15:78f3f517417f | 13 | this list of conditions and the following disclaimer. |
kevin1990 | 15:78f3f517417f | 14 | - Redistributions in binary form must reproduce the above copyright notice, |
kevin1990 | 15:78f3f517417f | 15 | this list of conditions and the following disclaimer in the documentation |
kevin1990 | 15:78f3f517417f | 16 | and/or other materials provided with the distribution. |
kevin1990 | 15:78f3f517417f | 17 | - Modified versions of the software must be conspicuously marked as such. |
kevin1990 | 15:78f3f517417f | 18 | - This software is licensed solely and exclusively for use with processors |
kevin1990 | 15:78f3f517417f | 19 | manufactured by or for Analog Devices, Inc. |
kevin1990 | 15:78f3f517417f | 20 | - This software may not be combined or merged with other code in any manner |
kevin1990 | 15:78f3f517417f | 21 | that would cause the software to become subject to terms and conditions |
kevin1990 | 15:78f3f517417f | 22 | which differ from those listed here. |
kevin1990 | 15:78f3f517417f | 23 | - Neither the name of Analog Devices, Inc. nor the names of its |
kevin1990 | 15:78f3f517417f | 24 | contributors may be used to endorse or promote products derived |
kevin1990 | 15:78f3f517417f | 25 | from this software without specific prior written permission. |
kevin1990 | 15:78f3f517417f | 26 | - The use of this software may or may not infringe the patent rights of one |
kevin1990 | 15:78f3f517417f | 27 | or more patent holders. This license does not release you from the |
kevin1990 | 15:78f3f517417f | 28 | requirement that you obtain separate licenses from these patent holders |
kevin1990 | 15:78f3f517417f | 29 | to use this software. |
kevin1990 | 15:78f3f517417f | 30 | |
kevin1990 | 15:78f3f517417f | 31 | THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES, INC. AND CONTRIBUTORS "AS IS" AND ANY |
kevin1990 | 15:78f3f517417f | 32 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT, |
kevin1990 | 15:78f3f517417f | 33 | TITLE, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN |
kevin1990 | 15:78f3f517417f | 34 | NO EVENT SHALL ANALOG DEVICES, INC. OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, |
kevin1990 | 15:78f3f517417f | 35 | INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, PUNITIVE OR CONSEQUENTIAL DAMAGES |
kevin1990 | 15:78f3f517417f | 36 | (INCLUDING, BUT NOT LIMITED TO, DAMAGES ARISING OUT OF CLAIMS OF INTELLECTUAL |
kevin1990 | 15:78f3f517417f | 37 | PROPERTY RIGHTS INFRINGEMENT; PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS |
kevin1990 | 15:78f3f517417f | 38 | OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
kevin1990 | 15:78f3f517417f | 39 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
kevin1990 | 15:78f3f517417f | 40 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, |
kevin1990 | 15:78f3f517417f | 41 | EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
kevin1990 | 15:78f3f517417f | 42 | * |
kevin1990 | 15:78f3f517417f | 43 | *****************************************************************************/ |
kevin1990 | 15:78f3f517417f | 44 | #include "mbed.h" |
kevin1990 | 15:78f3f517417f | 45 | #include "inc/adi_sense_api.h" |
kevin1990 | 15:78f3f517417f | 46 | #include "inc/adi_sense_1000/adi_sense_1000_api.h" |
kevin1990 | 15:78f3f517417f | 47 | #include "inc/adi_sense_log.h" |
kevin1990 | 15:78f3f517417f | 48 | #include "common/utils.h" |
kevin1990 | 15:78f3f517417f | 49 | |
kevin1990 | 15:78f3f517417f | 50 | extern ADI_SENSE_CONFIG sensor0_rtd_2w_pt100_config; |
kevin1990 | 15:78f3f517417f | 51 | extern ADI_SENSE_CONFIG sensor1_typeK_cjc1_config; |
kevin1990 | 15:78f3f517417f | 52 | extern ADI_SENSE_CONFIG sensor1_rtd_3w_pt100_config; |
kevin1990 | 15:78f3f517417f | 53 | extern ADI_SENSE_CONFIG sensor2_typeT_cjc0_config; |
kevin1990 | 15:78f3f517417f | 54 | extern ADI_SENSE_CONFIG sensor2_bridge_6w_pressure_config; |
kevin1990 | 15:78f3f517417f | 55 | extern ADI_SENSE_CONFIG sensor3_typeJ_cjc0_config; |
kevin1990 | 15:78f3f517417f | 56 | extern ADI_SENSE_CONFIG sensor3_thermistor_10k_ntc_config; |
kevin1990 | 15:78f3f517417f | 57 | extern ADI_SENSE_CONFIG voltage_honeywellPressure_config; |
kevin1990 | 15:78f3f517417f | 58 | extern ADI_SENSE_CONFIG current_honeywellPressure_config; |
kevin1990 | 15:78f3f517417f | 59 | extern ADI_SENSE_CONFIG i2c0_honeywellHumidicon_config; |
kevin1990 | 15:78f3f517417f | 60 | extern ADI_SENSE_CONFIG i2c0_sensirionSHT3X_config; |
kevin1990 | 15:78f3f517417f | 61 | extern ADI_SENSE_CONFIG spi0_honeywellTrustability_config; |
kevin1990 | 15:78f3f517417f | 62 | extern ADI_SENSE_CONFIG spi0_adiAdxl362_config; |
kevin1990 | 15:78f3f517417f | 63 | extern ADI_SENSE_CONFIG multichannel_continuous_config; |
kevin1990 | 15:78f3f517417f | 64 | extern ADI_SENSE_CONFIG multichannel_multicycle_config; |
kevin1990 | 15:78f3f517417f | 65 | extern ADI_SENSE_CONFIG multichannel_singlecycle_config; |
kevin1990 | 15:78f3f517417f | 66 | |
kevin1990 | 15:78f3f517417f | 67 | /* Change the following pointer to select any of the configurations above */ |
kevin1990 | 15:78f3f517417f | 68 | static ADI_SENSE_CONFIG *pSelectedConfig = &sensor0_rtd_2w_pt100_config; |
kevin1990 | 15:78f3f517417f | 69 | |
kevin1990 | 15:78f3f517417f | 70 | static ADI_SENSE_CONNECTION connectionInfo = { |
kevin1990 | 15:78f3f517417f | 71 | .type = ADI_SENSE_CONNECTION_TYPE_SPI, |
kevin1990 | 15:78f3f517417f | 72 | .spi = { |
kevin1990 | 15:78f3f517417f | 73 | .mosiPin = SPI_MOSI, |
kevin1990 | 15:78f3f517417f | 74 | .misoPin = SPI_MISO, |
kevin1990 | 15:78f3f517417f | 75 | .sckPin = SPI_SCK, |
kevin1990 | 15:78f3f517417f | 76 | .csPin = D10, |
kevin1990 | 15:78f3f517417f | 77 | .maxSpeedHz = 2000000, |
kevin1990 | 15:78f3f517417f | 78 | }, |
kevin1990 | 15:78f3f517417f | 79 | .gpio = { |
kevin1990 | 15:78f3f517417f | 80 | .resetPin = D6, |
kevin1990 | 15:78f3f517417f | 81 | .errorPin = D3, |
kevin1990 | 15:78f3f517417f | 82 | .alertPin = D4, |
kevin1990 | 15:78f3f517417f | 83 | .datareadyPin = D5, |
kevin1990 | 15:78f3f517417f | 84 | }, |
kevin1990 | 15:78f3f517417f | 85 | }; |
kevin1990 | 15:78f3f517417f | 86 | |
kevin1990 | 15:78f3f517417f | 87 | int main() |
kevin1990 | 15:78f3f517417f | 88 | { |
kevin1990 | 15:78f3f517417f | 89 | ADI_SENSE_RESULT res; |
kevin1990 | 15:78f3f517417f | 90 | ADI_SENSE_DEVICE_HANDLE hDevice; |
kevin1990 | 15:78f3f517417f | 91 | ADI_SENSE_MEASUREMENT_MODE eMeasurementMode = ADI_SENSE_MEASUREMENT_MODE_NORMAL; |
kevin1990 | 15:78f3f517417f | 92 | bool_t bDeviceReady; |
kevin1990 | 15:78f3f517417f | 93 | |
kevin1990 | 15:78f3f517417f | 94 | /* |
kevin1990 | 15:78f3f517417f | 95 | * Open an ADI Sense device instance. |
kevin1990 | 15:78f3f517417f | 96 | */ |
kevin1990 | 15:78f3f517417f | 97 | res = adi_sense_Open(0, &connectionInfo, &hDevice); |
kevin1990 | 15:78f3f517417f | 98 | if (res != ADI_SENSE_SUCCESS) |
kevin1990 | 15:78f3f517417f | 99 | { |
kevin1990 | 15:78f3f517417f | 100 | ADI_SENSE_LOG_ERROR("Failed to open device instance"); |
kevin1990 | 15:78f3f517417f | 101 | return res; |
kevin1990 | 15:78f3f517417f | 102 | } |
kevin1990 | 15:78f3f517417f | 103 | |
kevin1990 | 15:78f3f517417f | 104 | /* |
kevin1990 | 15:78f3f517417f | 105 | * Reset the given ADI Sense device.... |
kevin1990 | 15:78f3f517417f | 106 | */ |
kevin1990 | 15:78f3f517417f | 107 | ADI_SENSE_LOG_INFO("Resetting ADI Sense device, please wait..."); |
kevin1990 | 15:78f3f517417f | 108 | res = adi_sense_Reset(hDevice); |
kevin1990 | 15:78f3f517417f | 109 | if (res != ADI_SENSE_SUCCESS) |
kevin1990 | 15:78f3f517417f | 110 | { |
kevin1990 | 15:78f3f517417f | 111 | ADI_SENSE_LOG_ERROR("Failed to reset device"); |
kevin1990 | 15:78f3f517417f | 112 | return res; |
kevin1990 | 15:78f3f517417f | 113 | } |
kevin1990 | 15:78f3f517417f | 114 | /* |
kevin1990 | 15:78f3f517417f | 115 | * ...and wait until the device is ready. |
kevin1990 | 15:78f3f517417f | 116 | */ |
kevin1990 | 15:78f3f517417f | 117 | do { |
kevin1990 | 15:78f3f517417f | 118 | wait_ms(100); |
kevin1990 | 15:78f3f517417f | 119 | res = adi_sense_GetDeviceReadyState(hDevice, &bDeviceReady); |
kevin1990 | 15:78f3f517417f | 120 | if (res != ADI_SENSE_SUCCESS) |
kevin1990 | 15:78f3f517417f | 121 | { |
kevin1990 | 15:78f3f517417f | 122 | ADI_SENSE_LOG_ERROR("Failed to get device ready-state"); |
kevin1990 | 15:78f3f517417f | 123 | return res; |
kevin1990 | 15:78f3f517417f | 124 | } |
kevin1990 | 15:78f3f517417f | 125 | } while (! bDeviceReady); |
kevin1990 | 15:78f3f517417f | 126 | ADI_SENSE_LOG_INFO("ADI Sense device ready"); |
kevin1990 | 15:78f3f517417f | 127 | |
kevin1990 | 15:78f3f517417f | 128 | /* |
kevin1990 | 15:78f3f517417f | 129 | * Write configuration settings to the device registers. |
kevin1990 | 15:78f3f517417f | 130 | * Settings are not applied until adi_sense_ApplyConfigUpdates() is called. |
kevin1990 | 15:78f3f517417f | 131 | */ |
kevin1990 | 15:78f3f517417f | 132 | ADI_SENSE_LOG_INFO("Setting device configuration"); |
kevin1990 | 15:78f3f517417f | 133 | res = adi_sense_SetConfig(hDevice, pSelectedConfig); |
kevin1990 | 15:78f3f517417f | 134 | if (res != ADI_SENSE_SUCCESS) |
kevin1990 | 15:78f3f517417f | 135 | { |
kevin1990 | 15:78f3f517417f | 136 | ADI_SENSE_LOG_ERROR("Failed to set device configuration"); |
kevin1990 | 15:78f3f517417f | 137 | return res; |
kevin1990 | 15:78f3f517417f | 138 | } |
kevin1990 | 15:78f3f517417f | 139 | res = adi_sense_ApplyConfigUpdates(hDevice); |
kevin1990 | 15:78f3f517417f | 140 | if (res != ADI_SENSE_SUCCESS) |
kevin1990 | 15:78f3f517417f | 141 | { |
kevin1990 | 15:78f3f517417f | 142 | ADI_SENSE_LOG_ERROR("Failed to apply device configuration"); |
kevin1990 | 15:78f3f517417f | 143 | return res; |
kevin1990 | 15:78f3f517417f | 144 | } |
kevin1990 | 15:78f3f517417f | 145 | |
kevin1990 | 15:78f3f517417f | 146 | /* |
kevin1990 | 15:78f3f517417f | 147 | * Kick off the measurement cycle here |
kevin1990 | 15:78f3f517417f | 148 | */ |
kevin1990 | 15:78f3f517417f | 149 | ADI_SENSE_LOG_INFO("Configuration completed, starting measurement cycles"); |
kevin1990 | 15:78f3f517417f | 150 | utils_runMeasurement(hDevice, eMeasurementMode); |
kevin1990 | 15:78f3f517417f | 151 | |
kevin1990 | 15:78f3f517417f | 152 | /* |
kevin1990 | 15:78f3f517417f | 153 | * Clean up and exit |
kevin1990 | 15:78f3f517417f | 154 | */ |
kevin1990 | 15:78f3f517417f | 155 | res = adi_sense_Close(hDevice); |
kevin1990 | 15:78f3f517417f | 156 | if (res != ADI_SENSE_SUCCESS) |
kevin1990 | 15:78f3f517417f | 157 | { |
kevin1990 | 15:78f3f517417f | 158 | ADI_SENSE_LOG_ERROR("Failed to close device instance"); |
kevin1990 | 15:78f3f517417f | 159 | return res; |
kevin1990 | 15:78f3f517417f | 160 | } |
kevin1990 | 15:78f3f517417f | 161 | |
kevin1990 | 15:78f3f517417f | 162 | return 0; |
kevin1990 | 15:78f3f517417f | 163 | } |
kevin1990 | 12:97457cf77bcb | 164 |