Modified for compatibility with Rev.E. hardware

Fork of AkmSensor by AKM Development Platform

Revision:
23:50c98b286e41
Parent:
21:966724730ce6
Child:
24:1d37438f31a9
diff -r f44f1018081e -r 50c98b286e41 akmsensormanager.cpp
--- a/akmsensormanager.cpp	Mon Apr 10 23:02:52 2017 +0000
+++ b/akmsensormanager.cpp	Thu Apr 13 22:15:54 2017 +0000
@@ -231,13 +231,13 @@
 
 void AkmSensorManager::processCommand()
 {
-    // Gets command contained in the message
+    // Extracts command contained in the message
     Message::Command cmd = msg.getCommand();
     
     // Creates a message object to return
     Message resMsg;
     
-    // Return message contains the same command
+    // Return message contains the extracted command
     resMsg.setCommand(cmd);
     
     switch(cmd)
@@ -371,25 +371,30 @@
 {
     AkmSensorManager::Status status = AkmSensorManager::SUCCESS;
     
-    // command received from the host
+    // If event is a command received from the host
     if(eventCommandReceived)
     {
         processCommand();
         eventCommandReceived = false;          // clear the flag
     }
-    if(sensor->isEvent())  // sensor read data event
+    
+    // If event is sensor read data event, read the message
+    if(sensor->isEvent())
     {
         Message msg;
         if( sensor->readSensorData(&msg) != AkmSensor::SUCCESS) status = AkmSensorManager::ERROR;
-        throwMessage(&msg);            
+        throwMessage(&msg);                 // Process and output message to USB/BLE
     }
 
-    if(eventConnected)     // BLE connected. Start sensor.
+    // If event is the BLE being connected, clear the flag and start sensor
+    if(eventConnected)
     {
         eventConnected = false;                 // clear the flag
         MSG("#BLE connected.\r\n");
     }
-    if(eventDisconnected)  // BLE dis-connected. Stop sensor.
+    
+    // If event is the BLE being disconnected, stop the sensor
+    if(eventDisconnected)
     {
         MSG("#BLE dis-connected.\r\n");
         if( sensor->stopSensor() != AkmSensor::SUCCESS) status = AkmSensorManager::ERROR;
@@ -402,13 +407,13 @@
     int len = Message::getMaxMessageLength();
     char buf[len];
     
-    buf[0] = '$';
+    buf[0] = '$';           // Output message prefix
 
-    // Processes command
+    // Processes command in msg to ASCII
     char cmd = (char)msg->getCommand();
     Message::charToAscii(&buf[1], &cmd);
     
-    // Processes arguments
+    // Processes arguments in msg to ASCII
     for (int i=0; i < msg->getArgNum(); i++) {
         char arg = msg->getArgument(i);
         Message::charToAscii(&buf[3+2*i], &arg);
@@ -424,7 +429,11 @@
     buf[tIdx++] = CR;        // '\r'
     buf[tIdx++] = LF;        // '\n' 
     buf[tIdx] = '\0';    
-    if(isEnabledBle) uartService->writeString(buf);            
+    
+    // If BLE is enabled, send to AKDP app (?)
+    if(isEnabledBle) uartService->writeString(buf);
+    
+    // If USB is enabled, send to serial terminal (?)
     if(isEnabledUsb) serial->printf(buf);
     
     return SUCCESS;