Ironcup Mar 2020

Dependencies:   mbed mbed-rtos MotionSensor EthernetInterface

Committer:
Alexandre Seidy
Date:
Sat Apr 30 14:18:43 2016 -0300
Revision:
11:7f569811a5f1
Parent:
9:bd0fb9d17803
Child:
12:273752f540be
minor fixes

Who changed what in which revision?

UserRevisionLine numberNew contents of line
drelliak 0:88faaa1afb83 1 /* Copyright (c) 2015 NXP Semiconductors. MIT License
drelliak 0:88faaa1afb83 2 *
drelliak 0:88faaa1afb83 3 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
drelliak 0:88faaa1afb83 4 * and associated documentation files (the "Software"), to deal in the Software without
drelliak 0:88faaa1afb83 5 * restriction, including without limitation the rights to use, copy, modify, merge, publish,
drelliak 0:88faaa1afb83 6 * distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
drelliak 0:88faaa1afb83 7 * Software is furnished to do so, subject to the following conditions:
drelliak 0:88faaa1afb83 8 *
drelliak 0:88faaa1afb83 9 * The above copyright notice and this permission notice shall be included in all copies or
drelliak 0:88faaa1afb83 10 * substantial portions of the Software.
drelliak 0:88faaa1afb83 11 *
drelliak 0:88faaa1afb83 12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
drelliak 0:88faaa1afb83 13 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
drelliak 0:88faaa1afb83 14 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
drelliak 0:88faaa1afb83 15 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
drelliak 0:88faaa1afb83 16 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
drelliak 0:88faaa1afb83 17 */
drelliak 0:88faaa1afb83 18
drelliak 0:88faaa1afb83 19 #include "FXAS21002.h"
Alexandre Seidy 9:bd0fb9d17803 20 #include "mbed.h"
drelliak 0:88faaa1afb83 21
drelliak 0:88faaa1afb83 22 FXAS21002::FXAS21002(PinName sda, PinName scl) : gyroi2c(sda,scl)
Alexandre Seidy 9:bd0fb9d17803 23 {
drelliak 0:88faaa1afb83 24
Alexandre Seidy 9:bd0fb9d17803 25 }
Alexandre Seidy 9:bd0fb9d17803 26
Alexandre Seidy 9:bd0fb9d17803 27 void FXAS21002::set_gyro(gyro_mode mode){ // Protected method
Alexandre Seidy 9:bd0fb9d17803 28 char d[2];
Alexandre Seidy 9:bd0fb9d17803 29 d[0] = FXAS21002_CTRL_REG1; //Puts device in standby mode
Alexandre Seidy 9:bd0fb9d17803 30 d[1] = 0x08;
Alexandre Seidy 9:bd0fb9d17803 31 gyroi2c.write(FXAS21002_I2C_ADDRESS, d,2);
Alexandre Seidy 9:bd0fb9d17803 32
Alexandre Seidy 9:bd0fb9d17803 33 d[0] = FXAS21002_CTRL_REG0; //Sets FSR and Sensitivity
Alexandre Seidy 9:bd0fb9d17803 34 d[1] = mode;
Alexandre Seidy 9:bd0fb9d17803 35 gyroi2c.write(FXAS21002_I2C_ADDRESS, d, 2);
Alexandre Seidy 9:bd0fb9d17803 36
Alexandre Seidy 9:bd0fb9d17803 37 d[0] = FXAS21002_CTRL_REG1; //Puts device in active mode
Alexandre Seidy 9:bd0fb9d17803 38 d[1] = 0x0A;
Alexandre Seidy 9:bd0fb9d17803 39 gyroi2c.write(FXAS21002_I2C_ADDRESS, d,2);
Alexandre Seidy 9:bd0fb9d17803 40 }
Alexandre Seidy 9:bd0fb9d17803 41
Alexandre Seidy 9:bd0fb9d17803 42 void FXAS21002::gyro_config(void)
Alexandre Seidy 9:bd0fb9d17803 43 {
Alexandre Seidy 11:7f569811a5f1 44 set_gyro(MODE_2); //Default implementation
Alexandre Seidy 9:bd0fb9d17803 45 sensitivity = 0.03125;
Alexandre Seidy 9:bd0fb9d17803 46 }
drelliak 0:88faaa1afb83 47
Alexandre Seidy 9:bd0fb9d17803 48 void FXAS21002::gyro_config(gyro_mode mode){
Alexandre Seidy 9:bd0fb9d17803 49 set_gyro(mode);
Alexandre Seidy 9:bd0fb9d17803 50 switch(mode)
Alexandre Seidy 9:bd0fb9d17803 51 {
Alexandre Seidy 9:bd0fb9d17803 52 case MODE_1: sensitivity = 0.0625; break;
Alexandre Seidy 9:bd0fb9d17803 53 case MODE_2: sensitivity = 0.03125; break;
Alexandre Seidy 9:bd0fb9d17803 54 case MODE_3: sensitivity = 0.015625; break;
Alexandre Seidy 11:7f569811a5f1 55 case MODE_4: sensitivity = 0.0078125; break;
Alexandre Seidy 9:bd0fb9d17803 56 }
Alexandre Seidy 9:bd0fb9d17803 57 }
Alexandre Seidy 9:bd0fb9d17803 58
Alexandre Seidy 9:bd0fb9d17803 59 void FXAS21002::acquire_gyro_data_dps(float * g_data)
Alexandre Seidy 9:bd0fb9d17803 60 {
drelliak 0:88faaa1afb83 61
drelliak 0:88faaa1afb83 62 char data_bytes[7];
Alexandre Seidy 9:bd0fb9d17803 63 gyroi2c.write(FXAS21002_I2C_ADDRESS,FXAS21002_STATUS,1,true); // Read the 6 data bytes - LSB and MSB for X, Y and Z Axes.
Alexandre Seidy 9:bd0fb9d17803 64 gyroi2c.read(FXAS21002_I2C_ADDRESS,data_bytes,7);
Alexandre Seidy 9:bd0fb9d17803 65
Alexandre Seidy 9:bd0fb9d17803 66 g_data[0] = (float)((int16_t)((data_bytes[1]*256) + (data_bytes[2]))) * sensitivity;
Alexandre Seidy 9:bd0fb9d17803 67 g_data[1] = (float)((int16_t)((data_bytes[3]*256) + (data_bytes[4]))) * sensitivity;
Alexandre Seidy 9:bd0fb9d17803 68 g_data[2] = (float)((int16_t)((data_bytes[5]*256) + (data_bytes[6]))) * sensitivity;
drelliak 0:88faaa1afb83 69
Alexandre Seidy 9:bd0fb9d17803 70 }
drelliak 0:88faaa1afb83 71
drelliak 0:88faaa1afb83 72
drelliak 0:88faaa1afb83 73
drelliak 0:88faaa1afb83 74