Modified for compatibility with Rev.E. hardware

Fork of AkmSensor by AKM Development Platform

Revision:
11:cef8dc1cf010
Parent:
10:5c69b067d88a
Child:
13:d008249f0359
--- a/ak9750ctrl.cpp	Fri Jul 08 22:26:26 2016 +0000
+++ b/ak9750ctrl.cpp	Fri Jul 22 22:54:11 2016 +0000
@@ -55,68 +55,68 @@
         }
     }
     if(foundSensor != true){
-        MSG("#Failed to checkConnection AK9750.\n");
+        MSG("#Failed to checkConnection AK9750.\r\n");
         return AkmSensor::ERROR;
     }
     
     // reset
     if (ak9750->reset() != AK9750::SUCCESS) {
-        MSG("#Failed to reset AK9750.\n");
+        MSG("#Failed to reset AK9750.\r\n");
     }
     
     // Set to EEPROM mode to EEPROM access
     if(ak9750->setOperationMode(AK9750::MODE_EEPROM_ACCESS, AK9750::DF_0P3HZ) != AK9750::SUCCESS) {
-        MSG("#Error setOperationMode to EEPROM mode. AK9750.\n");
+        MSG("#Error setOperationMode to EEPROM mode. AK9750.\r\n");
         return AkmSensor::ERROR;
     }
     // Gets threshold from EEPROM
     AK9750::Threshold th;
     if (ak9750->getThresholdFromEEPROM(&th) != AK9750::SUCCESS) {
-        MSG("#Failed to get threshold from EEPROM AK9750.\n");
+        MSG("#Failed to get threshold from EEPROM AK9750.\r\n");
     }
     // Gets hysteresis from EEPROM
     AK9750::Hysteresis hys;
     if (ak9750->getHysteresisFromEEPROM(&hys) != AK9750::SUCCESS) {
-        MSG("#Failed to get hysteresis from EEPROM AK9750.\n");
+        MSG("#Failed to get hysteresis from EEPROM AK9750.\r\n");
     }
     // Gets interrupt status from EEPROM
     AK9750::InterruptStatus intStatus;
     if ((ak9750->getInterruptEnableFromEEPROM(&intStatus)) != AK9750::SUCCESS) {
-        MSG("#Failed to get interrupts of AK9750 from EEPROM.\n");
+        MSG("#Failed to get interrupts of AK9750 from EEPROM.\r\n");
     }
 
     // Gets operation mode from EEPROM
     if ((ak9750->getOperationModeFromEEPROM(&mode,&filter)) != AK9750::SUCCESS) {
-        MSG("#Failed to get operation mode of AK9750 from EEPROM.\n");
+        MSG("#Failed to get operation mode of AK9750 from EEPROM.\r\n");
     }
-    MSG("#Operation Mode:(0x%02X,0x%02X)\n",mode, filter);
+    MSG("#Operation Mode:(0x%02X,0x%02X)\r\n",mode, filter);
     
     // Back to Stand-by Mode for register access
     if(ak9750->setOperationMode(AK9750::MODE_STANDBY, filter) != AK9750::SUCCESS) {
-        MSG("#Error setOperationMode to stand-by mode of AK9750.\n");
+        MSG("#Error setOperationMode to stand-by mode of AK9750.\r\n");
         return AkmSensor::ERROR;
     }
     
     // Sets threshold from the red EEPROM values
     if (ak9750->setThreshold(&th) != AK9750::SUCCESS) {
-        MSG("#Failed to set threshold to AK9750.\n");
+        MSG("#Failed to set threshold to AK9750.\r\n");
     }
-    MSG("#Threshold:(0x%02X,0x%02X,0x%02X,0x%02X)\n",th.eth13h,th.eth13l,th.eth24h,th.eth24l);
+    MSG("#Threshold:(0x%02X,0x%02X,0x%02X,0x%02X)\r\n",th.eth13h,th.eth13l,th.eth24h,th.eth24l);
 
     // Sets hysteresis from the red EEPROM values
     if (ak9750->setHysteresis(&hys) != AK9750::SUCCESS) {
-        MSG("#Failed to set hysteresis to AK9750.\n");
+        MSG("#Failed to set hysteresis to AK9750.\r\n");
     }
