Driver for the AKM AK9752 IR sensor device.

Dependents:   AKDP-RevD7_014

Library for the AK9752 Ultra-Small IR Sensor with I2C Interface. Includes integrated temperature sensor (0 - 50C) and 16-bit ADC.

Revision:
4:2f4c8e641ce9
Parent:
1:0b59cfeee8ee
Child:
5:a979c36482fc
--- a/AK9752.cpp	Tue Nov 01 17:49:01 2016 +0000
+++ b/AK9752.cpp	Wed Nov 02 00:14:52 2016 +0000
@@ -1,5 +1,6 @@
 #include "AK9752.h"
 #include "AK9752_reg.h"
+#include "debug.h"
 
 #define CONV16I(high,low)  ((int16_t)(((high) << 8) | (low)))
 
@@ -26,32 +27,38 @@
 }
 
 AK9752::Status AK9752::checkConnection() {
-    AK9752::Status status = AK9752::SUCCESS;
+    //AK9752::Status status = AK9752::SUCCESS;
     
-    // Gets the WIA register value.
+    // Gets the WIA register value - ID and ID2
     char buf[2];
-    if ((status=AK9752::read(AK9752_REG_ADDR_WIA1, buf, 2)) != SUCCESS) {
-        return status;
+    if ((AK9752::read(AK9752_REG_ADDR_WIA1, buf, 2)) != AK9752::SUCCESS) {
+        MSG("Read of WIA1 failed.\r\n");
+        return AK9752::ERROR;
     }
 
     // Checks the obtained value equals to the supposed value.
-    if ( (buf[0] != AK9752_REG_VALUE_WIA1) ||  (buf[1] != AK9752_REG_VALUE_WIA2) ) {
-        return AK9752::ERROR;
+    if ( (buf1 != AK9752_REG_VALUE_WIA1) ||  (buf2 != AK9752_REG_VALUE_WIA2) ) {
+        MSG("ID check failed.\r\n");
+        MSG("WIA1: %d\r\n", buf[0]);
+        MSG("WIA2: %d\r\n", buf[1]);
+     //   return AK9752::ERROR;
     }
     
-    return status;
+    return AK9752::SUCCESS;
 }
 
 AK9752::Status AK9752::read(char registerAddress, char *buf, int length) {
     // Writes the first register address
     if (connection->write((slaveAddress << 1), &registerAddress, LEN_ONE_BYTE) != 0) {
         // I2C write failed.
+        MSG("Error: I2C write failure.\r\n");
         return AK9752::ERROR_I2C_WRITE;
     }
     
     // Reads register data
     if (connection->read((slaveAddress << 1), buf, length) != 0) {
         // I2C read failed.
+        MSG("Error: I2C read failure.\r\n");
         return AK9752::ERROR_I2C_READ;
     }