WPILibC++  2018.4.1-20180729223220-1149-g7bd3f9f
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages
DIOSim.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/DIOData.h"
17 
18 namespace frc {
19 namespace sim {
20 class DIOSim {
21  public:
22  explicit DIOSim(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_CancelDIOInitializedCallback);
28  store->SetUid(HALSIM_RegisterDIOInitializedCallback(
29  m_index, &CallbackStoreThunk, store.get(), initialNotify));
30  return store;
31  }
32  bool GetInitialized() { return HALSIM_GetDIOInitialized(m_index); }
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  bool GetValue() { return HALSIM_GetDIOValue(m_index); }
46  void SetValue(bool value) { HALSIM_SetDIOValue(m_index, value); }
47 
48  std::unique_ptr<CallbackStore> RegisterPulseLengthCallback(
49  NotifyCallback callback, bool initialNotify) {
50  auto store = std::make_unique<CallbackStore>(
51  m_index, -1, callback, &HALSIM_CancelDIOPulseLengthCallback);
52  store->SetUid(HALSIM_RegisterDIOPulseLengthCallback(
53  m_index, &CallbackStoreThunk, store.get(), initialNotify));
54  return store;
55  }
56  double GetPulseLength() { return HALSIM_GetDIOPulseLength(m_index); }
57  void SetPulseLength(double pulseLength) {
58  HALSIM_SetDIOPulseLength(m_index, pulseLength);
59  }
60 
61  std::unique_ptr<CallbackStore> RegisterIsInputCallback(
62  NotifyCallback callback, bool initialNotify) {
63  auto store = std::make_unique<CallbackStore>(
64  m_index, -1, callback, &HALSIM_CancelDIOIsInputCallback);
65  store->SetUid(HALSIM_RegisterDIOIsInputCallback(
66  m_index, &CallbackStoreThunk, store.get(), initialNotify));
67  return store;
68  }
69  bool GetIsInput() { return HALSIM_GetDIOIsInput(m_index); }
70  void SetIsInput(bool isInput) { HALSIM_SetDIOIsInput(m_index, isInput); }
71 
72  std::unique_ptr<CallbackStore> RegisterFilterIndexCallback(
73  NotifyCallback callback, bool initialNotify) {
74  auto store = std::make_unique<CallbackStore>(
75  m_index, -1, callback, &HALSIM_CancelDIOFilterIndexCallback);
76  store->SetUid(HALSIM_RegisterDIOFilterIndexCallback(
77  m_index, &CallbackStoreThunk, store.get(), initialNotify));
78  return store;
79  }
80  int GetFilterIndex() { return HALSIM_GetDIOFilterIndex(m_index); }
81  void SetFilterIndex(int filterIndex) {
82  HALSIM_SetDIOFilterIndex(m_index, filterIndex);
83  }
84 
85  void ResetData() { HALSIM_ResetDIOData(m_index); }
86 
87  private:
88  int m_index;
89 };
90 } // namespace sim
91 } // namespace frc
92 #endif // __FRC_ROBORIO__
WPILib FRC namespace.
Definition: SPIAccelerometerSim.h:18
Definition: DIOSim.h:20