(working) Use this code for calibrating the Load cells.

Fork of ADISense1000_Example_FW by Analog Devices

Revision:
2:2f9f9f7f0243
Parent:
0:76fed7dd9235
--- a/main.cpp	Wed Jul 18 11:40:48 2018 +0000
+++ b/main.cpp	Thu Jul 19 13:25:33 2018 +0000
@@ -43,10 +43,14 @@
 #include "inc/adi_sense_log.h"
 #include "common/utils.h"
 
-extern ADI_SENSE_CONFIG config;
+extern ADI_SENSE_CONFIG sensor2_bridge_6w_pressure_config;
+
+extern ADI_SENSE_1000_LUT_DESCRIPTOR *sample_lut_desc_list[];
+extern ADI_SENSE_1000_LUT_TABLE_DATA *sample_lut_data_list[];
+extern unsigned                       sample_lut_num_tables;
 
 /* Change the following pointer to select any of the configurations above */
-static ADI_SENSE_CONFIG *pSelectedConfig = &config;
+static ADI_SENSE_CONFIG *pSelectedConfig = &sensor2_bridge_6w_pressure_config;
 
 static ADI_SENSE_CONNECTION connectionInfo = {
     .type = ADI_SENSE_CONNECTION_TYPE_SPI,
@@ -117,13 +121,51 @@
         ADI_SENSE_LOG_ERROR("Failed to set device configuration");
         return res;
     }
+   
+
+    /*
+     * Assemble the list of user-defined Look-Up Tables from sample_lut_data.c
+     * into the single contiguous data format required by the device.
+     */
+    unsigned lutBufferSize = ADI_SENSE_LUT_MAX_SIZE;
+    ADI_SENSE_1000_LUT *pLutBuffer = (ADI_SENSE_1000_LUT *) ::operator new (lutBufferSize);
+    if (pLutBuffer == NULL)
+    {
+        ADI_SENSE_LOG_ERROR("Failed to allocate memory for user-defined LUT data buffer");
+        return ADI_SENSE_NO_MEM;
+    }
+
+    ADI_SENSE_LOG_INFO("Assembling LUT data");
+    res = adi_sense_1000_AssembleLutData(pLutBuffer, lutBufferSize,
+                                         sample_lut_num_tables,
+                                         sample_lut_desc_list,
+                                         sample_lut_data_list);
+    if (res != ADI_SENSE_SUCCESS)
+    {
+        ADI_SENSE_LOG_ERROR("Failed to assemble user-defined LUT data");
+        return res;
+    }
+
+    /*
+     * Write assembled user-defined Look-Up Table data structure to the device
+     * User-defined LUT data is not applied until adi_sense_ApplyConfigUpdates() is called.
+     */
+    ADI_SENSE_LOG_INFO("Setting LUT data");
+    res = adi_sense_1000_SetLutData(hDevice, pLutBuffer);
+    if (res != ADI_SENSE_SUCCESS)
+    {
+        ADI_SENSE_LOG_ERROR("Failed to set user-defined LUT data");
+        return res;
+    }
+
+    delete pLutBuffer;
+    
     res = adi_sense_ApplyConfigUpdates(hDevice);
     if (res != ADI_SENSE_SUCCESS)
     {
         ADI_SENSE_LOG_ERROR("Failed to apply device configuration");
         return res;
     }
-
     /*
      * Kick off the measurement cycle here
      */