blob: a36fc2ea20818d592f29ded00950c72291319815 [file] [log] [blame]
Brian Silverman07ec88e2014-12-28 00:13:08 -08001#ifndef FRC971_WPILIB_GYRO_H_
2#define FRC971_WPILIB_GYRO_H_
3
4#include <stdint.h>
5
6#include <atomic>
7
8#include "frc971/wpilib/gyro_interface.h"
9
10namespace frc971 {
11namespace wpilib {
12
13// Handles reading the gyro over SPI and sending out angles on a queue.
14//
15// This is designed to be passed into ::std::thread's constructor so it will run
16// as a separate thread.
17class GyroSender {
18 public:
19 GyroSender();
20
21 // For ::std::thread to call.
22 //
Brian Silverman5f17a972016-02-28 01:49:32 -050023 // Initializes the gyro and then loops until Quit() is called taking readings.
Brian Silverman07ec88e2014-12-28 00:13:08 -080024 void operator()();
25
26 void Quit() { run_ = false; }
27
28 private:
29
30 // Readings per second.
31 static const int kReadingRate = 200;
32
33 GyroInterface gyro_;
34
35 ::std::atomic<bool> run_{true};
36};
37
38} // namespace wpilib
39} // namespace frc971
40
41#endif // FRC971_WPILIB_GYRO_H_