artf4700: Added DigitalGlitchFilter

Initial Java support from Tyler Veness.
Final java support done by Jerry Morrison.

Change-Id: I1f85eb555f9ea4c0250c4c6729d7c51a76f5bef4
This commit is contained in:
Austin Schuh
2015-11-22 21:18:59 -08:00
committed by Peter Johnson
parent 6d00b77ef3
commit b3b03c43c8
19 changed files with 751 additions and 5 deletions

View File

@@ -14,6 +14,8 @@
#include <memory>
class DigitalGlitchFilter;
/**
* Class for counting the number of ticks on a digital input channel.
* This is a general purpose class for counting repetitive events. It can return
@@ -119,4 +121,5 @@ class Counter : public SensorBase,
uint32_t m_index = 0; ///< The index of this counter.
std::shared_ptr<ITable> m_table;
friend class DigitalGlitchFilter;
};

View File

@@ -0,0 +1,50 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2015. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
/*----------------------------------------------------------------------------*/
#pragma once
#include <array>
#include "HAL/cpp/priority_mutex.h"
#include "DigitalSource.h"
class Encoder;
class Counter;
/**
* Class to enable glitch filtering on a set of digital inputs.
* This class will manage adding and removing digital inputs from a FPGA glitch
* filter. The filter lets the user configure the time that an input must remain
* high or low before it is classified as high or low.
*/
class DigitalGlitchFilter : public SensorBase {
public:
DigitalGlitchFilter();
~DigitalGlitchFilter();
void Add(DigitalSource *input);
void Add(Encoder *input);
void Add(Counter *input);
void Remove(DigitalSource *input);
void Remove(Encoder *input);
void Remove(Counter *input);
void SetPeriodCycles(uint32_t fpga_cycles);
void SetPeriodNanoSeconds(uint64_t nanoseconds);
uint32_t GetPeriodCycles();
uint64_t GetPeriodNanoSeconds();
private:
// Sets the filter for the input to be the requested index. A value of 0
// disables the filter, and the filter value must be between 1 and 3,
// inclusive.
void DoAdd(DigitalSource *input, int requested_index);
int m_channelIndex = -1;
static priority_mutex m_mutex;
static ::std::array<bool, 3> m_filterAllocated;
};

View File

@@ -12,6 +12,8 @@
#include <memory>
#include <cstdint>
class DigitalGlitchFilter;
/**
* Class to read a digital input.
* This class will read digital inputs and return the current value on the
@@ -45,4 +47,5 @@ class DigitalInput : public DigitalSource, public LiveWindowSendable {
uint32_t m_channel;
std::shared_ptr<ITable> m_table;
friend class DigitalGlitchFilter;
};

View File

@@ -16,6 +16,7 @@
#include <memory>
class DigitalSource;
class DigitalGlitchFilter;
/**
* Class to read quad encoders.
@@ -116,4 +117,5 @@ class Encoder : public SensorBase,
int32_t m_encodingScale; // 1x, 2x, or 4x, per the encodingType
std::shared_ptr<ITable> m_table;
friend class DigitalGlitchFilter;
};

View File

@@ -68,6 +68,7 @@ typedef enum {
kResourceType_VictorSP,
kResourceType_TalonSRX,
kResourceType_CANTalonSRX,
kResourceType_DigitalGlitchFilter,
} tResourceType;
typedef enum {