Vybhav Kadaba / Mbed OS EV-PRO-MW1001_testing
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  thermocouple_typeK_cjc0_config;
00051 extern ADMW_CONFIG  thermocouple_typeT_cjc0_config;
00052 extern ADMW_CONFIG  thermocouple_typeJ_cjc0_config;
00053 extern ADMW_CONFIG  rtd_3w_pt100_config;
00054 extern ADMW_CONFIG  rtd_4w_config;
00055 extern ADMW_CONFIG  bridge_4w_load_cell_config;
00056 extern ADMW_CONFIG  multichannel_continuous_config;
00057 extern ADMW_CONFIG  multichannel_singlecycle_config;
00058 extern ADMW_CONFIG  i2c0_sensirionSHT3X_config;
00059 
00060 /* Use the following config if adding a configuration file from measureware designer*/
00061 extern ADMW_CONFIG  measureware_config;
00062 
00063 /* Change the following pointer to load or change the configurations  */
00064 static ADMW_CONFIG  *pSelectedConfig = &thermocouple_typeK_cjc0_config;
00065 
00066 static ADMW_CONNECTION  connectionInfo = PLATFORM_CONNECTION_INFO;
00067 
00068 
00069 int main()
00070 {
00071 
00072     ADMW_RESULT  res;
00073     ADMW_STATUS  status;
00074     ADMW_DEVICE_HANDLE  hDevice;
00075     ADMW_MEASUREMENT_MODE  eMeasurementMode = ADMW_MEASUREMENT_MODE_NORMAL ;
00076     bool bDeviceReady;
00077 
00078     /*
00079      * Open an ADMW1001 device instance.
00080      */
00081     res = admw_Open(0, &connectionInfo, &hDevice);
00082     if (res != ADMW_SUCCESS ) {
00083         ADMW_LOG_ERROR("Failed to open device instance");
00084         return res;
00085     }
00086 
00087     /*
00088      * Reset the given ADMW1001 device....
00089      */
00090     ADMW_LOG_INFO("Resetting ADMW1001 device, please wait...");
00091     res = admw_Reset(hDevice);
00092     if (res != ADMW_SUCCESS ) {
00093         ADMW_LOG_ERROR("Failed to reset device");
00094         return res;
00095     }
00096     /*
00097      * ...and wait until the device is ready.
00098      */
00099     do {
00100         wait_ms(100);
00101         res = admw_GetDeviceReadyState(hDevice, &bDeviceReady);
00102         if (res != ADMW_SUCCESS ) {
00103             ADMW_LOG_ERROR("Failed to get device ready-state");
00104             return res;
00105         }
00106     } while (! bDeviceReady);
00107     ADMW_LOG_INFO("ADMW1001 device ready");
00108     /*
00109      * Write configuration settings to the device registers.
00110      * Settings are not applied until admw_ApplyConfigUpdates() is called.
00111      */
00112     ADMW_LOG_INFO("Setting device configuration");
00113     res = admw_SetConfig(hDevice, pSelectedConfig);
00114     if (res != ADMW_SUCCESS ) {
00115         ADMW_LOG_ERROR("Failed to set device configuration");
00116         return res;
00117     }
00118     res = admw_ApplyConfigUpdates(hDevice);
00119     if (res != ADMW_SUCCESS ) {
00120         ADMW_LOG_ERROR("Failed to apply device configuration");
00121         return res;
00122     }
00123     /*
00124      * Check device status after updating the configuration
00125      */
00126     res = admw_GetStatus(hDevice, &status);
00127     admw_deviceInformation(hDevice);
00128     if (res != ADMW_SUCCESS ) {
00129         ADMW_LOG_ERROR("Failed to retrieve device status");
00130         return res;
00131     }
00132     if (status.deviceStatus  &
00133             (ADMW_DEVICE_STATUS_ERROR  | ADMW_DEVICE_STATUS_ALERT )) {
00134         utils_printStatus(&status);
00135     }
00136 
00137     /*
00138      * Kick off the measurement cycle here
00139      */
00140     ADMW_LOG_INFO("Configuration completed, starting measurement cycles");
00141     utils_runMeasurement(hDevice, eMeasurementMode);
00142 
00143     /*
00144      * Clean up and exit
00145      */
00146     res = admw_Close(hDevice);
00147     if (res != ADMW_SUCCESS ) {
00148         ADMW_LOG_ERROR("Failed to close device instance");
00149         return res;
00150     }
00151 
00152     return 0;
00153 }
00154