Modified for compatibility with Rev.E. hardware

Fork of AkmSensor by AKM Development Platform

Revision:
39:3821886c902e
Parent:
29:b488d2c89fba
Child:
40:42e48427e4b7
--- a/ak9752ctrl.cpp	Thu Jun 08 19:09:18 2017 +0000
+++ b/ak9752ctrl.cpp	Tue Jul 18 23:20:26 2017 +0000
@@ -9,7 +9,6 @@
  */
 Ak9752Ctrl::Ak9752Ctrl() : AkmSensor(){
     ak9752 = NULL;
-//    interrupt = NULL;
 }
 
 /**
@@ -18,14 +17,12 @@
  */
 Ak9752Ctrl::~Ak9752Ctrl(){
     if (ak9752) delete ak9752;
-//    if (interrupt) delete interrupt;
 }
 
 AkmSensor::Status Ak9752Ctrl::init(const uint8_t id, const uint8_t subid){
     primaryId = id;
     subId = subid;
 
-//    interrupt = new InterruptIn(I2C_DRDY);    
     I2C* i2c = new I2C(I2C_SDA,I2C_SCL);
     i2c->frequency(I2C_SPEED_100KHZ);
 
@@ -56,7 +53,7 @@
 
     // reset
     if (ak9752->reset() != AK9752::SUCCESS) {
-        MSG("#Failed to reset AK9752.\r\n");
+        MSG("#Error: Failed to reset AK9752.\r\n");
     }
         
     MSG("#Init success AK9752.\r\n");
@@ -74,12 +71,9 @@
     AK9752::SensorData data;
     ak9752->getSensorData(&data);
     
-    // enable interrupt
-//    interrupt->fall(callback(this, &Ak9752Ctrl::detectINT));
-    
     // set operation mode
     if(ak9752->setOperationMode(mode,fc_tmp, fc_ir) != AK9752::SUCCESS) {
-        MSG("#Start sensor failed %s\r\n", sensorName);
+        MSG("#Error: Start sensor failed %s\r\n", sensorName);
         return AkmSensor::ERROR;
     }
 
@@ -88,16 +82,14 @@
 }
 
 AkmSensor::Status Ak9752Ctrl::startSensor(const float sec){
-//    interrupt->fall(callback(this, &Ak9752Ctrl::detectINT));
     return AkmSensor::ERROR;
 }
 
 AkmSensor::Status Ak9752Ctrl::stopSensor(){
     AkmSensor::clearEvent();
 
-//    interrupt->fall(NULL);
     if(ak9752->setOperationMode(AK9752::MODE_STANDBY, fc_tmp, fc_ir) != AK9752::SUCCESS) {
-        MSG("#Error setOperationMode. AK9752.\r\n");
+        MSG("#Error: setOperationMode. AK9752.\r\n");
         return AkmSensor::ERROR;
     }
     
@@ -114,7 +106,7 @@
     AK9752::SensorData data;
     AK9752::Status status = ak9752->getSensorData(&data);
     if( status != AK9752::SUCCESS){
-        MSG("#Error getSensorData. AK9752.\r\n");
+        MSG("#Error: getSensorData. AK9752.\r\n");
         return AkmSensor::ERROR;
     }
     msg->setCommand(Message::CMD_START_MEASUREMENT);
@@ -144,7 +136,7 @@
         case Message::CMD_IR_GET_THRESHOLD:
         {
             if (ak9752->getThreshold(&th) != AK9752::SUCCESS) {
-                MSG("#Failed to set threshold to AK9752.\r\n");
+                MSG("#Error: Failed to set threshold to AK9752.\r\n");
                 return  AkmSensor::ERROR;
             }
             out->setArgument(0,(char)((int32_t)(th.thirh) >> 8));
@@ -165,7 +157,7 @@
             th.thtmpl = CONV16I(in->getArgument(6), in->getArgument(7));
             if (ak9752->setThreshold(&th) != AK9752::SUCCESS) {
                 status =  AkmSensor::ERROR;
-                MSG("#Failed to set threshold to AK9752.\r\n");
+                MSG("#Error: Failed to set threshold to AK9752.\r\n");
             }
             out->setArgument(0,(char)status);
             break;
@@ -173,7 +165,7 @@
         case Message::CMD_IR_GET_INTERRUPT:
         {
             if (ak9752->getInterruptEnable(&interruptStatus) != AK9752::SUCCESS) {
-                MSG("#Failed to set hysteresis to AK9752.\r\n");
+                MSG("#Error: Failed to set hysteresis to AK9752.\r\n");
                 return  AkmSensor::ERROR;
             }
             out->setArgument(0, interruptStatus.irh);
@@ -192,7 +184,7 @@
             interruptStatus.dr = in->getArgument(4);
             if (ak9752->setInterruptEnable(&interruptStatus) != AK9752::SUCCESS) {
                 status =  AkmSensor::ERROR;
-                MSG("#Failed to set hysteresis to AK9752.\r\n");
+                MSG("#Error: Failed to set hysteresis to AK9752.\r\n");
             }
             out->setArgument(0,(char)status);
             break;            
@@ -200,7 +192,7 @@
         case Message::CMD_IR_GET_OPERATION_MODE:
         {
             if(ak9752->getOperationMode(&mode, &fc_tmp, &fc_ir) != AK9752::SUCCESS) {
-                MSG("#Error getOperationMode. AK9752.\r\n");
+                MSG("#Error: getOperationMode. AK9752.\r\n");
                 return  AkmSensor::ERROR;
             }
             out->setArgument(0,(char)mode);
@@ -215,7 +207,7 @@
             fc_ir = (AK9752::FcIr)in->getArgument(2);
             if(ak9752->setOperationMode(mode, fc_tmp, fc_ir) != AK9752::SUCCESS) {
                 status =  AkmSensor::ERROR;
-                MSG("#Error setOperationMode. AK9752.\r\n");
+                MSG("#Error: setOperationMode. AK9752.\r\n");
             }
             out->setArgument(0,(char)status);
             break;
@@ -226,7 +218,7 @@
             char address = in->getArgument(0);
             int len = (int)in->getArgument(1);
             if(in->getArgNum() != len+2){
-                MSG("#Error argument num. Args=%d\r\n",in->getArgNum());
+                MSG("#Error: argument num. Args=%d\r\n",in->getArgNum());
                 status = AkmSensor::ERROR;
                 out->setArgument(0,(char)status);
                 return status;
@@ -238,7 +230,7 @@
             }
             if( ak9752->write(address, data, len) != AK9752::SUCCESS) {
                 status =  AkmSensor::ERROR;
-                MSG("#Error register write.\r\n");
+                MSG("#Error: register write.\r\n");
             }
             out->setArgument(0,(char)status);
             break;
@@ -247,7 +239,7 @@
         case Message::CMD_REG_READN:
         {
             if(in->getArgNum() != 2){
-                MSG("#Error argument num. Args=%d\r\n",in->getArgNum());
+                MSG("#Error: argument num. Args=%d\r\n",in->getArgNum());
                 return AkmSensor::ERROR;
             }
 
@@ -255,7 +247,7 @@
             int len = (int)in->getArgument(1);
             char data[len];
             if( ak9752->read(address, data, len) != AK9752::SUCCESS) {
-                MSG("#Error register read.\r\n");
+                MSG("#Error: register read.\r\n");
                 return AkmSensor::ERROR;
             }
             for(int i=0; i<len; i++){
@@ -265,7 +257,7 @@
         }
         default:
         {
-            MSG("#Error no command.\r\n");
+            MSG("#Error: No command.\r\n");
             status =  AkmSensor::ERROR;
             break;
         }