WPILibC++  2020.3.2
AnalogInSim.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/AnalogInData.h"
15 
16 namespace frc {
17 namespace sim {
18 class AnalogInSim {
19  public:
20  explicit AnalogInSim(int index) { m_index = index; }
21 
22  std::unique_ptr<CallbackStore> RegisterInitializedCallback(
23  NotifyCallback callback, bool initialNotify) {
24  auto store = std::make_unique<CallbackStore>(
25  m_index, -1, callback, &HALSIM_CancelAnalogInInitializedCallback);
26  store->SetUid(HALSIM_RegisterAnalogInInitializedCallback(
27  m_index, &CallbackStoreThunk, store.get(), initialNotify));
28  return store;
29  }
30 
31  bool GetInitialized() const { return HALSIM_GetAnalogInInitialized(m_index); }
32 
33  void SetInitialized(bool initialized) {
34  HALSIM_SetAnalogInInitialized(m_index, initialized);
35  }
36 
37  std::unique_ptr<CallbackStore> RegisterAverageBitsCallback(
38  NotifyCallback callback, bool initialNotify) {
39  auto store = std::make_unique<CallbackStore>(
40  m_index, -1, callback, &HALSIM_CancelAnalogInAverageBitsCallback);
41  store->SetUid(HALSIM_RegisterAnalogInAverageBitsCallback(
42  m_index, &CallbackStoreThunk, store.get(), initialNotify));
43  return store;
44  }
45 
46  int GetAverageBits() const { return HALSIM_GetAnalogInAverageBits(m_index); }
47 
48  void SetAverageBits(int averageBits) {
49  HALSIM_SetAnalogInAverageBits(m_index, averageBits);
50  }
51 
52  std::unique_ptr<CallbackStore> RegisterOversampleBitsCallback(
53  NotifyCallback callback, bool initialNotify) {
54  auto store = std::make_unique<CallbackStore>(
55  m_index, -1, callback, &HALSIM_CancelAnalogInOversampleBitsCallback);
56  store->SetUid(HALSIM_RegisterAnalogInOversampleBitsCallback(
57  m_index, &CallbackStoreThunk, store.get(), initialNotify));
58  return store;
59  }
60 
61  int GetOversampleBits() const {
62  return HALSIM_GetAnalogInOversampleBits(m_index);
63  }
64 
65  void SetOversampleBits(int oversampleBits) {
66  HALSIM_SetAnalogInOversampleBits(m_index, oversampleBits);
67  }
68 
69  std::unique_ptr<CallbackStore> RegisterVoltageCallback(
70  NotifyCallback callback, bool initialNotify) {
71  auto store = std::make_unique<CallbackStore>(
72  m_index, -1, callback, &HALSIM_CancelAnalogInVoltageCallback);
73  store->SetUid(HALSIM_RegisterAnalogInVoltageCallback(
74  m_index, &CallbackStoreThunk, store.get(), initialNotify));
75  return store;
76  }
77 
78  double GetVoltage() const { return HALSIM_GetAnalogInVoltage(m_index); }
79 
80  void SetVoltage(double voltage) {
81  HALSIM_SetAnalogInVoltage(m_index, voltage);
82  }
83 
84  std::unique_ptr<CallbackStore> RegisterAccumulatorInitializedCallback(
85  NotifyCallback callback, bool initialNotify) {
86  auto store = std::make_unique<CallbackStore>(
87  m_index, -1, callback,
88  &HALSIM_CancelAnalogInAccumulatorInitializedCallback);
89  store->SetUid(HALSIM_RegisterAnalogInAccumulatorInitializedCallback(
90  m_index, &CallbackStoreThunk, store.get(), initialNotify));
91  return store;
92  }
93 
94  bool GetAccumulatorInitialized() const {
95  return HALSIM_GetAnalogInAccumulatorInitialized(m_index);
96  }
97 
98  void SetAccumulatorInitialized(bool accumulatorInitialized) {
99  HALSIM_SetAnalogInAccumulatorInitialized(m_index, accumulatorInitialized);
100  }
101 
102  std::unique_ptr<CallbackStore> RegisterAccumulatorValueCallback(
103  NotifyCallback callback, bool initialNotify) {
104  auto store = std::make_unique<CallbackStore>(
105  m_index, -1, callback, &HALSIM_CancelAnalogInAccumulatorValueCallback);
106  store->SetUid(HALSIM_RegisterAnalogInAccumulatorValueCallback(
107  m_index, &CallbackStoreThunk, store.get(), initialNotify));
108  return store;
109  }
110 
111  int64_t GetAccumulatorValue() const {
112  return HALSIM_GetAnalogInAccumulatorValue(m_index);
113  }
114 
115  void SetAccumulatorValue(int64_t accumulatorValue) {
116  HALSIM_SetAnalogInAccumulatorValue(m_index, accumulatorValue);
117  }
118 
119  std::unique_ptr<CallbackStore> RegisterAccumulatorCountCallback(
120  NotifyCallback callback, bool initialNotify) {
121  auto store = std::make_unique<CallbackStore>(
122  m_index, -1, callback, &HALSIM_CancelAnalogInAccumulatorCountCallback);
123  store->SetUid(HALSIM_RegisterAnalogInAccumulatorCountCallback(
124  m_index, &CallbackStoreThunk, store.get(), initialNotify));
125  return store;
126  }
127 
128  int64_t GetAccumulatorCount() const {
129  return HALSIM_GetAnalogInAccumulatorCount(m_index);
130  }
131 
132  void SetAccumulatorCount(int64_t accumulatorCount) {
133  HALSIM_SetAnalogInAccumulatorCount(m_index, accumulatorCount);
134  }
135 
136  std::unique_ptr<CallbackStore> RegisterAccumulatorCenterCallback(
137  NotifyCallback callback, bool initialNotify) {
138  auto store = std::make_unique<CallbackStore>(
139  m_index, -1, callback, &HALSIM_CancelAnalogInAccumulatorCenterCallback);
140  store->SetUid(HALSIM_RegisterAnalogInAccumulatorCenterCallback(
141  m_index, &CallbackStoreThunk, store.get(), initialNotify));
142  return store;
143  }
144 
145  int GetAccumulatorCenter() const {
146  return HALSIM_GetAnalogInAccumulatorCenter(m_index);
147  }
148 
149  void SetAccumulatorCenter(int accumulatorCenter) {
150  HALSIM_SetAnalogInAccumulatorCenter(m_index, accumulatorCenter);
151  }
152 
153  std::unique_ptr<CallbackStore> RegisterAccumulatorDeadbandCallback(
154  NotifyCallback callback, bool initialNotify) {
155  auto store = std::make_unique<CallbackStore>(
156  m_index, -1, callback,
157  &HALSIM_CancelAnalogInAccumulatorDeadbandCallback);
158  store->SetUid(HALSIM_RegisterAnalogInAccumulatorDeadbandCallback(
159  m_index, &CallbackStoreThunk, store.get(), initialNotify));
160  return store;
161  }
162 
163  int GetAccumulatorDeadband() const {
164  return HALSIM_GetAnalogInAccumulatorDeadband(m_index);
165  }
166 
167  void SetAccumulatorDeadband(int accumulatorDeadband) {
168  HALSIM_SetAnalogInAccumulatorDeadband(m_index, accumulatorDeadband);
169  }
170 
171  void ResetData() { HALSIM_ResetAnalogInData(m_index); }
172 
173  private:
174  int m_index;
175 };
176 } // namespace sim
177 } // namespace frc
frc::sim::AnalogInSim
Definition: AnalogInSim.h:18
frc
A class that enforces constraints on the differential drive kinematics.
Definition: SPIAccelerometerSim.h:16