ClearCore Library
Loading...
Searching...
No Matches
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.
 
uint16_t FilterLength ()
 Get the connector's digital filter length in samples. The default is 3 samples.
 
virtual ConnectorModes Mode () override
 Get the connector's operational mode.
 
virtual bool Mode (ConnectorModes newMode) override
 Set the connector's operational mode.
 
Connector::ConnectorTypes Type () override
 Get connector type.
 
bool IsWritable () override
 Get R/W status of the connector.
 
int16_t State () override
 Get the connector's last majority-filtered sampled value.
 
bool InputRisen ()
 Clear on read accessor for this connector's rising input state.
 
bool InputFallen ()
 Clear on read accessor for this connector's falling input state.
 
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.
 
void InterruptEnable (bool enable)
 Enable or disable the interrupt on this connector.
 
- Public Member Functions inherited from ClearCore::Connector
void Reinitialize ()
 Reinitialize this connector to the power-up state.
 
int32_t ConnectorIndex ()
 Accessor for the bit index of this connector in the input register.
 
virtual bool State (int16_t newState)=0
 Set the state of a R/W connector.
 
virtual bool IsInHwFault ()=0
 Get whether the connector is in a hardware fault state.
 
uint32_t InputRegMask ()
 Get a bit mask representing this connector.
 

Member Enumeration Documentation

◆ FilterUnits

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

◆ FilterLength() [1/2]

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
}
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 i...
Definition DigitalIn.h:122
DigitalIn ConnectorDI6
DI-6 connector instance.
Note
One sample time is 200 microseconds.
Returns
The length of the digital input filter in samples.

◆ FilterLength() [2/2]

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)
@ FILTER_UNIT_MS
Definition DigitalIn.h:93
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.

◆ InputFallen()

bool ClearCore::DigitalIn::InputFallen ( )

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

// DI-7 falling edge detected since the last call
}
bool InputFallen()
Clear on read accessor for this connector's falling input state.
DigitalIn ConnectorDI7
DI-7 connector instance.
Returns
true if the input has fallen since the last call

◆ InputRisen()

bool ClearCore::DigitalIn::InputRisen ( )

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

// DI-7 rising edge detected since the last call
}
bool InputRisen()
Clear on read accessor for this connector's rising input state.
Returns
true if the input has risen since the last call

◆ InterruptEnable()

void ClearCore::DigitalIn::InterruptEnable ( bool  enable)

Enable or disable the interrupt on this connector.

// Enable interrupts on DI-6
void InterruptEnable(bool enable)
Enable or disable the interrupt on this connector.
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.

◆ InterruptHandlerSet()

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);
}
void Delay_ms(uint32_t ms)
Blocks operations for ms milliseconds.
Definition SysTiming.h:287
void InterruptsEnabled(bool enable)
Enable or disable digital interrupts board-wide.
int16_t State() override
Get LED's last sampled state.
InputManager & InputMgr
Input manager.
LedDriver ConnectorLed
User-driven LED instance.
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.

◆ IsWritable()

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::DigitalInAnalogIn, ClearCore::DigitalInOut, ClearCore::DigitalInOutAnalogOut, ClearCore::DigitalInOutHBridge, and ClearCore::MotorDriver.

◆ Mode() [1/2]

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

Get the connector's operational mode.

// DI-6 is currently a digital input.
}
@ INPUT_DIGITAL
Definition Connector.h:90
virtual ConnectorModes Mode() override
Get the connector's operational mode.
Definition DigitalIn.h:161
Returns
The connector's current operational mode.

Reimplemented from ClearCore::Connector.

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

Examples
ClearCoreCommandProtocol.cpp, and SerialCommExamples/ClearCoreCommandProtocol/ClearCoreCommandProtocol.cpp.

◆ Mode() [2/2]

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::DigitalInAnalogIn, ClearCore::DigitalInOut, ClearCore::DigitalInOutAnalogOut, and ClearCore::DigitalInOutHBridge.

◆ State()

int16_t ClearCore::DigitalIn::State ( )
overridevirtual

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

// DI-6's input is currently high
}
int16_t State() override
Get the connector's last majority-filtered sampled value.
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::DigitalInAnalogIn, ClearCore::DigitalInOut, ClearCore::DigitalInOutAnalogOut, and ClearCore::DigitalInOutHBridge.

◆ Type()

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

Get connector type.

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

Implements ClearCore::Connector.

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


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