PAL_AMB-behavior
PAL AMBIENT SENSE PAL is used to acquire sensor values.
[BEHAVIOR] (./) is used to describe the Parent Node Child Node.
The sensor is described directly using
Wire
instead of using the board behavior function to obtain values.Child Nodes are described by a state machine.
See the explanation of BRD_APPTWELITE, the explanation of PAL_AMB, and the explanation of PAL_AMB-usenap before the explanation of this ACT. Also see the description of BEHAVIOR.
This sample shows how to write BEHAVIOR. BEHAVIORS are used to describe more complex applications.
ACT FEATURES.
Uses the environmental sensor PAL AMBIENT SENSE PAL to acquire sensor values.
Use the sleep function to operate with coin cell batteries.
How to use ACT
Preparation for TWELITE
Role | Example |
---|---|
Parent Node | |
Child Node |
When using PAL as the Parent Node, coin cell batteries cannot be used. As a rule of thumb, prepare a power supply environment that can provide a stable current of 50 mA or more.
File Structure
PAL_AMB-behavior.hpp : Only
setup()
is defined. read DIP-SW and if D1..D3 is upper position, it works as Parent Node, otherwise it sets ID corresponding to DIP SW as Child Node.Parent/myAppBhvParent.hpp : behavior class definition for Parent Node
Parent/myAppBhvParent.cpp : implementation
Parent/myAppBhvParent-handlers.cpp : implementation of handlers
Parent/myAppBhvParent.hpp : behavior class definition for Child Nodes
Parent/myAppBhvParent.cpp : implementation
Parent/myAppBhvParent-handlers.cpp : implementation of handlers
The Parent Node's BEHAVIOR name is <MY_APP_PARENT>
and the Child Node is <MY_APP_CHILD>
.
Build files can be added by Makefile description /... /install_n_build/makefile.md).
Initialization setup()
If the DIP SW reading is 0, register the behavior <MY_APP_PARENT>
for the Parent Node, otherwise register the behavior <MY_APP_CHILD>
for the Child Node.
If the Parent Node is MONOSTICK, the DIP SW for PAL reads 0 and behaves as the Parent Node. However, this behavior is not defined in the MONOSTICK specifications.
Parent Node BEHAVIOR
The Parent Node behaves as a non-sleeping receiver and outputs packet information to the serial port when it receives a packet from a Child Node.
MY_APP_PARENT::receive()
When a packet is received for the Parent Node, if the first four characters of the packet can be matched (FOURCHARS
), the contents of the packet are displayed.
MY_APP_PARENT::MWX_TICKTIMER_INT()
The Parent Node's interrupt handler blinks the LED.
MY_APP_PARENT::MWX_DIO_EVENT(PAL_AMB::PIN_BTN)
When the button (5) on the PAL is pressed, the E_ORDER_KICK
event is issued to the state machine.
MY_APP_PARENT::MWX_STATE(E_MWX::STATE_0 .. 3)
The state machine is described as a reference for state transitions and is not meaningful for the operation of the application. It executes state transitions by the E_ORDER_KICK event sent from the button, timeouts, and so on.
BEHAVIOR of Child Node
The behavior flow of the Child Node is the same as that of the PAL_AMB-usenap. From the initial sleep, "wake up → start sensor operation → short sleep → wake up → acquire sensor value → wireless transmission → wait for wireless transmission completion → sleep" is repeated.
MY_APP_CHILD::on_begin()
The _begin()
function, called from on_begin()
, executes the first sleep.
(*It is acceptable to describe this process directly in on_begin()
without describing it in _begin()
function.)
MY_APP_CHILD::wakeup()
This is a description of the process of waking up from sleep.
The first time Wire.begin()
is executed here, which is redundant for the second and later times when the device wakes from sleep. This process can be moved to on_begin()
.
MY_APP_CHILD::transmit_complete()
Processes E_ORDER_KICK
messages to the state machine upon completion of transmission.
MY_APP_CHILD::transmit_complete()
Defines the state name.
MY_APP_CHILD::shtc3_???()
This is an example of sensor acquisition implementation for SHTC3. For details on sending commands, etc., refer to the SHTC3 datasheet.
MY_APP_CHILD::ltr308als_???()
This is an example of LTR308ALS sensor acquisition implementation. Please refer to the LTR308ALS datasheet for details on sending commands, etc.
WireWriteAndGet()
sends 1 byte of cmd
to the device of addr
, then receives 1 byte and returns the value.
MY_APP_CHILD::STATE_IDLE (0)
State 0 has a special meaning. It is the state immediately after startup or after returning from sleep.
Immediately after startup PEV_is_coldboot(ev,evarg)
judgment becomes true
and is called. Since it goes straight to sleep from on_begin()
, it does not contain any code that transitions the state. **At this point, the major initialization has not yet been completed, so complex processing such as sending wireless packets cannot be performed. **In order to perform the first state transition for such processing, send an event from on_begin()
and perform the state transition according to that event.
After returning from sleep, there is a first call to PEV_is_warmboot(ev,evarg)
which will be true
. A call to PEV_SetState()
will transition to the STATE_SENSOR
state.
MY_APP_CHILD::STATE_SENSOR
When the transition is made from STATE_IDLE
after returning from sleep, the state handler for STATE_SENSOR
is called continuously. The event ev
at this time is E_EVENT_NEW_STATE
.
Here, the operation of two sensors, SHTC3 and LTR308ALS, is started. After a certain period of time, the sensors will be ready to acquire data. This time wait is done with the sleep setting of 66
ms. Note that PEV_KeepStateOnWakeup()
is called before sleep. After this call, the state after returning from sleep is not STATE_IDLE
, but the state it was in when it went to sleep, i.e. STATE_SENSOR
.
When returning from a short sleep, a call is first made with the PEV_is_warmboot(ev,evarg)
decision set to true
. At the time of this call, wireless packets can be sent, etc. Transition to STATE_TX
.
MY_APP_CHILD::STATE_TX
Here, at the time of the E_EVENT_NEW_STATE
event, the sensor data reading and wireless packet transmission procedures are started. Please refer to other act sample examples for details of the transmission procedure.
Unlike the ACT description in the loop, the process of waiting for the message by PEV_Process()
from transmit_complete()
is used as a confirmation of completion. Sleep is performed upon receipt of the message. Sleep processing is done by transitioning to STATE_SLEEP
.
Finally, timeout processing is performed. This is in case the completion message of the sent packet has not been returned. PEV_u32Elaspsed_ms()
returns the elapsed time since the transition to that state in milliseconds [ms]. If the time has elapsed, the above will perform a system reset the_twelite.reset_system()
(assuming this timeout is too much).
MY_APP_CHILD::STATE_SLEEP
Perfom sleep. Describe it in E_EVENT_NEW_STATE
immediately after the transition from the previous state. Since other events may be called just before sleep, be sure to execute the_twelite.sleep()
in a decision expression that is executed only once.
最終更新