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