Modified for compatibility with Rev.E. hardware

Fork of AkmSensor by AKM Development Platform

Revision:
21:966724730ce6
Parent:
15:1238993fd75f
Child:
23:50c98b286e41
diff -r 1238993fd75f -r 966724730ce6 akmsensormanager.cpp
--- a/akmsensormanager.cpp	Fri Oct 28 21:27:33 2016 +0000
+++ b/akmsensormanager.cpp	Fri Mar 24 23:01:27 2017 +0000
@@ -194,22 +194,27 @@
 {
     MSG("#GetID\r\n");
     
-    I2C i2c(I2C_SDA, I2C_SCL);
+    I2C i2c(I2C_SDA, I2C_SCL);      // establish I2C to read ID
+    
     // ADC
-    MCP342X mcp342x(&i2c, MCP342X::SLAVE_ADDRESS_6EH);
-    mcp342x.setConversionMode(MCP342X::ONE_SHOT);
+    MCP342X mcp342x(&i2c, MCP342X::SLAVE_ADDRESS_6EH);  // ADC to convert voltage
+    mcp342x.setConversionMode(MCP342X::ONE_SHOT);       // Set to single sample
     MCP342X::AdcChannel ch;
-    if (pin == ANALOG_SENSOR_ID) {
+    
+    if (pin == ANALOG_SENSOR_ID) {                      // Primary ID
         ch = MCP342X::ADC_CH1;
-    } else { // pin == ANALOG_SENSOR_ID_SUB
-        ch = MCP342X::ADC_CH2;
+    } else { // pin == ANALOG_SENSOR_ID_SUB         
+        ch = MCP342X::ADC_CH2;                          // Secondary ID
     }
+    
     int16_t val = getAdcData(&mcp342x, ch, MCP342X::SAMPLE_240HZ_12BIT);
     MSG("#12bit ADC Val = %d.\r\n", val);
     
+    // Voltage boundaries for ID voltage divider system
     const int16_t VAL_MAX = 3000-2048;   // Corresponds to 3V
     const int16_t VAL_MIN = -2048;       // Corresponds to 0V
     
+    // Convert voltage to ID value
     uint8_t value = (uint8_t)((val - VAL_MIN)/(float)(VAL_MAX - VAL_MIN) * (1 << bits) + 0.5);
     MSG("#ID = %d.\r\n", value);
 
@@ -224,16 +229,15 @@
             eventDisconnected);
 }
 
-
 void AkmSensorManager::processCommand()
 {
-    // Gets command in the message
+    // Gets command contained in the message
     Message::Command cmd = msg.getCommand();
     
-    // Creates an message object to return
+    // Creates a message object to return
     Message resMsg;
     
-    // Return message has the same command as input
+    // Return message contains the same command
     resMsg.setCommand(cmd);
     
     switch(cmd)
@@ -371,7 +375,7 @@
     if(eventCommandReceived)
     {
         processCommand();
-        eventCommandReceived = false;
+        eventCommandReceived = false;          // clear the flag
     }
     if(sensor->isEvent())  // sensor read data event
     {
@@ -382,14 +386,14 @@
 
     if(eventConnected)     // BLE connected. Start sensor.
     {
-        eventConnected = false;   
+        eventConnected = false;                 // clear the flag
         MSG("#BLE connected.\r\n");
     }
     if(eventDisconnected)  // BLE dis-connected. Stop sensor.
     {
         MSG("#BLE dis-connected.\r\n");
         if( sensor->stopSensor() != AkmSensor::SUCCESS) status = AkmSensorManager::ERROR;
-        eventDisconnected = false;
+        eventDisconnected = false;              // clear the flag
     }
     return status;
 }