blob: 50f86fc34b51d3c529c9421c5e269649670f4934 [file] [log] [blame]
Brian Silvermand8f403a2014-12-13 19:12:04 -05001#ifndef FRC971_WPILIB_BUFFERED_PCM_H_
2#define FRC971_WPILIB_BUFFERED_PCM_H_
3
4#include <memory>
5
6#include "SolenoidBase.h"
7
8#include "frc971/wpilib/buffered_solenoid.h"
9
10namespace frc971 {
11namespace wpilib {
12
13// Manages setting values for all solenoids for a single PCM in a single CAN
14// message.
15//
16// The way to use this is to call MakeSolenoid for whichever solenoid numbers
17// you want, call Set on those, and then periodically call Flush on this object
18// to write all of the buffered values out.
19class BufferedPcm : public SolenoidBase {
20 public:
21 explicit BufferedPcm(uint8_t module = GetDefaultSolenoidModule())
22 : SolenoidBase(module) {}
23
24 // Creates a new BufferedSolenoid for a specified port number.
25 ::std::unique_ptr<BufferedSolenoid> MakeSolenoid(int number);
26
27 // Actually sends all of the values out.
28 void Flush();
29
30 private:
31 // WPILib declares this pure virtual and then never calls it...
32 virtual void InitSolenoid() override {}
33
34 void Set(int number, bool value);
35
36 uint8_t values_ = 0;
37
38 friend class BufferedSolenoid;
39};
40
41} // namespace wpilib
42} // namespace frc971
43
44#endif // FRC971_WPILIB_BUFFERED_PCM_H_