Modified for compatibility with Rev.E. hardware

Fork of AkmSensor by AKM Development Platform

Revision:
48:427bdb7bf31b
Parent:
46:5938ad2039b0
Child:
49:c8f8946129b6
diff -r 221ec4b404ec -r 427bdb7bf31b akmsensormanager.cpp
--- a/akmsensormanager.cpp	Thu Dec 14 00:21:43 2017 +0000
+++ b/akmsensormanager.cpp	Tue Dec 19 12:18:13 2017 -0800
@@ -126,6 +126,7 @@
             sensorNum = 1;
             break;
         }
+/*
         case AkmSensor::AKM_PRIMARY_ID_DEMO:
         {
             if(subId == 0x08){
@@ -148,6 +149,7 @@
             }
             break;
         }
+*/
         case AkmSensor::AKM_PRIMARY_ID_LINEAR_SENSOR:
         case AkmSensor::AKM_PRIMARY_ID_CURRENT_SENSOR_3V:
         case AkmSensor::AKM_PRIMARY_ID_CURRENT_SENSOR_5V:
@@ -199,12 +201,12 @@
     }
     
     if(primaryId != AkmSensor::AKM_PRIMARY_ID_DEMO){       
-        for(int i=0; i<sensorNum; i++){
-            if(sensor[i]->init(primaryId, subId) != AkmSensor::SUCCESS){
+//        for(int i=0; i<sensorNum; i++){
+            if(sensor[0]->init(primaryId, subId) != AkmSensor::SUCCESS){
                 MSG("#Error: sensor[i]->init failed. ID=%d SubID=%d %s\r\n", primaryId, subId, AKM_PRIMARY_ID_STR[primaryId]);    
                 return false;    // couldn't find
             }
-        }
+//        }
         MSG("#ID=%d SubID=%d %s\r\n", primaryId, subId, AKM_PRIMARY_ID_STR[primaryId]);    
     }
     
@@ -215,9 +217,9 @@
 
 void AkmSensorManager::detectDRDY(){
     VERBOSE("#detect DRDY.\r\n");
-    for(int i=0; i<sensorNum; i++){
-        sensor[i]->setEvent();
-    }
+//    for(int i=0; i<sensorNum; i++){
+        sensor[0]->setEvent();
+//    }
 }
 
 void AkmSensorManager::dummyCallbackForCommandReceived(){}
@@ -295,11 +297,11 @@
 bool AkmSensorManager::isEvent()
 {
     // check sensor related event
-    for(int i=0; i<sensorNum; i++){
-        if(sensor[i]->isEvent()){
+//    for(int i=0; i<sensorNum; i++){
+        if(sensor[0]->isEvent()){
             return true;
         }
-    }
+//    }
 
     // other events
     return (
@@ -394,29 +396,34 @@
         case Message::CMD_START_MEASUREMENT:
         {
             int error_code = AkmSensor::SUCCESS;
-            if(msg.getArgNum() == 0){
+            if(msg.getArgNum() == 0)
+            {
                 error_code = sensor[sensorIndex]->startSensor();
                 if( error_code != AkmSensor::SUCCESS ){
                     MSG("#Error: StartSensor Error. Code=%d\r\n",error_code);            
-                }else{
-                    switch(drdyType){
-                        case AkmAkd::INTERRUPT_ENABLED_PP:
-                        {
-                            interrupt->rise(callback(this, &AkmSensorManager::detectDRDY));                            
-                            break;
-                        }
-                        case AkmAkd::INTERRUPT_ENABLED_OD:
-                        {
-                            interrupt->fall(callback(this, &AkmSensorManager::detectDRDY));                            
-                            break;
-                        }
-                        default:
-                        {
-                            // nothing.
-                        }
-                    }
                 }
-            }else if(msg.getArgNum() == 1){
+                else
+                {
+	                switch(drdyType){
+	                    case AkmAkd::INTERRUPT_ENABLED_PP:
+	                    {
+	                        interrupt->rise(callback(this, &AkmSensorManager::detectDRDY));                            
+	                        break;
+	                    }
+	                    case AkmAkd::INTERRUPT_ENABLED_OD:
+	                    {
+	                        interrupt->fall(callback(this, &AkmSensorManager::detectDRDY));                            
+	                        break;
+	                    }
+	                    default:
+	                    {
+	                        // nothing.
+	                    }
+	                }
+				}
+            }
+            else if(msg.getArgNum() == 1)
+            {
                 float interval = (float)(1.0 / (double)msg.getArgument(0));
                 error_code = sensor[sensorIndex]->startSensor(interval);
                 if( error_code != AkmSensor::SUCCESS ){
@@ -440,9 +447,8 @@
                     sensor[sensorIndex]->readSensorData(&temp);
                     throwMessage(&temp);
                 }
+	            MSG("#Start measurement:%s index=%d.\r\n",sensor[sensorIndex]->getSensorName(), sensorIndex);
             }
-            
-            MSG("#Start measurement:%s.\r\n",sensor[sensorIndex]->getSensorName());
             break;
         }
         case Message::CMD_MOTOR_START_MOTOR:
@@ -512,13 +518,13 @@
     }
 
     // check sensor event
-    for(int i=0; i<sensorNum; i++){
-        if( sensor[i]->isEvent() ){
+//    for(int i=0; i<sensorNum; i++){
+        if( sensor[0]->isEvent() ){
             Message msg;
-            if( sensor[i]->readSensorData(&msg) != AkmSensor::SUCCESS) status = AkmSensorManager::ERROR;
+            if( sensor[0]->readSensorData(&msg) != AkmSensor::SUCCESS) status = AkmSensorManager::ERROR;
             throwMessage(&msg);     // Process and output message to USB/BLE
         }
-    }
+//    }
 
     if(eventConnected)     // If BLE connected, clear flag and start sensor.
     {
@@ -530,9 +536,9 @@
     if(eventDisconnected)
     {
         MSG("#BLE disconnected.\r\n");
-        for(int i=0; i<sensorNum; i++){
-            if( sensor[i]->stopSensor() != AkmSensor::SUCCESS) status = AkmSensorManager::ERROR;        
-        }
+//        for(int i=0; i<sensorNum; i++){
+            if( sensor[0]->stopSensor() != AkmSensor::SUCCESS) status = AkmSensorManager::ERROR;        
+//        }
         eventDisconnected = false;      // clear the flag
     }
     return status;
@@ -587,10 +593,10 @@
 
 char* AkmSensorManager::getSensorName(){
     char* name = "";
-    for(int i=0; i<sensorNum; i++){
-        name = my_strcat(name, (char *)sensor[i]->getSensorName());
-        if( sensorNum > (i+1) )name = my_strcat(name, "+");
-    }
+//    for(int i=0; i<sensorNum; i++){
+        name = my_strcat(name, (char *)sensor[0]->getSensorName());
+//        if( sensorNum > (i+1) )name = my_strcat(name, "+");
+//    }
     MSG("#Sensor Name='%s'.\r\n",name);
     return name;
 }