blob: 8271f2b7ac39f307eada80a3858771e170e0be70 [file] [log] [blame]
Brian Silverman425492b2015-12-30 15:23:55 -08001#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
12namespace frc971 {
13namespace wpilib {
14
15// Handles fetching values from the PDP. This is slow, so it has to happen in a
16// separate thread.
17class 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_