WPILibC++  2018.4.1-20180729184725-1146-g6db5f80
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages
RelaySim.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/RelayData.h"
17 
18 namespace frc {
19 namespace sim {
20 class RelaySim {
21  public:
22  explicit RelaySim(int index) { m_index = index; }
23 
24  std::unique_ptr<CallbackStore> RegisterInitializedForwardCallback(
25  NotifyCallback callback, bool initialNotify) {
26  auto store = std::make_unique<CallbackStore>(
27  m_index, -1, callback, &HALSIM_CancelRelayInitializedForwardCallback);
28  store->SetUid(HALSIM_RegisterRelayInitializedForwardCallback(
29  m_index, &CallbackStoreThunk, store.get(), initialNotify));
30  return store;
31  }
32  bool GetInitializedForward() {
33  return HALSIM_GetRelayInitializedForward(m_index);
34  }
35  void SetInitializedForward(bool initializedForward) {
36  HALSIM_SetRelayInitializedForward(m_index, initializedForward);
37  }
38 
39  std::unique_ptr<CallbackStore> RegisterInitializedReverseCallback(
40  NotifyCallback callback, bool initialNotify) {
41  auto store = std::make_unique<CallbackStore>(
42  m_index, -1, callback, &HALSIM_CancelRelayInitializedReverseCallback);
43  store->SetUid(HALSIM_RegisterRelayInitializedReverseCallback(
44  m_index, &CallbackStoreThunk, store.get(), initialNotify));
45  return store;
46  }
47  bool GetInitializedReverse() {
48  return HALSIM_GetRelayInitializedReverse(m_index);
49  }
50  void SetInitializedReverse(bool initializedReverse) {
51  HALSIM_SetRelayInitializedReverse(m_index, initializedReverse);
52  }
53 
54  std::unique_ptr<CallbackStore> RegisterForwardCallback(
55  NotifyCallback callback, bool initialNotify) {
56  auto store = std::make_unique<CallbackStore>(
57  m_index, -1, callback, &HALSIM_CancelRelayForwardCallback);
58  store->SetUid(HALSIM_RegisterRelayForwardCallback(
59  m_index, &CallbackStoreThunk, store.get(), initialNotify));
60  return store;
61  }
62  bool GetForward() { return HALSIM_GetRelayForward(m_index); }
63  void SetForward(bool forward) { HALSIM_SetRelayForward(m_index, forward); }
64 
65  std::unique_ptr<CallbackStore> RegisterReverseCallback(
66  NotifyCallback callback, bool initialNotify) {
67  auto store = std::make_unique<CallbackStore>(
68  m_index, -1, callback, &HALSIM_CancelRelayReverseCallback);
69  store->SetUid(HALSIM_RegisterRelayReverseCallback(
70  m_index, &CallbackStoreThunk, store.get(), initialNotify));
71  return store;
72  }
73  bool GetReverse() { return HALSIM_GetRelayReverse(m_index); }
74  void SetReverse(bool reverse) { HALSIM_SetRelayReverse(m_index, reverse); }
75 
76  void ResetData() { HALSIM_ResetRelayData(m_index); }
77 
78  private:
79  int m_index;
80 };
81 } // namespace sim
82 } // namespace frc
83 #endif // __FRC_ROBORIO__
WPILib FRC namespace.
Definition: SPIAccelerometerSim.h:18
Definition: RelaySim.h:20