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 | |
Austin Schuh | f6b9463 | 2019-02-02 22:11:27 -0800 | [diff] [blame] | 4 | #include <hal/HAL.h> |
Brian Silverman | d8f403a | 2014-12-13 19:12:04 -0500 | [diff] [blame] | 5 | |
Philipp Schrader | 790cb54 | 2023-07-05 21:06:52 -0700 | [diff] [blame] | 6 | #include <memory> |
| 7 | |
Brian Silverman | d8f403a | 2014-12-13 19:12:04 -0500 | [diff] [blame] | 8 | #include "frc971/wpilib/buffered_solenoid.h" |
| 9 | |
Stephan Pleines | d99b1ee | 2024-02-02 20:56:44 -0800 | [diff] [blame^] | 10 | namespace frc971::wpilib { |
Brian Silverman | d8f403a | 2014-12-13 19:12:04 -0500 | [diff] [blame] | 11 | |
| 12 | // Manages setting values for all solenoids for a single PCM in a single CAN |
| 13 | // message. |
| 14 | // |
| 15 | // The way to use this is to call MakeSolenoid for whichever solenoid numbers |
| 16 | // you want, call Set on those, and then periodically call Flush on this object |
| 17 | // to write all of the buffered values out. |
Austin Schuh | 547cf8a | 2017-11-23 13:21:16 -0800 | [diff] [blame] | 18 | class BufferedPcm { |
Brian Silverman | d8f403a | 2014-12-13 19:12:04 -0500 | [diff] [blame] | 19 | public: |
Austin Schuh | 547cf8a | 2017-11-23 13:21:16 -0800 | [diff] [blame] | 20 | explicit BufferedPcm(int module = 0); |
Brian Silverman | d8f403a | 2014-12-13 19:12:04 -0500 | [diff] [blame] | 21 | |
| 22 | // Creates a new BufferedSolenoid for a specified port number. |
| 23 | ::std::unique_ptr<BufferedSolenoid> MakeSolenoid(int number); |
| 24 | |
Austin Schuh | 547cf8a | 2017-11-23 13:21:16 -0800 | [diff] [blame] | 25 | // Returns a bitmask of the state of all the solenoids. |
| 26 | int32_t GetAll(); |
| 27 | |
Brian Silverman | d8f403a | 2014-12-13 19:12:04 -0500 | [diff] [blame] | 28 | // Actually sends all of the values out. |
| 29 | void Flush(); |
| 30 | |
| 31 | private: |
sabina | f558432 | 2017-09-23 18:37:19 -0700 | [diff] [blame] | 32 | void DoSet(int number, bool value); |
Brian Silverman | d8f403a | 2014-12-13 19:12:04 -0500 | [diff] [blame] | 33 | |
Austin Schuh | 547cf8a | 2017-11-23 13:21:16 -0800 | [diff] [blame] | 34 | int module_; |
| 35 | ::std::array<HAL_SolenoidHandle, 8> solenoid_handles_{ |
| 36 | {HAL_kInvalidHandle, HAL_kInvalidHandle, HAL_kInvalidHandle, |
| 37 | HAL_kInvalidHandle, HAL_kInvalidHandle, HAL_kInvalidHandle, |
| 38 | HAL_kInvalidHandle, HAL_kInvalidHandle}}; |
| 39 | |
Brian Silverman | d8f403a | 2014-12-13 19:12:04 -0500 | [diff] [blame] | 40 | uint8_t values_ = 0; |
| 41 | |
| 42 | friend class BufferedSolenoid; |
| 43 | }; |
| 44 | |
Stephan Pleines | d99b1ee | 2024-02-02 20:56:44 -0800 | [diff] [blame^] | 45 | } // namespace frc971::wpilib |
Brian Silverman | d8f403a | 2014-12-13 19:12:04 -0500 | [diff] [blame] | 46 | |
| 47 | #endif // FRC971_WPILIB_BUFFERED_PCM_H_ |