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

Detailed Description

ClearCore digital output connector class.

This manages a digital output connector on the ClearCore board. This connector can also be configured as a digital input.

The following connector instances support digital output functionality:

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

ClearCore digital output connector class. More...

#include <DigitalInOut.h>

+ Inheritance diagram for ClearCore::DigitalInOut:
+ Collaboration diagram for ClearCore::DigitalInOut:

Public Member Functions

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 State (int16_t newState) override
 Set the output state of the connector. More...
 
bool IsInHwFault () override
 Get whether the connector is in a hardware fault state. More...
 
void OutputPulsesStart (uint32_t onTime, uint32_t offTime, uint16_t pulseCount=0, bool blockUntilDone=false)
 Start an output pulse. More...
 
void OutputPulsesStop (bool stopImmediately=true)
 Stop an output pulse. More...
 
volatile const bool & OutputPulsesActive ()
 Check the output pulse state. More...
 
bool PwmDuty (uint8_t newDuty)
 Set the PWM duty on the I/O pin. More...
 
- Public Member Functions inherited from ClearCore::DigitalIn
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...
 
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...
 
uint32_t InputRegMask ()
 Get a bit mask representing this connector. More...
 

Additional Inherited Members

- Public Types inherited from ClearCore::DigitalIn
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...
 

Member Function Documentation

bool ClearCore::DigitalInOut::IsInHwFault ( )
inlineoverridevirtual

Get whether the connector is in a hardware fault state.

// IO-1 is in a fault state
}
Returns
True if the connector is in fault; false otherwise.

Implements ClearCore::Connector.

bool ClearCore::DigitalInOut::IsWritable ( )
inlineoverridevirtual

Get R/W status of the connector.

// IO-1 is in an output mode
}
Returns
True if in OUTPUT_DIGITAL or OUTPUT_PWM mode, false otherwise.

Reimplemented from ClearCore::DigitalIn.

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

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

Get the connector's operational mode.

// IO-1 is currently a digital output.
}
Returns
The connector's current operational mode.

Reimplemented from ClearCore::DigitalIn.

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

Examples:
AnalogIOExamples/ReadAnalogInput/ReadAnalogInput.cpp, DigitalIOExamples/WriteDigitalOutput/WriteDigitalOutput.cpp, and SerialCommExamples/ClearCoreCommandProtocol/ClearCoreCommandProtocol.cpp.
virtual bool ClearCore::DigitalInOut::Mode ( ConnectorModes  newMode)
overridevirtual

Set the connector's operational mode.

// Set IO-1's mode to be an output configured to produce PWM signals
Parameters
[in]newModeThe new mode to be set. The valid modes for this connector type are:
Returns
Returns false if the mode is invalid or setup fails.

Reimplemented from ClearCore::DigitalIn.

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

volatile const bool& ClearCore::DigitalInOut::OutputPulsesActive ( )
inline

Check the output pulse state.

This allows you to see if there is a currently running pulse on this output.

// IO-1 is outputting pulses
}
Returns
True if output pulses are currently active.
void ClearCore::DigitalInOut::OutputPulsesStart ( uint32_t  onTime,
uint32_t  offTime,
uint16_t  pulseCount = 0,
bool  blockUntilDone = false 
)

Start an output pulse.

This allows you to start a pulse on the output that is on for onTime milliseconds and off for offTime milliseconds and will stop after pulseCount cycles. A pulseCount of 0 will cause the pulse to run endlessly. If a pulse is already running, calling this will allow you to override the previous pulse (after the next change in state).

// Begin a 100ms on/200ms off pulse on IO-1's output that will complete
// 20 cycles and prevent further code execution until the cycles are
// complete
ConnectorIO1.OutputPulsesStart(100, 200, 20, true);
Parameters
[in]onTimeThe amount of time the input will be held on [ms].
[in]offTimeThe amount of time the input will be held off [ms].
[in]pulseCount(optional) The amount of cycles the pulse will run for. Default: 0 (pulse runs endlessly).
[in]blockUntilDone(optional) If true, the function call will wait until pulseCount pulses have been sent before returning. Default: false.
void ClearCore::DigitalInOut::OutputPulsesStop ( bool  stopImmediately = true)

Stop an output pulse.

This allows you to stop the currently running pulse on this output. The output will always be set to FALSE after canceling a pulse.

// Stop the active output pulse on IO-1
Parameters
[in]stopImmediately(optional) If true, the output pulses will be stopped immediately; if false, any active pulse will be completed first. Default: true.
bool ClearCore::DigitalInOut::PwmDuty ( uint8_t  newDuty)

Set the PWM duty on the I/O pin.

The pin must be in OUTPUT_PWM mode, or else nothing will happen and this function will return false.

// Configure IO-1 for PWM output
// Set the PWM output signal on IO-1 to be asserted 25% of the time
ConnectorIO1.PwmDuty(UINT8_MAX / 4);
Parameters
[in]newDutyThe PWM duty cycle for the pin, from 0 to 255 (UINT8_MAX).
Returns
Successfully set the PWM duty value.
int16_t ClearCore::DigitalInOut::State ( )
overridevirtual

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

// In this example, IO-1 has been configured for digital input
// IO-1's input is currently high
}
// In this example, IO-1 has been configured for PWM output
if (ConnectorIO1.State() > UINT8_MAX / 2) {
// IO-1 is outputting PWM at a duty cycle greater than 50%
}
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)).

Reimplemented from ClearCore::DigitalIn.

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

Examples:
AnalogIOExamples/ReadAnalogInput/ReadAnalogInput.cpp, and DigitalIOExamples/WriteDigitalOutput/WriteDigitalOutput.cpp.
bool ClearCore::DigitalInOut::State ( int16_t  newState)
overridevirtual

Set the output state of the connector.

This allows you to change the output value of the connector item.

// Configure IO-1 for digital output mode
// Set IO-1's output to high
// Configure IO-1 for PWM output mode
// Set IO-1 to output a PWM wave with 25% duty cycle
ConnectorIO1.State(UINT8_MAX / 4);
Parameters
[in]newStateThe value to be output.

Implements ClearCore::Connector.

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

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

Get connector type.

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

Reimplemented from ClearCore::DigitalIn.

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


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