2018-05-11 12:38:23 -07:00
|
|
|
/*----------------------------------------------------------------------------*/
|
2019-09-03 19:55:17 -07:00
|
|
|
/* Copyright (c) 2018-2019 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>
|
|
|
|
|
|
|
|
|
|
#include "CallbackStore.h"
|
2018-07-20 00:03:45 -07:00
|
|
|
#include "mockdata/DIOData.h"
|
2018-05-11 12:38:23 -07:00
|
|
|
|
|
|
|
|
namespace frc {
|
|
|
|
|
namespace sim {
|
|
|
|
|
class DIOSim {
|
|
|
|
|
public:
|
|
|
|
|
explicit DIOSim(int index) { m_index = index; }
|
|
|
|
|
|
|
|
|
|
std::unique_ptr<CallbackStore> RegisterInitializedCallback(
|
|
|
|
|
NotifyCallback callback, bool initialNotify) {
|
|
|
|
|
auto store = std::make_unique<CallbackStore>(
|
|
|
|
|
m_index, -1, callback, &HALSIM_CancelDIOInitializedCallback);
|
|
|
|
|
store->SetUid(HALSIM_RegisterDIOInitializedCallback(
|
|
|
|
|
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_GetDIOInitialized(m_index); }
|
|
|
|
|
|
2018-05-11 12:38:23 -07:00
|
|
|
void SetInitialized(bool initialized) {
|
|
|
|
|
HALSIM_SetDIOInitialized(m_index, initialized);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::unique_ptr<CallbackStore> RegisterValueCallback(NotifyCallback callback,
|
|
|
|
|
bool initialNotify) {
|
|
|
|
|
auto store = std::make_unique<CallbackStore>(
|
|
|
|
|
m_index, -1, callback, &HALSIM_CancelDIOValueCallback);
|
|
|
|
|
store->SetUid(HALSIM_RegisterDIOValueCallback(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 GetValue() const { return HALSIM_GetDIOValue(m_index); }
|
|
|
|
|
|
2018-05-11 12:38:23 -07:00
|
|
|
void SetValue(bool value) { HALSIM_SetDIOValue(m_index, value); }
|
|
|
|
|
|
|
|
|
|
std::unique_ptr<CallbackStore> RegisterPulseLengthCallback(
|
|
|
|
|
NotifyCallback callback, bool initialNotify) {
|
|
|
|
|
auto store = std::make_unique<CallbackStore>(
|
|
|
|
|
m_index, -1, callback, &HALSIM_CancelDIOPulseLengthCallback);
|
|
|
|
|
store->SetUid(HALSIM_RegisterDIOPulseLengthCallback(
|
|
|
|
|
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 GetPulseLength() const { return HALSIM_GetDIOPulseLength(m_index); }
|
|
|
|
|
|
2018-05-11 12:38:23 -07:00
|
|
|
void SetPulseLength(double pulseLength) {
|
|
|
|
|
HALSIM_SetDIOPulseLength(m_index, pulseLength);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::unique_ptr<CallbackStore> RegisterIsInputCallback(
|
|
|
|
|
NotifyCallback callback, bool initialNotify) {
|
|
|
|
|
auto store = std::make_unique<CallbackStore>(
|
|
|
|
|
m_index, -1, callback, &HALSIM_CancelDIOIsInputCallback);
|
|
|
|
|
store->SetUid(HALSIM_RegisterDIOIsInputCallback(
|
|
|
|
|
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 GetIsInput() const { return HALSIM_GetDIOIsInput(m_index); }
|
|
|
|
|
|
2018-05-11 12:38:23 -07:00
|
|
|
void SetIsInput(bool isInput) { HALSIM_SetDIOIsInput(m_index, isInput); }
|
|
|
|
|
|
|
|
|
|
std::unique_ptr<CallbackStore> RegisterFilterIndexCallback(
|
|
|
|
|
NotifyCallback callback, bool initialNotify) {
|
|
|
|
|
auto store = std::make_unique<CallbackStore>(
|
|
|
|
|
m_index, -1, callback, &HALSIM_CancelDIOFilterIndexCallback);
|
|
|
|
|
store->SetUid(HALSIM_RegisterDIOFilterIndexCallback(
|
|
|
|
|
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
|
|
|
|
|
|
|
|
int GetFilterIndex() const { return HALSIM_GetDIOFilterIndex(m_index); }
|
|
|
|
|
|
2018-05-11 12:38:23 -07:00
|
|
|
void SetFilterIndex(int filterIndex) {
|
|
|
|
|
HALSIM_SetDIOFilterIndex(m_index, filterIndex);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ResetData() { HALSIM_ResetDIOData(m_index); }
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
int m_index;
|
|
|
|
|
};
|
|
|
|
|
} // namespace sim
|
|
|
|
|
} // namespace frc
|