2018-05-11 12:38:23 -07:00
|
|
|
/*----------------------------------------------------------------------------*/
|
2020-06-27 22:11:24 -07:00
|
|
|
/* Copyright (c) 2018-2020 FIRST. All Rights Reserved. */
|
2018-05-11 12:38:23 -07:00
|
|
|
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
|
|
|
|
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
|
|
|
|
/* the project. */
|
|
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
|
#include <utility>
|
|
|
|
|
|
2020-06-27 22:11:24 -07:00
|
|
|
#include <hal/simulation/AnalogOutData.h>
|
|
|
|
|
|
2018-05-11 12:38:23 -07:00
|
|
|
#include "CallbackStore.h"
|
2020-07-04 10:10:43 -07:00
|
|
|
#include "frc/AnalogOutput.h"
|
2018-05-11 12:38:23 -07:00
|
|
|
|
|
|
|
|
namespace frc {
|
|
|
|
|
namespace sim {
|
2020-07-04 10:10:43 -07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Class to control a simulated analog output.
|
|
|
|
|
*/
|
|
|
|
|
class AnalogOutputSim {
|
2018-05-11 12:38:23 -07:00
|
|
|
public:
|
2020-07-04 10:10:43 -07:00
|
|
|
/**
|
|
|
|
|
* Constructs from an AnalogOutput object.
|
|
|
|
|
*
|
|
|
|
|
* @param analogOutput AnalogOutput to simulate
|
|
|
|
|
*/
|
|
|
|
|
explicit AnalogOutputSim(const AnalogOutput& analogOutput)
|
|
|
|
|
: m_index{analogOutput.GetChannel()} {}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Constructs from an analog output channel number.
|
|
|
|
|
*
|
|
|
|
|
* @param channel Channel number
|
|
|
|
|
*/
|
|
|
|
|
explicit AnalogOutputSim(int channel) : m_index{channel} {}
|
2018-05-11 12:38:23 -07:00
|
|
|
|
|
|
|
|
std::unique_ptr<CallbackStore> RegisterVoltageCallback(
|
|
|
|
|
NotifyCallback callback, bool initialNotify) {
|
|
|
|
|
auto store = std::make_unique<CallbackStore>(
|
|
|
|
|
m_index, -1, callback, &HALSIM_CancelAnalogOutVoltageCallback);
|
|
|
|
|
store->SetUid(HALSIM_RegisterAnalogOutVoltageCallback(
|
|
|
|
|
m_index, &CallbackStoreThunk, store.get(), initialNotify));
|
2018-05-16 19:45:46 -07:00
|
|
|
return store;
|
2018-05-11 12:38:23 -07:00
|
|
|
}
|
2018-08-16 01:17:59 -04:00
|
|
|
|
|
|
|
|
double GetVoltage() const { return HALSIM_GetAnalogOutVoltage(m_index); }
|
|
|
|
|
|
2018-05-11 12:38:23 -07:00
|
|
|
void SetVoltage(double voltage) {
|
|
|
|
|
HALSIM_SetAnalogOutVoltage(m_index, voltage);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::unique_ptr<CallbackStore> RegisterInitializedCallback(
|
|
|
|
|
NotifyCallback callback, bool initialNotify) {
|
|
|
|
|
auto store = std::make_unique<CallbackStore>(
|
|
|
|
|
m_index, -1, callback, &HALSIM_CancelAnalogOutInitializedCallback);
|
|
|
|
|
store->SetUid(HALSIM_RegisterAnalogOutInitializedCallback(
|
|
|
|
|
m_index, &CallbackStoreThunk, store.get(), initialNotify));
|
2018-05-16 19:45:46 -07:00
|
|
|
return store;
|
2018-05-11 12:38:23 -07:00
|
|
|
}
|
2018-08-16 01:17:59 -04:00
|
|
|
|
|
|
|
|
bool GetInitialized() const {
|
|
|
|
|
return HALSIM_GetAnalogOutInitialized(m_index);
|
|
|
|
|
}
|
|
|
|
|
|
2018-05-11 12:38:23 -07:00
|
|
|
void SetInitialized(bool initialized) {
|
|
|
|
|
HALSIM_SetAnalogOutInitialized(m_index, initialized);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ResetData() { HALSIM_ResetAnalogOutData(m_index); }
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
int m_index;
|
|
|
|
|
};
|
|
|
|
|
} // namespace sim
|
|
|
|
|
} // namespace frc
|