Ross O'Halloran / Mbed OS AdiSense1000_SmartBabySeat

Fork of AdiSense1000_SmartBabySeat by SDMP_IOT

Branch:
v2.0
Revision:
30:119ff4f3aef6
Parent:
29:57edca10d78c
Child:
31:de49744b57a6
--- a/common/utils.c	Tue May 22 13:45:24 2018 +0100
+++ b/common/utils.c	Tue Jun 12 21:27:34 2018 +0100
@@ -101,6 +101,14 @@
                     ADI_SENSE_LOG_INFO("\t\t\tOver Look-Up Table Range alert detected");
             }
         }
+
+        if ((pStatus->deviceStatus & ADI_SENSE_DEVICE_STATUS_ERROR) ||
+            (pStatus->deviceStatus & ADI_SENSE_DEVICE_STATUS_ALERT))
+        {
+            ADI_SENSE_LOG_INFO("\t\tLast Debug Code: %u-%u",
+                               (pStatus->debugCode >> 16) & 0xFFFF,
+                               (pStatus->debugCode >> 0) & 0xFFFF);
+        }
     }
 }
 
@@ -138,17 +146,18 @@
 
 static void gpioCallbackFn(ADI_SENSE_GPIO_PIN ePinId, void * pArg)
 {
-    volatile bool_t *pbFlag = (volatile bool_t *)pArg;
+    volatile bool *pbFlag = (volatile bool *)pArg;
     *pbFlag = true;
 }
 
 ADI_SENSE_RESULT utils_registerCallbacks(
     ADI_SENSE_DEVICE_HANDLE hDevice,
-    volatile bool_t *pbDataReady,
-    volatile bool_t *pbError,
-    volatile bool_t *pbAlert)
+    volatile bool *pbDataReady,
+    volatile bool *pbError,
+    volatile bool *pbAlert)
 {
     ADI_SENSE_RESULT res;
+    bool state;
 
     res = adi_sense_RegisterGpioCallback(hDevice, ADI_SENSE_GPIO_PIN_DATAREADY,
                                          gpioCallbackFn, (void *)pbDataReady);
@@ -158,6 +167,17 @@
         return res;
     }
 
+    res = adi_sense_GetGpioState(hDevice, ADI_SENSE_GPIO_PIN_ERROR, &state);
+    if (res != ADI_SENSE_SUCCESS)
+    {
+        ADI_SENSE_LOG_ERROR("Failed to get current ERROR state");
+        return res;
+    }
+    if (state)
+    {
+        ADI_SENSE_LOG_ERROR("ERROR signal already asserted");
+        return ADI_SENSE_FAILURE;
+    }
     res = adi_sense_RegisterGpioCallback(hDevice, ADI_SENSE_GPIO_PIN_ERROR,
                                          gpioCallbackFn, (void *)pbError);
     if (res != ADI_SENSE_SUCCESS)
@@ -166,6 +186,17 @@
         return res;
     }
 
+    res = adi_sense_GetGpioState(hDevice, ADI_SENSE_GPIO_PIN_ALERT, &state);
+    if (res != ADI_SENSE_SUCCESS)
+    {
+        ADI_SENSE_LOG_ERROR("Failed to get current ALERT state");
+        return res;
+    }
+    if (state)
+    {
+        ADI_SENSE_LOG_ERROR("ALERT signal already asserted");
+        return ADI_SENSE_FAILURE;
+    }
     res = adi_sense_RegisterGpioCallback(hDevice, ADI_SENSE_GPIO_PIN_ALERT,
                                          gpioCallbackFn, (void *)pbAlert);
     if (res != ADI_SENSE_SUCCESS)
@@ -215,9 +246,9 @@
 {
     ADI_SENSE_RESULT res;
 
-    volatile bool_t bDataReady = false;
-    volatile bool_t bError = false;
-    volatile bool_t bAlert = false;
+    volatile bool bDataReady = false;
+    volatile bool bError = false;
+    volatile bool bAlert = false;
     res = utils_registerCallbacks(hDevice, &bDataReady, &bError, &bAlert);
     if (res != ADI_SENSE_SUCCESS)
         return res;
@@ -256,6 +287,7 @@
     /*
      * Kick off the measurement cycle(s) here
      */
+    ADI_SENSE_LOG_INFO("Starting measurement");
     res = adi_sense_StartMeasurement(hDevice, eMeasurementMode);
     if (res != ADI_SENSE_SUCCESS)
     {
@@ -267,10 +299,10 @@
      * Loop continuously unless operating mode is single-cycle
      */
     uint32_t nSampleCount = 0;
+    uint32_t nReturned;
     while (true)
     {
         ADI_SENSE_STATUS status;
-        uint32_t nReturned;
 
         /*
          * Wait until the next batch of 1 or more samples is ready, continuously
@@ -357,7 +389,7 @@
              * will de-assert in this mode when the measurement command has
              * completed a single cycle.
              */
-            bool_t bCommandRunning;
+            bool bCommandRunning;
             res = adi_sense_GetCommandRunningState(hDevice, &bCommandRunning);
             if (res != ADI_SENSE_SUCCESS)
             {
@@ -370,6 +402,7 @@
         }
     }
 
+    ADI_SENSE_LOG_INFO("Stopping measurement");
     res = adi_sense_StopMeasurement(hDevice);
     if (res != ADI_SENSE_SUCCESS)
     {