WPILibC++  2019.1.1-beta-2-14-gdf347e3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages
DigitalPWMSim.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/DigitalPWMData.h"
17 
18 namespace frc {
19 namespace sim {
21  public:
22  explicit DigitalPWMSim(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_CancelDigitalPWMInitializedCallback);
28  store->SetUid(HALSIM_RegisterDigitalPWMInitializedCallback(
29  m_index, &CallbackStoreThunk, store.get(), initialNotify));
30  return store;
31  }
32 
33  bool GetInitialized() const {
34  return HALSIM_GetDigitalPWMInitialized(m_index);
35  }
36 
37  void SetInitialized(bool initialized) {
38  HALSIM_SetDigitalPWMInitialized(m_index, initialized);
39  }
40 
41  std::unique_ptr<CallbackStore> RegisterDutyCycleCallback(
42  NotifyCallback callback, bool initialNotify) {
43  auto store = std::make_unique<CallbackStore>(
44  m_index, -1, callback, &HALSIM_CancelDigitalPWMDutyCycleCallback);
45  store->SetUid(HALSIM_RegisterDigitalPWMDutyCycleCallback(
46  m_index, &CallbackStoreThunk, store.get(), initialNotify));
47  return store;
48  }
49 
50  double GetDutyCycle() const { return HALSIM_GetDigitalPWMDutyCycle(m_index); }
51 
52  void SetDutyCycle(double dutyCycle) {
53  HALSIM_SetDigitalPWMDutyCycle(m_index, dutyCycle);
54  }
55 
56  std::unique_ptr<CallbackStore> RegisterPinCallback(NotifyCallback callback,
57  bool initialNotify) {
58  auto store = std::make_unique<CallbackStore>(
59  m_index, -1, callback, &HALSIM_CancelDigitalPWMPinCallback);
60  store->SetUid(HALSIM_RegisterDigitalPWMPinCallback(
61  m_index, &CallbackStoreThunk, store.get(), initialNotify));
62  return store;
63  }
64 
65  int GetPin() const { return HALSIM_GetDigitalPWMPin(m_index); }
66 
67  void SetPin(int pin) { HALSIM_SetDigitalPWMPin(m_index, pin); }
68 
69  void ResetData() { HALSIM_ResetDigitalPWMData(m_index); }
70 
71  private:
72  int m_index;
73 };
74 } // namespace sim
75 } // namespace frc
76 #endif // __FRC_ROBORIO__
WPILib FRC namespace.
Definition: SPIAccelerometerSim.h:18
Definition: DigitalPWMSim.h:20