Initial I2C Working

Dependencies:   mbed

Revision:
2:832cb4376d2a
Parent:
1:444546e8cd20
Child:
3:c6aad2355a40
--- a/main.cpp	Wed Mar 29 12:20:34 2017 +0000
+++ b/main.cpp	Wed Mar 29 17:55:38 2017 +0000
@@ -5,44 +5,24 @@
 
 int main()
 {
-    char data[2];
+    // Example of how to Configure Sensor
     
-    data[0] = 0x01;
-    data[1] = 0x72;
-    
-    printf("Write Return Value = %d\r\n",TempSensor.I2C_Write(data,2));
-    
-    data[0] = 0x01;
+    int configSuccess = TempSensor.ConfigSensor(0x00,0x01,0x00,0x02,0x03,0x00);
     
-    printf("Write Return Value = %d\r\n",TempSensor.I2C_Write(data,1));   
-    
-    TempSensor.I2C_Read(1);
-    
-    data[0] = 0x00;
-    TempSensor.I2C_Write(data,1);
-    
-    int len = 2;
-    char *buffer = TempSensor.I2C_Read(len);
-    
-    char inBuffer[len];
+    // Print value returned from ConfigSensor
+    // 0 indicates success, 1 indicates failure
+    printf("CONFIG Success = %d\r\n\r\n",configSuccess);
     
-    for(int i = 0; i < len; i++)
-    {
-        inBuffer[i] = *(buffer+i);
-    }
-    
-    int dat = (((inBuffer[0] << 8) | inBuffer[1])>>4);
-    
-    printf("data value = %04x\r\n",dat);
+    // Print raw temp value
+    // Anything other than 0x0FF0 indicates success
+    printf("Temp Raw = %04x\r\n",TempSensor.RawTempValue());
     
-    if(dat > 2047)
-    {
-        dat -= 4096;
-    }
-    
-    float tempC = 0.0625*dat;
-    printf("Temp C = %f\r\n\r\n",tempC);   
-    
-    
-    
+    // Print converted temp values
+    // Anything other than -2000.000 indicates success
+    printf("Temp C = %f\r\n",TempSensor.FormattedTempValue(CELCIUS));
+    printf("Temp F = %f\r\n",TempSensor.FormattedTempValue(FARENHEIT));
+    printf("Temp K = %f\r\n",TempSensor.FormattedTempValue(KELVIN));
+   
+   // Example of failure from sending wrong format
+   printf("Temp ? = %f\r\n",TempSensor.FormattedTempValue(0x0F));
 }
\ No newline at end of file