Fabio Faria / ISR_Mini-explorer_tmp2

Dependencies:   RF24

Dependents:   ISR_Mini-explorer_Rangefinder

Fork of ISR_Mini-explorer by ISR UC

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Rangefinder.cpp Source File

Rangefinder.cpp

00001 #include "Rangefinder.h"
00002 #include "mbed.h"
00003 
00004 const int rgfAddr = 0x14;
00005 uint16_t rgfMeasurements[16];
00006 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.
00007 
00008 I2C* _i2c;
00009 Mutex* _mutex;
00010 
00011 void init_rangefinder(I2C* i2c_in, Mutex* mutex_in)
00012 {
00013     _i2c = i2c_in;
00014     _mutex = mutex_in;
00015     wait(1);
00016     _mutex->lock();
00017     _i2c->write(rgfAddr, sensors_selection, 16);
00018     _mutex->unlock();
00019     wait(1);
00020 }
00021 
00022 int read_rangefinder()
00023 {
00024     int i2c_result;
00025 
00026     _mutex->lock();
00027     i2c_result = _i2c->read(rgfAddr, (char*)rgfMeasurements, sizeof(rgfMeasurements));
00028     _mutex->unlock();
00029 
00030     return i2c_result;
00031 }