Brian Silverman | d8f403a | 2014-12-13 19:12:04 -0500 | [diff] [blame] | 1 | #ifndef FRC971_WPILIB_BUFFERED_PCM_H_ |
| 2 | #define FRC971_WPILIB_BUFFERED_PCM_H_ |
| 3 | |
| 4 | #include <memory> |
| 5 | |
Austin Schuh | f6b9463 | 2019-02-02 22:11:27 -0800 | [diff] [blame] | 6 | #include <hal/HAL.h> |
Brian Silverman | d8f403a | 2014-12-13 19:12:04 -0500 | [diff] [blame] | 7 | |
| 8 | #include "frc971/wpilib/buffered_solenoid.h" |
| 9 | |
| 10 | namespace frc971 { |
| 11 | namespace 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 Schuh | 547cf8a | 2017-11-23 13:21:16 -0800 | [diff] [blame] | 19 | class BufferedPcm { |
Brian Silverman | d8f403a | 2014-12-13 19:12:04 -0500 | [diff] [blame] | 20 | public: |
Austin Schuh | 547cf8a | 2017-11-23 13:21:16 -0800 | [diff] [blame] | 21 | explicit BufferedPcm(int module = 0); |
Brian Silverman | d8f403a | 2014-12-13 19:12:04 -0500 | [diff] [blame] | 22 | |
| 23 | // Creates a new BufferedSolenoid for a specified port number. |
| 24 | ::std::unique_ptr<BufferedSolenoid> MakeSolenoid(int number); |
| 25 | |
Austin Schuh | 547cf8a | 2017-11-23 13:21:16 -0800 | [diff] [blame] | 26 | // Returns a bitmask of the state of all the solenoids. |
| 27 | int32_t GetAll(); |
| 28 | |
Brian Silverman | d8f403a | 2014-12-13 19:12:04 -0500 | [diff] [blame] | 29 | // Actually sends all of the values out. |
| 30 | void Flush(); |
| 31 | |
| 32 | private: |
sabina | f558432 | 2017-09-23 18:37:19 -0700 | [diff] [blame] | 33 | void DoSet(int number, bool value); |
Brian Silverman | d8f403a | 2014-12-13 19:12:04 -0500 | [diff] [blame] | 34 | |
Austin Schuh | 547cf8a | 2017-11-23 13:21:16 -0800 | [diff] [blame] | 35 | 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 Silverman | d8f403a | 2014-12-13 19:12:04 -0500 | [diff] [blame] | 41 | 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_ |