SM_SIMPLE is provided to wait for processing such as state transitions, waiting for timeouts, and completion of transmission in the sample code.
The following is a basic code excerpt from SM_SIMPLE.
To use SM_SIMPLE, you need to define an enum class
as a list of states. In the above, it is defined as STATE
. The class object is generated as SM_SIMPLE<STATE> step;
with this stage as a parameter. The generated class object should be initialized by .setup()
.
The initial state of SM_SIMPLE has the value 0, corresponding to STATE::INIT
in the above example. To get the current state, use .state()
and use it as a judgment expression in the switch clause of the do while statement as in the above example.
Call .next()
for state transitions. If the state changes, b_more_loop()
is set to true
and the loop in the do while clause is executed again. In the example, calling .next(STATE::TX)
from the STATE::SENSOR
state will cause the loop to be executed again and the case STATE::TX:
clause will also be executed. If the state is not changed, the do while loop is escaped and the loop()
is terminated once. Wait until the next call to loop()
.
If you want to wait for processing such as completion of transmission, call .clear_flag()
, and then signal the completion of processing by .set_flag(uint32_t)
in another callback function or the like. Parameters of type uint32_t
specified here can be read from .get_flag_value()
.
If you want to process a timeout, you can record the time when you call .set_timeout(uint32_t)
and check if the timeout time has elapsed with .is_timeout()
.
SM_SIMPLE will be used again when returning from sleep, but it should always be called .on_sleep(bool)
before sleep. If you put false
in the parameter, it will start from the 0
state after recovery, and if you put true
, it will resume from the state just before sleep.
The following is the source code for SM_SIMPLE.
Contents may change depending on the version.
The main body will be stored in SM_SIMPLE.hpp in the mwx library resource folder.