blob: 4ff625b57c22e71b3f70caef6921ca5204b6861d [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
Adam Snaidere0554ef2017-03-11 23:02:45 -08006#include "Solenoid.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.
Adam Snaidere0554ef2017-03-11 23:02:45 -080020class BufferedPcm : public Solenoid {
Brian Silvermand8f403a2014-12-13 19:12:04 -050021 public:
Adam Snaidere0554ef2017-03-11 23:02:45 -080022 explicit BufferedPcm() : Solenoid(0) {}
Brian Silvermand8f403a2014-12-13 19:12:04 -050023
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...
Austin Schuh3b5b69b2015-10-31 18:55:47 -070032#ifdef WPILIB2015
Brian Silvermand8f403a2014-12-13 19:12:04 -050033 virtual void InitSolenoid() override {}
Austin Schuh3b5b69b2015-10-31 18:55:47 -070034#endif
Brian Silvermand8f403a2014-12-13 19:12:04 -050035
sabinaf5584322017-09-23 18:37:19 -070036 void DoSet(int number, bool value);
Brian Silvermand8f403a2014-12-13 19:12:04 -050037
38 uint8_t values_ = 0;
39
40 friend class BufferedSolenoid;
41};
42
43} // namespace wpilib
44} // namespace frc971
45
46#endif // FRC971_WPILIB_BUFFERED_PCM_H_