library for m3Dpi robot, based on the Pololu 3pi and m3pi. m3Dpi has multiple distance sensors, gyroscope, compass and accelerometer sensor to be fully aware of its environment. With the addition of xbee or nrf24n01 module it has wireless communication capabilities.

Dependencies:   m3pi ADXL345_I2C HMC5583L ITG3200 PCA9547 TLC59116 VL6180x RGB-fun xbee

Dependents:   m3Dpi-helloworld

lib/vl6180xManager.cpp

Committer:
sillevl
Date:
2016-01-20
Revision:
12:4cb092df6958
Parent:
11:6f2440be5aa4

File content as of revision 12:4cb092df6958:

#include "vl6180xManager.h"

VL6180xManager::VL6180xManager(I2C &_i2c): mux(_i2c), i2c(_i2c), sensor(i2c)
{
    initialize();
}

VL6180xManager::VL6180xManager(PinName sda, PinName scl) : mux(sda, scl), i2c(sda, scl), sensor(sda, scl)
{
    i2c.frequency(400000);   
    initialize();
}

void VL6180xManager::initialize()
{  
    for(int i = 0; i < SENSOR_COUNT; i++) {
        select(i);
        sensor.initialize();
        sensor.startContinuousOperation();
    }
}

void VL6180xManager::select(int index)
{
    mux.select(index);
}

m3dpi::Distance VL6180xManager::getAllDistance()
{
    m3dpi::Distance distance;
    distance.front          = getDistance(0);
    distance.front_right    = getDistance(1);
    distance.right          = getDistance(2);
    distance.back_right     = getDistance(3);
    distance.back           = getDistance(4);
    distance.back_left      = getDistance(5);
    distance.left           = getDistance(6);
    distance.front_left     = getDistance(7);
    return distance;
}

int VL6180xManager::getDistance(int index)
{
    mux.select(index);
    return sensor.getDistance();
}