-    MSG("#Hysteresis:(0x%02X,0x%02X)\n",hys.ehys13,hys.ehys24);
+    MSG("#Hysteresis:(0x%02X,0x%02X)\r\n",hys.ehys13,hys.ehys24);
     
     // Sets interruput status from the red EEPROM values
     AK9750::Status status = ak9750->setInterruptEnable(&intStatus);
     if (status != AK9750::SUCCESS) {
-        MSG("#Failed to set interrupts of AK9750. Status = 0x%02X\n", status);
+        MSG("#Failed to set interrupts of AK9750. Status = 0x%02X\r\n", status);
     }
-    MSG("#Interrupt:(0x%02X,0x%02X,0x%02X,0x%02X,0x%02X)\n",intStatus.ir13h,intStatus.ir13l,intStatus.ir24h,intStatus.ir24l,intStatus.drdy);
+    MSG("#Interrupt:(0x%02X,0x%02X,0x%02X,0x%02X,0x%02X)\r\n",intStatus.ir13h,intStatus.ir13l,intStatus.ir24h,intStatus.ir24l,intStatus.drdy);
     
-    MSG("#Init success AK9750.\n");
+    MSG("#Init success AK9750.\r\n");
     return AkmSensor::SUCCESS;
 }
 
@@ -129,13 +129,20 @@
 }
 
 AkmSensor::Status Ak9750Ctrl::startSensor(){
+    // read one data to clear INT pin
+    AK9750::SensorData data;
+    ak9750->getSensorData(&data);
+
+    // enable interrupt
+    interrupt->fall(this, &Ak9750Ctrl::detectINT);
+
+    // set operation mode
     if(ak9750->setOperationMode(mode,filter) != AK9750::SUCCESS) {
-        MSG("#Error setOperationMode. AK9750.\n");
+        MSG("#Start sensor failed.\r\n");
         return AkmSensor::ERROR;
     }
-
-    interrupt->fall(this, &Ak9750Ctrl::detectINT);
-    MSG("#Start Sensor success AK9750.\n");
+    
+    MSG("#Start sensor succceeded.\r\n");
     return AkmSensor::SUCCESS;
 }
 
@@ -146,15 +153,15 @@
 
 AkmSensor::Status Ak9750Ctrl::stopSensor(){
     event = false;
-    interrupt->fall(0);
+    interrupt->fall(NULL);
     if(ak9750->setOperationMode(AK9750::MODE_STANDBY, filter) != AK9750::SUCCESS) {
-        MSG("#Error setOperationMode. AK9750.\n");
+        MSG("#Error setOperationMode. AK9750.\r\n");
         return AkmSensor::ERROR;
     }
     
     // read one data to clear INT pin
-    Message msg;
-    Ak9750Ctrl::readSensorData(&msg);
+    AK9750::SensorData data;
+    ak9750->getSensorData(&data);
     
     return AkmSensor::SUCCESS;
 }
@@ -165,7 +172,7 @@
     AK9750::SensorData data;
     AK9750::Status status = ak9750->getSensorData(&data);
     if( status != AK9750::SUCCESS){
-        MSG("#Error getSensorData. AK9750.\n");
+        MSG("#Error getSensorData. AK9750.\r\n");
         return AkmSensor::ERROR;
     }
     msg->setCommand(Message::CMD_START_MEASUREMENT);
