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