WPILibC++  2018.4.1-20180728210220-1136-g75a6720
 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  bool GetInitialized() { return HALSIM_GetDigitalPWMInitialized(m_index); }
33  void SetInitialized(bool initialized) {
34  HALSIM_SetDigitalPWMInitialized(m_index, initialized);
35  }
36 
37  std::unique_ptr<CallbackStore> RegisterDutyCycleCallback(
38  NotifyCallback callback, bool initialNotify) {
39  auto store = std::make_unique<CallbackStore>(
40  m_index, -1, callback, &HALSIM_CancelDigitalPWMDutyCycleCallback);
41  store->SetUid(HALSIM_RegisterDigitalPWMDutyCycleCallback(
42  m_index, &CallbackStoreThunk, store.get(), initialNotify));
43  return store;
44  }
45  double GetDutyCycle() { return HALSIM_GetDigitalPWMDutyCycle(m_index); }
46  void SetDutyCycle(double dutyCycle) {
47  HALSIM_SetDigitalPWMDutyCycle(m_index, dutyCycle);
48  }
49 
50  std::unique_ptr<CallbackStore> RegisterPinCallback(NotifyCallback callback,
51  bool initialNotify) {
52  auto store = std::make_unique<CallbackStore>(
53  m_index, -1, callback, &HALSIM_CancelDigitalPWMPinCallback);
54  store->SetUid(HALSIM_RegisterDigitalPWMPinCallback(
55  m_index, &CallbackStoreThunk, store.get(), initialNotify));
56  return store;
57  }
58  int GetPin() { return HALSIM_GetDigitalPWMPin(m_index); }
59  void SetPin(int pin) { HALSIM_SetDigitalPWMPin(m_index, pin); }
60 
61  void ResetData() { HALSIM_ResetDigitalPWMData(m_index); }
62 
63  private:
64  int m_index;
65 };
66 } // namespace sim
67 } // namespace frc
68 #endif // __FRC_ROBORIO__
Definition: SPIAccelerometerSim.h:18
Definition: DigitalPWMSim.h:20