Modified for compatibility with Rev.E. hardware

Fork of AkmSensor by AKM Development Platform

Revision:
6:c4401549d68f
Parent:
4:af13b985c689
Child:
7:e269411568c9
--- a/akmsensormanager.cpp	Mon May 09 17:09:40 2016 +0000
+++ b/akmsensormanager.cpp	Fri May 13 23:52:37 2016 +0000
@@ -3,12 +3,14 @@
 #include "akmanglesensor.h"
 #include "akmhallswitch.h"
 #include "akmlinearsensor.h"
+#include "akmcurrentsensor.h"
 #include "akmirsensor.h"
 #include "akmakd.h"
 #include "debug.h"
 #include "Message.h"
 #ifdef REV_D
 #include "mcp342x.h"
+#include "I2CNano.h"
 #endif
 
 #define FIRMWARE_VERSION   0x02
@@ -70,6 +72,8 @@
     
     // primary id check
     id = AkmSensorManager::getId(ANALOG_SENSOR_ID,4);
+//    id=14;
+//    subId=1;
     
     switch(id){
         case AkmSensor::AKM_PRIMARY_ID_AKD_I2C:
@@ -79,7 +83,7 @@
             sensor = akd;
             break;
             
-        case AkmSensor::AKM_PRIMARY_ID_AKD_SPI:                         // Temporary
+//        case AkmSensor::AKM_PRIMARY_ID_AKD_SPI:                         // Temporary
         case AkmSensor::AKM_PRIMARY_ID_ANGLE_SENSOR:
             subId = AkmSensorManager::getId(ANALOG_SENSOR_ID_SUB,4);    // 4bit sub id
             AkmAngleSensor* angleSensor;
@@ -106,6 +110,13 @@
             sensor = linearsensor;
             break;
         
+        case AkmSensor::AKM_PRIMARY_ID_CURRENT_SENSOR:
+            subId = AkmSensorManager::getId(ANALOG_SENSOR_ID_SUB,4);    // 4bit sub id
+            AkmCurrentSensor* currentsensor;
+            currentsensor = new AkmCurrentSensor();
+            sensor = currentsensor;
+            break;
+        
         case AkmSensor::AKM_PRIMARY_ID_IR_SENSOR:
             subId = AkmSensorManager::getId(ANALOG_SENSOR_ID_SUB,4);    // 4bit sub id
             AkmIrSensor* irsensor;
@@ -173,7 +184,8 @@
 #else
     /* Rev.D */
     MSG("#GetID\n");
-    I2C i2c(I2C_SDA0, I2C_SCL0);
+    
+    I2C i2c(I2C_SDA, I2C_SCL);
     // ADC
     MCP342X mcp342x(&i2c, MCP342X::SLAVE_ADDRESS_6EH);
     mcp342x.setConversionMode(MCP342X::ONE_SHOT);
@@ -189,8 +201,12 @@
     const int16_t VAL_MAX = 3000-2048;   // Corresponds to 3V
     const int16_t VAL_MIN = -2048;       // Corresponds to 0V
     
-    uint8_t value = (uint8_t)((val - VAL_MIN)/(float)(VAL_MAX - VAL_MIN) * (1 << bits));
+    uint8_t value = (uint8_t)((val - VAL_MIN)/(float)(VAL_MAX - VAL_MIN) * (1 << bits) + 0.5);
     MSG("#ID = %d.\n", value);
+   
+   // I2C turn off 
+    releaseTWI();
+
 #endif    
     return value;
 }
@@ -366,6 +382,13 @@
     return SUCCESS;   
 }
 
+void AkmSensorManager::releaseTWI(){
+    NRF_TWI0->ENABLE = TWI_ENABLE_ENABLE_Disabled << TWI_ENABLE_ENABLE_Pos;
+    NRF_TWI0->POWER  = 0;
+    NRF_TWI1->ENABLE = TWI_ENABLE_ENABLE_Disabled << TWI_ENABLE_ENABLE_Pos;
+    NRF_TWI1->POWER  = 0;
+}
+
 /*
 void AkmSensorManager::dataOut(char* str){
     if(isBleMode) uartService->writeString(str);