blob: 4933c250696c7af560707254065e864e9123d3a1 [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
Austin Schuhf6b94632019-02-02 22:11:27 -08004#include <hal/HAL.h>
Brian Silvermand8f403a2014-12-13 19:12:04 -05005
Philipp Schrader790cb542023-07-05 21:06:52 -07006#include <memory>
7
Brian Silvermand8f403a2014-12-13 19:12:04 -05008#include "frc971/wpilib/buffered_solenoid.h"
9
Stephan Pleinesd99b1ee2024-02-02 20:56:44 -080010namespace frc971::wpilib {
Brian Silvermand8f403a2014-12-13 19:12:04 -050011
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 Schuh547cf8a2017-11-23 13:21:16 -080018class BufferedPcm {
Brian Silvermand8f403a2014-12-13 19:12:04 -050019 public:
Austin Schuh547cf8a2017-11-23 13:21:16 -080020 explicit BufferedPcm(int module = 0);
Brian Silvermand8f403a2014-12-13 19:12:04 -050021
22 // Creates a new BufferedSolenoid for a specified port number.
23 ::std::unique_ptr<BufferedSolenoid> MakeSolenoid(int number);
24
Austin Schuh547cf8a2017-11-23 13:21:16 -080025 // Returns a bitmask of the state of all the solenoids.
26 int32_t GetAll();
27
Brian Silvermand8f403a2014-12-13 19:12:04 -050028 // Actually sends all of the values out.
29 void Flush();
30
31 private:
sabinaf5584322017-09-23 18:37:19 -070032 void DoSet(int number, bool value);
Brian Silvermand8f403a2014-12-13 19:12:04 -050033
Austin Schuh547cf8a2017-11-23 13:21:16 -080034 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 Silvermand8f403a2014-12-13 19:12:04 -050040 uint8_t values_ = 0;
41
42 friend class BufferedSolenoid;
43};
44
Stephan Pleinesd99b1ee2024-02-02 20:56:44 -080045} // namespace frc971::wpilib
Brian Silvermand8f403a2014-12-13 19:12:04 -050046
47#endif // FRC971_WPILIB_BUFFERED_PCM_H_