WPILibC++  2018.4.1-20180810231726-1152-g44099d9
 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  bool GetInitialized() { return HALSIM_GetPWMInitialized(m_index); }
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  int GetRawValue() { return HALSIM_GetPWMRawValue(m_index); }
46  void SetRawValue(int rawValue) { HALSIM_SetPWMRawValue(m_index, rawValue); }
47 
48  std::unique_ptr<CallbackStore> RegisterSpeedCallback(NotifyCallback callback,
49  bool initialNotify) {
50  auto store = std::make_unique<CallbackStore>(
51  m_index, -1, callback, &HALSIM_CancelPWMSpeedCallback);
52  store->SetUid(HALSIM_RegisterPWMSpeedCallback(m_index, &CallbackStoreThunk,
53  store.get(), initialNotify));
54  return store;
55  }
56  double GetSpeed() { return HALSIM_GetPWMSpeed(m_index); }
57  void SetSpeed(double speed) { HALSIM_SetPWMSpeed(m_index, speed); }
58 
59  std::unique_ptr<CallbackStore> RegisterPositionCallback(
60  NotifyCallback callback, bool initialNotify) {
61  auto store = std::make_unique<CallbackStore>(
62  m_index, -1, callback, &HALSIM_CancelPWMPositionCallback);
63  store->SetUid(HALSIM_RegisterPWMPositionCallback(
64  m_index, &CallbackStoreThunk, store.get(), initialNotify));
65  return store;
66  }
67  double GetPosition() { return HALSIM_GetPWMPosition(m_index); }
68  void SetPosition(double position) {
69  HALSIM_SetPWMPosition(m_index, position);
70  }
71 
72  std::unique_ptr<CallbackStore> RegisterPeriodScaleCallback(
73  NotifyCallback callback, bool initialNotify) {
74  auto store = std::make_unique<CallbackStore>(
75  m_index, -1, callback, &HALSIM_CancelPWMPeriodScaleCallback);
76  store->SetUid(HALSIM_RegisterPWMPeriodScaleCallback(
77  m_index, &CallbackStoreThunk, store.get(), initialNotify));
78  return store;
79  }
80  int GetPeriodScale() { return HALSIM_GetPWMPeriodScale(m_index); }
81  void SetPeriodScale(int periodScale) {
82  HALSIM_SetPWMPeriodScale(m_index, periodScale);
83  }
84 
85  std::unique_ptr<CallbackStore> RegisterZeroLatchCallback(
86  NotifyCallback callback, bool initialNotify) {
87  auto store = std::make_unique<CallbackStore>(
88  m_index, -1, callback, &HALSIM_CancelPWMZeroLatchCallback);
89  store->SetUid(HALSIM_RegisterPWMZeroLatchCallback(
90  m_index, &CallbackStoreThunk, store.get(), initialNotify));
91  return store;
92  }
93  bool GetZeroLatch() { return HALSIM_GetPWMZeroLatch(m_index); }
94  void SetZeroLatch(bool zeroLatch) {
95  HALSIM_SetPWMZeroLatch(m_index, zeroLatch);
96  }
97 
98  void ResetData() { HALSIM_ResetPWMData(m_index); }
99 
100  private:
101  int m_index;
102 };
103 } // namespace sim
104 } // namespace frc
105 #endif // __FRC_ROBORIO__
WPILib FRC namespace.
Definition: SPIAccelerometerSim.h:18
Definition: PWMSim.h:20