Denwis La / Mbed OS mDot_Send_Data

Dependencies:   libmDot-dev-mbed5-deprecated ISL29011

Fork of mdot-examples by 3mdeb

Revision:
12:bdf16bf682ec
Parent:
11:dce6c1b255fd
Child:
13:e336881e0a3e
diff -r dce6c1b255fd -r bdf16bf682ec peer_to_peer_example.cpp
--- a/peer_to_peer_example.cpp	Sat Dec 09 02:37:51 2017 +0000
+++ b/peer_to_peer_example.cpp	Sat Dec 09 02:56:19 2017 +0000
@@ -85,7 +85,7 @@
 int DS7505sWrite(unsigned char registerAddress, unsigned char data);
 char * DS7505sRead(int hex);
 
-unsigned char * twosComplementConversion(unsigned char *value);
+char * twosComplementConversion(char *value);
 void flushSerialBuffer(void);
 //---------------------End of prototype functions-----------------------------//
 
@@ -103,7 +103,8 @@
                 "a: SPI reset for ADXL372\n\r"
                 "b: Initialize Accelerometer with SPI\n\r"
                 "c: Check data in status register with SPI\n\r"
-                "d: Perform self test with SPI\n\r");
+                "d: Perform self test with SPI\n\r"
+                "e: Perform two's complement on accel data\n\r");
 }
 
 
@@ -428,7 +429,30 @@
                 }
                 pc.printf("0x%x\n\r", testResult);
                 break;
-            
+            case 101:   // e for two's complement of accel data
+                regAddress = 0x08;
+                
+                accelValues = accelerometerI2CRead(regAddress);
+                XData = ((*(accelValues + 0) << 8) | *(accelValues + 1)) >> 4;  // Combine two bytes into short int(16 bits), remove last 4 flag bits
+                YData = ((*(accelValues + 2) << 8) | *(accelValues + 3)) >> 4;
+                ZData = ((*(accelValues + 4) << 8) | *(accelValues + 5)) >> 4;
+                pc.printf("\n X:: H: %x | L: %x | Y:: H: %x | L: %x | Z: H: %x | L: %x \n\r", *(accelValues + 0),
+                                                                                              *(accelValues + 1),
+                                                                                              *(accelValues + 2),
+                                                                                              *(accelValues + 3),
+                                                                                              *(accelValues + 4),
+                                                                                              *(accelValues + 5));
+                pc.printf("Converted \n\r");
+                
+                pc.printf("\n X:: H: %x | L: %x | Y:: H: %x | L: %x | Z: H: %x | L: %x \n\r", twosComplementConversion(accelValues[0]),
+                                                                                              twosComplementConversion(accelValues[1]),
+                                                                                              twosComplementConversion(accelValues[2]),
+                                                                                              twosComplementConversion(accelValues[3]),
+                                                                                              twosComplementConversion(accelValues[4]),
+                                                                                              twosComplementConversion(accelValues[5]));
+                wait(0.2);
+                
+                break;
             default:
                 printMenu();
                 break;
@@ -639,7 +663,7 @@
  *  Not really needed. But keep just in case because I don't want to rewrite it
  ******************************************************************************/
 ////////////////////////////////////////////////////////////////////////////////
-unsigned char twosComplementConversion(unsigned char value)
+char twosComplementConversion(char value)
 {
     /*
      * Go from bit 0 to bit 7 and invert them