blob: 033ded67cc6c7e29be13f97d0854c9a43c9ab589 [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
Austin Schuhf6b94632019-02-02 22:11:27 -08006#include <hal/HAL.h>
Brian Silvermand8f403a2014-12-13 19:12:04 -05007
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.
Austin Schuh547cf8a2017-11-23 13:21:16 -080019class BufferedPcm {
Brian Silvermand8f403a2014-12-13 19:12:04 -050020 public:
Austin Schuh547cf8a2017-11-23 13:21:16 -080021 explicit BufferedPcm(int module = 0);
Brian Silvermand8f403a2014-12-13 19:12:04 -050022
23 // Creates a new BufferedSolenoid for a specified port number.
24 ::std::unique_ptr<BufferedSolenoid> MakeSolenoid(int number);
25
Austin Schuh547cf8a2017-11-23 13:21:16 -080026 // Returns a bitmask of the state of all the solenoids.
27 int32_t GetAll();
28
Brian Silvermand8f403a2014-12-13 19:12:04 -050029 // Actually sends all of the values out.
30 void Flush();
31
32 private:
sabinaf5584322017-09-23 18:37:19 -070033 void DoSet(int number, bool value);
Brian Silvermand8f403a2014-12-13 19:12:04 -050034
Austin Schuh547cf8a2017-11-23 13:21:16 -080035 int module_;
36 ::std::array<HAL_SolenoidHandle, 8> solenoid_handles_{
37 {HAL_kInvalidHandle, HAL_kInvalidHandle, HAL_kInvalidHandle,
38 HAL_kInvalidHandle, HAL_kInvalidHandle, HAL_kInvalidHandle,
39 HAL_kInvalidHandle, HAL_kInvalidHandle}};
40
Brian Silvermand8f403a2014-12-13 19:12:04 -050041 uint8_t values_ = 0;
42
43 friend class BufferedSolenoid;
44};
45
46} // namespace wpilib
47} // namespace frc971
48
49#endif // FRC971_WPILIB_BUFFERED_PCM_H_