WPILibC++  2019.1.1-beta-2-5-g55493b0
 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 
33  bool GetInitialized() const { return HALSIM_GetDIOInitialized(m_index); }
34 
35  void SetInitialized(bool initialized) {
36  HALSIM_SetDIOInitialized(m_index, initialized);
37  }
38 
39  std::unique_ptr<CallbackStore> RegisterValueCallback(NotifyCallback callback,
40  bool initialNotify) {
41  auto store = std::make_unique<CallbackStore>(
42  m_index, -1, callback, &HALSIM_CancelDIOValueCallback);
43  store->SetUid(HALSIM_RegisterDIOValueCallback(m_index, &CallbackStoreThunk,
44  store.get(), initialNotify));
45  return store;
46  }
47 
48  bool GetValue() const { return HALSIM_GetDIOValue(m_index); }
49 
50  void SetValue(bool value) { HALSIM_SetDIOValue(m_index, value); }
51 
52  std::unique_ptr<CallbackStore> RegisterPulseLengthCallback(
53  NotifyCallback callback, bool initialNotify) {
54  auto store = std::make_unique<CallbackStore>(
55  m_index, -1, callback, &HALSIM_CancelDIOPulseLengthCallback);
56  store->SetUid(HALSIM_RegisterDIOPulseLengthCallback(
57  m_index, &CallbackStoreThunk, store.get(), initialNotify));
58  return store;
59  }
60 
61  double GetPulseLength() const { return HALSIM_GetDIOPulseLength(m_index); }
62 
63  void SetPulseLength(double pulseLength) {
64  HALSIM_SetDIOPulseLength(m_index, pulseLength);
65  }
66 
67  std::unique_ptr<CallbackStore> RegisterIsInputCallback(
68  NotifyCallback callback, bool initialNotify) {
69  auto store = std::make_unique<CallbackStore>(
70  m_index, -1, callback, &HALSIM_CancelDIOIsInputCallback);
71  store->SetUid(HALSIM_RegisterDIOIsInputCallback(
72  m_index, &CallbackStoreThunk, store.get(), initialNotify));
73  return store;
74  }
75 
76  bool GetIsInput() const { return HALSIM_GetDIOIsInput(m_index); }
77 
78  void SetIsInput(bool isInput) { HALSIM_SetDIOIsInput(m_index, isInput); }
79 
80  std::unique_ptr<CallbackStore> RegisterFilterIndexCallback(
81  NotifyCallback callback, bool initialNotify) {
82  auto store = std::make_unique<CallbackStore>(
83  m_index, -1, callback, &HALSIM_CancelDIOFilterIndexCallback);
84  store->SetUid(HALSIM_RegisterDIOFilterIndexCallback(
85  m_index, &CallbackStoreThunk, store.get(), initialNotify));
86  return store;
87  }
88 
89  int GetFilterIndex() const { return HALSIM_GetDIOFilterIndex(m_index); }
90 
91  void SetFilterIndex(int filterIndex) {
92  HALSIM_SetDIOFilterIndex(m_index, filterIndex);
93  }
94 
95  void ResetData() { HALSIM_ResetDIOData(m_index); }
96 
97  private:
98  int m_index;
99 };
100 } // namespace sim
101 } // namespace frc
102 #endif // __FRC_ROBORIO__
WPILib FRC namespace.
Definition: SPIAccelerometerSim.h:18
Definition: DIOSim.h:20