mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-07-05 03:21:42 +00:00
Changes DigitalSource API for HAL ease of use (#144)
This commit is contained in:
committed by
Peter Johnson
parent
7597e3c274
commit
4a3e3a6324
@@ -9,6 +9,7 @@
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "HAL/AnalogTrigger.h"
|
||||
#include "HAL/Handles.h"
|
||||
|
||||
enum Mode {
|
||||
@@ -23,13 +24,15 @@ HalCounterHandle initializeCounter(Mode mode, int32_t* index, int32_t* status);
|
||||
void freeCounter(HalCounterHandle counter_handle, int32_t* status);
|
||||
void setCounterAverageSize(HalCounterHandle counter_handle, int32_t size,
|
||||
int32_t* status);
|
||||
void setCounterUpSource(HalCounterHandle counter_handle, uint32_t pin,
|
||||
bool analogTrigger, int32_t* status);
|
||||
void setCounterUpSource(HalCounterHandle counter_handle,
|
||||
HalHandle digitalSourceHandle,
|
||||
AnalogTriggerType analogTriggerType, int32_t* status);
|
||||
void setCounterUpSourceEdge(HalCounterHandle counter_handle, bool risingEdge,
|
||||
bool fallingEdge, int32_t* status);
|
||||
void clearCounterUpSource(HalCounterHandle counter_handle, int32_t* status);
|
||||
void setCounterDownSource(HalCounterHandle counter_handle, uint32_t pin,
|
||||
bool analogTrigger, int32_t* status);
|
||||
void setCounterDownSource(HalCounterHandle counter_handle,
|
||||
HalHandle digitalSourceHandle,
|
||||
AnalogTriggerType analogTriggerType, int32_t* status);
|
||||
void setCounterDownSourceEdge(HalCounterHandle counter_handle, bool risingEdge,
|
||||
bool fallingEdge, int32_t* status);
|
||||
void clearCounterDownSource(HalCounterHandle counter_handle, int32_t* status);
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "HAL/AnalogTrigger.h"
|
||||
#include "HAL/Handles.h"
|
||||
|
||||
extern "C" {
|
||||
@@ -21,8 +22,8 @@ enum EncoderIndexingType {
|
||||
enum EncoderEncodingType { HAL_Encoder_k1X, HAL_Encoder_k2X, HAL_Encoder_k4X };
|
||||
|
||||
HalEncoderHandle initializeEncoder(
|
||||
uint8_t port_a_module, uint32_t port_a_pin, bool port_a_analog_trigger,
|
||||
uint8_t port_b_module, uint32_t port_b_pin, bool port_b_analog_trigger,
|
||||
HalHandle digitalSourceHandleA, AnalogTriggerType analogTriggerTypeA,
|
||||
HalHandle digitalSourceHandleB, AnalogTriggerType analogTriggerTypeB,
|
||||
bool reverseDirection, EncoderEncodingType encodingType, int32_t* status);
|
||||
void freeEncoder(HalEncoderHandle encoder_handle, int32_t* status);
|
||||
int32_t getEncoder(HalEncoderHandle encoder_handle, int32_t* status);
|
||||
@@ -48,9 +49,10 @@ void setEncoderSamplesToAverage(HalEncoderHandle encoder_handle,
|
||||
int32_t getEncoderSamplesToAverage(HalEncoderHandle encoder_handle,
|
||||
int32_t* status);
|
||||
|
||||
void setEncoderIndexSource(HalEncoderHandle encoder_handle, uint32_t pin,
|
||||
uint8_t analogTrigger, EncoderIndexingType type,
|
||||
int32_t* status);
|
||||
void setEncoderIndexSource(HalEncoderHandle encoder_handle,
|
||||
HalHandle digitalSourceHandle,
|
||||
AnalogTriggerType analogTriggerType,
|
||||
EncoderIndexingType type, int32_t* status);
|
||||
|
||||
int32_t getEncoderFPGAIndex(HalEncoderHandle encoder_handle, int32_t* status);
|
||||
|
||||
|
||||
@@ -9,7 +9,8 @@
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "Handles.h"
|
||||
#include "HAL/AnalogTrigger.h"
|
||||
#include "HAL/Handles.h"
|
||||
|
||||
extern "C" {
|
||||
typedef void (*InterruptHandlerFunction)(uint32_t interruptAssertedMask,
|
||||
@@ -27,8 +28,8 @@ double readRisingTimestamp(HalInterruptHandle interrupt_handle,
|
||||
double readFallingTimestamp(HalInterruptHandle interrupt_handle,
|
||||
int32_t* status);
|
||||
void requestInterrupts(HalInterruptHandle interrupt_handle,
|
||||
uint8_t routing_module, uint32_t routing_pin,
|
||||
bool routing_analog_trigger, int32_t* status);
|
||||
HalHandle digitalSourceHandle,
|
||||
AnalogTriggerType analogTriggerType, int32_t* status);
|
||||
void attachInterruptHandler(HalInterruptHandle interrupt_handle,
|
||||
InterruptHandlerFunction handler, void* param,
|
||||
int32_t* status);
|
||||
|
||||
@@ -69,21 +69,30 @@ void setCounterAverageSize(HalCounterHandle counter_handle, int32_t size,
|
||||
* Set the source object that causes the counter to count up.
|
||||
* Set the up counting DigitalSource.
|
||||
*/
|
||||
void setCounterUpSource(HalCounterHandle counter_handle, uint32_t pin,
|
||||
bool analogTrigger, int32_t* status) {
|
||||
void setCounterUpSource(HalCounterHandle counter_handle,
|
||||
HalHandle digitalSourceHandle,
|
||||
AnalogTriggerType analogTriggerType, int32_t* status) {
|
||||
auto counter = counterHandles.Get(counter_handle);
|
||||
if (counter == nullptr) {
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return;
|
||||
}
|
||||
|
||||
uint8_t module;
|
||||
bool routingAnalogTrigger = false;
|
||||
uint32_t routingPin = 0;
|
||||
uint8_t routingModule = 0;
|
||||
bool success =
|
||||
remapDigitalSource(digitalSourceHandle, analogTriggerType, routingPin,
|
||||
routingModule, routingAnalogTrigger);
|
||||
if (!success) {
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return;
|
||||
}
|
||||
|
||||
remapDigitalSource(analogTrigger, pin, module);
|
||||
|
||||
counter->counter->writeConfig_UpSource_Module(module, status);
|
||||
counter->counter->writeConfig_UpSource_Channel(pin, status);
|
||||
counter->counter->writeConfig_UpSource_AnalogTrigger(analogTrigger, status);
|
||||
counter->counter->writeConfig_UpSource_Module(routingModule, status);
|
||||
counter->counter->writeConfig_UpSource_Channel(routingPin, status);
|
||||
counter->counter->writeConfig_UpSource_AnalogTrigger(routingAnalogTrigger,
|
||||
status);
|
||||
|
||||
if (counter->counter->readConfig_Mode(status) == kTwoPulse ||
|
||||
counter->counter->readConfig_Mode(status) == kExternalDirection) {
|
||||
@@ -127,8 +136,10 @@ void clearCounterUpSource(HalCounterHandle counter_handle, int32_t* status) {
|
||||
* Set the source object that causes the counter to count down.
|
||||
* Set the down counting DigitalSource.
|
||||
*/
|
||||
void setCounterDownSource(HalCounterHandle counter_handle, uint32_t pin,
|
||||
bool analogTrigger, int32_t* status) {
|
||||
void setCounterDownSource(HalCounterHandle counter_handle,
|
||||
HalHandle digitalSourceHandle,
|
||||
AnalogTriggerType analogTriggerType,
|
||||
int32_t* status) {
|
||||
auto counter = counterHandles.Get(counter_handle);
|
||||
if (counter == nullptr) {
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
@@ -142,13 +153,21 @@ void setCounterDownSource(HalCounterHandle counter_handle, uint32_t pin,
|
||||
return;
|
||||
}
|
||||
|
||||
uint8_t module;
|
||||
bool routingAnalogTrigger = false;
|
||||
uint32_t routingPin = 0;
|
||||
uint8_t routingModule = 0;
|
||||
bool success =
|
||||
remapDigitalSource(digitalSourceHandle, analogTriggerType, routingPin,
|
||||
routingModule, routingAnalogTrigger);
|
||||
if (!success) {
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return;
|
||||
}
|
||||
|
||||
remapDigitalSource(analogTrigger, pin, module);
|
||||
|
||||
counter->counter->writeConfig_DownSource_Module(module, status);
|
||||
counter->counter->writeConfig_DownSource_Channel(pin, status);
|
||||
counter->counter->writeConfig_DownSource_AnalogTrigger(analogTrigger, status);
|
||||
counter->counter->writeConfig_DownSource_Module(routingModule, status);
|
||||
counter->counter->writeConfig_DownSource_Channel(routingPin, status);
|
||||
counter->counter->writeConfig_DownSource_AnalogTrigger(routingAnalogTrigger,
|
||||
status);
|
||||
|
||||
setCounterDownSourceEdge(counter_handle, true, false, status);
|
||||
counter->counter->strobeReset(status);
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
|
||||
#include "ChipObject.h"
|
||||
#include "FRC_NetworkCommunication/LoadOut.h"
|
||||
#include "HAL/AnalogTrigger.h"
|
||||
#include "HAL/HAL.h"
|
||||
#include "HAL/Ports.h"
|
||||
#include "HAL/cpp/priority_mutex.h"
|
||||
@@ -107,17 +108,30 @@ uint32_t remapMXPPWMChannel(uint32_t pin) {
|
||||
* If it's an analog trigger, determine the module from the high order routing
|
||||
* channel else do normal digital input remapping based on pin number (MXP)
|
||||
*/
|
||||
extern "C++" void remapDigitalSource(bool analogTrigger, uint32_t& pin,
|
||||
uint8_t& module) {
|
||||
if (analogTrigger) {
|
||||
extern "C++" bool remapDigitalSource(HalHandle digitalSourceHandle,
|
||||
AnalogTriggerType analogTriggerType,
|
||||
uint32_t& pin, uint8_t& module,
|
||||
bool& analogTrigger) {
|
||||
if (isHandleType(digitalSourceHandle, HalHandleEnum::AnalogTrigger)) {
|
||||
// If handle passed, index is not negative
|
||||
uint32_t index = getHandleIndex(digitalSourceHandle);
|
||||
pin = (index << 2) + analogTriggerType;
|
||||
module = pin >> 4;
|
||||
} else {
|
||||
if (pin >= kNumDigitalHeaders) {
|
||||
pin = remapMXPChannel(pin);
|
||||
analogTrigger = true;
|
||||
return true;
|
||||
} else if (isHandleType(digitalSourceHandle, HalHandleEnum::DIO)) {
|
||||
uint32_t index = getHandleIndex(digitalSourceHandle);
|
||||
if (index >= kNumDigitalHeaders) {
|
||||
pin = remapMXPChannel(index);
|
||||
module = 1;
|
||||
} else {
|
||||
pin = index;
|
||||
module = 0;
|
||||
}
|
||||
analogTrigger = false;
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#include <stdint.h>
|
||||
|
||||
#include "ChipObject.h"
|
||||
#include "HAL/AnalogTrigger.h"
|
||||
#include "HAL/Handles.h"
|
||||
#include "HAL/Ports.h"
|
||||
#include "PortsInternal.h"
|
||||
@@ -69,7 +70,9 @@ extern DigitalHandleResource<HalDigitalHandle, DigitalPort,
|
||||
digitalPinHandles;
|
||||
|
||||
void initializeDigital(int32_t* status);
|
||||
void remapDigitalSource(bool analogTrigger, uint32_t& pin, uint8_t& module);
|
||||
bool remapDigitalSource(HalHandle digitalSourceHandle,
|
||||
AnalogTriggerType analogTriggerType, uint32_t& pin,
|
||||
uint8_t& module, bool& analogTrigger);
|
||||
uint32_t remapMXPPWMChannel(uint32_t pin);
|
||||
uint32_t remapMXPChannel(uint32_t pin);
|
||||
}
|
||||
|
||||
@@ -17,19 +17,18 @@
|
||||
|
||||
using namespace hal;
|
||||
|
||||
Encoder::Encoder(uint8_t port_a_module, uint32_t port_a_pin,
|
||||
bool port_a_analog_trigger, uint8_t port_b_module,
|
||||
uint32_t port_b_pin, bool port_b_analog_trigger,
|
||||
bool reverseDirection, EncoderEncodingType encodingType,
|
||||
int32_t* status) {
|
||||
Encoder::Encoder(HalHandle digitalSourceHandleA,
|
||||
AnalogTriggerType analogTriggerTypeA,
|
||||
HalHandle digitalSourceHandleB,
|
||||
AnalogTriggerType analogTriggerTypeB, bool reverseDirection,
|
||||
EncoderEncodingType encodingType, int32_t* status) {
|
||||
m_encodingType = encodingType;
|
||||
switch (encodingType) {
|
||||
case HAL_Encoder_k4X: {
|
||||
m_encodingScale = 4;
|
||||
m_encoder = initializeFPGAEncoder(port_a_module, port_a_pin,
|
||||
port_a_analog_trigger, port_b_module,
|
||||
port_b_pin, port_b_analog_trigger,
|
||||
reverseDirection, &m_index, status);
|
||||
m_encoder = initializeFPGAEncoder(
|
||||
digitalSourceHandleA, analogTriggerTypeA, digitalSourceHandleB,
|
||||
analogTriggerTypeB, reverseDirection, &m_index, status);
|
||||
if (*status != 0) {
|
||||
return;
|
||||
}
|
||||
@@ -39,9 +38,9 @@ Encoder::Encoder(uint8_t port_a_module, uint32_t port_a_pin,
|
||||
}
|
||||
case HAL_Encoder_k1X:
|
||||
case HAL_Encoder_k2X: {
|
||||
SetupCounter(port_a_module, port_a_pin, port_a_analog_trigger,
|
||||
port_b_module, port_b_pin, port_b_analog_trigger,
|
||||
reverseDirection, encodingType, status);
|
||||
SetupCounter(digitalSourceHandleA, analogTriggerTypeA,
|
||||
digitalSourceHandleB, analogTriggerTypeB, reverseDirection,
|
||||
encodingType, status);
|
||||
|
||||
m_encodingScale = encodingType == HAL_Encoder_k1X ? 1 : 2;
|
||||
break;
|
||||
@@ -52,9 +51,10 @@ Encoder::Encoder(uint8_t port_a_module, uint32_t port_a_pin,
|
||||
}
|
||||
}
|
||||
|
||||
void Encoder::SetupCounter(uint8_t port_a_module, uint32_t port_a_pin,
|
||||
bool port_a_analog_trigger, uint8_t port_b_module,
|
||||
uint32_t port_b_pin, bool port_b_analog_trigger,
|
||||
void Encoder::SetupCounter(HalHandle digitalSourceHandleA,
|
||||
AnalogTriggerType analogTriggerTypeA,
|
||||
HalHandle digitalSourceHandleB,
|
||||
AnalogTriggerType analogTriggerTypeB,
|
||||
bool reverseDirection,
|
||||
EncoderEncodingType encodingType, int32_t* status) {
|
||||
m_encodingScale = encodingType == HAL_Encoder_k1X ? 1 : 2;
|
||||
@@ -62,9 +62,11 @@ void Encoder::SetupCounter(uint8_t port_a_module, uint32_t port_a_pin,
|
||||
if (*status != 0) return;
|
||||
setCounterMaxPeriod(m_counter, 0.5, status);
|
||||
if (*status != 0) return;
|
||||
setCounterUpSource(m_counter, port_a_pin, port_a_analog_trigger, status);
|
||||
setCounterUpSource(m_counter, digitalSourceHandleA, analogTriggerTypeA,
|
||||
status);
|
||||
if (*status != 0) return;
|
||||
setCounterDownSource(m_counter, port_b_pin, port_b_analog_trigger, status);
|
||||
setCounterDownSource(m_counter, digitalSourceHandleB, analogTriggerTypeB,
|
||||
status);
|
||||
if (*status != 0) return;
|
||||
if (encodingType == HAL_Encoder_k1X) {
|
||||
setCounterUpSourceEdge(m_counter, true, false, status);
|
||||
@@ -187,7 +189,8 @@ int32_t Encoder::GetSamplesToAverage(int32_t* status) const {
|
||||
}
|
||||
}
|
||||
|
||||
void Encoder::SetIndexSource(uint32_t pin, bool analogTrigger,
|
||||
void Encoder::SetIndexSource(HalHandle digitalSourceHandle,
|
||||
AnalogTriggerType analogTriggerType,
|
||||
EncoderIndexingType type, int32_t* status) {
|
||||
if (m_counter) {
|
||||
*status = HAL_COUNTER_NOT_SUPPORTED;
|
||||
@@ -197,8 +200,8 @@ void Encoder::SetIndexSource(uint32_t pin, bool analogTrigger,
|
||||
(type == HAL_kResetWhileHigh) || (type == HAL_kResetOnRisingEdge);
|
||||
bool edgeSensitive =
|
||||
(type == HAL_kResetOnFallingEdge) || (type == HAL_kResetOnRisingEdge);
|
||||
setFPGAEncoderIndexSource(m_encoder, pin, analogTrigger, activeHigh,
|
||||
edgeSensitive, status);
|
||||
setFPGAEncoderIndexSource(m_encoder, digitalSourceHandle, analogTriggerType,
|
||||
activeHigh, edgeSensitive, status);
|
||||
}
|
||||
|
||||
double Encoder::DecodingScaleFactor() const {
|
||||
@@ -221,13 +224,12 @@ static LimitedClassedHandleResource<HalEncoderHandle, Encoder,
|
||||
|
||||
extern "C" {
|
||||
HalEncoderHandle initializeEncoder(
|
||||
uint8_t port_a_module, uint32_t port_a_pin, bool port_a_analog_trigger,
|
||||
uint8_t port_b_module, uint32_t port_b_pin, bool port_b_analog_trigger,
|
||||
HalHandle digitalSourceHandleA, AnalogTriggerType analogTriggerTypeA,
|
||||
HalHandle digitalSourceHandleB, AnalogTriggerType analogTriggerTypeB,
|
||||
bool reverseDirection, EncoderEncodingType encodingType, int32_t* status) {
|
||||
auto encoder = std::make_shared<Encoder>(
|
||||
port_a_module, port_a_pin, port_a_analog_trigger, port_b_module,
|
||||
port_b_pin, port_b_analog_trigger, reverseDirection, encodingType,
|
||||
status);
|
||||
digitalSourceHandleA, analogTriggerTypeA, digitalSourceHandleB,
|
||||
analogTriggerTypeB, reverseDirection, encodingType, status);
|
||||
if (*status != 0) return HAL_INVALID_HANDLE; // return in creation error
|
||||
auto handle = encoderHandles.Allocate(encoder);
|
||||
if (handle == HAL_INVALID_HANDLE) {
|
||||
@@ -413,15 +415,16 @@ EncoderEncodingType getEncoderEncodingType(HalEncoderHandle encoder_handle,
|
||||
return encoder->GetEncodingType();
|
||||
}
|
||||
|
||||
void setEncoderIndexSource(HalEncoderHandle encoder_handle, uint32_t pin,
|
||||
uint8_t analogTrigger, EncoderIndexingType type,
|
||||
int32_t* status) {
|
||||
void setEncoderIndexSource(HalEncoderHandle encoder_handle,
|
||||
HalHandle digitalSourceHandle,
|
||||
AnalogTriggerType analogTriggerType,
|
||||
EncoderIndexingType type, int32_t* status) {
|
||||
auto encoder = encoderHandles.Get(encoder_handle);
|
||||
if (encoder == nullptr) {
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return;
|
||||
}
|
||||
encoder->SetIndexSource(pin, analogTrigger, type, status);
|
||||
encoder->SetIndexSource(digitalSourceHandle, analogTriggerType, type, status);
|
||||
}
|
||||
|
||||
int32_t getEncoderFPGAIndex(HalEncoderHandle encoder_handle, int32_t* status) {
|
||||
|
||||
@@ -14,9 +14,8 @@
|
||||
namespace hal {
|
||||
class Encoder {
|
||||
public:
|
||||
Encoder(uint8_t port_a_module, uint32_t port_a_pin,
|
||||
bool port_a_analog_trigger, uint8_t port_b_module,
|
||||
uint32_t port_b_pin, bool port_b_analog_trigger,
|
||||
Encoder(HalHandle digitalSourceHandleA, AnalogTriggerType analogTriggerTypeA,
|
||||
HalHandle digitalSourceHandleB, AnalogTriggerType analogTriggerTypeB,
|
||||
bool reverseDirection, EncoderEncodingType encodingType,
|
||||
int32_t* status);
|
||||
~Encoder();
|
||||
@@ -39,7 +38,8 @@ class Encoder {
|
||||
void SetSamplesToAverage(int samplesToAverage, int32_t* status);
|
||||
int32_t GetSamplesToAverage(int32_t* status) const;
|
||||
|
||||
void SetIndexSource(uint32_t pin, bool analogTrigger,
|
||||
void SetIndexSource(HalHandle digitalSourceHandle,
|
||||
AnalogTriggerType analogTriggerType,
|
||||
EncoderIndexingType type, int32_t* status);
|
||||
|
||||
int32_t GetFPGAIndex() const { return m_index; }
|
||||
@@ -53,11 +53,11 @@ class Encoder {
|
||||
EncoderEncodingType GetEncodingType() const { return m_encodingType; }
|
||||
|
||||
private:
|
||||
void SetupCounter(uint8_t port_a_module, uint32_t port_a_pin,
|
||||
bool port_a_analog_trigger, uint8_t port_b_module,
|
||||
uint32_t port_b_pin, bool port_b_analog_trigger,
|
||||
bool reverseDirection, EncoderEncodingType encodingType,
|
||||
int32_t* status);
|
||||
void SetupCounter(HalHandle digitalSourceHandleA,
|
||||
AnalogTriggerType analogTriggerTypeA,
|
||||
HalHandle digitalSourceHandleB,
|
||||
AnalogTriggerType analogTriggerTypeB, bool reverseDirection,
|
||||
EncoderEncodingType encodingType, int32_t* status);
|
||||
|
||||
HalFPGAEncoderHandle m_encoder = HAL_INVALID_HANDLE;
|
||||
|
||||
|
||||
@@ -27,12 +27,29 @@ static LimitedHandleResource<HalFPGAEncoderHandle, Encoder, kNumEncoders,
|
||||
fpgaEncoderHandles;
|
||||
|
||||
extern "C" {
|
||||
HalFPGAEncoderHandle initializeFPGAEncoder(
|
||||
uint8_t port_a_module, uint32_t port_a_pin, bool port_a_analog_trigger,
|
||||
uint8_t port_b_module, uint32_t port_b_pin, bool port_b_analog_trigger,
|
||||
bool reverseDirection, int32_t* index, int32_t* status) {
|
||||
remapDigitalSource(port_a_analog_trigger, port_a_pin, port_a_module);
|
||||
remapDigitalSource(port_b_analog_trigger, port_b_pin, port_b_module);
|
||||
HalFPGAEncoderHandle initializeFPGAEncoder(HalHandle digitalSourceHandleA,
|
||||
AnalogTriggerType analogTriggerTypeA,
|
||||
HalHandle digitalSourceHandleB,
|
||||
AnalogTriggerType analogTriggerTypeB,
|
||||
bool reverseDirection,
|
||||
int32_t* index, int32_t* status) {
|
||||
bool routingAnalogTriggerA = false;
|
||||
uint32_t routingPinA = 0;
|
||||
uint8_t routingModuleA = 0;
|
||||
bool successA =
|
||||
remapDigitalSource(digitalSourceHandleA, analogTriggerTypeA, routingPinA,
|
||||
routingModuleA, routingAnalogTriggerA);
|
||||
bool routingAnalogTriggerB = false;
|
||||
uint32_t routingPinB = 0;
|
||||
uint8_t routingModuleB = 0;
|
||||
bool successB =
|
||||
remapDigitalSource(digitalSourceHandleB, analogTriggerTypeB, routingPinB,
|
||||
routingModuleB, routingAnalogTriggerB);
|
||||
|
||||
if (!successA || !successB) {
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return HAL_INVALID_HANDLE;
|
||||
}
|
||||
|
||||
auto handle = fpgaEncoderHandles.Allocate();
|
||||
if (handle == HAL_INVALID_HANDLE) { // out of resources
|
||||
@@ -42,7 +59,7 @@ HalFPGAEncoderHandle initializeFPGAEncoder(
|
||||
|
||||
auto encoder = fpgaEncoderHandles.Get(handle);
|
||||
if (encoder == nullptr) { // will only error on thread issue
|
||||
*status = PARAMETER_OUT_OF_RANGE;
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return HAL_INVALID_HANDLE;
|
||||
}
|
||||
|
||||
@@ -51,13 +68,13 @@ HalFPGAEncoderHandle initializeFPGAEncoder(
|
||||
*index = encoder->index;
|
||||
// TODO: if (index == ~0ul) { CloneError(quadEncoders); return; }
|
||||
encoder->encoder = tEncoder::create(encoder->index, status);
|
||||
encoder->encoder->writeConfig_ASource_Module(port_a_module, status);
|
||||
encoder->encoder->writeConfig_ASource_Channel(port_a_pin, status);
|
||||
encoder->encoder->writeConfig_ASource_AnalogTrigger(port_a_analog_trigger,
|
||||
encoder->encoder->writeConfig_ASource_Module(routingModuleA, status);
|
||||
encoder->encoder->writeConfig_ASource_Channel(routingPinA, status);
|
||||
encoder->encoder->writeConfig_ASource_AnalogTrigger(routingAnalogTriggerA,
|
||||
status);
|
||||
encoder->encoder->writeConfig_BSource_Module(port_b_module, status);
|
||||
encoder->encoder->writeConfig_BSource_Channel(port_b_pin, status);
|
||||
encoder->encoder->writeConfig_BSource_AnalogTrigger(port_b_analog_trigger,
|
||||
encoder->encoder->writeConfig_BSource_Module(routingModuleB, status);
|
||||
encoder->encoder->writeConfig_BSource_Channel(routingPinB, status);
|
||||
encoder->encoder->writeConfig_BSource_AnalogTrigger(routingAnalogTriggerB,
|
||||
status);
|
||||
encoder->encoder->strobeReset(status);
|
||||
encoder->encoder->writeConfig_Reverse(reverseDirection, status);
|
||||
@@ -71,7 +88,7 @@ void freeFPGAEncoder(HalFPGAEncoderHandle fpga_encoder_handle,
|
||||
auto encoder = fpgaEncoderHandles.Get(fpga_encoder_handle);
|
||||
fpgaEncoderHandles.Free(fpga_encoder_handle);
|
||||
if (encoder == nullptr) {
|
||||
*status = PARAMETER_OUT_OF_RANGE;
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return;
|
||||
}
|
||||
delete encoder->encoder;
|
||||
@@ -85,7 +102,7 @@ void resetFPGAEncoder(HalFPGAEncoderHandle fpga_encoder_handle,
|
||||
int32_t* status) {
|
||||
auto encoder = fpgaEncoderHandles.Get(fpga_encoder_handle);
|
||||
if (encoder == nullptr) {
|
||||
*status = PARAMETER_OUT_OF_RANGE;
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return;
|
||||
}
|
||||
encoder->encoder->strobeReset(status);
|
||||
@@ -101,7 +118,7 @@ int32_t getFPGAEncoder(HalFPGAEncoderHandle fpga_encoder_handle,
|
||||
int32_t* status) {
|
||||
auto encoder = fpgaEncoderHandles.Get(fpga_encoder_handle);
|
||||
if (encoder == nullptr) {
|
||||
*status = PARAMETER_OUT_OF_RANGE;
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return 0;
|
||||
}
|
||||
return encoder->encoder->readOutput_Value(status);
|
||||
@@ -121,7 +138,7 @@ double getFPGAEncoderPeriod(HalFPGAEncoderHandle fpga_encoder_handle,
|
||||
int32_t* status) {
|
||||
auto encoder = fpgaEncoderHandles.Get(fpga_encoder_handle);
|
||||
if (encoder == nullptr) {
|
||||
*status = PARAMETER_OUT_OF_RANGE;
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return 0.0;
|
||||
}
|
||||
tEncoder::tTimerOutput output = encoder->encoder->readTimerOutput(status);
|
||||
@@ -157,7 +174,7 @@ void setFPGAEncoderMaxPeriod(HalFPGAEncoderHandle fpga_encoder_handle,
|
||||
double maxPeriod, int32_t* status) {
|
||||
auto encoder = fpgaEncoderHandles.Get(fpga_encoder_handle);
|
||||
if (encoder == nullptr) {
|
||||
*status = PARAMETER_OUT_OF_RANGE;
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return;
|
||||
}
|
||||
encoder->encoder->writeTimerConfig_StallPeriod(
|
||||
@@ -175,7 +192,7 @@ bool getFPGAEncoderStopped(HalFPGAEncoderHandle fpga_encoder_handle,
|
||||
int32_t* status) {
|
||||
auto encoder = fpgaEncoderHandles.Get(fpga_encoder_handle);
|
||||
if (encoder == nullptr) {
|
||||
*status = PARAMETER_OUT_OF_RANGE;
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return false;
|
||||
}
|
||||
return encoder->encoder->readTimerOutput_Stalled(status) != 0;
|
||||
@@ -189,7 +206,7 @@ bool getFPGAEncoderDirection(HalFPGAEncoderHandle fpga_encoder_handle,
|
||||
int32_t* status) {
|
||||
auto encoder = fpgaEncoderHandles.Get(fpga_encoder_handle);
|
||||
if (encoder == nullptr) {
|
||||
*status = PARAMETER_OUT_OF_RANGE;
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return false;
|
||||
}
|
||||
return encoder->encoder->readOutput_Direction(status);
|
||||
@@ -205,7 +222,7 @@ void setFPGAEncoderReverseDirection(HalFPGAEncoderHandle fpga_encoder_handle,
|
||||
bool reverseDirection, int32_t* status) {
|
||||
auto encoder = fpgaEncoderHandles.Get(fpga_encoder_handle);
|
||||
if (encoder == nullptr) {
|
||||
*status = PARAMETER_OUT_OF_RANGE;
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return;
|
||||
}
|
||||
encoder->encoder->writeConfig_Reverse(reverseDirection, status);
|
||||
@@ -222,7 +239,7 @@ void setFPGAEncoderSamplesToAverage(HalFPGAEncoderHandle fpga_encoder_handle,
|
||||
int32_t* status) {
|
||||
auto encoder = fpgaEncoderHandles.Get(fpga_encoder_handle);
|
||||
if (encoder == nullptr) {
|
||||
*status = PARAMETER_OUT_OF_RANGE;
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return;
|
||||
}
|
||||
if (samplesToAverage < 1 || samplesToAverage > 127) {
|
||||
@@ -241,7 +258,7 @@ uint32_t getFPGAEncoderSamplesToAverage(
|
||||
HalFPGAEncoderHandle fpga_encoder_handle, int32_t* status) {
|
||||
auto encoder = fpgaEncoderHandles.Get(fpga_encoder_handle);
|
||||
if (encoder == nullptr) {
|
||||
*status = PARAMETER_OUT_OF_RANGE;
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return 0;
|
||||
}
|
||||
return encoder->encoder->readTimerConfig_AverageSize(status);
|
||||
@@ -252,17 +269,30 @@ uint32_t getFPGAEncoderSamplesToAverage(
|
||||
* encoder's count.
|
||||
*/
|
||||
void setFPGAEncoderIndexSource(HalFPGAEncoderHandle fpga_encoder_handle,
|
||||
uint32_t pin, bool analogTrigger,
|
||||
HalHandle digitalSourceHandle,
|
||||
AnalogTriggerType analogTriggerType,
|
||||
bool activeHigh, bool edgeSensitive,
|
||||
int32_t* status) {
|
||||
auto encoder = fpgaEncoderHandles.Get(fpga_encoder_handle);
|
||||
if (encoder == nullptr) {
|
||||
*status = PARAMETER_OUT_OF_RANGE;
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return;
|
||||
}
|
||||
encoder->encoder->writeConfig_IndexSource_Channel((unsigned char)pin, status);
|
||||
encoder->encoder->writeConfig_IndexSource_Module((unsigned char)0, status);
|
||||
encoder->encoder->writeConfig_IndexSource_AnalogTrigger(analogTrigger,
|
||||
|
||||
bool routingAnalogTrigger = false;
|
||||
uint32_t routingPin = 0;
|
||||
uint8_t routingModule = 0;
|
||||
bool success =
|
||||
remapDigitalSource(digitalSourceHandle, analogTriggerType, routingPin,
|
||||
routingModule, routingAnalogTrigger);
|
||||
if (!success) {
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return;
|
||||
}
|
||||
|
||||
encoder->encoder->writeConfig_IndexSource_Channel(routingPin, status);
|
||||
encoder->encoder->writeConfig_IndexSource_Module(routingModule, status);
|
||||
encoder->encoder->writeConfig_IndexSource_AnalogTrigger(routingAnalogTrigger,
|
||||
status);
|
||||
encoder->encoder->writeConfig_IndexActiveHigh(activeHigh, status);
|
||||
encoder->encoder->writeConfig_IndexEdgeSensitive(edgeSensitive, status);
|
||||
|
||||
@@ -9,14 +9,16 @@
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "HAL/AnalogTrigger.h"
|
||||
#include "HAL/Handles.h"
|
||||
|
||||
extern "C" {
|
||||
HalFPGAEncoderHandle initializeFPGAEncoder(
|
||||
uint8_t port_a_module, uint32_t port_a_pin, bool port_a_analog_trigger,
|
||||
uint8_t port_b_module, uint32_t port_b_pin, bool port_b_analog_trigger,
|
||||
bool reverseDirection, int32_t* index,
|
||||
int32_t* status); // TODO: fix routing
|
||||
HalFPGAEncoderHandle initializeFPGAEncoder(HalHandle digitalSourceHandleA,
|
||||
AnalogTriggerType analogTriggerTypeA,
|
||||
HalHandle digitalSourceHandleB,
|
||||
AnalogTriggerType analogTriggerTypeB,
|
||||
bool reverseDirection,
|
||||
int32_t* index, int32_t* status);
|
||||
void freeFPGAEncoder(HalFPGAEncoderHandle fpga_encoder_handle, int32_t* status);
|
||||
void resetFPGAEncoder(HalFPGAEncoderHandle fpga_encoder_handle,
|
||||
int32_t* status);
|
||||
@@ -37,7 +39,8 @@ void setFPGAEncoderSamplesToAverage(HalFPGAEncoderHandle fpga_encoder_handle,
|
||||
uint32_t getFPGAEncoderSamplesToAverage(
|
||||
HalFPGAEncoderHandle fpga_encoder_handle, int32_t* status);
|
||||
void setFPGAEncoderIndexSource(HalFPGAEncoderHandle fpga_encoder_handle,
|
||||
uint32_t pin, bool analogTrigger,
|
||||
HalHandle digitalSourceHandle,
|
||||
AnalogTriggerType analogTriggerType,
|
||||
bool activeHigh, bool edgeSensitive,
|
||||
int32_t* status);
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
#include "DigitalInternal.h"
|
||||
#include "HAL/Errors.h"
|
||||
#include "PortsInternal.h"
|
||||
#include "handles/HandlesInternal.h"
|
||||
#include "handles/LimitedHandleResource.h"
|
||||
|
||||
using namespace hal;
|
||||
@@ -147,19 +148,28 @@ double readFallingTimestamp(HalInterruptHandle interrupt_handle,
|
||||
}
|
||||
|
||||
void requestInterrupts(HalInterruptHandle interrupt_handle,
|
||||
uint8_t routing_module, uint32_t routing_pin,
|
||||
bool routing_analog_trigger, int32_t* status) {
|
||||
HalHandle digitalSourceHandle,
|
||||
AnalogTriggerType analogTriggerType, int32_t* status) {
|
||||
auto anInterrupt = interruptHandles.Get(interrupt_handle);
|
||||
if (anInterrupt == nullptr) {
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return;
|
||||
}
|
||||
anInterrupt->anInterrupt->writeConfig_WaitForAck(false, status);
|
||||
remapDigitalSource(routing_analog_trigger, routing_pin, routing_module);
|
||||
bool routingAnalogTrigger = false;
|
||||
uint32_t routingPin = 0;
|
||||
uint8_t routingModule = 0;
|
||||
bool success =
|
||||
remapDigitalSource(digitalSourceHandle, analogTriggerType, routingPin,
|
||||
routingModule, routingAnalogTrigger);
|
||||
if (!success) {
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return;
|
||||
}
|
||||
anInterrupt->anInterrupt->writeConfig_Source_AnalogTrigger(
|
||||
routing_analog_trigger, status);
|
||||
anInterrupt->anInterrupt->writeConfig_Source_Channel(routing_pin, status);
|
||||
anInterrupt->anInterrupt->writeConfig_Source_Module(routing_module, status);
|
||||
routingAnalogTrigger, status);
|
||||
anInterrupt->anInterrupt->writeConfig_Source_Channel(routingPin, status);
|
||||
anInterrupt->anInterrupt->writeConfig_Source_Module(routingModule, status);
|
||||
}
|
||||
|
||||
void attachInterruptHandler(HalInterruptHandle interrupt_handle,
|
||||
|
||||
@@ -49,10 +49,10 @@ class AnalogTriggerOutput : public DigitalSource {
|
||||
bool Get() const;
|
||||
|
||||
// DigitalSource interface
|
||||
virtual uint32_t GetChannelForRouting() const override;
|
||||
virtual uint32_t GetModuleForRouting() const override;
|
||||
virtual bool GetAnalogTriggerForRouting() const override;
|
||||
virtual HalHandle GetPortHandle() const override;
|
||||
virtual HalHandle GetPortHandleForRouting() const override;
|
||||
virtual AnalogTriggerType GetAnalogTriggerTypeForRouting() const override;
|
||||
virtual bool IsAnalogTrigger() const override;
|
||||
virtual uint32_t GetChannel() const override;
|
||||
|
||||
protected:
|
||||
AnalogTriggerOutput(const AnalogTrigger& trigger,
|
||||
|
||||
@@ -29,13 +29,12 @@ class DigitalInput : public DigitalSource, public LiveWindowSendable {
|
||||
explicit DigitalInput(uint32_t channel);
|
||||
virtual ~DigitalInput();
|
||||
bool Get() const;
|
||||
uint32_t GetChannel() const;
|
||||
uint32_t GetChannel() const override;
|
||||
|
||||
// Digital Source Interface
|
||||
virtual uint32_t GetChannelForRouting() const;
|
||||
virtual uint32_t GetModuleForRouting() const;
|
||||
virtual bool GetAnalogTriggerForRouting() const;
|
||||
virtual HalHandle GetPortHandle() const;
|
||||
virtual HalHandle GetPortHandleForRouting() const override;
|
||||
virtual AnalogTriggerType GetAnalogTriggerTypeForRouting() const override;
|
||||
virtual bool IsAnalogTrigger() const override;
|
||||
|
||||
void UpdateTable();
|
||||
void StartLiveWindowMode();
|
||||
|
||||
@@ -27,7 +27,7 @@ class DigitalOutput : public DigitalSource,
|
||||
explicit DigitalOutput(uint32_t channel);
|
||||
virtual ~DigitalOutput();
|
||||
void Set(uint32_t value);
|
||||
uint32_t GetChannel() const;
|
||||
uint32_t GetChannel() const override;
|
||||
void Pulse(float length);
|
||||
bool IsPulsing() const;
|
||||
void SetPWMRate(float rate);
|
||||
@@ -36,10 +36,9 @@ class DigitalOutput : public DigitalSource,
|
||||
void UpdateDutyCycle(float dutyCycle);
|
||||
|
||||
// Digital Source Interface
|
||||
virtual uint32_t GetChannelForRouting() const;
|
||||
virtual uint32_t GetModuleForRouting() const;
|
||||
virtual bool GetAnalogTriggerForRouting() const;
|
||||
virtual HalHandle GetPortHandle() const;
|
||||
virtual HalHandle GetPortHandleForRouting() const override;
|
||||
virtual AnalogTriggerType GetAnalogTriggerTypeForRouting() const override;
|
||||
virtual bool IsAnalogTrigger() const override;
|
||||
|
||||
virtual void ValueChanged(ITable* source, llvm::StringRef key,
|
||||
std::shared_ptr<nt::Value> value, bool isNew);
|
||||
|
||||
@@ -23,8 +23,8 @@
|
||||
class DigitalSource : public InterruptableSensorBase {
|
||||
public:
|
||||
virtual ~DigitalSource() = default;
|
||||
virtual uint32_t GetChannelForRouting() const = 0;
|
||||
virtual uint32_t GetModuleForRouting() const = 0;
|
||||
virtual bool GetAnalogTriggerForRouting() const = 0;
|
||||
virtual HalHandle GetPortHandle() const = 0;
|
||||
virtual HalHandle GetPortHandleForRouting() const = 0;
|
||||
virtual AnalogTriggerType GetAnalogTriggerTypeForRouting() const = 0;
|
||||
virtual bool IsAnalogTrigger() const = 0;
|
||||
virtual uint32_t GetChannel() const = 0;
|
||||
};
|
||||
|
||||
@@ -98,6 +98,7 @@ class Encoder : public SensorBase,
|
||||
|
||||
std::shared_ptr<DigitalSource> m_aSource; // the A phase of the quad encoder
|
||||
std::shared_ptr<DigitalSource> m_bSource; // the B phase of the quad encoder
|
||||
std::unique_ptr<DigitalSource> m_indexSource = nullptr;
|
||||
HalEncoderHandle m_encoder = HAL_INVALID_HANDLE;
|
||||
|
||||
std::shared_ptr<ITable> m_table;
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "HAL/AnalogTrigger.h"
|
||||
#include "HAL/Interrupts.h"
|
||||
#include "SensorBase.h"
|
||||
|
||||
@@ -23,9 +24,8 @@ class InterruptableSensorBase : public SensorBase {
|
||||
|
||||
InterruptableSensorBase();
|
||||
virtual ~InterruptableSensorBase() = default;
|
||||
virtual uint32_t GetChannelForRouting() const = 0;
|
||||
virtual uint32_t GetModuleForRouting() const = 0;
|
||||
virtual bool GetAnalogTriggerForRouting() const = 0;
|
||||
virtual HalHandle GetPortHandleForRouting() const = 0;
|
||||
virtual AnalogTriggerType GetAnalogTriggerTypeForRouting() const = 0;
|
||||
virtual void RequestInterrupts(
|
||||
InterruptHandlerFunction handler,
|
||||
void* param); ///< Asynchronus handler version.
|
||||
|
||||
@@ -50,26 +50,26 @@ bool AnalogTriggerOutput::Get() const {
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The value to be written to the channel field of a routing mux.
|
||||
*/
|
||||
uint32_t AnalogTriggerOutput::GetChannelForRouting() const {
|
||||
return (m_trigger.m_index << 2) + m_outputType;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The value to be written to the module field of a routing mux.
|
||||
*/
|
||||
uint32_t AnalogTriggerOutput::GetModuleForRouting() const { return 0; }
|
||||
|
||||
/**
|
||||
* @return The value to be written to the module field of a routing mux.
|
||||
*/
|
||||
bool AnalogTriggerOutput::GetAnalogTriggerForRouting() const { return true; }
|
||||
|
||||
/**
|
||||
* @return The HAL Handle to the specified source.
|
||||
*/
|
||||
HalHandle AnalogTriggerOutput::GetPortHandle() const {
|
||||
HalHandle AnalogTriggerOutput::GetPortHandleForRouting() const {
|
||||
return m_trigger.m_trigger;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is source an AnalogTrigger
|
||||
*/
|
||||
bool AnalogTriggerOutput::IsAnalogTrigger() const { return true; }
|
||||
|
||||
/**
|
||||
* @return The type of analog trigger output to be used.
|
||||
*/
|
||||
AnalogTriggerType AnalogTriggerOutput::GetAnalogTriggerTypeForRouting() const {
|
||||
return m_outputType;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The channel of the source.
|
||||
*/
|
||||
uint32_t AnalogTriggerOutput::GetChannel() const { return m_trigger.m_index; }
|
||||
|
||||
@@ -234,8 +234,8 @@ void Counter::SetUpSource(std::shared_ptr<DigitalSource> source) {
|
||||
CloneError(*m_upSource);
|
||||
} else {
|
||||
int32_t status = 0;
|
||||
setCounterUpSource(m_counter, source->GetChannelForRouting(),
|
||||
source->GetAnalogTriggerForRouting(), &status);
|
||||
setCounterUpSource(m_counter, source->GetPortHandleForRouting(),
|
||||
source->GetAnalogTriggerTypeForRouting(), &status);
|
||||
wpi_setErrorWithContext(status, getHALErrorMessage(status));
|
||||
}
|
||||
}
|
||||
@@ -340,8 +340,8 @@ void Counter::SetDownSource(std::shared_ptr<DigitalSource> source) {
|
||||
CloneError(*m_downSource);
|
||||
} else {
|
||||
int32_t status = 0;
|
||||
setCounterDownSource(m_counter, source->GetChannelForRouting(),
|
||||
source->GetAnalogTriggerForRouting(), &status);
|
||||
setCounterDownSource(m_counter, source->GetPortHandleForRouting(),
|
||||
source->GetAnalogTriggerTypeForRouting(), &status);
|
||||
wpi_setErrorWithContext(status, getHALErrorMessage(status));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,21 +53,22 @@ void DigitalGlitchFilter::DoAdd(DigitalSource* input, int requested_index) {
|
||||
// here, we catch the issue more generally.
|
||||
if (input) {
|
||||
// we don't support GlitchFilters on AnalogTriggers.
|
||||
if (input->GetAnalogTriggerForRouting()) {
|
||||
if (input->IsAnalogTrigger()) {
|
||||
wpi_setErrorWithContext(
|
||||
-1, "Analog Triggers not supported for DigitalGlitchFilters");
|
||||
return;
|
||||
}
|
||||
int32_t status = 0;
|
||||
setFilterSelect(input->GetPortHandle(), requested_index, &status);
|
||||
setFilterSelect(input->GetPortHandleForRouting(), requested_index, &status);
|
||||
wpi_setErrorWithContext(status, getHALErrorMessage(status));
|
||||
|
||||
// Validate that we set it correctly.
|
||||
int actual_index = getFilterSelect(input->GetPortHandle(), &status);
|
||||
int actual_index =
|
||||
getFilterSelect(input->GetPortHandleForRouting(), &status);
|
||||
wpi_assertEqual(actual_index, requested_index);
|
||||
|
||||
HALReport(HALUsageReporting::kResourceType_DigitalInput,
|
||||
input->GetChannelForRouting());
|
||||
input->GetChannel());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -78,25 +78,22 @@ bool DigitalInput::Get() const {
|
||||
*/
|
||||
uint32_t DigitalInput::GetChannel() const { return m_channel; }
|
||||
|
||||
/**
|
||||
* @return The value to be written to the channel field of a routing mux.
|
||||
*/
|
||||
uint32_t DigitalInput::GetChannelForRouting() const { return GetChannel(); }
|
||||
|
||||
/**
|
||||
* @return The value to be written to the module field of a routing mux.
|
||||
*/
|
||||
uint32_t DigitalInput::GetModuleForRouting() const { return 0; }
|
||||
|
||||
/**
|
||||
* @return The value to be written to the analog trigger field of a routing mux.
|
||||
*/
|
||||
bool DigitalInput::GetAnalogTriggerForRouting() const { return false; }
|
||||
|
||||
/**
|
||||
* @return The HAL Handle to the specified source.
|
||||
*/
|
||||
HalHandle DigitalInput::GetPortHandle() const { return m_handle; }
|
||||
HalHandle DigitalInput::GetPortHandleForRouting() const { return m_handle; }
|
||||
|
||||
/**
|
||||
* Is source an AnalogTrigger
|
||||
*/
|
||||
bool DigitalInput::IsAnalogTrigger() const { return false; }
|
||||
|
||||
/**
|
||||
* @return The type of analog trigger output to be used. 0 for Digitals
|
||||
*/
|
||||
AnalogTriggerType DigitalInput::GetAnalogTriggerTypeForRouting() const {
|
||||
return (AnalogTriggerType)0;
|
||||
}
|
||||
|
||||
void DigitalInput::UpdateTable() {
|
||||
if (m_table != nullptr) {
|
||||
|
||||
@@ -193,25 +193,22 @@ void DigitalOutput::UpdateDutyCycle(float dutyCycle) {
|
||||
wpi_setErrorWithContext(status, getHALErrorMessage(status));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The value to be written to the channel field of a routing mux.
|
||||
*/
|
||||
uint32_t DigitalOutput::GetChannelForRouting() const { return GetChannel(); }
|
||||
|
||||
/**
|
||||
* @return The value to be written to the module field of a routing mux.
|
||||
*/
|
||||
uint32_t DigitalOutput::GetModuleForRouting() const { return 0; }
|
||||
|
||||
/**
|
||||
* @return The value to be written to the analog trigger field of a routing mux.
|
||||
*/
|
||||
bool DigitalOutput::GetAnalogTriggerForRouting() const { return false; }
|
||||
|
||||
/**
|
||||
* @return The HAL Handle to the specified source.
|
||||
*/
|
||||
HalHandle DigitalOutput::GetPortHandle() const { return m_handle; }
|
||||
HalHandle DigitalOutput::GetPortHandleForRouting() const { return m_handle; }
|
||||
|
||||
/**
|
||||
* Is source an AnalogTrigger
|
||||
*/
|
||||
bool DigitalOutput::IsAnalogTrigger() const { return false; }
|
||||
|
||||
/**
|
||||
* @return The type of analog trigger output to be used. 0 for Digitals
|
||||
*/
|
||||
AnalogTriggerType DigitalOutput::GetAnalogTriggerTypeForRouting() const {
|
||||
return (AnalogTriggerType)0;
|
||||
}
|
||||
|
||||
void DigitalOutput::ValueChanged(ITable* source, llvm::StringRef key,
|
||||
std::shared_ptr<nt::Value> value, bool isNew) {
|
||||
|
||||
@@ -31,18 +31,18 @@
|
||||
*/
|
||||
void Encoder::InitEncoder(bool reverseDirection, EncodingType encodingType) {
|
||||
int32_t status = 0;
|
||||
m_encoder = initializeEncoder(
|
||||
m_aSource->GetModuleForRouting(), m_aSource->GetChannelForRouting(),
|
||||
m_aSource->GetAnalogTriggerForRouting(), m_bSource->GetModuleForRouting(),
|
||||
m_bSource->GetChannelForRouting(),
|
||||
m_bSource->GetAnalogTriggerForRouting(), reverseDirection,
|
||||
(EncoderEncodingType)encodingType, &status);
|
||||
m_encoder = initializeEncoder(m_aSource->GetPortHandleForRouting(),
|
||||
m_aSource->GetAnalogTriggerTypeForRouting(),
|
||||
m_bSource->GetPortHandleForRouting(),
|
||||
m_bSource->GetAnalogTriggerTypeForRouting(),
|
||||
reverseDirection,
|
||||
(EncoderEncodingType)encodingType, &status);
|
||||
wpi_setErrorWithContext(status, getHALErrorMessage(status));
|
||||
|
||||
HALReport(HALUsageReporting::kResourceType_Encoder, GetFPGAIndex(),
|
||||
encodingType);
|
||||
LiveWindow::GetInstance()->AddSensor("Encoder",
|
||||
m_aSource->GetChannelForRouting(), this);
|
||||
LiveWindow::GetInstance()->AddSensor("Encoder", m_aSource->GetChannel(),
|
||||
this);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -447,10 +447,9 @@ double Encoder::PIDGet() {
|
||||
* @param type The state that will cause the encoder to reset
|
||||
*/
|
||||
void Encoder::SetIndexSource(uint32_t channel, Encoder::IndexingType type) {
|
||||
int32_t status = 0;
|
||||
setEncoderIndexSource(m_encoder, channel, false, (EncoderIndexingType)type,
|
||||
&status);
|
||||
wpi_setErrorWithContext(status, getHALErrorMessage(status));
|
||||
// Force digital input if just given an index
|
||||
m_indexSource = std::make_unique<DigitalInput>(channel);
|
||||
SetIndexSource(m_indexSource.get(), type);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -478,8 +477,8 @@ void Encoder::SetIndexSource(DigitalSource* source,
|
||||
void Encoder::SetIndexSource(const DigitalSource& source,
|
||||
Encoder::IndexingType type) {
|
||||
int32_t status = 0;
|
||||
setEncoderIndexSource(m_encoder, source.GetChannelForRouting(),
|
||||
source.GetAnalogTriggerForRouting(),
|
||||
setEncoderIndexSource(m_encoder, source.GetPortHandleForRouting(),
|
||||
source.GetAnalogTriggerTypeForRouting(),
|
||||
(EncoderIndexingType)type, &status);
|
||||
wpi_setErrorWithContext(status, getHALErrorMessage(status));
|
||||
}
|
||||
|
||||
@@ -30,8 +30,8 @@ void InterruptableSensorBase::RequestInterrupts(
|
||||
if (StatusIsFatal()) return; // if allocate failed, out of interrupts
|
||||
|
||||
int32_t status = 0;
|
||||
requestInterrupts(m_interrupt, GetModuleForRouting(), GetChannelForRouting(),
|
||||
GetAnalogTriggerForRouting(), &status);
|
||||
requestInterrupts(m_interrupt, GetPortHandleForRouting(),
|
||||
GetAnalogTriggerTypeForRouting(), &status);
|
||||
SetUpSourceEdge(true, false);
|
||||
attachInterruptHandler(m_interrupt, handler, param, &status);
|
||||
wpi_setErrorWithContext(status, getHALErrorMessage(status));
|
||||
@@ -52,8 +52,8 @@ void InterruptableSensorBase::RequestInterrupts() {
|
||||
if (StatusIsFatal()) return; // if allocate failed, out of interrupts
|
||||
|
||||
int32_t status = 0;
|
||||
requestInterrupts(m_interrupt, GetModuleForRouting(), GetChannelForRouting(),
|
||||
GetAnalogTriggerForRouting(), &status);
|
||||
requestInterrupts(m_interrupt, GetPortHandleForRouting(),
|
||||
GetAnalogTriggerTypeForRouting(), &status);
|
||||
wpi_setErrorWithContext(status, getHALErrorMessage(status));
|
||||
SetUpSourceEdge(true, false);
|
||||
}
|
||||
|
||||
@@ -82,17 +82,19 @@ Java_edu_wpi_first_wpilibj_hal_CounterJNI_setCounterAverageSize(
|
||||
/*
|
||||
* Class: edu_wpi_first_wpilibj_hal_CounterJNI
|
||||
* Method: setCounterUpSource
|
||||
* Signature: (IIZ)V
|
||||
* Signature: (III)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL
|
||||
Java_edu_wpi_first_wpilibj_hal_CounterJNI_setCounterUpSource(
|
||||
JNIEnv* env, jclass, jint id, jint pin, jboolean analogTrigger) {
|
||||
JNIEnv* env, jclass, jint id, jint digitalSourceHandle,
|
||||
jint analogTriggerType) {
|
||||
COUNTERJNI_LOG(logDEBUG) << "Calling COUNTERJNI setCounterUpSource";
|
||||
COUNTERJNI_LOG(logDEBUG) << "Counter Handle = " << (HalCounterHandle)id;
|
||||
COUNTERJNI_LOG(logDEBUG) << "Pin = " << pin;
|
||||
COUNTERJNI_LOG(logDEBUG) << "AnalogTrigger = " << (jint)analogTrigger;
|
||||
COUNTERJNI_LOG(logDEBUG) << "digitalSourceHandle = " << digitalSourceHandle;
|
||||
COUNTERJNI_LOG(logDEBUG) << "analogTriggerType = " << analogTriggerType;
|
||||
int32_t status = 0;
|
||||
setCounterUpSource((HalCounterHandle)id, pin, analogTrigger, &status);
|
||||
setCounterUpSource((HalCounterHandle)id, (HalHandle)digitalSourceHandle,
|
||||
(AnalogTriggerType)analogTriggerType, &status);
|
||||
COUNTERJNI_LOG(logDEBUG) << "Status = " << status;
|
||||
CheckStatus(env, status);
|
||||
}
|
||||
@@ -138,13 +140,15 @@ Java_edu_wpi_first_wpilibj_hal_CounterJNI_clearCounterUpSource(
|
||||
*/
|
||||
JNIEXPORT void JNICALL
|
||||
Java_edu_wpi_first_wpilibj_hal_CounterJNI_setCounterDownSource(
|
||||
JNIEnv* env, jclass, jint id, jint pin, jboolean analogTrigger) {
|
||||
JNIEnv* env, jclass, jint id, jint digitalSourceHandle,
|
||||
jint analogTriggerType) {
|
||||
COUNTERJNI_LOG(logDEBUG) << "Calling COUNTERJNI setCounterDownSource";
|
||||
COUNTERJNI_LOG(logDEBUG) << "Counter Handle = " << (HalCounterHandle)id;
|
||||
COUNTERJNI_LOG(logDEBUG) << "Pin = " << pin;
|
||||
COUNTERJNI_LOG(logDEBUG) << "AnalogTrigger = " << (jint)analogTrigger;
|
||||
COUNTERJNI_LOG(logDEBUG) << "digitalSourceHandle = " << digitalSourceHandle;
|
||||
COUNTERJNI_LOG(logDEBUG) << "analogTriggerType = " << analogTriggerType;
|
||||
int32_t status = 0;
|
||||
setCounterDownSource((HalCounterHandle)id, pin, analogTrigger, &status);
|
||||
setCounterDownSource((HalCounterHandle)id, (HalHandle)digitalSourceHandle,
|
||||
(AnalogTriggerType)analogTriggerType, &status);
|
||||
COUNTERJNI_LOG(logDEBUG) << "Status = " << status;
|
||||
if (status == PARAMETER_OUT_OF_RANGE) {
|
||||
ThrowIllegalArgumentException(env,
|
||||
|
||||
@@ -29,29 +29,27 @@ extern "C" {
|
||||
/*
|
||||
* Class: edu_wpi_first_wpilibj_hal_EncoderJNI
|
||||
* Method: initializeEncoder
|
||||
* Signature: (BIZBIZZI)I
|
||||
* Signature: (IIIIZI)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_edu_wpi_first_wpilibj_hal_EncoderJNI_initializeEncoder(
|
||||
JNIEnv* env, jclass, jbyte port_a_module, jint port_a_pin,
|
||||
jboolean port_a_analog_trigger, jbyte port_b_module, jint port_b_pin,
|
||||
jboolean port_b_analog_trigger, jboolean reverseDirection, jint encodingType) {
|
||||
JNIEnv* env, jclass, jint digitalSourceHandleA, jint analogTriggerTypeA,
|
||||
jint digitalSourceHandleB, jint analogTriggerTypeB, jboolean reverseDirection,
|
||||
jint encodingType) {
|
||||
ENCODERJNI_LOG(logDEBUG) << "Calling ENCODERJNI initializeEncoder";
|
||||
ENCODERJNI_LOG(logDEBUG) << "Module A = " << (jint)port_a_module;
|
||||
ENCODERJNI_LOG(logDEBUG) << "Pin A = " << port_a_pin;
|
||||
ENCODERJNI_LOG(logDEBUG) << "Analog Trigger A = "
|
||||
<< (jint)port_a_analog_trigger;
|
||||
ENCODERJNI_LOG(logDEBUG) << "Module B = " << (jint)port_b_module;
|
||||
ENCODERJNI_LOG(logDEBUG) << "Pin B = " << port_b_pin;
|
||||
ENCODERJNI_LOG(logDEBUG) << "Analog Trigger B = "
|
||||
<< (jint)port_b_analog_trigger;
|
||||
ENCODERJNI_LOG(logDEBUG) << "Source Handle A = " << digitalSourceHandleA;
|
||||
ENCODERJNI_LOG(logDEBUG) << "Analog Trigger Type A = "
|
||||
<< analogTriggerTypeA;
|
||||
ENCODERJNI_LOG(logDEBUG) << "Source Handle B = " << digitalSourceHandleB;
|
||||
ENCODERJNI_LOG(logDEBUG) << "Analog Trigger Type B = "
|
||||
<< analogTriggerTypeB;
|
||||
ENCODERJNI_LOG(logDEBUG) << "Reverse direction = " << (jint)reverseDirection;
|
||||
ENCODERJNI_LOG(logDEBUG) << "EncodingType = " << encodingType;
|
||||
int32_t status = 0;
|
||||
auto encoder = initializeEncoder(
|
||||
port_a_module, port_a_pin, port_a_analog_trigger, port_b_module,
|
||||
port_b_pin, port_b_analog_trigger, reverseDirection,
|
||||
(EncoderEncodingType)encodingType, &status);
|
||||
(HalHandle)digitalSourceHandleA, (AnalogTriggerType)analogTriggerTypeA,
|
||||
(HalHandle)digitalSourceHandleB, (AnalogTriggerType)analogTriggerTypeB,
|
||||
reverseDirection, (EncoderEncodingType)encodingType, &status);
|
||||
|
||||
ENCODERJNI_LOG(logDEBUG) << "Status = " << status;
|
||||
ENCODERJNI_LOG(logDEBUG) << "ENCODER Handle = " << encoder;
|
||||
@@ -336,20 +334,21 @@ Java_edu_wpi_first_wpilibj_hal_EncoderJNI_getEncoderSamplesToAverage(
|
||||
/*
|
||||
* Class: edu_wpi_first_wpilibj_hal_EncoderJNI
|
||||
* Method: setEncoderIndexSource
|
||||
* Signature: (IIZI)V
|
||||
* Signature: (IIII)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL
|
||||
Java_edu_wpi_first_wpilibj_hal_EncoderJNI_setEncoderIndexSource(
|
||||
JNIEnv* env, jclass, jint id, jint pin, jboolean analogTrigger,
|
||||
jint type) {
|
||||
JNIEnv* env, jclass, jint id, jint digitalSourceHandle,
|
||||
jint analogTriggerType, jint type) {
|
||||
ENCODERJNI_LOG(logDEBUG) << "Calling ENCODERJNI setEncoderIndexSource";
|
||||
ENCODERJNI_LOG(logDEBUG) << "Encoder Handle = " << (HalEncoderHandle)id;
|
||||
ENCODERJNI_LOG(logDEBUG) << "Pin = " << pin;
|
||||
ENCODERJNI_LOG(logDEBUG) << "Analog Trigger = "
|
||||
<< (analogTrigger ? "true" : "false");
|
||||
ENCODERJNI_LOG(logDEBUG) << "Source Handle = " << digitalSourceHandle;
|
||||
ENCODERJNI_LOG(logDEBUG) << "Analog Trigger Type = "
|
||||
<< analogTriggerType;
|
||||
ENCODERJNI_LOG(logDEBUG) << "IndexingType = " << type;
|
||||
int32_t status = 0;
|
||||
setEncoderIndexSource((HalEncoderHandle)id, pin, analogTrigger,
|
||||
setEncoderIndexSource((HalEncoderHandle)id, (HalHandle)digitalSourceHandle,
|
||||
(AnalogTriggerType)analogTriggerType,
|
||||
(EncoderIndexingType)type, &status);
|
||||
ENCODERJNI_LOG(logDEBUG) << "Status = " << status;
|
||||
CheckStatus(env, status);
|
||||
|
||||
@@ -257,22 +257,20 @@ Java_edu_wpi_first_wpilibj_hal_InterruptJNI_readFallingTimestamp(
|
||||
/*
|
||||
* Class: edu_wpi_first_wpilibj_hal_InterruptJNI
|
||||
* Method: requestInterrupts
|
||||
* Signature: (JBIZ)V
|
||||
* Signature: (III)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL
|
||||
Java_edu_wpi_first_wpilibj_hal_InterruptJNI_requestInterrupts(
|
||||
JNIEnv* env, jclass, jint interrupt_handle, jbyte routing_module,
|
||||
jint routing_pin, jboolean routing_analog_trigger) {
|
||||
JNIEnv* env, jclass, jint interrupt_handle, jint digitalSourceHandle,
|
||||
jint analogTriggerType) {
|
||||
INTERRUPTJNI_LOG(logDEBUG) << "Calling INTERRUPTJNI requestInterrupts";
|
||||
INTERRUPTJNI_LOG(logDEBUG) << "Interrupt Handle = " << (HalInterruptHandle)interrupt_handle;
|
||||
INTERRUPTJNI_LOG(logDEBUG) << "routing module = " << (jint)routing_module;
|
||||
INTERRUPTJNI_LOG(logDEBUG) << "routing pin = " << routing_pin;
|
||||
INTERRUPTJNI_LOG(logDEBUG) << "routing analog trigger = "
|
||||
<< (jint)routing_analog_trigger;
|
||||
INTERRUPTJNI_LOG(logDEBUG) << "digitalSourceHandle = " << digitalSourceHandle;
|
||||
INTERRUPTJNI_LOG(logDEBUG) << "analogTriggerType = " << analogTriggerType;
|
||||
|
||||
int32_t status = 0;
|
||||
requestInterrupts((HalInterruptHandle)interrupt_handle, (uint8_t)routing_module,
|
||||
(uint32_t)routing_pin, routing_analog_trigger, &status);
|
||||
requestInterrupts((HalInterruptHandle)interrupt_handle, (HalHandle)digitalSourceHandle,
|
||||
(AnalogTriggerType)analogTriggerType, &status);
|
||||
|
||||
INTERRUPTJNI_LOG(logDEBUG) << "Status = " << status;
|
||||
CheckStatus(env, status);
|
||||
|
||||
@@ -101,23 +101,23 @@ public class AnalogTriggerOutput extends DigitalSource {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getChannelForRouting() {
|
||||
return (m_trigger.m_index << 2) + m_outputType.m_value;
|
||||
public int getPortHandleForRouting() {
|
||||
return m_trigger.m_port;
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte getModuleForRouting() {
|
||||
return (byte) (m_trigger.m_index >> 2);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getAnalogTriggerForRouting() {
|
||||
return true;
|
||||
public int getAnalogTriggerTypeForRouting() {
|
||||
return m_outputType.m_value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPortHandle() {
|
||||
return m_trigger.m_port;
|
||||
public int getChannel() {
|
||||
return m_trigger.m_index;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAnalogTrigger() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -230,8 +230,8 @@ public class Counter extends SensorBase implements CounterBase, LiveWindowSendab
|
||||
m_allocatedUpSource = false;
|
||||
}
|
||||
m_upSource = source;
|
||||
CounterJNI.setCounterUpSource(m_counter, source.getChannelForRouting(),
|
||||
source.getAnalogTriggerForRouting());
|
||||
CounterJNI.setCounterUpSource(m_counter, source.getPortHandleForRouting(),
|
||||
source.getAnalogTriggerTypeForRouting());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -303,8 +303,8 @@ public class Counter extends SensorBase implements CounterBase, LiveWindowSendab
|
||||
m_downSource.free();
|
||||
m_allocatedDownSource = false;
|
||||
}
|
||||
CounterJNI.setCounterDownSource(m_counter, source.getChannelForRouting(),
|
||||
source.getAnalogTriggerForRouting());
|
||||
CounterJNI.setCounterDownSource(m_counter, source.getPortHandleForRouting(),
|
||||
source.getAnalogTriggerTypeForRouting());
|
||||
m_downSource = source;
|
||||
}
|
||||
|
||||
|
||||
@@ -54,12 +54,12 @@ public class DigitalGlitchFilter extends SensorBase {
|
||||
private static void setFilter(DigitalSource input, int channelIndex) {
|
||||
if (input != null) { // Counter might have just one input
|
||||
// analog triggers are not supported for DigitalGlitchFilters
|
||||
if (input.getAnalogTriggerForRouting()) {
|
||||
if (input.isAnalogTrigger()) {
|
||||
throw new IllegalStateException("Analog Triggers not supported for DigitalGlitchFilters");
|
||||
}
|
||||
DigitalGlitchFilterJNI.setFilterSelect(input.getPortHandle(), channelIndex);
|
||||
DigitalGlitchFilterJNI.setFilterSelect(input.getPortHandleForRouting(), channelIndex);
|
||||
|
||||
int selected = DigitalGlitchFilterJNI.getFilterSelect(input.getPortHandle());
|
||||
int selected = DigitalGlitchFilterJNI.getFilterSelect(input.getPortHandleForRouting());
|
||||
if (selected != channelIndex) {
|
||||
throw new IllegalStateException("DigitalGlitchFilterJNI.setFilterSelect("
|
||||
+ channelIndex + ") failed -> " + selected);
|
||||
|
||||
@@ -65,37 +65,28 @@ public class DigitalInput extends DigitalSource implements LiveWindowSendable {
|
||||
*
|
||||
* @return The GPIO channel number that this object represents.
|
||||
*/
|
||||
@Override
|
||||
public int getChannel() {
|
||||
return m_channel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the channel routing number.
|
||||
* Get the analog trigger type.
|
||||
*
|
||||
* @return channel routing number
|
||||
* @return false
|
||||
*/
|
||||
@Override
|
||||
public int getChannelForRouting() {
|
||||
return m_channel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the module routing number.
|
||||
*
|
||||
* @return 0
|
||||
*/
|
||||
@Override
|
||||
public byte getModuleForRouting() {
|
||||
public int getAnalogTriggerTypeForRouting() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Is this an analog trigger.
|
||||
*
|
||||
* @return true if this is an analog trigger
|
||||
*/
|
||||
@Override
|
||||
public boolean getAnalogTriggerForRouting() {
|
||||
public boolean isAnalogTrigger() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -105,11 +96,10 @@ public class DigitalInput extends DigitalSource implements LiveWindowSendable {
|
||||
* @return The HAL Handle to the specified source.
|
||||
*/
|
||||
@Override
|
||||
public int getPortHandle() {
|
||||
public int getPortHandleForRouting() {
|
||||
return m_handle;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getSmartDashboardType() {
|
||||
return "Digital Input";
|
||||
|
||||
@@ -67,6 +67,7 @@ public class DigitalOutput extends DigitalSource implements LiveWindowSendable {
|
||||
/**
|
||||
* @return The GPIO channel number that this object represents.
|
||||
*/
|
||||
@Override
|
||||
public int getChannel() {
|
||||
return m_channel;
|
||||
}
|
||||
@@ -170,34 +171,24 @@ public class DigitalOutput extends DigitalSource implements LiveWindowSendable {
|
||||
}
|
||||
DIOJNI.setDigitalPWMDutyCycle(m_pwmGenerator, dutyCycle);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the channel routing number.
|
||||
*
|
||||
* @return channel routing number
|
||||
*/
|
||||
@Override
|
||||
public int getChannelForRouting() {
|
||||
return m_channel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the module routing number.
|
||||
* Get the analog trigger type.
|
||||
*
|
||||
* @return 0
|
||||
* @return false
|
||||
*/
|
||||
@Override
|
||||
public byte getModuleForRouting() {
|
||||
public int getAnalogTriggerTypeForRouting() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Is this an analog trigger.
|
||||
*
|
||||
* @return true if this is an analog trigger
|
||||
*/
|
||||
@Override
|
||||
public boolean getAnalogTriggerForRouting() {
|
||||
public boolean isAnalogTrigger() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -207,7 +198,7 @@ public class DigitalOutput extends DigitalSource implements LiveWindowSendable {
|
||||
* @return The HAL Handle to the specified source.
|
||||
*/
|
||||
@Override
|
||||
public int getPortHandle() {
|
||||
public int getPortHandleForRouting() {
|
||||
return m_handle;
|
||||
}
|
||||
|
||||
|
||||
@@ -14,5 +14,7 @@ package edu.wpi.first.wpilibj;
|
||||
* source. The source can either be a digital input or analog trigger but not both.
|
||||
*/
|
||||
public abstract class DigitalSource extends InterruptableSensorBase {
|
||||
public abstract int getPortHandle();
|
||||
public abstract boolean isAnalogTrigger();
|
||||
|
||||
public abstract int getChannel();
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ import edu.wpi.first.wpilibj.hal.EncoderJNI;
|
||||
import edu.wpi.first.wpilibj.livewindow.LiveWindow;
|
||||
import edu.wpi.first.wpilibj.livewindow.LiveWindowSendable;
|
||||
import edu.wpi.first.wpilibj.tables.ITable;
|
||||
import edu.wpi.first.wpilibj.util.AllocationException;
|
||||
|
||||
/**
|
||||
* Class to read quad encoders. Quadrature encoders are devices that count shaft rotation and can
|
||||
@@ -72,15 +73,14 @@ public class Encoder extends SensorBase implements CounterBase, PIDSource, LiveW
|
||||
* @param reverseDirection If true, counts down instead of up (this is all relative)
|
||||
*/
|
||||
private void initEncoder(boolean reverseDirection, final EncodingType type) {
|
||||
m_encoder = EncoderJNI.initializeEncoder(m_aSource.getModuleForRouting(),
|
||||
(byte)m_aSource.getChannelForRouting(), m_aSource.getAnalogTriggerForRouting(),
|
||||
m_bSource.getModuleForRouting(), (byte)m_bSource.getChannelForRouting(),
|
||||
m_bSource.getAnalogTriggerForRouting(), reverseDirection, type.value);
|
||||
m_encoder = EncoderJNI.initializeEncoder(m_aSource.getPortHandleForRouting(),
|
||||
m_aSource.getAnalogTriggerTypeForRouting(), m_bSource.getPortHandleForRouting(),
|
||||
m_bSource.getAnalogTriggerTypeForRouting(), reverseDirection, type.value);
|
||||
|
||||
m_pidSource = PIDSourceType.kDisplacement;
|
||||
|
||||
UsageReporting.report(tResourceType.kResourceType_Encoder, getFPGAIndex(), type.value);
|
||||
LiveWindow.addSensor("Encoder", m_aSource.getChannelForRouting(), this);
|
||||
LiveWindow.addSensor("Encoder", m_aSource.getChannel(), this);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -164,7 +164,7 @@ public class Encoder extends SensorBase implements CounterBase, PIDSource, LiveW
|
||||
m_bSource = new DigitalInput(channelB);
|
||||
m_indexSource = new DigitalInput(indexChannel);
|
||||
initEncoder(reverseDirection, EncodingType.k4X);
|
||||
setIndexSource(indexChannel);
|
||||
setIndexSource(m_indexSource);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -564,7 +564,12 @@ public class Encoder extends SensorBase implements CounterBase, PIDSource, LiveW
|
||||
* @param type The state that will cause the encoder to reset
|
||||
*/
|
||||
public void setIndexSource(int channel, IndexingType type) {
|
||||
EncoderJNI.setEncoderIndexSource(m_encoder, channel, false, type.value);
|
||||
if (m_allocatedI) {
|
||||
throw new AllocationException("Digital Input for Indexing already allocated");
|
||||
}
|
||||
m_indexSource = new DigitalInput(channel);
|
||||
m_allocatedI = true;
|
||||
setIndexSource(m_indexSource, type);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -575,8 +580,8 @@ public class Encoder extends SensorBase implements CounterBase, PIDSource, LiveW
|
||||
* @param type The state that will cause the encoder to reset
|
||||
*/
|
||||
public void setIndexSource(DigitalSource source, IndexingType type) {
|
||||
EncoderJNI.setEncoderIndexSource(m_encoder, source.getChannelForRouting(),
|
||||
source.getAnalogTriggerForRouting(), type.value);
|
||||
EncoderJNI.setEncoderIndexSource(m_encoder, source.getPortHandleForRouting(),
|
||||
source.getAnalogTriggerTypeForRouting(), type.value);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -61,21 +61,14 @@ public abstract class InterruptableSensorBase extends SensorBase {
|
||||
*
|
||||
* @return true if this is an analog trigger.
|
||||
*/
|
||||
abstract boolean getAnalogTriggerForRouting();
|
||||
public abstract int getAnalogTriggerTypeForRouting();
|
||||
|
||||
/**
|
||||
* The channel routing number.
|
||||
*
|
||||
* @return channel routing number
|
||||
*/
|
||||
abstract int getChannelForRouting();
|
||||
|
||||
/**
|
||||
* The modules routing number.
|
||||
*
|
||||
* @return module routing number
|
||||
*/
|
||||
abstract byte getModuleForRouting();
|
||||
public abstract int getPortHandleForRouting();
|
||||
|
||||
/**
|
||||
* Request one of the 8 interrupts asynchronously on this digital input.
|
||||
@@ -95,8 +88,8 @@ public abstract class InterruptableSensorBase extends SensorBase {
|
||||
|
||||
assert (m_interrupt != 0);
|
||||
|
||||
InterruptJNI.requestInterrupts(m_interrupt, getModuleForRouting(), getChannelForRouting(),
|
||||
getAnalogTriggerForRouting());
|
||||
InterruptJNI.requestInterrupts(m_interrupt, getPortHandleForRouting(),
|
||||
getAnalogTriggerTypeForRouting());
|
||||
setUpSourceEdge(true, false);
|
||||
InterruptJNI.attachInterruptHandler(m_interrupt, handler.m_function,
|
||||
handler.overridableParameter());
|
||||
@@ -116,8 +109,8 @@ public abstract class InterruptableSensorBase extends SensorBase {
|
||||
|
||||
assert (m_interrupt != 0);
|
||||
|
||||
InterruptJNI.requestInterrupts(m_interrupt, getModuleForRouting(), getChannelForRouting(),
|
||||
getAnalogTriggerForRouting());
|
||||
InterruptJNI.requestInterrupts(m_interrupt, getPortHandleForRouting(),
|
||||
getAnalogTriggerTypeForRouting());
|
||||
setUpSourceEdge(true, false);
|
||||
|
||||
}
|
||||
|
||||
@@ -16,16 +16,16 @@ public class CounterJNI extends JNIWrapper {
|
||||
|
||||
public static native void setCounterAverageSize(int counterHandle, int size);
|
||||
|
||||
public static native void setCounterUpSource(int counterHandle, int pin,
|
||||
boolean analogTrigger);
|
||||
public static native void setCounterUpSource(int counterHandle, int digitalSourceHandle,
|
||||
int analogTriggerType);
|
||||
|
||||
public static native void setCounterUpSourceEdge(int counterHandle, boolean risingEdge,
|
||||
boolean fallingEdge);
|
||||
|
||||
public static native void clearCounterUpSource(int counterHandle);
|
||||
|
||||
public static native void setCounterDownSource(int counterHandle, int pin,
|
||||
boolean analogTrigger);
|
||||
public static native void setCounterDownSource(int counterHandle, int digitalSourceHandle,
|
||||
int analogTriggerType);
|
||||
|
||||
public static native void setCounterDownSourceEdge(int counterHandle, boolean risingEdge,
|
||||
boolean fallingEdge);
|
||||
|
||||
@@ -11,10 +11,9 @@ import java.nio.IntBuffer;
|
||||
|
||||
public class EncoderJNI extends JNIWrapper {
|
||||
|
||||
public static native int initializeEncoder(byte portAModule, int portAPin,
|
||||
boolean portAAnalogTrigger, byte portBModule,
|
||||
int portBPin, boolean portBAnalogTrigger,
|
||||
boolean reverseDirection, int encodingType);
|
||||
public static native int initializeEncoder(int digitalSourceHandleA, int analogTriggerTypeA,
|
||||
int digitalSourceHandleB, int analogTriggerTypeB,
|
||||
boolean reverseDirection, int encodingType);
|
||||
|
||||
public static native void freeEncoder(int encoderHandle);
|
||||
|
||||
@@ -50,8 +49,8 @@ public class EncoderJNI extends JNIWrapper {
|
||||
|
||||
public static native int getEncoderSamplesToAverage(int encoderHandle);
|
||||
|
||||
public static native void setEncoderIndexSource(int encoderHandle, int pin,
|
||||
boolean analogTrigger, int indexingType);
|
||||
public static native void setEncoderIndexSource(int encoderHandle, int digitalSourceHandle,
|
||||
int analogTriggerType, int indexingType);
|
||||
|
||||
@SuppressWarnings("AbbreviationAsWordInName")
|
||||
public static native int getEncoderFPGAIndex(int encoderHandle);
|
||||
|
||||
@@ -29,8 +29,8 @@ public class InterruptJNI extends JNIWrapper {
|
||||
|
||||
public static native double readFallingTimestamp(int interruptHandle);
|
||||
|
||||
public static native void requestInterrupts(int interruptHandle, byte routingModule,
|
||||
int routingPin, boolean routingAnalogTrigger);
|
||||
public static native void requestInterrupts(int interruptHandle, int digitalSourceHandle,
|
||||
int analogTriggerType);
|
||||
|
||||
public static native void attachInterruptHandler(int interruptHandle,
|
||||
InterruptJNIHandlerFunction handler,
|
||||
|
||||
Reference in New Issue
Block a user