ClearCore Library
List of all members | Public Types | Public Member Functions
ClearCore::DigitalIn Class Reference

Detailed Description

ClearCore digital input connector class.

This manages a digital input connector on the ClearCore board.

The following connector instances support digital input functionality:

For more detailed information on the ClearCore Connector interface, check out the ClearCore Connector System informational page.

ClearCore digital input connector class. More...

#include <DigitalIn.h>

+ Inheritance diagram for ClearCore::DigitalIn:
+ Collaboration diagram for ClearCore::DigitalIn:

Public Types

enum  FilterUnits { FILTER_UNIT_MS, FILTER_UNIT_SAMPLES }
 Units for the digital filter length. More...
 
- Public Types inherited from ClearCore::Connector
enum  ConnectorModes {
  INVALID_NONE, INPUT_ANALOG, INPUT_DIGITAL, OUTPUT_ANALOG,
  OUTPUT_DIGITAL, OUTPUT_H_BRIDGE, OUTPUT_PWM, OUTPUT_TONE,
  OUTPUT_WAVE, CPM_MODE_A_DIRECT_B_DIRECT, CPM_MODE_STEP_AND_DIR, CPM_MODE_A_DIRECT_B_PWM,
  CPM_MODE_A_PWM_B_PWM, TTL, RS232, SPI,
  CCIO, USB_CDC
}
 All possible operational modes for a connector. More...
 
enum  ConnectorTypes {
  DIGITAL_IN_TYPE, DIGITAL_IN_OUT_TYPE, SHIFT_REG_TYPE, ANALOG_IN_DIGITAL_IN_TYPE,
  ANALOG_OUT_DIGITAL_IN_OUT_TYPE, H_BRIDGE_TYPE, CPM_TYPE, SERIAL_TYPE,
  SERIAL_USB_TYPE, CCIO_DIGITAL_IN_OUT_TYPE
}
 The different types of ClearCore connectors. More...
 

Public Member Functions

void FilterLength (uint16_t length, FilterUnits units=FILTER_UNIT_SAMPLES)
 Set the connector's digital transition filter length. The default digital filter length for digital input connectors is 3 samples. More...
 
uint16_t FilterLength ()
 Get the connector's digital filter length in samples. The default is 3 samples. More...
 
virtual ConnectorModes Mode () override
 Get the connector's operational mode. More...
 
virtual bool Mode (ConnectorModes newMode) override
 Set the connector's operational mode. More...
 
Connector::ConnectorTypes Type () override
 Get connector type. More...
 
bool IsWritable () override
 Get R/W status of the connector. More...
 
int16_t State () override
 Get the connector's last majority-filtered sampled value. More...
 
bool InputRisen ()
 Clear on read accessor for this connector's rising input state. More...
 
bool InputFallen ()
 Clear on read accessor for this connector's falling input state. More...
 
bool InterruptHandlerSet (voidFuncPtr callback=nullptr, InputManager::InterruptTrigger trigger=InputManager::InterruptTrigger::RISING, bool enable=true)
 Register the interrupt service routine to be triggered when the given input state condition is met on this connector. More...
 
void InterruptEnable (bool enable)
 Enable or disable the interrupt on this connector. More...
 
- Public Member Functions inherited from ClearCore::Connector
void Reinitialize ()
 Reinitialize this connector to the power-up state. More...
 
int32_t ConnectorIndex ()
 Accessor for the bit index of this connector in the input register. More...
 
virtual bool State (int16_t newState)=0
 Set the state of a R/W connector. More...
 
virtual bool IsInHwFault ()=0
 Get whether the connector is in a hardware fault state. More...
 
uint32_t InputRegMask ()
 Get a bit mask representing this connector. More...
 

Member Enumeration Documentation

Units for the digital filter length.

Note
One sample time is 200 microseconds, so 1 ms = 5 sample times.
Enumerator
FILTER_UNIT_MS 

Milliseconds.

FILTER_UNIT_SAMPLES 

Sample times.

Member Function Documentation

void ClearCore::DigitalIn::FilterLength ( uint16_t  length,
FilterUnits  units = FILTER_UNIT_SAMPLES 
)
inline

Set the connector's digital transition filter length. The default digital filter length for digital input connectors is 3 samples.

This will set the length, in samples (default) or milliseconds, of the connector's transition filter and restarts any filtering in progress.

// Sets DI-6's filter to 20 samples (4ms)
// Sets DI-6's filter to 10ms (50 samples)
Note
One sample time is 200 microseconds.
Parameters
[in]lengthThe length of the filter.
[in]unitsThe units of the specified filter length: samples (default) or milliseconds.
uint16_t ClearCore::DigitalIn::FilterLength ( )
inline

Get the connector's digital filter length in samples. The default is 3 samples.

This will get the length, in samples, of the connector's filter.

