blob: 288cdfb8cf0f04757d6f0fe4260da6985f64923d [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"
Austin Schuh6d5d9ae2015-10-31 19:39:57 -07007#undef ERROR
Brian Silvermand8f403a2014-12-13 19:12:04 -05008
9#include "frc971/wpilib/buffered_solenoid.h"
10
11namespace frc971 {
12namespace wpilib {
13
14// Manages setting values for all solenoids for a single PCM in a single CAN
15// message.
16//
17// The way to use this is to call MakeSolenoid for whichever solenoid numbers
18// you want, call Set on those, and then periodically call Flush on this object
19// to write all of the buffered values out.
20class BufferedPcm : public SolenoidBase {
21 public:
22 explicit BufferedPcm(uint8_t module = GetDefaultSolenoidModule())
23 : SolenoidBase(module) {}
24
25 // Creates a new BufferedSolenoid for a specified port number.
26 ::std::unique_ptr<BufferedSolenoid> MakeSolenoid(int number);
27
28 // Actually sends all of the values out.
29 void Flush();
30
31 private:
32 // WPILib declares this pure virtual and then never calls it...
Austin Schuh3b5b69b2015-10-31 18:55:47 -070033#ifdef WPILIB2015
Brian Silvermand8f403a2014-12-13 19:12:04 -050034 virtual void InitSolenoid() override {}
Austin Schuh3b5b69b2015-10-31 18:55:47 -070035#endif
Brian Silvermand8f403a2014-12-13 19:12:04 -050036
37 void Set(int number, bool value);
38
39 uint8_t values_ = 0;
40
41 friend class BufferedSolenoid;
42};
43
44} // namespace wpilib
45} // namespace frc971
46
47#endif // FRC971_WPILIB_BUFFERED_PCM_H_