Modified to run on Renesas GR Peach board

Dependencies:   EthernetInterface HTTP-Server Webpage mbed-rpc mbed-src

Fork of HTTPServer_echoback by Takuya Urakawa

Committer:
webOnBoard
Date:
Wed Oct 07 20:42:51 2015 +0000
Revision:
16:5d102be2566c
web based AHRS demo Renesas GR Peach board; Using HTTP Server/RPC Adafruit 10DOF

Who changed what in which revision?

UserRevisionLine numberNew contents of line
webOnBoard 16:5d102be2566c 1 /***************************************************
webOnBoard 16:5d102be2566c 2 This is a library for the L3GD20 GYROSCOPE
webOnBoard 16:5d102be2566c 3
webOnBoard 16:5d102be2566c 4 Designed specifically to work with the Adafruit L3GD20 Breakout
webOnBoard 16:5d102be2566c 5 ----> https://www.adafruit.com/products/1032
webOnBoard 16:5d102be2566c 6
webOnBoard 16:5d102be2566c 7 These sensors use I2C or SPI to communicate, 2 pins (I2C)
webOnBoard 16:5d102be2566c 8 or 4 pins (SPI) are required to interface.
webOnBoard 16:5d102be2566c 9
webOnBoard 16:5d102be2566c 10 Adafruit invests time and resources providing this open source code,
webOnBoard 16:5d102be2566c 11 please support Adafruit and open-source hardware by purchasing
webOnBoard 16:5d102be2566c 12 products from Adafruit!
webOnBoard 16:5d102be2566c 13
webOnBoard 16:5d102be2566c 14 Written by Kevin "KTOWN" Townsend for Adafruit Industries.
webOnBoard 16:5d102be2566c 15 BSD license, all text above must be included in any redistribution
webOnBoard 16:5d102be2566c 16 ****************************************************/
webOnBoard 16:5d102be2566c 17
webOnBoard 16:5d102be2566c 18 #include "Adafruit_L3GD20_U.h"
webOnBoard 16:5d102be2566c 19
webOnBoard 16:5d102be2566c 20
webOnBoard 16:5d102be2566c 21 //Timer timer;
webOnBoard 16:5d102be2566c 22
webOnBoard 16:5d102be2566c 23 //extern I2C i2c(I2C_SDA, I2C_SCL); // sda, scl
webOnBoard 16:5d102be2566c 24
webOnBoard 16:5d102be2566c 25 /***************************************************************************
webOnBoard 16:5d102be2566c 26 PRIVATE FUNCTIONS
webOnBoard 16:5d102be2566c 27 ***************************************************************************/
webOnBoard 16:5d102be2566c 28
webOnBoard 16:5d102be2566c 29 /**************************************************************************/
webOnBoard 16:5d102be2566c 30 /*!
webOnBoard 16:5d102be2566c 31 @brief Abstract away platform differences in Arduino wire library
webOnBoard 16:5d102be2566c 32 */
webOnBoard 16:5d102be2566c 33 /**************************************************************************/
webOnBoard 16:5d102be2566c 34 void Adafruit_L3GD20_Unified::write8(byte reg, byte value)
webOnBoard 16:5d102be2566c 35 {
webOnBoard 16:5d102be2566c 36 char data_write[2];
webOnBoard 16:5d102be2566c 37
webOnBoard 16:5d102be2566c 38 data_write[0] = reg;
webOnBoard 16:5d102be2566c 39 data_write[1] = value;
webOnBoard 16:5d102be2566c 40 int status = i2c->write(L3GD20_ADDRESS, data_write, 2, 0);
webOnBoard 16:5d102be2566c 41
webOnBoard 16:5d102be2566c 42 }
webOnBoard 16:5d102be2566c 43
webOnBoard 16:5d102be2566c 44 /**************************************************************************/
webOnBoard 16:5d102be2566c 45 /*!
webOnBoard 16:5d102be2566c 46 @brief Abstract away platform differences in Arduino wire library
webOnBoard 16:5d102be2566c 47 */
webOnBoard 16:5d102be2566c 48 /**************************************************************************/
webOnBoard 16:5d102be2566c 49 byte Adafruit_L3GD20_Unified::read8(byte reg)
webOnBoard 16:5d102be2566c 50 {
webOnBoard 16:5d102be2566c 51 byte value;
webOnBoard 16:5d102be2566c 52
webOnBoard 16:5d102be2566c 53
webOnBoard 16:5d102be2566c 54 char data_write[2];
webOnBoard 16:5d102be2566c 55 char data_read[2];
webOnBoard 16:5d102be2566c 56
webOnBoard 16:5d102be2566c 57
webOnBoard 16:5d102be2566c 58 // Read register
webOnBoard 16:5d102be2566c 59 data_write[0] = reg;
webOnBoard 16:5d102be2566c 60 i2c->write(L3GD20_ADDRESS, data_write, 1, 1); // no stop
webOnBoard 16:5d102be2566c 61 i2c->read(L3GD20_ADDRESS, data_read, 2, 0);
webOnBoard 16:5d102be2566c 62 value = data_read[0];
webOnBoard 16:5d102be2566c 63
webOnBoard 16:5d102be2566c 64 return value;
webOnBoard 16:5d102be2566c 65 }
webOnBoard 16:5d102be2566c 66
webOnBoard 16:5d102be2566c 67 /***************************************************************************
webOnBoard 16:5d102be2566c 68 CONSTRUCTOR
webOnBoard 16:5d102be2566c 69 ***************************************************************************/
webOnBoard 16:5d102be2566c 70
webOnBoard 16:5d102be2566c 71 /**************************************************************************/
webOnBoard 16:5d102be2566c 72 /*!
webOnBoard 16:5d102be2566c 73 @brief Instantiates a new Adafruit_L3GD20_Unified class
webOnBoard 16:5d102be2566c 74 */
webOnBoard 16:5d102be2566c 75 /**************************************************************************/
webOnBoard 16:5d102be2566c 76 Adafruit_L3GD20_Unified::Adafruit_L3GD20_Unified(int32_t sensorID) {
webOnBoard 16:5d102be2566c 77 _sensorID = sensorID;
webOnBoard 16:5d102be2566c 78 _autoRangeEnabled = false;
webOnBoard 16:5d102be2566c 79 }
webOnBoard 16:5d102be2566c 80
webOnBoard 16:5d102be2566c 81 /***************************************************************************
webOnBoard 16:5d102be2566c 82 PUBLIC FUNCTIONS
webOnBoard 16:5d102be2566c 83 ***************************************************************************/
webOnBoard 16:5d102be2566c 84
webOnBoard 16:5d102be2566c 85 /**************************************************************************/
webOnBoard 16:5d102be2566c 86 /*!
webOnBoard 16:5d102be2566c 87 @brief Setups the HW
webOnBoard 16:5d102be2566c 88 */
webOnBoard 16:5d102be2566c 89 /**************************************************************************/
webOnBoard 16:5d102be2566c 90 bool Adafruit_L3GD20_Unified::begin(gyroRange_t rng)
webOnBoard 16:5d102be2566c 91 {
webOnBoard 16:5d102be2566c 92
webOnBoard 16:5d102be2566c 93 /* Set the range the an appropriate value */
webOnBoard 16:5d102be2566c 94 _range = rng;
webOnBoard 16:5d102be2566c 95
webOnBoard 16:5d102be2566c 96 /* Make sure we have the correct chip ID since this checks
webOnBoard 16:5d102be2566c 97 for correct address and that the IC is properly connected */
webOnBoard 16:5d102be2566c 98 uint8_t id = read8(GYRO_REGISTER_WHO_AM_I);
webOnBoard 16:5d102be2566c 99 //Serial.println(id, HEX);
webOnBoard 16:5d102be2566c 100 if ((id != L3GD20_ID) && (id != L3GD20H_ID))
webOnBoard 16:5d102be2566c 101 {
webOnBoard 16:5d102be2566c 102 return false;
webOnBoard 16:5d102be2566c 103 }
webOnBoard 16:5d102be2566c 104
webOnBoard 16:5d102be2566c 105 /* Set CTRL_REG1 (0x20)
webOnBoard 16:5d102be2566c 106 ====================================================================
webOnBoard 16:5d102be2566c 107 BIT Symbol Description Default
webOnBoard 16:5d102be2566c 108 --- ------ --------------------------------------------- -------
webOnBoard 16:5d102be2566c 109 7-6 DR1/0 Output data rate 00
webOnBoard 16:5d102be2566c 110 5-4 BW1/0 Bandwidth selection 00
webOnBoard 16:5d102be2566c 111 3 PD 0 = Power-down mode, 1 = normal/sleep mode 0
webOnBoard 16:5d102be2566c 112 2 ZEN Z-axis enable (0 = disabled, 1 = enabled) 1
webOnBoard 16:5d102be2566c 113 1 YEN Y-axis enable (0 = disabled, 1 = enabled) 1
webOnBoard 16:5d102be2566c 114 0 XEN X-axis enable (0 = disabled, 1 = enabled) 1 */
webOnBoard 16:5d102be2566c 115
webOnBoard 16:5d102be2566c 116 /* Reset then switch to normal mode and enable all three channels */
webOnBoard 16:5d102be2566c 117 write8(GYRO_REGISTER_CTRL_REG1, 0x00);
webOnBoard 16:5d102be2566c 118 write8(GYRO_REGISTER_CTRL_REG1, 0x0F);
webOnBoard 16:5d102be2566c 119 /* ------------------------------------------------------------------ */
webOnBoard 16:5d102be2566c 120
webOnBoard 16:5d102be2566c 121 /* Set CTRL_REG2 (0x21)
webOnBoard 16:5d102be2566c 122 ====================================================================
webOnBoard 16:5d102be2566c 123 BIT Symbol Description Default
webOnBoard 16:5d102be2566c 124 --- ------ --------------------------------------------- -------
webOnBoard 16:5d102be2566c 125 5-4 HPM1/0 High-pass filter mode selection 00
webOnBoard 16:5d102be2566c 126 3-0 HPCF3..0 High-pass filter cutoff frequency selection 0000 */
webOnBoard 16:5d102be2566c 127
webOnBoard 16:5d102be2566c 128 /* Nothing to do ... keep default values */
webOnBoard 16:5d102be2566c 129 /* ------------------------------------------------------------------ */
webOnBoard 16:5d102be2566c 130
webOnBoard 16:5d102be2566c 131 /* Set CTRL_REG3 (0x22)
webOnBoard 16:5d102be2566c 132 ====================================================================
webOnBoard 16:5d102be2566c 133 BIT Symbol Description Default
webOnBoard 16:5d102be2566c 134 --- ------ --------------------------------------------- -------
webOnBoard 16:5d102be2566c 135 7 I1_Int1 Interrupt enable on INT1 (0=disable,1=enable) 0
webOnBoard 16:5d102be2566c 136 6 I1_Boot Boot status on INT1 (0=disable,1=enable) 0
webOnBoard 16:5d102be2566c 137 5 H-Lactive Interrupt active config on INT1 (0=high,1=low) 0
webOnBoard 16:5d102be2566c 138 4 PP_OD Push-Pull/Open-Drain (0=PP, 1=OD) 0
webOnBoard 16:5d102be2566c 139 3 I2_DRDY Data ready on DRDY/INT2 (0=disable,1=enable) 0
webOnBoard 16:5d102be2566c 140 2 I2_WTM FIFO wtrmrk int on DRDY/INT2 (0=dsbl,1=enbl) 0
webOnBoard 16:5d102be2566c 141 1 I2_ORun FIFO overrun int on DRDY/INT2 (0=dsbl,1=enbl) 0
webOnBoard 16:5d102be2566c 142 0 I2_Empty FIFI empty int on DRDY/INT2 (0=dsbl,1=enbl) 0 */
webOnBoard 16:5d102be2566c 143
webOnBoard 16:5d102be2566c 144 /* Nothing to do ... keep default values */
webOnBoard 16:5d102be2566c 145 /* ------------------------------------------------------------------ */
webOnBoard 16:5d102be2566c 146
webOnBoard 16:5d102be2566c 147 /* Set CTRL_REG4 (0x23)
webOnBoard 16:5d102be2566c 148 ====================================================================
webOnBoard 16:5d102be2566c 149 BIT Symbol Description Default
webOnBoard 16:5d102be2566c 150 --- ------ --------------------------------------------- -------
webOnBoard 16:5d102be2566c 151 7 BDU Block Data Update (0=continuous, 1=LSB/MSB) 0
webOnBoard 16:5d102be2566c 152 6 BLE Big/Little-Endian (0=Data LSB, 1=Data MSB) 0
webOnBoard 16:5d102be2566c 153 5-4 FS1/0 Full scale selection 00
webOnBoard 16:5d102be2566c 154 00 = 250 dps
webOnBoard 16:5d102be2566c 155 01 = 500 dps
webOnBoard 16:5d102be2566c 156 10 = 2000 dps
webOnBoard 16:5d102be2566c 157 11 = 2000 dps
webOnBoard 16:5d102be2566c 158 0 SIM SPI Mode (0=4-wire, 1=3-wire) 0 */
webOnBoard 16:5d102be2566c 159
webOnBoard 16:5d102be2566c 160 /* Adjust resolution if requested */
webOnBoard 16:5d102be2566c 161 switch(_range)
webOnBoard 16:5d102be2566c 162 {
webOnBoard 16:5d102be2566c 163 case GYRO_RANGE_250DPS:
webOnBoard 16:5d102be2566c 164 write8(GYRO_REGISTER_CTRL_REG4, 0x00);
webOnBoard 16:5d102be2566c 165 break;
webOnBoard 16:5d102be2566c 166 case GYRO_RANGE_500DPS:
webOnBoard 16:5d102be2566c 167 write8(GYRO_REGISTER_CTRL_REG4, 0x10);
webOnBoard 16:5d102be2566c 168 break;
webOnBoard 16:5d102be2566c 169 case GYRO_RANGE_2000DPS:
webOnBoard 16:5d102be2566c 170 write8(GYRO_REGISTER_CTRL_REG4, 0x20);
webOnBoard 16:5d102be2566c 171 break;
webOnBoard 16:5d102be2566c 172 }
webOnBoard 16:5d102be2566c 173 /* ------------------------------------------------------------------ */
webOnBoard 16:5d102be2566c 174
webOnBoard 16:5d102be2566c 175 /* Set CTRL_REG5 (0x24)
webOnBoard 16:5d102be2566c 176 ====================================================================
webOnBoard 16:5d102be2566c 177 BIT Symbol Description Default
webOnBoard 16:5d102be2566c 178 --- ------ --------------------------------------------- -------
webOnBoard 16:5d102be2566c 179 7 BOOT Reboot memory content (0=normal, 1=reboot) 0
webOnBoard 16:5d102be2566c 180 6 FIFO_EN FIFO enable (0=FIFO disable, 1=enable) 0
webOnBoard 16:5d102be2566c 181 4 HPen High-pass filter enable (0=disable,1=enable) 0
webOnBoard 16:5d102be2566c 182 3-2 INT1_SEL INT1 Selection config 00
webOnBoard 16:5d102be2566c 183 1-0 OUT_SEL Out selection config 00 */
webOnBoard 16:5d102be2566c 184
webOnBoard 16:5d102be2566c 185 /* Nothing to do ... keep default values */
webOnBoard 16:5d102be2566c 186 /* ------------------------------------------------------------------ */
webOnBoard 16:5d102be2566c 187
webOnBoard 16:5d102be2566c 188 return true;
webOnBoard 16:5d102be2566c 189 }
webOnBoard 16:5d102be2566c 190
webOnBoard 16:5d102be2566c 191 /**************************************************************************/
webOnBoard 16:5d102be2566c 192 /*!
webOnBoard 16:5d102be2566c 193 @brief Enables or disables auto-ranging
webOnBoard 16:5d102be2566c 194 */
webOnBoard 16:5d102be2566c 195 /**************************************************************************/
webOnBoard 16:5d102be2566c 196 void Adafruit_L3GD20_Unified::enableAutoRange(bool enabled)
webOnBoard 16:5d102be2566c 197 {
webOnBoard 16:5d102be2566c 198 _autoRangeEnabled = enabled;
webOnBoard 16:5d102be2566c 199 }
webOnBoard 16:5d102be2566c 200
webOnBoard 16:5d102be2566c 201 /**************************************************************************/
webOnBoard 16:5d102be2566c 202 /*!
webOnBoard 16:5d102be2566c 203 @brief Gets the most recent sensor event
webOnBoard 16:5d102be2566c 204 */
webOnBoard 16:5d102be2566c 205 /**************************************************************************/
webOnBoard 16:5d102be2566c 206 bool Adafruit_L3GD20_Unified::getEvent(sensors_event_t* event)
webOnBoard 16:5d102be2566c 207 {
webOnBoard 16:5d102be2566c 208 char data_write[2];
webOnBoard 16:5d102be2566c 209 char data_read[6];
webOnBoard 16:5d102be2566c 210 uint32_t status;
webOnBoard 16:5d102be2566c 211 uint8_t xhi;
webOnBoard 16:5d102be2566c 212 uint8_t xlo;
webOnBoard 16:5d102be2566c 213 uint8_t zhi;
webOnBoard 16:5d102be2566c 214 uint8_t zlo;
webOnBoard 16:5d102be2566c 215 uint8_t yhi;
webOnBoard 16:5d102be2566c 216 uint8_t ylo;
webOnBoard 16:5d102be2566c 217
webOnBoard 16:5d102be2566c 218 bool readingValid = false;
webOnBoard 16:5d102be2566c 219
webOnBoard 16:5d102be2566c 220 /* Clear the event */
webOnBoard 16:5d102be2566c 221 memset(event, 0, sizeof(sensors_event_t));
webOnBoard 16:5d102be2566c 222
webOnBoard 16:5d102be2566c 223 event->version = sizeof(sensors_event_t);
webOnBoard 16:5d102be2566c 224 event->sensor_id = _sensorID;
webOnBoard 16:5d102be2566c 225 event->type = SENSOR_TYPE_GYROSCOPE;
webOnBoard 16:5d102be2566c 226
webOnBoard 16:5d102be2566c 227 while(!readingValid)
webOnBoard 16:5d102be2566c 228 {
webOnBoard 16:5d102be2566c 229 event->timestamp = timer.read_ms();//millis();
webOnBoard 16:5d102be2566c 230
webOnBoard 16:5d102be2566c 231 // Read 6 bytes from the sensor
webOnBoard 16:5d102be2566c 232 //status = Sample_RIIC_Read(L3GD20_ADDRESS,GYRO_REGISTER_OUT_X_L | 0x80,6,data_read);
webOnBoard 16:5d102be2566c 233 data_write[0] = GYRO_REGISTER_OUT_X_L | 0x80 ;
webOnBoard 16:5d102be2566c 234 i2c->write(L3GD20_ADDRESS, data_write, 1, 1);// non stop i2c
webOnBoard 16:5d102be2566c 235
webOnBoard 16:5d102be2566c 236 // Read the accelerometer
webOnBoard 16:5d102be2566c 237 // Read 6 byte data
webOnBoard 16:5d102be2566c 238 //status = i2c->read(L3GD20_ADDRESS, data_read, 6, 0);
webOnBoard 16:5d102be2566c 239 status = i2c->read(L3GD20_ADDRESS, data_read, 6, 0);
webOnBoard 16:5d102be2566c 240 // Read the accelerometer
webOnBoard 16:5d102be2566c 241
webOnBoard 16:5d102be2566c 242 // Wait around until enough data is available
webOnBoard 16:5d102be2566c 243
webOnBoard 16:5d102be2566c 244 if ( status == 0 )
webOnBoard 16:5d102be2566c 245 {
webOnBoard 16:5d102be2566c 246 xlo = data_read[0];
webOnBoard 16:5d102be2566c 247 xhi = data_read[1];
webOnBoard 16:5d102be2566c 248 ylo = data_read[2];
webOnBoard 16:5d102be2566c 249 yhi = data_read[3];
webOnBoard 16:5d102be2566c 250 zlo = data_read[4];
webOnBoard 16:5d102be2566c 251 zhi = data_read[5];
webOnBoard 16:5d102be2566c 252 }
webOnBoard 16:5d102be2566c 253 /* Shift values to create properly formed integer (low byte first) */
webOnBoard 16:5d102be2566c 254 event->gyro.x = (int16_t)(xlo | (xhi << 8));
webOnBoard 16:5d102be2566c 255 event->gyro.y = (int16_t)(ylo | (yhi << 8));
webOnBoard 16:5d102be2566c 256 event->gyro.z = (int16_t)(zlo | (zhi << 8));
webOnBoard 16:5d102be2566c 257
webOnBoard 16:5d102be2566c 258 /* Make sure the sensor isn't saturating if auto-ranging is enabled */
webOnBoard 16:5d102be2566c 259 if (!_autoRangeEnabled)
webOnBoard 16:5d102be2566c 260 {
webOnBoard 16:5d102be2566c 261 readingValid = true;
webOnBoard 16:5d102be2566c 262 }
webOnBoard 16:5d102be2566c 263 else
webOnBoard 16:5d102be2566c 264 {
webOnBoard 16:5d102be2566c 265 /* Check if the sensor is saturating or not */
webOnBoard 16:5d102be2566c 266 if ( (event->gyro.x >= 32760) | (event->gyro.x <= -32760) |
webOnBoard 16:5d102be2566c 267 (event->gyro.y >= 32760) | (event->gyro.y <= -32760) |
webOnBoard 16:5d102be2566c 268 (event->gyro.z >= 32760) | (event->gyro.z <= -32760) )
webOnBoard 16:5d102be2566c 269 {
webOnBoard 16:5d102be2566c 270 /* Saturating .... increase the range if we can */
webOnBoard 16:5d102be2566c 271 switch(_range)
webOnBoard 16:5d102be2566c 272 {
webOnBoard 16:5d102be2566c 273 case GYRO_RANGE_500DPS:
webOnBoard 16:5d102be2566c 274 /* Push the range up to 2000dps */
webOnBoard 16:5d102be2566c 275 _range = GYRO_RANGE_2000DPS;
webOnBoard 16:5d102be2566c 276 write8(GYRO_REGISTER_CTRL_REG1, 0x00);
webOnBoard 16:5d102be2566c 277 write8(GYRO_REGISTER_CTRL_REG1, 0x0F);
webOnBoard 16:5d102be2566c 278 write8(GYRO_REGISTER_CTRL_REG4, 0x20);
webOnBoard 16:5d102be2566c 279 write8(GYRO_REGISTER_CTRL_REG5, 0x80);
webOnBoard 16:5d102be2566c 280 readingValid = false;
webOnBoard 16:5d102be2566c 281 // Serial.println("Changing range to 2000DPS");
webOnBoard 16:5d102be2566c 282 break;
webOnBoard 16:5d102be2566c 283 case GYRO_RANGE_250DPS:
webOnBoard 16:5d102be2566c 284 /* Push the range up to 500dps */
webOnBoard 16:5d102be2566c 285 _range = GYRO_RANGE_500DPS;
webOnBoard 16:5d102be2566c 286 write8(GYRO_REGISTER_CTRL_REG1, 0x00);
webOnBoard 16:5d102be2566c 287 write8(GYRO_REGISTER_CTRL_REG1, 0x0F);
webOnBoard 16:5d102be2566c 288 write8(GYRO_REGISTER_CTRL_REG4, 0x10);
webOnBoard 16:5d102be2566c 289 write8(GYRO_REGISTER_CTRL_REG5, 0x80);
webOnBoard 16:5d102be2566c 290 readingValid = false;
webOnBoard 16:5d102be2566c 291 // Serial.println("Changing range to 500DPS");
webOnBoard 16:5d102be2566c 292 break;
webOnBoard 16:5d102be2566c 293 default:
webOnBoard 16:5d102be2566c 294 readingValid = true;
webOnBoard 16:5d102be2566c 295 break;
webOnBoard 16:5d102be2566c 296 }
webOnBoard 16:5d102be2566c 297 }
webOnBoard 16:5d102be2566c 298 else
webOnBoard 16:5d102be2566c 299 {
webOnBoard 16:5d102be2566c 300 /* All values are withing range */
webOnBoard 16:5d102be2566c 301 readingValid = true;
webOnBoard 16:5d102be2566c 302 }
webOnBoard 16:5d102be2566c 303 }
webOnBoard 16:5d102be2566c 304 }
webOnBoard 16:5d102be2566c 305
webOnBoard 16:5d102be2566c 306 /* Compensate values depending on the resolution */
webOnBoard 16:5d102be2566c 307 switch(_range)
webOnBoard 16:5d102be2566c 308 {
webOnBoard 16:5d102be2566c 309 case GYRO_RANGE_250DPS:
webOnBoard 16:5d102be2566c 310 event->gyro.x *= GYRO_SENSITIVITY_250DPS;
webOnBoard 16:5d102be2566c 311 event->gyro.y *= GYRO_SENSITIVITY_250DPS;
webOnBoard 16:5d102be2566c 312 event->gyro.z *= GYRO_SENSITIVITY_250DPS;
webOnBoard 16:5d102be2566c 313 break;
webOnBoard 16:5d102be2566c 314 case GYRO_RANGE_500DPS:
webOnBoard 16:5d102be2566c 315 event->gyro.x *= GYRO_SENSITIVITY_500DPS;
webOnBoard 16:5d102be2566c 316 event->gyro.y *= GYRO_SENSITIVITY_500DPS;
webOnBoard 16:5d102be2566c 317 event->gyro.z *= GYRO_SENSITIVITY_500DPS;
webOnBoard 16:5d102be2566c 318 break;
webOnBoard 16:5d102be2566c 319 case GYRO_RANGE_2000DPS:
webOnBoard 16:5d102be2566c 320 event->gyro.x *= GYRO_SENSITIVITY_2000DPS;
webOnBoard 16:5d102be2566c 321 event->gyro.y *= GYRO_SENSITIVITY_2000DPS;
webOnBoard 16:5d102be2566c 322 event->gyro.z *= GYRO_SENSITIVITY_2000DPS;
webOnBoard 16:5d102be2566c 323 break;
webOnBoard 16:5d102be2566c 324 }
webOnBoard 16:5d102be2566c 325
webOnBoard 16:5d102be2566c 326 /* Convert values to rad/s */
webOnBoard 16:5d102be2566c 327 event->gyro.x *= SENSORS_DPS_TO_RADS;
webOnBoard 16:5d102be2566c 328 event->gyro.y *= SENSORS_DPS_TO_RADS;
webOnBoard 16:5d102be2566c 329 event->gyro.z *= SENSORS_DPS_TO_RADS;
webOnBoard 16:5d102be2566c 330
webOnBoard 16:5d102be2566c 331 return true;
webOnBoard 16:5d102be2566c 332 }
webOnBoard 16:5d102be2566c 333
webOnBoard 16:5d102be2566c 334 /**************************************************************************/
webOnBoard 16:5d102be2566c 335 /*!
webOnBoard 16:5d102be2566c 336 @brief Gets the sensor_t data
webOnBoard 16:5d102be2566c 337 */
webOnBoard 16:5d102be2566c 338 /**************************************************************************/
webOnBoard 16:5d102be2566c 339 void Adafruit_L3GD20_Unified::getSensor(sensor_t* sensor)
webOnBoard 16:5d102be2566c 340 {
webOnBoard 16:5d102be2566c 341 /* Clear the sensor_t object */
webOnBoard 16:5d102be2566c 342 memset(sensor, 0, sizeof(sensor_t));
webOnBoard 16:5d102be2566c 343
webOnBoard 16:5d102be2566c 344 /* Insert the sensor name in the fixed length char array */
webOnBoard 16:5d102be2566c 345 strncpy (sensor->name, "L3GD20", sizeof(sensor->name) - 1);
webOnBoard 16:5d102be2566c 346 sensor->name[sizeof(sensor->name)- 1] = 0;
webOnBoard 16:5d102be2566c 347 sensor->version = 1;
webOnBoard 16:5d102be2566c 348 sensor->sensor_id = _sensorID;
webOnBoard 16:5d102be2566c 349 sensor->type = SENSOR_TYPE_GYROSCOPE;
webOnBoard 16:5d102be2566c 350 sensor->min_delay = 0;
webOnBoard 16:5d102be2566c 351 sensor->max_value = (float)this->_range * SENSORS_DPS_TO_RADS;
webOnBoard 16:5d102be2566c 352 sensor->min_value = (this->_range * -1.0) * SENSORS_DPS_TO_RADS;
webOnBoard 16:5d102be2566c 353 sensor->resolution = 0.0F; // TBD
webOnBoard 16:5d102be2566c 354 }