WPILibC++  2020.3.2
DIOSim.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/DIOData.h"
15 
16 namespace frc {
17 namespace sim {
18 class DIOSim {
19  public:
20  explicit DIOSim(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_CancelDIOInitializedCallback);
26  store->SetUid(HALSIM_RegisterDIOInitializedCallback(
27  m_index, &CallbackStoreThunk, store.get(), initialNotify));
28  return store;
29  }
30 
31  bool GetInitialized() const { return HALSIM_GetDIOInitialized(m_index); }
32 
33  void SetInitialized(bool initialized) {
34  HALSIM_SetDIOInitialized(m_index, initialized);
35  }
36 
37  std::unique_ptr<CallbackStore> RegisterValueCallback(NotifyCallback callback,
38  bool initialNotify) {
39  auto store = std::make_unique<CallbackStore>(
40  m_index, -1, callback, &HALSIM_CancelDIOValueCallback);
41  store->SetUid(HALSIM_RegisterDIOValueCallback(m_index, &CallbackStoreThunk,
42  store.get(), initialNotify));
43  return store;
44  }
45 
46  bool GetValue() const { return HALSIM_GetDIOValue(m_index); }
47 
48  void SetValue(bool value) { HALSIM_SetDIOValue(m_index, value); }
49 
50  std::unique_ptr<CallbackStore> RegisterPulseLengthCallback(
51  NotifyCallback callback, bool initialNotify) {
52  auto store = std::make_unique<CallbackStore>(
53  m_index, -1, callback, &HALSIM_CancelDIOPulseLengthCallback);
54  store->SetUid(HALSIM_RegisterDIOPulseLengthCallback(
55  m_index, &CallbackStoreThunk, store.get(), initialNotify));
56  return store;
57  }
58 
59  double GetPulseLength() const { return HALSIM_GetDIOPulseLength(m_index); }
60 
61  void SetPulseLength(double pulseLength) {
62  HALSIM_SetDIOPulseLength(m_index, pulseLength);
63  }
64 
65  std::unique_ptr<CallbackStore> RegisterIsInputCallback(
66  NotifyCallback callback, bool initialNotify) {
67  auto store = std::make_unique<CallbackStore>(
68  m_index, -1, callback, &HALSIM_CancelDIOIsInputCallback);
69  store->SetUid(HALSIM_RegisterDIOIsInputCallback(
70  m_index, &CallbackStoreThunk, store.get(), initialNotify));
71  return store;
72  }
73 
74  bool GetIsInput() const { return HALSIM_GetDIOIsInput(m_index); }
75 
76  void SetIsInput(bool isInput) { HALSIM_SetDIOIsInput(m_index, isInput); }
77 
78  std::unique_ptr<CallbackStore> RegisterFilterIndexCallback(
79  NotifyCallback callback, bool initialNotify) {
80  auto store = std::make_unique<CallbackStore>(
81  m_index, -1, callback, &HALSIM_CancelDIOFilterIndexCallback);
82  store->SetUid(HALSIM_RegisterDIOFilterIndexCallback(
83  m_index, &CallbackStoreThunk, store.get(), initialNotify));
84  return store;
85  }
86 
87  int GetFilterIndex() const { return HALSIM_GetDIOFilterIndex(m_index); }
88 
89  void SetFilterIndex(int filterIndex) {
90  HALSIM_SetDIOFilterIndex(m_index, filterIndex);
91  }
92 
93  void ResetData() { HALSIM_ResetDIOData(m_index); }
94 
95  private:
96  int m_index;
97 };
98 } // namespace sim
99 } // namespace frc
frc::sim::DIOSim
Definition: DIOSim.h:18
frc
A class that enforces constraints on the differential drive kinematics.
Definition: SPIAccelerometerSim.h:16