Fork of original library from sburg. Identical except it takes an I2C object as the input rather than individual pin names. Useful if you have multiple I2C devices on a single bus.

Dependents:   TestBenchSerenity-proto_F429ZI TestBenchFlow HSPFLOW1 TestBenchFlow1 ... more

Fork of VL6180 by Steven Burg

Revision:
5:190457e8c69e
Parent:
4:7ab2e81d6596
--- a/VL6180.cpp	Fri Jul 14 18:51:32 2017 +0000
+++ b/VL6180.cpp	Thu Jul 20 20:44:03 2017 +0000
@@ -1,7 +1,8 @@
 #include "VL6180.h"
 #include "mbed.h"
 
-VL6180::VL6180(I2C &i2c) : _i2c(i2c) {
+VL6180::VL6180(I2C &i2c) : _i2c(i2c)
+{
     char poweron;
     poweron = readI2C(0x16);
     if(poweron == 1) {
@@ -40,61 +41,64 @@
         writeI2C(0x0011,0x10);// Enables polling for ‘New Sample ready’ when measurement completes
         writeI2C(0x010a,0x30);// Set the averaging sample period (compromise between lower noise and increased execution time)
         writeI2C(0x003f,0x46);// Sets the light and dark gain (upper nibble). Dark gain should not be changed.
-        writeI2C(0x0031,0xFF);// sets the # of range measurements after which auto calibration of system is performed 
+        writeI2C(0x0031,0xFF);// sets the # of range measurements after which auto calibration of system is performed
         writeI2C(0x0040,0x63);// Set ALS integration time to 100ms
-        writeI2C(0x002e,0x01);// perform a single temperature calibration of the ranging sensor 
+        writeI2C(0x002e,0x01);// perform a single temperature calibration of the ranging sensor
         //optional initialization
         writeI2C(0x001b,0x09);// Set default ranging inter-measurement period to 100ms
         writeI2C(0x003e,0x31);// Set default ALS inter-measurement period to 500ms
         writeI2C(0x0014,0x24);// Configures interrupt on ‘New Sample Ready threshold event’
-        
+
         writeI2C(0x016,0x00);//change fresh out of set status to 0
     }
 }
 
-float VL6180::read() {
+float VL6180::read()
+{
     char status;
     char retn;
-    
+
     writeI2C(0x18, 0x01);
-    
+
     status = readI2C(0x4F);
     while((status & 0x7) != 4) {
         status = readI2C(0x4F);
     }
-    
+
     retn = readI2C(0x62);
-    
+
     writeI2C(0x15, 0x07);
-    
+
     return (float)retn / 10.0;
 }
 
-VL6180::operator float() {
+VL6180::operator float()
+{
     return read();
 }
 
 
-void VL6180::writeI2C(int reg, char data) {
+void VL6180::writeI2C(int reg, char data)
+{
     char dataout[3];
-    
+
     dataout[0] = (reg >> 8) & 0xFF;
     dataout[1] = reg & 0xFF;
     dataout[2] = data & 0xFF;
-    
+
     _i2c.write(_addr, dataout, 3);
 }
 
-char VL6180::readI2C(int reg) {
+char VL6180::readI2C(int reg)
+{
     char dataout[2];
     char datain[1];
-    
+
     dataout[0] = (reg >> 8) & 0xFF;
     dataout[1] = reg & 0xFF;
-    
+
     _i2c.write(_addr, dataout, 2);
     _i2c.read(_addr, datain, 1);
-    
+
     return datain[0];
-}
-    
\ No newline at end of file
+}
\ No newline at end of file