blob: baba248c81d57ef04156f24734c1921788a812dd [file] [log] [blame]
Brian Silverman07ec88e2014-12-28 00:13:08 -08001#ifndef FRC971_WPILIB_GYRO_INTERFACE_H_
2#define FRC971_WPILIB_GYRO_INTERFACE_H_
3
4#include <memory>
5
6#include "SPI.h"
7
8namespace frc971 {
9namespace wpilib {
10
11class GyroInterface {
12 public:
13 GyroInterface();
14
15 // Runs the recommended gyro startup procedure including checking all of the
16 // self-test bits.
17 // Returns true if it succeeds.
18 bool InitializeGyro();
19
20 // Reads one of the gyro's "registers" and returns the value.
21 // Retries until it succeeds.
22 uint16_t DoRead(uint8_t address);
23
24 // Returns all of the non-data bits in the "header" except the parity from
25 // value.
26 uint8_t ExtractStatus(uint32_t value) { return (value >> 26) & ~4; }
27 // Returns all of the error bits in the "footer" from value.
28 uint8_t ExtractErrors(uint32_t value) { return (value >> 1) & 0x7F; }
29
30 // Returns the anglular rate contained in value.
31 double ExtractAngle(uint32_t value);
32
33 // Performs a transaction with the gyro.
34 // to_write is the value to write. This function handles setting the checksum
35 // bit.
36 // result is where to stick the result. This function verifies the parity bit.
37 // Returns true for success.
38 bool DoTransaction(uint32_t to_write, uint32_t *result);
39
40 // Returns the part ID from the gyro.
41 // Retries until it succeeds.
42 uint32_t ReadPartID();
43
44 // Gets a reading from the gyro.
45 // Returns a value to be passed to the Extract* methods or 0 for error.
46 uint32_t GetReading();
47
48 private:
49 ::std::unique_ptr<SPI> gyro_;
50};
51
52} // namespace wpilib
53} // namespace frc971
54
55#endif // FRC971_WPILIB_GYRO_INTERFACE_H_