WPILibC++  2018.4.1-20180729123227-1139-ga11fcb6
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages
AnalogInSim.h
1 /*----------------------------------------------------------------------------*/
2 /* Copyright (c) 2018 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 #ifndef __FRC_ROBORIO__
11 
12 #include <memory>
13 #include <utility>
14 
15 #include "CallbackStore.h"
16 #include "mockdata/AnalogInData.h"
17 
18 namespace frc {
19 namespace sim {
20 class AnalogInSim {
21  public:
22  explicit AnalogInSim(int index) { m_index = index; }
23 
24  std::unique_ptr<CallbackStore> RegisterInitializedCallback(
25  NotifyCallback callback, bool initialNotify) {
26  auto store = std::make_unique<CallbackStore>(
27  m_index, -1, callback, &HALSIM_CancelAnalogInInitializedCallback);
28  store->SetUid(HALSIM_RegisterAnalogInInitializedCallback(
29  m_index, &CallbackStoreThunk, store.get(), initialNotify));
30  return store;
31  }
32  bool GetInitialized() { return HALSIM_GetAnalogInInitialized(m_index); }
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  int GetAverageBits() { return HALSIM_GetAnalogInAverageBits(m_index); }
46  void SetAverageBits(int averageBits) {
47  HALSIM_SetAnalogInAverageBits(m_index, averageBits);
48  }
49 
50  std::unique_ptr<CallbackStore> RegisterOversampleBitsCallback(
51  NotifyCallback callback, bool initialNotify) {
52  auto store = std::make_unique<CallbackStore>(
53  m_index, -1, callback, &HALSIM_CancelAnalogInOversampleBitsCallback);
54  store->SetUid(HALSIM_RegisterAnalogInOversampleBitsCallback(
55  m_index, &CallbackStoreThunk, store.get(), initialNotify));
56  return store;
57  }
58  int GetOversampleBits() { return HALSIM_GetAnalogInOversampleBits(m_index); }
59  void SetOversampleBits(int oversampleBits) {
60  HALSIM_SetAnalogInOversampleBits(m_index, oversampleBits);
61  }
62 
63  std::unique_ptr<CallbackStore> RegisterVoltageCallback(
64  NotifyCallback callback, bool initialNotify) {
65  auto store = std::make_unique<CallbackStore>(
66  m_index, -1, callback, &HALSIM_CancelAnalogInVoltageCallback);
67  store->SetUid(HALSIM_RegisterAnalogInVoltageCallback(
68  m_index, &CallbackStoreThunk, store.get(), initialNotify));
69  return store;
70  }
71  double GetVoltage() { return HALSIM_GetAnalogInVoltage(m_index); }
72  void SetVoltage(double voltage) {
73  HALSIM_SetAnalogInVoltage(m_index, voltage);
74  }
75 
76  std::unique_ptr<CallbackStore> RegisterAccumulatorInitializedCallback(
77  NotifyCallback callback, bool initialNotify) {
78  auto store = std::make_unique<CallbackStore>(
79  m_index, -1, callback,
80  &HALSIM_CancelAnalogInAccumulatorInitializedCallback);
81  store->SetUid(HALSIM_RegisterAnalogInAccumulatorInitializedCallback(
82  m_index, &CallbackStoreThunk, store.get(), initialNotify));
83  return store;
84  }
85  bool GetAccumulatorInitialized() {
86  return HALSIM_GetAnalogInAccumulatorInitialized(m_index);
87  }
88  void SetAccumulatorInitialized(bool accumulatorInitialized) {
89  HALSIM_SetAnalogInAccumulatorInitialized(m_index, accumulatorInitialized);
90  }
91 
92  std::unique_ptr<CallbackStore> RegisterAccumulatorValueCallback(
93  NotifyCallback callback, bool initialNotify) {
94  auto store = std::make_unique<CallbackStore>(
95  m_index, -1, callback, &HALSIM_CancelAnalogInAccumulatorValueCallback);
96  store->SetUid(HALSIM_RegisterAnalogInAccumulatorValueCallback(
97  m_index, &CallbackStoreThunk, store.get(), initialNotify));
98  return store;
99  }
100  int64_t GetAccumulatorValue() {
101  return HALSIM_GetAnalogInAccumulatorValue(m_index);
102  }
103  void SetAccumulatorValue(int64_t accumulatorValue) {
104  HALSIM_SetAnalogInAccumulatorValue(m_index, accumulatorValue);
105  }
106 
107  std::unique_ptr<CallbackStore> RegisterAccumulatorCountCallback(
108  NotifyCallback callback, bool initialNotify) {
109  auto store = std::make_unique<CallbackStore>(
110  m_index, -1, callback, &HALSIM_CancelAnalogInAccumulatorCountCallback);
111  store->SetUid(HALSIM_RegisterAnalogInAccumulatorCountCallback(
112  m_index, &CallbackStoreThunk, store.get(), initialNotify));
113  return store;
114  }
115  int64_t GetAccumulatorCount() {
116  return HALSIM_GetAnalogInAccumulatorCount(m_index);
117  }
118  void SetAccumulatorCount(int64_t accumulatorCount) {
119  HALSIM_SetAnalogInAccumulatorCount(m_index, accumulatorCount);
120  }
121 
122  std::unique_ptr<CallbackStore> RegisterAccumulatorCenterCallback(
123  NotifyCallback callback, bool initialNotify) {
124  auto store = std::make_unique<CallbackStore>(
125  m_index, -1, callback, &HALSIM_CancelAnalogInAccumulatorCenterCallback);
126  store->SetUid(HALSIM_RegisterAnalogInAccumulatorCenterCallback(
127  m_index, &CallbackStoreThunk, store.get(), initialNotify));
128  return store;
129  }
130  int GetAccumulatorCenter() {
131  return HALSIM_GetAnalogInAccumulatorCenter(m_index);
132  }
133  void SetAccumulatorCenter(int accumulatorCenter) {
134  HALSIM_SetAnalogInAccumulatorCenter(m_index, accumulatorCenter);
135  }
136 
137  std::unique_ptr<CallbackStore> RegisterAccumulatorDeadbandCallback(
138  NotifyCallback callback, bool initialNotify) {
139  auto store = std::make_unique<CallbackStore>(
140  m_index, -1, callback,
141  &HALSIM_CancelAnalogInAccumulatorDeadbandCallback);
142  store->SetUid(HALSIM_RegisterAnalogInAccumulatorDeadbandCallback(
143  m_index, &CallbackStoreThunk, store.get(), initialNotify));
144  return store;
145  }
146  int GetAccumulatorDeadband() {
147  return HALSIM_GetAnalogInAccumulatorDeadband(m_index);
148  }
149  void SetAccumulatorDeadband(int accumulatorDeadband) {
150  HALSIM_SetAnalogInAccumulatorDeadband(m_index, accumulatorDeadband);
151  }
152 
153  void ResetData() { HALSIM_ResetAnalogInData(m_index); }
154 
155  private:
156  int m_index;
157 };
158 } // namespace sim
159 } // namespace frc
160 #endif // __FRC_ROBORIO__
Definition: SPIAccelerometerSim.h:18
Definition: AnalogInSim.h:20