-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgyro.cpp
More file actions
24 lines (19 loc) · 696 Bytes
/
Copy pathgyro.cpp
File metadata and controls
24 lines (19 loc) · 696 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
// gyro.cpp
#include "gyro.h"
#include "register.h"
void initGyro(int device) {
// setup L3G4200D(gyro)
setRegister(device, 0x20, 0b00001111); // CTRL_REG1
setRegister(device, 0x21, 0b00000000); // CTRL_REG2
setRegister(device, 0x22, 0b00001000); // CTRL_REG3
setRegister(device, 0x23, 0b00000000); // CTRL_REG4
setRegister(device, 0x24, 0b00010000); // CTRL_REG5
}
void readGyro(int device, Vector3 *data) {
data->x = (readRegister(device, 0x29) << 8);
data->x |= readRegister(device, 0x28);
data->y = (readRegister(device, 0x2B) << 8);
data->y |= readRegister(device, 0x2A);
data->z = (readRegister(device, 0x2D) << 8);
data->z |= readRegister(device, 0x2C);
}