State and functionality related to monitoring dry contacts.
More...
#include <nrfcxx/sensor/contact.hpp>
|
template<typename INTEGRAL > |
static constexpr INTEGRAL | ts_from_ms (INTEGRAL dur_ms) |
| Calculate a timestamp duration derived from milliseconds.
|
|
template<typename INTEGRAL > |
static constexpr INTEGRAL | utt_from_ts (INTEGRAL dur_ts) |
| Calculate an uptime duration derived from timestamp ticks.
|
|
template<typename DurT = duration_type> |
constexpr static DurT | to_duration (timediff_type dts) |
| Generic conversion from timestamp ticks to a std::chrono::duration type. More...
|
|
static timestamp_type | now () |
| Get the full-scale current time in the representation of recorded contact events.
|
|
static reduced_timestamp_type | timestamp () |
| Get the reduced-range current time in the representation of recorded contact events. More...
|
|
static bool | state_from_ordinal (ordinal_type eo) |
| Synthesize pin state from an event ordinal.
|
|
|
uint8_t const | psel |
| The GPIO pin on which the contact is monitored.
|
|
◆ change_callback_bi
Signature for a contact state change notification.
- Parameters
-
- Note
- If the contact state changes fast enough that state_type::ordinal increments multiple times, the notification will occur after the last increment.
-
Functions with this signature are expected to be invoked when the GPIOTE IRQ is blocked.
◆ duration_type
Full precision duration type for timestamp clock.
- Warning
- As with other std::chrono durations the representation type is signed, so be careful if a negative duration might end up in a context where it's converted to an unsigned counter value.
◆ reduced_timestamp_type
The type used for stored contact state changes.
The value of the timestamp will be as though obtained through timestamp(). At the default TIMESTAMP_Hz of 128 the timestamp wraps at the same interval as clock::uptime::now24().
◆ timestamp_type
The type used for full-scale contact state change event times.
See now().
◆ contact()
Construct and configure a contact with callback on change.
- Parameters
-
psel | the GPIO pin number on which the contact will be monitored. |
callback | function invoked when the contact state changes. |
pin_cnf | the pin configuration to use for the GPIO identified by psel_ . |
◆ epoch_ts()
The absolute time at which the contact initial state was captured.
Values are from the range of now().
◆ event_listener()
Construct a GPIOTE event listener for contact state changes.
This method allows contacts to use hardware notifications of state changes:
auto notify = [&events](ordinal_type ordinal) {events.set(EVT_BUTTON1);};
contact ordinal1{NRFCXX_BOARD_PSEL_BUTTON1, notify, pin_cnf};
auto b0ch = GPIOTE::allocate();
b0ch->config_event(ordinal1.psel);
GPIOTE::event_listener button1{ordinal1.event_listener(*b0ch)};
button1.enable();
b0ch->enable_event();
◆ live_state()
bool nrfcxx::sensor::contact::live_state |
( |
| ) |
const |
|
inline |
Read the contact state.
A logic high level is considered closed and is represented by true
.
A logic low level is considered open and is represented by false
.
◆ record_change_bi()
void nrfcxx::sensor::contact::record_change_bi |
( |
bool |
double_tap = false | ) |
|
Update the ordinal to reflect a state change.
Increment the ordinal to reflect a state change, recording the current time as the time when the change occurred.
If double_tap
we've been informed that there was a state change, but the observed state is the same as the last one, so record a second, concurrent, state change.
- Parameters
-
double_tap | if true record two changes. |
◆ recorded_state_bi_()
bool nrfcxx::sensor::contact::recorded_state_bi_ |
( |
| ) |
const |
|
inlineprotected |
Return the last confirmed contact state.
Values match those of live_state().
◆ sense_listener()
Construct a GPIOTE sense listener for contact state changes.
This method allows contacts to use a shared hardware notification of state changes:
auto notify = [&events](ordinal_type ordinal) {events.set(EVT_BUTTON1);};
contact ordinal1{NRFCXX_BOARD_PSEL_BUTTON1, notify, pin_cnf};
GPIOTE::sense_listener button1{ordinal1.sense_listener()};
GPIOTE::enable_sense();
button1.enable();
- Warning
- If the sense returns to its original state prior to the GPIOTE FLIH executing no change will be detected. This is in contrast to the use of event_listener(), which will detect even transient changes but at the cost of requiring a dedicated GPIOTE resource.
◆ snapshot()
state_type nrfcxx::sensor::contact::snapshot |
( |
| ) |
const |
◆ timestamp()
Get the reduced-range current time in the representation of recorded contact events.
This is equivalent to but faster than fetching the low 16 bits of now().
◆ to_duration()
template<typename DurT = duration_type>
constexpr static DurT nrfcxx::sensor::contact::to_duration |
( |
timediff_type |
dts | ) |
|
|
inlinestaticconstexpr |
Generic conversion from timestamp ticks to a std::chrono::duration type.
- Template Parameters
-
DurT | the duration type to use. |
- Parameters
-
ts | the difference between two timestamps. |
The documentation for this class was generated from the following file: