Pololu Minimu-9 library

Committer:
bengo
Date:
Tue Feb 21 13:34:27 2012 +0000
Revision:
0:6ee4ef99c382
first release

Who changed what in which revision?

UserRevisionLine numberNew contents of line
bengo 0:6ee4ef99c382 1 /* mbed Minimu-9 Library version 0beta1
bengo 0:6ee4ef99c382 2 * Copyright (c) 2012 bengo
bengo 0:6ee4ef99c382 3 *
bengo 0:6ee4ef99c382 4 * Permission is hereby granted, free of charge, to any person obtaining a copy
bengo 0:6ee4ef99c382 5 * of this software and associated documentation files (the "Software"), to deal
bengo 0:6ee4ef99c382 6 * in the Software without restriction, including without limitation the rights
bengo 0:6ee4ef99c382 7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
bengo 0:6ee4ef99c382 8 * copies of the Software, and to permit persons to whom the Software is
bengo 0:6ee4ef99c382 9 * furnished to do so, subject to the following conditions:
bengo 0:6ee4ef99c382 10 *
bengo 0:6ee4ef99c382 11 * The above copyright notice and this permission notice shall be included in
bengo 0:6ee4ef99c382 12 * all copies or substantial portions of the Software.
bengo 0:6ee4ef99c382 13 *
bengo 0:6ee4ef99c382 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
bengo 0:6ee4ef99c382 15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
bengo 0:6ee4ef99c382 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
bengo 0:6ee4ef99c382 17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
bengo 0:6ee4ef99c382 18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
bengo 0:6ee4ef99c382 19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
bengo 0:6ee4ef99c382 20 * THE SOFTWARE.
bengo 0:6ee4ef99c382 21 */
bengo 0:6ee4ef99c382 22
bengo 0:6ee4ef99c382 23 #include <minimu9.h>
bengo 0:6ee4ef99c382 24
bengo 0:6ee4ef99c382 25 // -------------------------------------------
bengo 0:6ee4ef99c382 26 minimu9::minimu9( PinName sda, PinName scl ) : _i2c(sda, scl), _lsm( sda, scl ), _l3g( sda, scl ) {
bengo 0:6ee4ef99c382 27 _status = _lsm.getStatus() * _l3g.getStatus();
bengo 0:6ee4ef99c382 28 }
bengo 0:6ee4ef99c382 29
bengo 0:6ee4ef99c382 30 // -------------------------------------------
bengo 0:6ee4ef99c382 31 std::vector<short> minimu9::read( void ) {
bengo 0:6ee4ef99c382 32 std::vector<short> data(9,0);
bengo 0:6ee4ef99c382 33 std::vector<short> acc = _lsm.accRead();
bengo 0:6ee4ef99c382 34 _status = _lsm.getStatus();
bengo 0:6ee4ef99c382 35 if( _status == 0 ) {
bengo 0:6ee4ef99c382 36 std::vector<short> mag = _lsm.magRead();
bengo 0:6ee4ef99c382 37 _status = _lsm.getStatus();
bengo 0:6ee4ef99c382 38 if( _status == 0 ) {
bengo 0:6ee4ef99c382 39 std::vector<short> gyr = _l3g.read();
bengo 0:6ee4ef99c382 40 _status = _l3g.getStatus();
bengo 0:6ee4ef99c382 41 if( _status == 0 ) {
bengo 0:6ee4ef99c382 42 for( int i=0; i<3; i++ ) {
bengo 0:6ee4ef99c382 43 data[i ] = acc[i];
bengo 0:6ee4ef99c382 44 data[i+3] = mag[i];
bengo 0:6ee4ef99c382 45 data[i+6] = gyr[i];
bengo 0:6ee4ef99c382 46 }
bengo 0:6ee4ef99c382 47 }
bengo 0:6ee4ef99c382 48 }
bengo 0:6ee4ef99c382 49 }
bengo 0:6ee4ef99c382 50 return( data );
bengo 0:6ee4ef99c382 51 }