// DI6's filter length is greater than 5 samples (1ms), do something
}
Note
One sample time is 200 microseconds.
Returns
The length of the digital input filter in samples.
bool ClearCore::DigitalIn::InputFallen ( )

Clear on read accessor for this connector's falling input state.

// DI-7 falling edge detected since the last call
}
Returns
true if the input has fallen since the last call
bool ClearCore::DigitalIn::InputRisen ( )

Clear on read accessor for this connector's rising input state.

// DI-7 rising edge detected since the last call
}
Returns
true if the input has risen since the last call
void ClearCore::DigitalIn::InterruptEnable ( bool  enable)

Enable or disable the interrupt on this connector.

// Enable interrupts on DI-6
Parameters
[in]enableIf true, enable the interrupt. If false, disable the interrupt.
Note
Only connectors DI-6 through A-12 can trigger interrupts.
InputManager has a global version of this function that enables or disables the interrupts for all connectors.
bool ClearCore::DigitalIn::InterruptHandlerSet ( voidFuncPtr  callback = nullptr,
InputManager::InterruptTrigger  trigger = InputManager::InterruptTrigger::RISING,
bool  enable = true 
)

Register the interrupt service routine to be triggered when the given input state condition is met on this connector.

// Signature for interrupt service routine (ISR)
void myCallback();
void setup() {
// Set an interrupt service routine (ISR) to be called when the
// state of the interrupt connector goes from TRUE to FALSE.
InterruptConnector.InterruptHandlerSet(&myCallback,
InputManager::FALLING);
// Enable digital interrupts.
}
// The function to be triggered on an interrupt.
// This function blinks the user-controlled LED once.
void myCallback() {
Delay_ms(100);
Delay_ms(100);
}
Parameters
[in]callbackThe ISR to be called when the interrupt is triggered
[in]triggerThe input state condition on which to trigger the interrupt.
[in]enableWhether this interrupt should be immediately enabled.
Returns
true if the ISR was registered successfully, false otherwise.
Note
Only connectors DI-6 through A-12 can trigger interrupts.
bool ClearCore::DigitalIn::IsWritable ( )
inlineoverridevirtual

Get R/W status of the connector.

if (!ConnectorAlias.IsWritable()) {
// This generic connector is not an output
}
Returns
False because the connector is read-only.

Implements ClearCore::Connector.

Reimplemented in ClearCore::MotorDriver, ClearCore::DigitalInOutHBridge, ClearCore::DigitalInAnalogIn, ClearCore::DigitalInOut, and ClearCore::DigitalInOutAnalogOut.

virtual ConnectorModes ClearCore::DigitalIn::Mode ( )
inlineoverridevirtual

Get the connector's operational mode.

// DI-6 is currently a digital input.
}
Returns
The connector's current operational mode.

Reimplemented from ClearCore::Connector.

Reimplemented in ClearCore::MotorDriver, ClearCore::DigitalInOutHBridge, ClearCore::DigitalInAnalogIn, ClearCore::DigitalInOut, and ClearCore::DigitalInOutAnalogOut.

Examples:
SerialCommExamples/ClearCoreCommandProtocol/ClearCoreCommandProtocol.cpp.
virtual bool ClearCore::DigitalIn::Mode ( ConnectorModes  newMode)
inlineoverridevirtual

Set the connector's operational mode.

Parameters
[in]newModeThe new mode to be set. The only valid mode for this connector type is: INPUT_DIGITAL.
Returns
Returns false if the mode is invalid or setup fails.

Implements ClearCore::Connector.

Reimplemented in ClearCore::DigitalInOutHBridge, ClearCore::DigitalInAnalogIn, ClearCore::DigitalInOut, and ClearCore::DigitalInOutAnalogOut.

int16_t ClearCore::DigitalIn::State ( )
overridevirtual

Get the connector's last majority-filtered sampled value.

// DI-6's input is currently high
}
Returns
The latest filtered value on this connector.
Note
If the filter length is set to 0, this will return the real-time value from the hardware register instead (see #FilterLength(uint16_t samples)).

Implements ClearCore::Connector.

Reimplemented in ClearCore::DigitalInOutHBridge, ClearCore::DigitalInAnalogIn, ClearCore::DigitalInOut, and ClearCore::DigitalInOutAnalogOut.

Connector::ConnectorTypes ClearCore::DigitalIn::Type ( )
inlineoverridevirtual

Get connector type.

if (ConnectorAlias.Type() == Connector::DIGITAL_IN_TYPE) {
// This generic connector variable is a DigitalIn connector
}
Returns
The type of the current connector.

Implements ClearCore::Connector.

Reimplemented in ClearCore::MotorDriver, ClearCore::DigitalInOutHBridge, ClearCore::DigitalInAnalogIn, ClearCore::DigitalInOut, and ClearCore::DigitalInOutAnalogOut.


The documentation for this class was generated from the following file: