WPILibC++  2020.3.2
DutyCycleSim.h
1 /*----------------------------------------------------------------------------*/
2 /* Copyright (c) 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/DutyCycleData.h"
15 
16 namespace frc {
17 namespace sim {
18 class DutyCycleSim {
19  public:
20  explicit DutyCycleSim(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_CancelDutyCycleInitializedCallback);
26  store->SetUid(HALSIM_RegisterDutyCycleInitializedCallback(
27  m_index, &CallbackStoreThunk, store.get(), initialNotify));
28  return store;
29  }
30 
31  bool GetInitialized() const {
32  return HALSIM_GetDutyCycleInitialized(m_index);
33  }
34 
35  void SetInitialized(bool initialized) {
36  HALSIM_SetDutyCycleInitialized(m_index, initialized);
37  }
38 
39  std::unique_ptr<CallbackStore> RegisterFrequencyCallback(
40  NotifyCallback callback, bool initialNotify) {
41  auto store = std::make_unique<CallbackStore>(
42  m_index, -1, callback, &HALSIM_CancelDutyCycleFrequencyCallback);
43  store->SetUid(HALSIM_RegisterDutyCycleFrequencyCallback(
44  m_index, &CallbackStoreThunk, store.get(), initialNotify));
45  return store;
46  }
47 
48  int GetFrequency() const { return HALSIM_GetDutyCycleFrequency(m_index); }
49 
50  void SetFrequency(int count) { HALSIM_SetDutyCycleFrequency(m_index, count); }
51 
52  std::unique_ptr<CallbackStore> RegisterOutputCallback(NotifyCallback callback,
53  bool initialNotify) {
54  auto store = std::make_unique<CallbackStore>(
55  m_index, -1, callback, &HALSIM_CancelDutyCycleOutputCallback);
56  store->SetUid(HALSIM_RegisterDutyCycleOutputCallback(
57  m_index, &CallbackStoreThunk, store.get(), initialNotify));
58  return store;
59  }
60 
61  double GetOutput() const { return HALSIM_GetDutyCycleOutput(m_index); }
62 
63  void SetOutput(double period) { HALSIM_SetDutyCycleOutput(m_index, period); }
64 
65  void ResetData() { HALSIM_ResetDutyCycleData(m_index); }
66 
67  private:
68  int m_index;
69 };
70 } // namespace sim
71 } // namespace frc
frc
A class that enforces constraints on the differential drive kinematics.
Definition: SPIAccelerometerSim.h:16
frc::sim::DutyCycleSim
Definition: DutyCycleSim.h:18