There are two ways of monitoring changes on the digital input line:
To poll the input pin periodically. In this case, you can potentially miss an input if your application reads the value at the wrong time.
To receive events when the input value changes. You can configure event generation for specific changes, for example, when the level on a pin rises. You can also configure the adapter to generate events periodically.
To configure events, use the DlnGpioPinSetEventCfg() function. You need to specify the eventType
and the eventPeriod
parameters. The DlnGpioPinGetSupportedEventTypes() function returns the list of event types available for a pin.
The eventType
parameter can have one of the following values:
Event Type | Description |
DLN_GPIO_EVENT_NONE | A DLN adapter does not generate any events. |
DLN_GPIO_EVENT_CHANGE | A DLN adapter generates events when the level on the digital input line changes. For details, read DLN_GPIO_EVENT_CHANGE Events |
DLN_GPIO_EVENT_LEVEL_HIGH | A DLN adapter generates events when the high level is present on the digital input line or after transition from low to high level. For details, read DLN_GPIO_EVENT_LEVEL_HIGH Events |
DLN_GPIO_EVENT_LEVEL_LOW | A DLN adapter generates events when the low level is present on the digital input line or after transition from high to low level. For details, read DLN_GPIO_EVENT_LEVEL_LOW Events |
DLN_GPIO_EVENT_ALWAYS | A DLN adapter generates events continuously, regardless of the level. For details, read DLN_GPIO_EVENT_ALWAYS Events |
The eventPeriod
parameter defines the interval between repeated events in milliseconds (ms). This parameter must be non-zero for the DLN_GPIO_EVENT_ALWAYS
events. For other events, this parameter is optional.
If the Debounce Filter in enabled on a pin, the level change event is generated after the debounce filter accepts a new value.
You can configure events for each input pin individually. If the pin is configured as a digital input, the new settings are applied immediately. If you configure events when a pin is defined as an output or is not assigned to the GPIO module at all, this configuration is saved in the internal memory and is applied when the pin becomes a GPIO input.
When an event occurs, your application is notified (see the Notifications section). Call the DlnGetMessage() function to obtain the event details. The DLN_GPIO_CONDITION_MET_EV structure describes this information.
By default, event generation is disabled for all pins (the eventType
parameter is set to DLN_GPIO_EVENT_NONE).
The following GPIO Interface functions can be used to control and monitor events:
Configures event generation for a pin.
Retrieves event generation configuration for a pin.
Returns the list of the event types available for a pin.
A DLN adapter generates the DLN_GPIO_EVENT_CHANGE
events each time the level on the input pin changes.
Use the DlnGpioPinSetEventCfg()function to configure events. Pass DLN_GPIO_EVENT_CHANGE
for the eventType
parameter.
If the eventPeriod
parameter is zero, the DLN adapter generates single events when the level on the input pin changes.
If the eventPeriod
is non-zero, the DLN adapter resents the events periodically with the eventPeriod
interval while the level on the pin remains unchanged (a series of events).
A series of e vents begins when the level on the GPIO line changes. At this moment, the DLN adapter sends the first event in the series. The eventCount
field of the first event is set to zero and the value
field contains the actual value on the GPIO line. Then, while the level on the GPIO line remains unchanged, the DLN adapter repeatedly sends events with the same value in the value
field. The interval between recurring events is equal to eventPeriod
milliseconds. The eventCount
field increments for each event in the series. You can use this field to calculate the time passed from the last level change (time = eventCount * eventPeriod).When the level on the GPIO line changes, a new series of events begins. The eventCount
field is reset to zero and the value
field is set to the actual value present on the line after the change.
A DLN adapter generates the DLN_GPIO_EVENT_LEVEL_HIGH
events each time the level on the input pin rises.
Use the DlnGpioPinSetEventCfg()function to configure events. Pass DLN_GPIO_EVENT_LEVEL_HIGH
for the eventType
parameter.
If the eventPeriod
is zero, the DLN adapter generates single events when the level on the input pin rises (after transition from low to high level).
If the eventPeriod
is non-zero , the DLN adapter resents events periodically with the eventPeriod
interval while the level is high:
A series of events begins when the level on the GPIO line rises. At this moment, the DLN adapter sends the first event in the series. The eventCount
field of the first event is set to zero and the value
field is set to 1 to reflect the actual value on the GPIO line. Then, while the level on the GPIO line remains high, the DLN adapter repeatedly sends events. The same value in the value
field stays the same. The eventCount
field increments for every new event. The interval between recurring events is equal to eventPeriod
milliseconds. You can calculate the time passed from the last level rise (time = eventCount * eventPeriod
).
When the level on the GPIO line drops, the series of events ends. When the level on the line rises again, a new series of events begins. The eventCount
field is reset to zero.
A DLN adapter generates the DLN_GPIO_EVENT_LEVEL_LOW
events each time the level on the input pin drops.
Use the DlnGpioPinSetEventCfg()function to configure events. Pass DLN_GPIO_EVENT_LEVEL_LOW
for the eventType
parameter.
If the eventPeriod
is zero, the DLN adapter generates single events when the level on the input pin drops (after transition from high to low level).
If the eventPeriod
is non-zero, the DLN adapter resents events periodically with the eventPeriod
interval while the level is low.
A series of events begins when the level on the GPIO line drops. At this moment, the DLN adapter sends the first event in the series. The eventCount
field of the first event is set to zero and the value
field contains 0 to reflect the actual value on the GPIO line. Then, while the level on the GPIO line remains low, the DLN adapter repeatedly sends events. The value in the value
field stays the same. The eventCount
field increments for every new event. The interval between recurring events is equal to eventPeriod
milliseconds. You can calculate the time passed from the last level lowering (time = eventCount * eventPeriod
).
When the level on the GPIO line rises, the series of events ends. When the level on the line drops again, a new series of events begins. The eventCount
field is reset to zero.
A DLN adapter generates the DLN_GPIO_EVENT_ALWAYS
events periodically with the eventPeriod
interval regardless of the level on the pin and its changes. This event notifies the current signal level on a pin.
Call the DlnGpioPinSetEventCfg()function to configure events. Specify DLN_GPIO_EVENT_ALWAYS
as the eventType
parameter.
For the DLN_GPIO_EVENT_ALWAYS
events, the eventPeriod
parameter is required to be non-zero.
Immediately after you configure the DLN_GPIO_EVENT_ALWAYS
event, the DLN adapter sends the first event. The eventCount
field is set to zero and the value
field contains the actual value on the GPIO line. Then, the DLN adapter repeatedly sends events with the actual value on the line in the value
field. The interval between recurring events is equal to eventPeriod
milliseconds. The eventCount
field increments for each event in the series.
The changes of the level on the pin do not affect the eventCount
field. You can only reset it if you change the event configuration.