WPILibC++  2020.3.2
RelaySim.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/RelayData.h"
15 
16 namespace frc {
17 namespace sim {
18 class RelaySim {
19  public:
20  explicit RelaySim(int index) { m_index = index; }
21 
22  std::unique_ptr<CallbackStore> RegisterInitializedForwardCallback(
23  NotifyCallback callback, bool initialNotify) {
24  auto store = std::make_unique<CallbackStore>(
25  m_index, -1, callback, &HALSIM_CancelRelayInitializedForwardCallback);
26  store->SetUid(HALSIM_RegisterRelayInitializedForwardCallback(
27  m_index, &CallbackStoreThunk, store.get(), initialNotify));
28  return store;
29  }
30 
31  bool GetInitializedForward() const {
32  return HALSIM_GetRelayInitializedForward(m_index);
33  }
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 
48  bool GetInitializedReverse() const {
49  return HALSIM_GetRelayInitializedReverse(m_index);
50  }
51 
52  void SetInitializedReverse(bool initializedReverse) {
53  HALSIM_SetRelayInitializedReverse(m_index, initializedReverse);
54  }
55 
56  std::unique_ptr<CallbackStore> RegisterForwardCallback(
57  NotifyCallback callback, bool initialNotify) {
58  auto store = std::make_unique<CallbackStore>(
59  m_index, -1, callback, &HALSIM_CancelRelayForwardCallback);
60  store->SetUid(HALSIM_RegisterRelayForwardCallback(
61  m_index, &CallbackStoreThunk, store.get(), initialNotify));
62  return store;
63  }
64 
65  bool GetForward() const { return HALSIM_GetRelayForward(m_index); }
66 
67  void SetForward(bool forward) { HALSIM_SetRelayForward(m_index, forward); }
68 
69  std::unique_ptr<CallbackStore> RegisterReverseCallback(
70  NotifyCallback callback, bool initialNotify) {
71  auto store = std::make_unique<CallbackStore>(
72  m_index, -1, callback, &HALSIM_CancelRelayReverseCallback);
73  store->SetUid(HALSIM_RegisterRelayReverseCallback(
74  m_index, &CallbackStoreThunk, store.get(), initialNotify));
75  return store;
76  }
77 
78  bool GetReverse() const { return HALSIM_GetRelayReverse(m_index); }
79 
80  void SetReverse(bool reverse) { HALSIM_SetRelayReverse(m_index, reverse); }
81 
82  void ResetData() { HALSIM_ResetRelayData(m_index); }
83 
84  private:
85  int m_index;
86 };
87 } // namespace sim
88 } // namespace frc
frc::sim::RelaySim
Definition: RelaySim.h:18
frc
A class that enforces constraints on the differential drive kinematics.
Definition: SPIAccelerometerSim.h:16