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