Vybhav Kadaba / Mbed OS EV-PRO-MW1001_oct21
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

Go to the documentation of this file.
00001 /*
00002 Copyright 2019 (c) Analog Devices, Inc.
00003 
00004 All rights reserved.
00005 
00006 Redistribution and use in source and binary forms, with or without
00007 modification, are permitted provided that the following conditions are met:
00008   - Redistributions of source code must retain the above copyright
00009     notice, this list of conditions and the following disclaimer.
00010   - Redistributions in binary form must reproduce the above copyright
00011     notice, this list of conditions and the following disclaimer in
00012     the documentation and/or other materials provided with the
00013     distribution.
00014   - Neither the name of Analog Devices, Inc. nor the names of its
00015     contributors may be used to endorse or promote products derived
00016     from this software without specific prior written permission.
00017   - The use of this software may or may not infringe the patent rights
00018     of one or more patent holders. This license does not release you
00019     from the requirement that you obtain separate licenses from these
00020     patent holders to use this software.
00021   - Use of the software either in source or binary form, must be run
00022     on or directly connected to an Analog Devices Inc. component.
00023 
00024 THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR
00025 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT,
00026 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
00027 IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT,
00028 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00029 LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR
00030 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00031 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00032 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00033 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00034 
00035  *****************************************************************************/
00036 /*!
00037  ******************************************************************************
00038  * @file:
00039  *-----------------------------------------------------------------------------
00040  *
00041  */
00042 #include "mbed.h"
00043 #include "admw_api.h"
00044 #include "admw1001/admw1001_api.h"
00045 #include "admw_log.h"
00046 #include "common/utils.h"
00047 #include "common/platform.h"
00048 #include "admw1001/ADMW1001_REGISTERS.h"
00049 
00050 extern ADMW_CONFIG  sensor0_typeK_cjc0_config;
00051 extern ADMW_CONFIG  sensor1_rtd_3w_pt100_config;
00052 extern ADMW_CONFIG  sensor2_typeT_cjc0_config;
00053 extern ADMW_CONFIG  sensor3_typeJ_cjc0_config;
00054 extern ADMW_CONFIG  i2c0_sensirionSHT3X_config;
00055 extern ADMW_CONFIG  multichannel_continuous_config;
00056 extern ADMW_CONFIG  multichannel_singlecycle_config;
00057 extern ADMW_CONFIG  sensor2_bridge_4w_load_cell_config;
00058 extern ADMW_CONFIG  rtd_4w_config;
00059 extern ADMW_CONFIG  config;
00060 /* Change the following pointer to select any of the configurations above */
00061 static ADMW_CONFIG  *pSelectedConfig = &multichannel_continuous_config;
00062 
00063 static ADMW_CONNECTION  connectionInfo = PLATFORM_CONNECTION_INFO;
00064 
00065 
00066 int main()
00067 {
00068     ADMW_RESULT  res;
00069     ADMW_STATUS  status;
00070     ADMW_DEVICE_HANDLE  hDevice;
00071     ADMW_MEASUREMENT_MODE  eMeasurementMode = ADMW_MEASUREMENT_MODE_NORMAL ;
00072     bool bDeviceReady;
00073 
00074     /*
00075      * Open an ADMW1001 device instance.
00076      */
00077     res = admw_Open(0, &connectionInfo, &hDevice);
00078     if (res != ADMW_SUCCESS ) {
00079         ADMW_LOG_ERROR("Failed to open device instance");
00080         return res;
00081     }
00082 
00083     /*
00084      * Reset the given ADMW1001 device....
00085      */
00086     ADMW_LOG_INFO("Resetting ADMW1001 device, please wait...");
00087     res = admw_Reset(hDevice);
00088     if (res != ADMW_SUCCESS ) {
00089         ADMW_LOG_ERROR("Failed to reset device");
00090         return res;
00091     }
00092     /*
00093      * ...and wait until the device is ready.
00094      */
00095     do {
00096         wait_ms(100);
00097         res = admw_GetDeviceReadyState(hDevice, &bDeviceReady);
00098         if (res != ADMW_SUCCESS ) {
00099             ADMW_LOG_ERROR("Failed to get device ready-state");
00100             return res;
00101         }
00102     } while (! bDeviceReady);
00103     ADMW_LOG_INFO("ADMW1001 device ready");
00104     /*
00105      * Write configuration settings to the device registers.
00106      * Settings are not applied until admw_ApplyConfigUpdates() is called.
00107      */
00108     ADMW_LOG_INFO("Setting device configuration");
00109     res = admw_SetConfig(hDevice, pSelectedConfig);
00110     if (res != ADMW_SUCCESS ) {
00111         ADMW_LOG_ERROR("Failed to set device configuration");
00112         return res;
00113     }
00114     res = admw_ApplyConfigUpdates(hDevice);
00115     if (res != ADMW_SUCCESS ) {
00116         ADMW_LOG_ERROR("Failed to apply device configuration");
00117         return res;
00118     }
00119     /*
00120      * Check device status after updating the configuration
00121      */
00122     res = admw_GetStatus(hDevice, &status);
00123     deviceInformation(hDevice);
00124     if (res != ADMW_SUCCESS ) {
00125         ADMW_LOG_ERROR("Failed to retrieve device status");
00126         return res;
00127     }
00128     if (status.deviceStatus  &
00129             (ADMW_DEVICE_STATUS_ERROR  | ADMW_DEVICE_STATUS_ALERT )) {
00130         utils_printStatus(&status);
00131     }
00132 
00133     /*
00134      * Kick off the measurement cycle here
00135      */
00136     ADMW_LOG_INFO("Configuration completed, starting measurement cycles");
00137     utils_runMeasurement(hDevice, eMeasurementMode);
00138 
00139     /*
00140      * Clean up and exit
00141      */
00142     res = admw_Close(hDevice);
00143     if (res != ADMW_SUCCESS ) {
00144         ADMW_LOG_ERROR("Failed to close device instance");
00145         return res;
00146     }
00147 
00148     return 0;
00149 }
00150