nrfcxx  0.1.0
C++-17 Framework for Nordic nRF5 Devices
Public Member Functions | Protected Types | Protected Member Functions | Protected Attributes
nrfcxx::lpm::lpsm_capable Class Reference

Base (or mixin) class for anything that supports a state_machine. More...

#include <nrfcxx/lpm.hpp>

Inheritance diagram for nrfcxx::lpm::lpsm_capable:
nrfcxx::misc::lipo_monitor nrfcxx::sensor::adc::lpsm_wrapper nrfcxx::sensor::bme280 nrfcxx::sensor::ccs811 nrfcxx::sensor::hts221 nrfcxx::sensor::lps22hb nrfcxx::sensor::sdp8xx nrfcxx::sensor::sht21

Public Member Functions

virtual int lpsm_start ()
 Validate and prepare to initiate an LPM collection. More...
 
virtual int lpsm_sample ()
 Ask the LPM infrastructure to initiate a new sample. More...
 
lpm::state_machine::process_flags_type lpsm_process ()
 Make progress on an LPM collection. More...
 
int lpsm_stop ()
 
int lpsm_reset ()
 
int lpsm_process_rc () const
 Get the internal result code from the last invocation of lpsm_process_(). More...
 
const lpm::state_machinemachine () const
 Gain read-only access to the LPM machine state.
 

Protected Types

using state_type = state_machine::state_type
 
using process_flags_type = state_machine::process_flags_type
 

Protected Member Functions

 lpsm_capable (notifier_type notify)
 Create a state machine that records state and supports delayed transitions. More...
 
virtual int lpsm_process_ (int &delay, process_flags_type &pf)
 Override to implement machine-specific operations of lpsm_process(). More...
 
virtual void lpsm_reset_ ()
 Override to reset state that is held outside the machine.
 

Protected Attributes

state_machine machine_
 

Detailed Description

Base (or mixin) class for anything that supports a state_machine.

This provides ownership of the machine, access to it, and the documentation and default implementation of the application-accessible machine operations.

Constructor & Destructor Documentation

◆ lpsm_capable()

nrfcxx::lpm::lpsm_capable::lpsm_capable ( notifier_type  notify)
inlineprotected

Create a state machine that records state and supports delayed transitions.

Parameters
notifyas with lpsm::state_machine.

Member Function Documentation

◆ lpsm_process()

lpm::state_machine::process_flags_type nrfcxx::lpm::lpsm_capable::lpsm_process ( )

Make progress on an LPM collection.

This function should be invoked when the application detects that the need-to-process signal has been set.

Returns
a set of flags such as lpm::state_machine::PF_OBSERVATION. If the machine is in an error state the returned value has no flags set.

◆ lpsm_process_()

virtual int nrfcxx::lpm::lpsm_capable::lpsm_process_ ( int &  delay,
process_flags_type &  pf 
)
inlineprotectedvirtual

Override to implement machine-specific operations of lpsm_process().

The wrapper confirms that the machine is not in off, error, or failed state before invoking this function. If an error is returned the wrapper puts the machine into an error state; otherwise it sets up any requested delay and returns the process flags to its caller.

Applications may observe the last returned value through the lpsm_process_rc() API.

Parameters
[out]delayset in the call to indicate that state_machine::post_event() should be invoked in support of either a blocking or fallback delay.
[out]pfprocess flags to return to the caller.
Returns
a negative value to mark the machine as being in an error state. Return non-negative if the machine was successful.

◆ lpsm_process_rc()

int nrfcxx::lpm::lpsm_capable::lpsm_process_rc ( ) const
inline

Get the internal result code from the last invocation of lpsm_process_().

This may be useful for diagnostics, but the value has no generic interpretation.

◆ lpsm_sample()

virtual int nrfcxx::lpm::lpsm_capable::lpsm_sample ( )
virtual

Ask the LPM infrastructure to initiate a new sample.

The default implementation confirms that the machine is in state_machine::MS_IDLE and initiates a transition to state_machine::MS_ENTRY_SAMPLE.

Note
This function is only used for machines that don't automatically generate new readings through an internal interval or event, such as sensor::sht21 or sensor::hts221 in one-shot mode. The declaration may be hidden on machines where it cannot be used.
Returns
zero on success, or a negative error code if the sample could not be initiated. An error return does not affect the machine state.

Reimplemented in nrfcxx::sensor::hts221, and nrfcxx::sensor::lps22hb.

◆ lpsm_start()

virtual int nrfcxx::lpm::lpsm_capable::lpsm_start ( )
virtual

Validate and prepare to initiate an LPM collection.

This should be invoked to transfer a machine from state_machine::MS_OFF. The default implementation initiates a move to state_machine::MS_ENTRY_START.

Note
Invoking this merely validates and prepares the state machine for execution. To initiate the collection lpsm_process() must be invoked consequent to detecting the need-to-process event.
Subclasses may override or post-extend superclass implementations.
Returns
zero on success, or a negative error code if starting the machine is not permitted.

◆ lpsm_stop()

int nrfcxx::lpm::lpsm_capable::lpsm_stop ( )
inline
Todo:
figure out how machines should be stopped

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