WPILibC++  2020.3.2-60-g3011ebe
PWMSim.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/PWMData.h"
15 
16 namespace frc {
17 namespace sim {
18 class PWMSim {
19  public:
20  explicit PWMSim(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_CancelPWMInitializedCallback);
26  store->SetUid(HALSIM_RegisterPWMInitializedCallback(
27  m_index, &CallbackStoreThunk, store.get(), initialNotify));
28  return store;
29  }
30 
31  bool GetInitialized() const { return HALSIM_GetPWMInitialized(m_index); }
32 
33  void SetInitialized(bool initialized) {
34  HALSIM_SetPWMInitialized(m_index, initialized);
35  }
36 
37  std::unique_ptr<CallbackStore> RegisterRawValueCallback(
38  NotifyCallback callback, bool initialNotify) {
39  auto store = std::make_unique<CallbackStore>(
40  m_index, -1, callback, &HALSIM_CancelPWMRawValueCallback);
41  store->SetUid(HALSIM_RegisterPWMRawValueCallback(
42  m_index, &CallbackStoreThunk, store.get(), initialNotify));
43  return store;
44  }
45 
46  int GetRawValue() const { return HALSIM_GetPWMRawValue(m_index); }
47 
48  void SetRawValue(int rawValue) { HALSIM_SetPWMRawValue(m_index, rawValue); }
49 
50  std::unique_ptr<CallbackStore> RegisterSpeedCallback(NotifyCallback callback,
51  bool initialNotify) {
52  auto store = std::make_unique<CallbackStore>(
53  m_index, -1, callback, &HALSIM_CancelPWMSpeedCallback);
54  store->SetUid(HALSIM_RegisterPWMSpeedCallback(m_index, &CallbackStoreThunk,
55  store.get(), initialNotify));
56  return store;
57  }
58 
59  double GetSpeed() const { return HALSIM_GetPWMSpeed(m_index); }
60 
61  void SetSpeed(double speed) { HALSIM_SetPWMSpeed(m_index, speed); }
62 
63  std::unique_ptr<CallbackStore> RegisterPositionCallback(
64  NotifyCallback callback, bool initialNotify) {
65  auto store = std::make_unique<CallbackStore>(
66  m_index, -1, callback, &HALSIM_CancelPWMPositionCallback);
67  store->SetUid(HALSIM_RegisterPWMPositionCallback(
68  m_index, &CallbackStoreThunk, store.get(), initialNotify));
69  return store;
70  }
71 
72  double GetPosition() const { return HALSIM_GetPWMPosition(m_index); }
73 
74  void SetPosition(double position) {
75  HALSIM_SetPWMPosition(m_index, position);
76  }
77 
78  std::unique_ptr<CallbackStore> RegisterPeriodScaleCallback(
79  NotifyCallback callback, bool initialNotify) {
80  auto store = std::make_unique<CallbackStore>(
81  m_index, -1, callback, &HALSIM_CancelPWMPeriodScaleCallback);
82  store->SetUid(HALSIM_RegisterPWMPeriodScaleCallback(
83  m_index, &CallbackStoreThunk, store.get(), initialNotify));
84  return store;
85  }
86 
87  int GetPeriodScale() const { return HALSIM_GetPWMPeriodScale(m_index); }
88 
89  void SetPeriodScale(int periodScale) {
90  HALSIM_SetPWMPeriodScale(m_index, periodScale);
91  }
92 
93  std::unique_ptr<CallbackStore> RegisterZeroLatchCallback(
94  NotifyCallback callback, bool initialNotify) {
95  auto store = std::make_unique<CallbackStore>(
96  m_index, -1, callback, &HALSIM_CancelPWMZeroLatchCallback);
97  store->SetUid(HALSIM_RegisterPWMZeroLatchCallback(
98  m_index, &CallbackStoreThunk, store.get(), initialNotify));
99  return store;
100  }
101 
102  bool GetZeroLatch() const { return HALSIM_GetPWMZeroLatch(m_index); }
103 
104  void SetZeroLatch(bool zeroLatch) {
105  HALSIM_SetPWMZeroLatch(m_index, zeroLatch);
106  }
107 
108  void ResetData() { HALSIM_ResetPWMData(m_index); }
109 
110  private:
111  int m_index;
112 };
113 } // namespace sim
114 } // namespace frc
frc::sim::PWMSim
Definition: PWMSim.h:18
frc
A class that enforces constraints on the differential drive kinematics.
Definition: PDPSim.h:16