2017-08-18 21:35:53 -07:00
|
|
|
/*----------------------------------------------------------------------------*/
|
2019-10-04 22:56:24 -07:00
|
|
|
/* Copyright (c) 2017-2019 FIRST. All Rights Reserved. */
|
2017-08-18 21:35:53 -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. */
|
|
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
|
|
#include "../PortsInternal.h"
|
|
|
|
|
#include "EncoderDataInternal.h"
|
|
|
|
|
|
|
|
|
|
using namespace hal;
|
|
|
|
|
|
2017-12-10 19:38:53 -08:00
|
|
|
namespace hal {
|
|
|
|
|
namespace init {
|
|
|
|
|
void InitializeEncoderData() {
|
|
|
|
|
static EncoderData sed[kNumEncoders];
|
|
|
|
|
::hal::SimEncoderData = sed;
|
|
|
|
|
}
|
|
|
|
|
} // namespace init
|
|
|
|
|
} // namespace hal
|
|
|
|
|
|
|
|
|
|
EncoderData* hal::SimEncoderData;
|
2017-08-18 21:35:53 -07:00
|
|
|
void EncoderData::ResetData() {
|
2018-09-03 16:08:07 -07:00
|
|
|
digitalChannelA = 0;
|
2019-10-04 17:29:34 -07:00
|
|
|
digitalChannelB = 0;
|
2018-09-03 16:08:07 -07:00
|
|
|
initialized.Reset(false);
|
2019-10-04 22:56:24 -07:00
|
|
|
simDevice = 0;
|
2018-09-03 16:08:07 -07:00
|
|
|
count.Reset(0);
|
|
|
|
|
period.Reset(std::numeric_limits<double>::max());
|
|
|
|
|
reset.Reset(false);
|
|
|
|
|
maxPeriod.Reset(0);
|
|
|
|
|
direction.Reset(false);
|
|
|
|
|
reverseDirection.Reset(false);
|
|
|
|
|
samplesToAverage.Reset(0);
|
|
|
|
|
distancePerPulse.Reset(1);
|
2018-01-02 17:53:39 -05:00
|
|
|
}
|
|
|
|
|
|
2017-08-18 21:35:53 -07:00
|
|
|
extern "C" {
|
|
|
|
|
void HALSIM_ResetEncoderData(int32_t index) {
|
|
|
|
|
SimEncoderData[index].ResetData();
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-04 17:29:34 -07:00
|
|
|
int32_t HALSIM_GetEncoderDigitalChannelA(int32_t index) {
|
2018-09-03 16:08:07 -07:00
|
|
|
return SimEncoderData[index].digitalChannelA;
|
2017-08-18 21:35:53 -07:00
|
|
|
}
|
|
|
|
|
|
2019-10-04 17:29:34 -07:00
|
|
|
int32_t HALSIM_GetEncoderDigitalChannelB(int32_t index) {
|
|
|
|
|
return SimEncoderData[index].digitalChannelB;
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-04 22:56:24 -07:00
|
|
|
HAL_SimDeviceHandle HALSIM_GetEncoderSimDevice(int32_t index) {
|
|
|
|
|
return SimEncoderData[index].simDevice;
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-03 16:08:07 -07:00
|
|
|
#define DEFINE_CAPI(TYPE, CAPINAME, LOWERNAME) \
|
|
|
|
|
HAL_SIMDATAVALUE_DEFINE_CAPI(TYPE, HALSIM, Encoder##CAPINAME, \
|
|
|
|
|
SimEncoderData, LOWERNAME)
|
2017-08-18 21:35:53 -07:00
|
|
|
|
2018-09-03 16:08:07 -07:00
|
|
|
DEFINE_CAPI(HAL_Bool, Initialized, initialized)
|
|
|
|
|
DEFINE_CAPI(int32_t, Count, count)
|
|
|
|
|
DEFINE_CAPI(double, Period, period)
|
|
|
|
|
DEFINE_CAPI(HAL_Bool, Reset, reset)
|
|
|
|
|
DEFINE_CAPI(double, MaxPeriod, maxPeriod)
|
|
|
|
|
DEFINE_CAPI(HAL_Bool, Direction, direction)
|
|
|
|
|
DEFINE_CAPI(HAL_Bool, ReverseDirection, reverseDirection)
|
|
|
|
|
DEFINE_CAPI(int32_t, SamplesToAverage, samplesToAverage)
|
|
|
|
|
DEFINE_CAPI(double, DistancePerPulse, distancePerPulse)
|
2017-08-18 21:35:53 -07:00
|
|
|
|
2018-09-03 16:08:07 -07:00
|
|
|
#define REGISTER(NAME) \
|
|
|
|
|
SimEncoderData[index].NAME.RegisterCallback(callback, param, initialNotify)
|
2018-07-12 23:11:26 -04:00
|
|
|
|
2017-10-22 01:45:41 -04:00
|
|
|
void HALSIM_RegisterEncoderAllCallbacks(int32_t index,
|
|
|
|
|
HAL_NotifyCallback callback,
|
|
|
|
|
void* param, HAL_Bool initialNotify) {
|
2018-09-03 16:08:07 -07:00
|
|
|
REGISTER(initialized);
|
|
|
|
|
REGISTER(count);
|
|
|
|
|
REGISTER(period);
|
|
|
|
|
REGISTER(reset);
|
|
|
|
|
REGISTER(maxPeriod);
|
|
|
|
|
REGISTER(direction);
|
|
|
|
|
REGISTER(reverseDirection);
|
|
|
|
|
REGISTER(samplesToAverage);
|
|
|
|
|
REGISTER(distancePerPulse);
|
2017-10-22 01:45:41 -04:00
|
|
|
}
|
2017-10-16 19:56:08 -07:00
|
|
|
} // extern "C"
|