WPILibC++  2020.3.2
PCMSim.h
1 /*----------------------------------------------------------------------------*/
2 /* Copyright (c) 2018-2019 FIRST. All Rights Reserved. */
3 /* Open Source Software - may be modified and shared by FRC teams. The code */
4 /* must be accompanied by the FIRST BSD license file in the root directory of */
5 /* the project. */
6 /*----------------------------------------------------------------------------*/
7 
8 #pragma once
9 
10 #include <memory>
11 #include <utility>
12 
13 #include "CallbackStore.h"
14 #include "mockdata/PCMData.h"
15 
16 namespace frc {
17 namespace sim {
18 class PCMSim {
19  public:
20  explicit PCMSim(int index) { m_index = index; }
21 
22  std::unique_ptr<CallbackStore> RegisterSolenoidInitializedCallback(
23  int channel, NotifyCallback callback, bool initialNotify) {
24  auto store = std::make_unique<CallbackStore>(
25  m_index, channel, -1, callback,
26  &HALSIM_CancelPCMSolenoidInitializedCallback);
27  store->SetUid(HALSIM_RegisterPCMSolenoidInitializedCallback(
28  m_index, channel, &CallbackStoreThunk, store.get(), initialNotify));
29  return store;
30  }
31 
32  bool GetSolenoidInitialized(int channel) const {
33  return HALSIM_GetPCMSolenoidInitialized(m_index, channel);
34  }
35 
36  void SetSolenoidInitialized(int channel, bool solenoidInitialized) {
37  HALSIM_SetPCMSolenoidInitialized(m_index, channel, solenoidInitialized);
38  }
39 
40  std::unique_ptr<CallbackStore> RegisterSolenoidOutputCallback(
41  int channel, NotifyCallback callback, bool initialNotify) {
42  auto store = std::make_unique<CallbackStore>(
43  m_index, channel, -1, callback,
44  &HALSIM_CancelPCMSolenoidOutputCallback);
45  store->SetUid(HALSIM_RegisterPCMSolenoidOutputCallback(
46  m_index, channel, &CallbackStoreThunk, store.get(), initialNotify));
47  return store;
48  }
49 
50  bool GetSolenoidOutput(int channel) const {
51  return HALSIM_GetPCMSolenoidOutput(m_index, channel);
52  }
53 
54  void SetSolenoidOutput(int channel, bool solenoidOutput) {
55  HALSIM_SetPCMSolenoidOutput(m_index, channel, solenoidOutput);
56  }
57 
58  std::unique_ptr<CallbackStore> RegisterCompressorInitializedCallback(
59  NotifyCallback callback, bool initialNotify) {
60  auto store = std::make_unique<CallbackStore>(
61  m_index, -1, callback, &HALSIM_CancelPCMCompressorInitializedCallback);
62  store->SetUid(HALSIM_RegisterPCMCompressorInitializedCallback(
63  m_index, &CallbackStoreThunk, store.get(), initialNotify));
64  return store;
65  }
66 
67  bool GetCompressorInitialized() const {
68  return HALSIM_GetPCMCompressorInitialized(m_index);
69  }
70 
71  void SetCompressorInitialized(bool compressorInitialized) {
72  HALSIM_SetPCMCompressorInitialized(m_index, compressorInitialized);
73  }
74 
75  std::unique_ptr<CallbackStore> RegisterCompressorOnCallback(
76  NotifyCallback callback, bool initialNotify) {
77  auto store = std::make_unique<CallbackStore>(
78  m_index, -1, callback, &HALSIM_CancelPCMCompressorOnCallback);
79  store->SetUid(HALSIM_RegisterPCMCompressorOnCallback(
80  m_index, &CallbackStoreThunk, store.get(), initialNotify));
81  return store;
82  }
83 
84  bool GetCompressorOn() const { return HALSIM_GetPCMCompressorOn(m_index); }
85 
86  void SetCompressorOn(bool compressorOn) {
87  HALSIM_SetPCMCompressorOn(m_index, compressorOn);
88  }
89 
90  std::unique_ptr<CallbackStore> RegisterClosedLoopEnabledCallback(
91  NotifyCallback callback, bool initialNotify) {
92  auto store = std::make_unique<CallbackStore>(
93  m_index, -1, callback, &HALSIM_CancelPCMClosedLoopEnabledCallback);
94  store->SetUid(HALSIM_RegisterPCMClosedLoopEnabledCallback(
95  m_index, &CallbackStoreThunk, store.get(), initialNotify));
96  return store;
97  }
98 
99  bool GetClosedLoopEnabled() const {
100  return HALSIM_GetPCMClosedLoopEnabled(m_index);
101  }
102 
103  void SetClosedLoopEnabled(bool closedLoopEnabled) {
104  HALSIM_SetPCMClosedLoopEnabled(m_index, closedLoopEnabled);
105  }
106 
107  std::unique_ptr<CallbackStore> RegisterPressureSwitchCallback(
108  NotifyCallback callback, bool initialNotify) {
109  auto store = std::make_unique<CallbackStore>(
110  m_index, -1, callback, &HALSIM_CancelPCMPressureSwitchCallback);
111  store->SetUid(HALSIM_RegisterPCMPressureSwitchCallback(
112  m_index, &CallbackStoreThunk, store.get(), initialNotify));
113  return store;
114  }
115 
116  bool GetPressureSwitch() const {
117  return HALSIM_GetPCMPressureSwitch(m_index);
118  }
119 
120  void SetPressureSwitch(bool pressureSwitch) {
121  HALSIM_SetPCMPressureSwitch(m_index, pressureSwitch);
122  }
123 
124  std::unique_ptr<CallbackStore> RegisterCompressorCurrentCallback(
125  NotifyCallback callback, bool initialNotify) {
126  auto store = std::make_unique<CallbackStore>(
127  m_index, -1, callback, &HALSIM_CancelPCMCompressorCurrentCallback);
128  store->SetUid(HALSIM_RegisterPCMCompressorCurrentCallback(
129  m_index, &CallbackStoreThunk, store.get(), initialNotify));
130  return store;
131  }
132 
133  double GetCompressorCurrent() const {
134  return HALSIM_GetPCMCompressorCurrent(m_index);
135  }
136 
137  void SetCompressorCurrent(double compressorCurrent) {
138  HALSIM_SetPCMCompressorCurrent(m_index, compressorCurrent);
139  }
140 
141  uint8_t GetAllSolenoidOutputs() {
142  uint8_t ret = 0;
143  HALSIM_GetPCMAllSolenoids(m_index, &ret);
144  return ret;
145  }
146 
147  void SetAllSolenoidOutputs(uint8_t outputs) {
148  HALSIM_SetPCMAllSolenoids(m_index, outputs);
149  }
150 
151  void ResetData() { HALSIM_ResetPCMData(m_index); }
152 
153  private:
154  int m_index;
155 };
156 } // namespace sim
157 } // namespace frc
frc
A class that enforces constraints on the differential drive kinematics.
Definition: SPIAccelerometerSim.h:16
frc::sim::PCMSim
Definition: PCMSim.h:18