Temperature (cjc0, sensor0) Humidity I2C_0 Accelerometer SPI_0
Fork of ADISense1000_Example_FW by
main.cpp@1:982f6f565e14, 2018-08-24 (annotated)
- Committer:
- nfathurr
- Date:
- Fri Aug 24 09:01:59 2018 +0000
- Revision:
- 1:982f6f565e14
- Parent:
- 0:76fed7dd9235
Prosiwft with Temperature, Humidity, and Accelerometer
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
seanwilson10 | 0:76fed7dd9235 | 1 | /* |
seanwilson10 | 0:76fed7dd9235 | 2 | ****************************************************************************** |
seanwilson10 | 0:76fed7dd9235 | 3 | * file: main.cpp |
seanwilson10 | 0:76fed7dd9235 | 4 | *----------------------------------------------------------------------------- |
seanwilson10 | 0:76fed7dd9235 | 5 | * |
seanwilson10 | 0:76fed7dd9235 | 6 | Copyright 2017 (c) Analog Devices, Inc. |
seanwilson10 | 0:76fed7dd9235 | 7 | |
seanwilson10 | 0:76fed7dd9235 | 8 | All rights reserved. |
seanwilson10 | 0:76fed7dd9235 | 9 | |
seanwilson10 | 0:76fed7dd9235 | 10 | Redistribution and use in source and binary forms, with or without |
seanwilson10 | 0:76fed7dd9235 | 11 | modification, are permitted provided that the following conditions are met: |
seanwilson10 | 0:76fed7dd9235 | 12 | - Redistributions of source code must retain the above copyright |
seanwilson10 | 0:76fed7dd9235 | 13 | notice, this list of conditions and the following disclaimer. |
seanwilson10 | 0:76fed7dd9235 | 14 | - Redistributions in binary form must reproduce the above copyright |
seanwilson10 | 0:76fed7dd9235 | 15 | notice, this list of conditions and the following disclaimer in |
seanwilson10 | 0:76fed7dd9235 | 16 | the documentation and/or other materials provided with the |
seanwilson10 | 0:76fed7dd9235 | 17 | distribution. |
seanwilson10 | 0:76fed7dd9235 | 18 | - Neither the name of Analog Devices, Inc. nor the names of its |
seanwilson10 | 0:76fed7dd9235 | 19 | contributors may be used to endorse or promote products derived |
seanwilson10 | 0:76fed7dd9235 | 20 | from this software without specific prior written permission. |
seanwilson10 | 0:76fed7dd9235 | 21 | - The use of this software may or may not infringe the patent rights |
seanwilson10 | 0:76fed7dd9235 | 22 | of one or more patent holders. This license does not release you |
seanwilson10 | 0:76fed7dd9235 | 23 | from the requirement that you obtain separate licenses from these |
seanwilson10 | 0:76fed7dd9235 | 24 | patent holders to use this software. |
seanwilson10 | 0:76fed7dd9235 | 25 | - Use of the software either in source or binary form, must be run |
seanwilson10 | 0:76fed7dd9235 | 26 | on or directly connected to an Analog Devices Inc. component. |
seanwilson10 | 0:76fed7dd9235 | 27 | |
seanwilson10 | 0:76fed7dd9235 | 28 | THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR |
seanwilson10 | 0:76fed7dd9235 | 29 | IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT, |
seanwilson10 | 0:76fed7dd9235 | 30 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
seanwilson10 | 0:76fed7dd9235 | 31 | IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT, |
seanwilson10 | 0:76fed7dd9235 | 32 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
seanwilson10 | 0:76fed7dd9235 | 33 | LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR |
seanwilson10 | 0:76fed7dd9235 | 34 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
seanwilson10 | 0:76fed7dd9235 | 35 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
seanwilson10 | 0:76fed7dd9235 | 36 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
seanwilson10 | 0:76fed7dd9235 | 37 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
seanwilson10 | 0:76fed7dd9235 | 38 | * |
seanwilson10 | 0:76fed7dd9235 | 39 | *****************************************************************************/ |
seanwilson10 | 0:76fed7dd9235 | 40 | #include "mbed.h" |
seanwilson10 | 0:76fed7dd9235 | 41 | #include "inc/adi_sense_api.h" |
seanwilson10 | 0:76fed7dd9235 | 42 | #include "inc/adi_sense_log.h" |
seanwilson10 | 0:76fed7dd9235 | 43 | #include "common/utils.h" |
seanwilson10 | 0:76fed7dd9235 | 44 | |
seanwilson10 | 0:76fed7dd9235 | 45 | extern ADI_SENSE_CONFIG config; |
seanwilson10 | 0:76fed7dd9235 | 46 | |
nfathurr | 1:982f6f565e14 | 47 | ADI_SENSE_RESULT res; |
nfathurr | 1:982f6f565e14 | 48 | ADI_SENSE_DEVICE_HANDLE hDevice; |
nfathurr | 1:982f6f565e14 | 49 | ADI_SENSE_MEASUREMENT_MODE eMeasurementMode = ADI_SENSE_MEASUREMENT_MODE_NORMAL; |
nfathurr | 1:982f6f565e14 | 50 | bool_t bDeviceReady; |
nfathurr | 1:982f6f565e14 | 51 | |
seanwilson10 | 0:76fed7dd9235 | 52 | /* Change the following pointer to select any of the configurations above */ |
seanwilson10 | 0:76fed7dd9235 | 53 | static ADI_SENSE_CONFIG *pSelectedConfig = &config; |
seanwilson10 | 0:76fed7dd9235 | 54 | |
seanwilson10 | 0:76fed7dd9235 | 55 | static ADI_SENSE_CONNECTION connectionInfo = { |
seanwilson10 | 0:76fed7dd9235 | 56 | .type = ADI_SENSE_CONNECTION_TYPE_SPI, |
seanwilson10 | 0:76fed7dd9235 | 57 | .spi = { |
seanwilson10 | 0:76fed7dd9235 | 58 | .mosiPin = SPI_MOSI, |
seanwilson10 | 0:76fed7dd9235 | 59 | .misoPin = SPI_MISO, |
seanwilson10 | 0:76fed7dd9235 | 60 | .sckPin = SPI_SCK, |
seanwilson10 | 0:76fed7dd9235 | 61 | .csPin = D10, |
seanwilson10 | 0:76fed7dd9235 | 62 | .maxSpeedHz = 2000000, |
seanwilson10 | 0:76fed7dd9235 | 63 | }, |
seanwilson10 | 0:76fed7dd9235 | 64 | .gpio = { |
seanwilson10 | 0:76fed7dd9235 | 65 | .resetPin = D6, |
seanwilson10 | 0:76fed7dd9235 | 66 | .errorPin = D3, |
seanwilson10 | 0:76fed7dd9235 | 67 | .alertPin = D4, |
seanwilson10 | 0:76fed7dd9235 | 68 | .datareadyPin = D5, |
seanwilson10 | 0:76fed7dd9235 | 69 | }, |
seanwilson10 | 0:76fed7dd9235 | 70 | }; |
seanwilson10 | 0:76fed7dd9235 | 71 | |
nfathurr | 1:982f6f565e14 | 72 | uint8_t adisense1000_boot(void) |
seanwilson10 | 0:76fed7dd9235 | 73 | { |
nfathurr | 1:982f6f565e14 | 74 | bool_t bDeviceReady; |
seanwilson10 | 0:76fed7dd9235 | 75 | |
seanwilson10 | 0:76fed7dd9235 | 76 | res = adi_sense_Open(0, &connectionInfo, &hDevice); |
seanwilson10 | 0:76fed7dd9235 | 77 | if (res != ADI_SENSE_SUCCESS) |
seanwilson10 | 0:76fed7dd9235 | 78 | { |
seanwilson10 | 0:76fed7dd9235 | 79 | ADI_SENSE_LOG_ERROR("Failed to open device instance"); |
seanwilson10 | 0:76fed7dd9235 | 80 | return res; |
seanwilson10 | 0:76fed7dd9235 | 81 | } |
seanwilson10 | 0:76fed7dd9235 | 82 | |
seanwilson10 | 0:76fed7dd9235 | 83 | ADI_SENSE_LOG_INFO("Resetting ADI Sense device, please wait..."); |
seanwilson10 | 0:76fed7dd9235 | 84 | res = adi_sense_Reset(hDevice); |
seanwilson10 | 0:76fed7dd9235 | 85 | if (res != ADI_SENSE_SUCCESS) |
seanwilson10 | 0:76fed7dd9235 | 86 | { |
seanwilson10 | 0:76fed7dd9235 | 87 | ADI_SENSE_LOG_ERROR("Failed to reset device"); |
seanwilson10 | 0:76fed7dd9235 | 88 | return res; |
seanwilson10 | 0:76fed7dd9235 | 89 | } |
nfathurr | 1:982f6f565e14 | 90 | |
seanwilson10 | 0:76fed7dd9235 | 91 | do { |
seanwilson10 | 0:76fed7dd9235 | 92 | wait_ms(100); |
seanwilson10 | 0:76fed7dd9235 | 93 | res = adi_sense_GetDeviceReadyState(hDevice, &bDeviceReady); |
seanwilson10 | 0:76fed7dd9235 | 94 | if (res != ADI_SENSE_SUCCESS) |
seanwilson10 | 0:76fed7dd9235 | 95 | { |
seanwilson10 | 0:76fed7dd9235 | 96 | ADI_SENSE_LOG_ERROR("Failed to get device ready-state"); |
seanwilson10 | 0:76fed7dd9235 | 97 | return res; |
seanwilson10 | 0:76fed7dd9235 | 98 | } |
seanwilson10 | 0:76fed7dd9235 | 99 | } while (! bDeviceReady); |
seanwilson10 | 0:76fed7dd9235 | 100 | ADI_SENSE_LOG_INFO("ADI Sense device ready"); |
seanwilson10 | 0:76fed7dd9235 | 101 | |
seanwilson10 | 0:76fed7dd9235 | 102 | ADI_SENSE_LOG_INFO("Setting device configuration"); |
seanwilson10 | 0:76fed7dd9235 | 103 | res = adi_sense_SetConfig(hDevice, pSelectedConfig); |
seanwilson10 | 0:76fed7dd9235 | 104 | if (res != ADI_SENSE_SUCCESS) |
seanwilson10 | 0:76fed7dd9235 | 105 | { |
seanwilson10 | 0:76fed7dd9235 | 106 | ADI_SENSE_LOG_ERROR("Failed to set device configuration"); |
seanwilson10 | 0:76fed7dd9235 | 107 | return res; |
seanwilson10 | 0:76fed7dd9235 | 108 | } |
seanwilson10 | 0:76fed7dd9235 | 109 | res = adi_sense_ApplyConfigUpdates(hDevice); |
seanwilson10 | 0:76fed7dd9235 | 110 | if (res != ADI_SENSE_SUCCESS) |
seanwilson10 | 0:76fed7dd9235 | 111 | { |
seanwilson10 | 0:76fed7dd9235 | 112 | ADI_SENSE_LOG_ERROR("Failed to apply device configuration"); |
seanwilson10 | 0:76fed7dd9235 | 113 | return res; |
seanwilson10 | 0:76fed7dd9235 | 114 | } |
seanwilson10 | 0:76fed7dd9235 | 115 | return 0; |
seanwilson10 | 0:76fed7dd9235 | 116 | } |
seanwilson10 | 0:76fed7dd9235 | 117 | |
nfathurr | 1:982f6f565e14 | 118 | void blink_led() |
nfathurr | 1:982f6f565e14 | 119 | { |
nfathurr | 1:982f6f565e14 | 120 | DigitalOut led1(LED1); |
nfathurr | 1:982f6f565e14 | 121 | int i=0; |
nfathurr | 1:982f6f565e14 | 122 | for(i=0; i<10; i++) { |
nfathurr | 1:982f6f565e14 | 123 | led1 = !led1; |
nfathurr | 1:982f6f565e14 | 124 | wait(0.5); |
nfathurr | 1:982f6f565e14 | 125 | } |
nfathurr | 1:982f6f565e14 | 126 | } |
nfathurr | 1:982f6f565e14 | 127 | |
nfathurr | 1:982f6f565e14 | 128 | int main() |
nfathurr | 1:982f6f565e14 | 129 | { |
nfathurr | 1:982f6f565e14 | 130 | wait(0.5); |
nfathurr | 1:982f6f565e14 | 131 | blink_led(); |
nfathurr | 1:982f6f565e14 | 132 | |
nfathurr | 1:982f6f565e14 | 133 | adisense1000_boot(); |
nfathurr | 1:982f6f565e14 | 134 | ADI_SENSE_LOG_INFO("Configuration Set Success"); |
nfathurr | 1:982f6f565e14 | 135 | wait(0.5); |
nfathurr | 1:982f6f565e14 | 136 | |
nfathurr | 1:982f6f565e14 | 137 | ADI_SENSE_LOG_INFO("~ Get Data\n\r"); |
nfathurr | 1:982f6f565e14 | 138 | |
nfathurr | 1:982f6f565e14 | 139 | //temp_comp temp pressure himidity AccX AccY AccZ |
nfathurr | 1:982f6f565e14 | 140 | |
nfathurr | 1:982f6f565e14 | 141 | ADI_SENSE_LOG_INFO("tc_raw\ttc_pro\tt_raw\tt_pro\tp_raw\tp_pro\th_raw\th_pro\tax_raw\tax_pro\tay_raw\tay_pro\taz_raw\taz_pro"); |
nfathurr | 1:982f6f565e14 | 142 | //ADI_SENSE_LOG_INFO("tc_pro t_pro h_pro ax_pro ay_pro az_pro"); |
nfathurr | 1:982f6f565e14 | 143 | |
nfathurr | 1:982f6f565e14 | 144 | utils_runMeasurement(hDevice, eMeasurementMode); |
nfathurr | 1:982f6f565e14 | 145 | |
nfathurr | 1:982f6f565e14 | 146 | } |
nfathurr | 1:982f6f565e14 | 147 |