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