@@ -203,7 +210,7 @@
         {
             if (ak9750->getThreshold(&th) != AK9750::SUCCESS) {
                 status =  AkmSensor::ERROR;
-                MSG("#Failed to set threshold to AK9750.\n");
+                MSG("#Failed to set threshold to AK9750.\r\n");
             }
             out->setArgument(0,(char)((int32_t)(th.eth13h) >> 8));
             out->setArgument(1,(char)((int32_t)(th.eth13h) & 0x00FF));
@@ -223,7 +230,7 @@
             th.eth24l = CONV16I(in->getArgument(6), in->getArgument(7));
             if (ak9750->setThreshold(&th) != AK9750::SUCCESS) {
                 status =  AkmSensor::ERROR;
-                MSG("#Failed to set threshold to AK9750.\n");
+                MSG("#Failed to set threshold to AK9750.\r\n");
             }
             out->setArgument(0,(char)status);
             break;
@@ -232,7 +239,7 @@
         {
             if (ak9750->getHysteresis(&hys) != AK9750::SUCCESS) {
                 status =  AkmSensor::ERROR;
-                MSG("#Failed to set hysteresis to AK9750.\n");
+                MSG("#Failed to set hysteresis to AK9750.\r\n");
             }
             out->setArgument(0,hys.ehys13);
             out->setArgument(1,hys.ehys24);
@@ -244,7 +251,7 @@
             hys.ehys24 = in->getArgument(1);
             if (ak9750->setHysteresis(&hys) != AK9750::SUCCESS) {
                 status =  AkmSensor::ERROR;
-                MSG("#Failed to set hysteresis to AK9750.\n");
+                MSG("#Failed to set hysteresis to AK9750.\r\n");
             }
             out->setArgument(0,(char)status);
             break;
@@ -253,7 +260,7 @@
         {
             if (ak9750->getInterruptEnable(&interrupt) != AK9750::SUCCESS) {
                 status =  AkmSensor::ERROR;
-                MSG("#Failed to set hysteresis to AK9750.\n");
+                MSG("#Failed to set hysteresis to AK9750.\r\n");
             }
             out->setArgument(0, interrupt.ir13h);
             out->setArgument(1, interrupt.ir13l);
@@ -271,7 +278,7 @@
             interrupt.drdy = in->getArgument(4);
             if (ak9750->setInterruptEnable(&interrupt) != AK9750::SUCCESS) {
                 status =  AkmSensor::ERROR;
-                MSG("#Failed to set hysteresis to AK9750.\n");
+                MSG("#Failed to set hysteresis to AK9750.\r\n");
             }
             out->setArgument(0,(char)status);
             break;            
@@ -280,7 +287,7 @@
         {
             if(ak9750->getOperationMode(&mode, &filter) != AK9750::SUCCESS) {
                 status =  AkmSensor::ERROR;
-                MSG("#Error setOperationMode. AK9750.\n");
+                MSG("#Error setOperationMode. AK9750.\r\n");
             }
             out->setArgument(0,(char)mode);
             out->setArgument(1,(char)filter);
@@ -292,7 +299,7 @@
             filter = (AK9750::DigitalFilter)in->getArgument(1);
             if(ak9750->setOperationMode(mode, filter) != AK9750::SUCCESS) {
                 status =  AkmSensor::ERROR;
-                MSG("#Error setOperationMode. AK9750.\n");
+                MSG("#Error setOperationMode. AK9750.\r\n");
             }
             out->setArgument(0,(char)status);
             break;
@@ -301,7 +308,7 @@
         {
             if (ak9750->getThresholdFromEEPROM(&th) != AK9750::SUCCESS) {
                 status =  AkmSensor::ERROR;
-                MSG("#Failed to set threshold to AK9750(EEPROM).\n");
+                MSG("#Failed to set threshold to AK9750(EEPROM).\r\n");
             }
             out->setArgument(0,(char)((int32_t)(th.eth13h) >> 8));
             out->setArgument(1,(char)((int32_t)(th.eth13h) & 0x00FF));
@@ -321,7 +328,7 @@
             th.eth24l = CONV16I(in->getArgument(6), in->getArgument(7));
             if (ak9750->setThresholdToEEPROM(&th) != AK9750::SUCCESS) {
                 status =  AkmSensor::ERROR;
-                MSG("#Failed to set threshold to AK9750(EEPROM).\n");
+                MSG("#Failed to set threshold to AK9750(EEPROM).\r\n");
             }
             out->setArgument(0,(char)status);
             break;
@@ -330,7 +337,7 @@
         {
             if (ak9750->getHysteresisFromEEPROM(&hys) != AK9750::SUCCESS) {
                 status =  AkmSensor::ERROR;
-                MSG("#Failed to set hysteresis to AK9750(EEPROM).\n");
+                MSG("#Failed to set hysteresis to AK9750(EEPROM).\r\n");
             }
             out->setArgument(0,hys.ehys13);
             out->setArgument(1,hys.ehys24);
@@ -342,7 +349,7 @@
             hys.ehys24 = in->getArgument(1);
             if (ak9750->setHysteresisToEEPROM(&hys) != AK9750::SUCCESS) {
                 status =  AkmSensor::ERROR;
-                MSG("#Failed to set hysteresis to AK9750(EEPROM).\n");
+                MSG("#Failed to set hysteresis to AK9750(EEPROM).\r\n");
             }
             out->setArgument(0,(char)status);
             break;
@@ -351,7 +358,7 @@
         {
             if (ak9750->getInterruptEnableFromEEPROM(&interrupt) != AK9750::SUCCESS) {
                 status =  AkmSensor::ERROR;
-                MSG("#Failed to set interrupt to AK9750(EEPROM).\n");
+                MSG("#Failed to set interrupt to AK9750(EEPROM).\r\n");
             }
             out->setArgument(0, interrupt.ir13h);
             out->setArgument(1, interrupt.ir13l);
@@ -369,7 +376,7 @@
             interrupt.drdy = in->getArgument(4);
             if (ak9750->setInterruptEnableToEEPROM(&interrupt) != AK9750::SUCCESS) {
                 status =  AkmSensor::ERROR;
-                MSG("#Failed to set interrupt to AK9750(EEPROM).\n");
+                MSG("#Failed to set interrupt to AK9750(EEPROM).\r\n");
             }
             out->setArgument(0,(char)status);
             break;            
@@ -378,7 +385,7 @@
         {
             if(ak9750->getOperationModeFromEEPROM(&mode, &filter) != AK9750::SUCCESS) {
                 status =  AkmSensor::ERROR;
-                MSG("#Error getOperationMode. AK9750(EEPROM).\n");
+                MSG("#Error getOperationMode. AK9750(EEPROM).\r\n");
             }
             out->setArgument(0,(char)mode);
             out->setArgument(1,(char)filter);
@@ -390,7 +397,7 @@
             filter = (AK9750::DigitalFilter)in->getArgument(1);
             if(ak9750->setOperationModeToEEPROM(mode, filter) != AK9750::SUCCESS) {
                 status =  AkmSensor::ERROR;
-                MSG("#Error setOperationMode. AK9750(EEPROM).\n");
+                MSG("#Error setOperationMode. AK9750(EEPROM).\r\n");
             }
             out->setArgument(0,(char)status);
             break;
@@ -402,7 +409,7 @@
             const char data = in->getArgument(2);
             if( ak9750->write(address, &data, len) != AK9750::SUCCESS) {
                 status =  AkmSensor::ERROR;
-                MSG("#Error register write.\n");
+                MSG("#Error register write.\r\n");
             }
             out->setArgument(0,(char)status);
             break;
@@ -417,7 +424,7 @@
             }
             if( ak9750->write(address, data, len) != AK9750::SUCCESS) {
                 status =  AkmSensor::ERROR;
-                MSG("#Error register write.\n");
+                MSG("#Error register write.\r\n");
             }
             out->setArgument(0,(char)status);
             break;
@@ -429,7 +436,7 @@
             char data;
             if( ak9750->read(address, &data, len) != AK9750::SUCCESS) {
                 status =  AkmSensor::ERROR;
-                MSG("#Error register read.\n");
+                MSG("#Error register read.\r\n");
             }
             out->setArgument(0,data);
             break;
@@ -441,7 +448,7 @@
             char data[len];
             if( ak9750->read(address, data, len) != AK9750::SUCCESS) {
                 status =  AkmSensor::ERROR;
-                MSG("#Error register read.\n");
+                MSG("#Error register read.\r\n");
             }
             for(int i=0; i<len; i++){
                 out->setArgument(i, data[i]);
@@ -450,7 +457,7 @@
         }
         default:
         {
-            MSG("#Error no command.\n");
+            MSG("#Error no command.\r\n");
             status =  AkmSensor::ERROR;
             break;
         }