Sabina Davis | adc5854 | 2019-02-01 22:23:00 -0800 | [diff] [blame^] | 1 | #ifndef FRC971_WPILIB_SENSOR_READER_H_ |
| 2 | #define FRC971_WPILIB_SENSOR_READER_H_ |
| 3 | |
| 4 | #include <atomic> |
| 5 | #include <chrono> |
| 6 | |
| 7 | #include "aos/stl_mutex/stl_mutex.h" |
| 8 | #include "aos/time/time.h" |
| 9 | #include "frc971/wpilib/ahal/DigitalGlitchFilter.h" |
| 10 | #include "frc971/wpilib/ahal/DigitalInput.h" |
| 11 | |
| 12 | using ::aos::monotonic_clock; |
| 13 | namespace chrono = ::std::chrono; |
| 14 | |
| 15 | namespace frc971 { |
| 16 | namespace wpilib { |
| 17 | |
| 18 | class SensorReader { |
| 19 | public: |
| 20 | SensorReader(); |
| 21 | |
| 22 | void set_pwm_trigger(::std::unique_ptr<frc::DigitalInput> pwm_trigger); |
| 23 | |
| 24 | protected: |
| 25 | void RunPWMDetecter(); |
| 26 | |
| 27 | ::std::unique_ptr<frc::DigitalInput> pwm_trigger_; |
| 28 | |
| 29 | frc::DigitalGlitchFilter fast_encoder_filter_, medium_encoder_filter_, |
| 30 | hall_filter_; |
| 31 | |
| 32 | // Mutex to manage access to the period and tick time variables. |
| 33 | ::aos::stl_mutex tick_time_mutex_; |
| 34 | monotonic_clock::time_point last_tick_time_monotonic_timepoint_ = |
| 35 | monotonic_clock::min_time; |
| 36 | chrono::nanoseconds last_period_ = chrono::microseconds(5050); |
| 37 | |
| 38 | ::std::atomic<bool> run_{true}; |
| 39 | }; |
| 40 | |
| 41 | } // namespace wpilib |
| 42 | } // namespace frc971 |
| 43 | |
| 44 | #endif // FRC971_WPILIB_SENSOR_READER_H_ |