WPILibC++  2020.3.2
DigitalPWMSim.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/DigitalPWMData.h"
15 
16 namespace frc {
17 namespace sim {
19  public:
20  explicit DigitalPWMSim(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_CancelDigitalPWMInitializedCallback);
26  store->SetUid(HALSIM_RegisterDigitalPWMInitializedCallback(
27  m_index, &CallbackStoreThunk, store.get(), initialNotify));
28  return store;
29  }
30 
31  bool GetInitialized() const {
32  return HALSIM_GetDigitalPWMInitialized(m_index);
33  }
34 
35  void SetInitialized(bool initialized) {
36  HALSIM_SetDigitalPWMInitialized(m_index, initialized);
37  }
38 
39  std::unique_ptr<CallbackStore> RegisterDutyCycleCallback(
40  NotifyCallback callback, bool initialNotify) {
41  auto store = std::make_unique<CallbackStore>(
42  m_index, -1, callback, &HALSIM_CancelDigitalPWMDutyCycleCallback);
43  store->SetUid(HALSIM_RegisterDigitalPWMDutyCycleCallback(
44  m_index, &CallbackStoreThunk, store.get(), initialNotify));
45  return store;
46  }
47 
48  double GetDutyCycle() const { return HALSIM_GetDigitalPWMDutyCycle(m_index); }
49 
50  void SetDutyCycle(double dutyCycle) {
51  HALSIM_SetDigitalPWMDutyCycle(m_index, dutyCycle);
52  }
53 
54  std::unique_ptr<CallbackStore> RegisterPinCallback(NotifyCallback callback,
55  bool initialNotify) {
56  auto store = std::make_unique<CallbackStore>(
57  m_index, -1, callback, &HALSIM_CancelDigitalPWMPinCallback);
58  store->SetUid(HALSIM_RegisterDigitalPWMPinCallback(
59  m_index, &CallbackStoreThunk, store.get(), initialNotify));
60  return store;
61  }
62 
63  int GetPin() const { return HALSIM_GetDigitalPWMPin(m_index); }
64 
65  void SetPin(int pin) { HALSIM_SetDigitalPWMPin(m_index, pin); }
66 
67  void ResetData() { HALSIM_ResetDigitalPWMData(m_index); }
68 
69  private:
70  int m_index;
71 };
72 } // namespace sim
73 } // namespace frc
frc::sim::DigitalPWMSim
Definition: DigitalPWMSim.h:18
frc
A class that enforces constraints on the differential drive kinematics.
Definition: SPIAccelerometerSim.h:16