Modified for compatibility with Rev.E. hardware

Fork of AkmSensor by AKM Development Platform

Revision:
33:d3e1e9eb2ef9
Parent:
24:1d37438f31a9
Child:
34:1ea3357c8d9a
--- a/akmsensormanager.cpp	Wed Apr 19 23:14:04 2017 +0000
+++ b/akmsensormanager.cpp	Fri Apr 21 20:23:24 2017 +0000
@@ -8,6 +8,7 @@
 #include "ak9752ctrl.h"
 #include "ak7451ctrl.h"
 #include "ak7401ctrl.h"
+#include "ap1017ctrl.h"
 #include "akmakd.h"
 #include "debug.h"
 #include "Message.h"
@@ -145,7 +146,16 @@
             
             break;
         }
-
+        case AkmSensor::AKM_PRIMARY_ID_MOTOR_DRIVER:
+        {       // TODO: Other motor driver cases
+            if(subId == Ap1017Ctrl::SUB_ID_AP1017){
+                Ap1017Ctrl* ap1017ctrl = new Ap1017Ctrl();
+                sensor = ap1017ctrl;
+            }else{
+                return NULL;
+            }
+            break;
+        }
         default:
         {
             MSG("#Can't find ID=%d SubID=%d %s\r\n", primaryId, subId, AKM_PRIMARY_ID_STR[primaryId]);
@@ -165,6 +175,8 @@
         
 void AkmSensorManager::dummyCallbackForCommandReceived(){}
 
+
+// For commands received via BLE
 AkmSensorManager::Status AkmSensorManager::commandReceived(char* buf){
     // Construct message
     Status status = SUCCESS;
@@ -172,15 +184,16 @@
     if ((Message::parse(&msg, buf)) != Message::SUCCESS) {
         MSG("#Failed to parse message. %s\r\n", buf);
         status = ERROR;
-        eventCommandReceived = false;
+        eventCommandReceived = false;           // Reset flag
     }else{       
-        eventCommandReceived = true;
+        eventCommandReceived = true;            // Set flag
 //        MSG("#Parsed message. %s\r\n", buf);
     }
     t.attach(callback(this, &AkmSensorManager::dummyCallbackForCommandReceived),0); // wake-up from ble.waitForEvent
     return status;
 }
 
+
 int16_t AkmSensorManager::getAdcData(MCP342X *mcp3428, MCP342X::AdcChannel ch, MCP342X::SampleSetting s) {
     const int WAIT_ADC_MS = 1;
 
@@ -199,6 +212,7 @@
     return data.value;
 }
 
+
 uint8_t AkmSensorManager::getId(PinName pin, uint8_t bits)
 {
     MSG("#GetID\r\n");
@@ -230,6 +244,7 @@
     return value;
 }
 
+
 bool AkmSensorManager::isEvent()
 {
     return (sensor->isEvent() || 
@@ -238,6 +253,7 @@
             eventDisconnected);
 }
 
+
 void AkmSensorManager::processCommand()
 {
     // Extracts command contained in the message
@@ -327,6 +343,10 @@
             }
             break;
         }
+        case Message::CMD_MOTOR_START_MOTOR:
+        case Message::CMD_MOTOR_STOP_MOTOR:
+        case Message::CMD_MOTOR_SET_DIRECTION:
+        case Message::CMD_MOTOR_SET_DUTY_CYCLE:
         case Message::CMD_PROGSW_GET_THRESHOLD:
         case Message::CMD_PROGSW_SET_THRESHOLD:
         case Message::CMD_PROGSW_GET_READ_COFIGURATION:
@@ -380,7 +400,7 @@
 {
     AkmSensorManager::Status status = AkmSensorManager::SUCCESS;
     
-    // If event is a command received from the host
+    // If event is a command received from BLE
     if(eventCommandReceived)
     {
 //        MSG("#Command received.\r\n");
@@ -441,10 +461,10 @@
     buf[tIdx++] = LF;        // '\n' 
     buf[tIdx] = '\0';    
     
-    // If BLE is enabled, send to AKDP app (?)
+    // If BLE is enabled, send to AKDP app
     if(isEnabledBle) uartService->writeString(buf);
     
-    // If USB is enabled, send to serial terminal (?)
+    // If USB is enabled, send to serial terminal
     if(isEnabledUsb) serial->printf(buf);
     
     return SUCCESS;