Brian Silverman | 425492b | 2015-12-30 15:23:55 -0800 | [diff] [blame^] | 1 | #ifndef FRC971_WPILIB_PDP_FETCHER_H_ |
| 2 | #define FRC971_WPILIB_PDP_FETCHER_H_ |
| 3 | |
| 4 | #include <memory> |
| 5 | #include <atomic> |
| 6 | |
| 7 | #include "aos/common/messages/robot_state.q.h" |
| 8 | #include "aos/common/mutex.h" |
| 9 | |
| 10 | #include "PowerDistributionPanel.h" |
| 11 | |
| 12 | namespace frc971 { |
| 13 | namespace wpilib { |
| 14 | |
| 15 | // Handles fetching values from the PDP. This is slow, so it has to happen in a |
| 16 | // separate thread. |
| 17 | class PDPFetcher { |
| 18 | public: |
| 19 | PDPFetcher(); |
| 20 | |
| 21 | void Quit() { run_ = false; } |
| 22 | |
| 23 | // Retrieves the latest set of values and stores it in *pdp_values. |
| 24 | // This is safe to call from any thread. |
| 25 | void GetValues(::aos::PDPValues *pdp_values); |
| 26 | |
| 27 | // To be called by a ::std::thread. |
| 28 | void operator()(); |
| 29 | |
| 30 | private: |
| 31 | const ::std::unique_ptr<PowerDistributionPanel> pdp_; |
| 32 | |
| 33 | ::aos::PDPValues pdp_values_; |
| 34 | ::aos::Mutex values_lock_; |
| 35 | |
| 36 | ::std::atomic<bool> run_{true}; |
| 37 | }; |
| 38 | |
| 39 | } // namespace wpilib |
| 40 | } // namespace frc971 |
| 41 | |
| 42 | #endif // FRC971_WPILIB_PDP_FETCHER_H_ |