Energy harvesting mobile robot. Developed at Institute of Systems and Robotics — University of Coimbra.

Dependencies:   RF24

Fork of ISR_Mini-explorer by ISR UC

Rangefinder.cpp

Committer:
fabiofaria
Date:
2018-04-19
Revision:
4:560d24c0e5f8

File content as of revision 4:560d24c0e5f8:

#include "Rangefinder.h"
#include "mbed.h"

const int rgfAddr = 0x14;
uint16_t rgfMeasurements[16];
//char sensors_selection[] = {1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0}; // Only allows a maximum of 11 sensors simultaneously.
//char sensors_selection[] = {1,0,0,0,1,0,1,0,1,0,1,0,1,0,1,0}; // Only allows a maximum of 11 sensors simultaneously.
char sensors_selection[] = {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; // Only allows a maximum of 11 sensors simultaneously.

I2C* _i2c;
Mutex* _mutex;

void init_rangefinder(I2C* i2c_in, Mutex* mutex_in)
{
    _i2c = i2c_in;
    _mutex = mutex_in;
    wait(1);
    _mutex->lock();
    _i2c->write(rgfAddr, sensors_selection, 16);
    _mutex->unlock();
    wait(1);
}

int read_rangefinder()
{
    int i2c_result;

    _mutex->lock();
    i2c_result = _i2c->read(rgfAddr, (char*)rgfMeasurements, sizeof(rgfMeasurements));
    _mutex->unlock();

    return i2c_result;
}