For suitable output, we recommend to use Google Chrome (15+) or Microsoft Edge (79+).
As of 2025-07-24Callback Functions
Various callback functions
These are callback functions where the application description is written. Callback means that it is called from the system (library). By defining several callback functions, the user describes the behavior of the system.
The following callback functions are mandatory definitions.
Functions other than these will be linked as empty functions that do nothing if not defined.
Normal callback invocation order
init_coldboot()
↓ (TWENET internal processing: Initialization 1)
setup()
↓ (TWENET internal processing: Initialization 2)
begin() --- only once
↓
loop() <--+
↓ | Event processing, behavior processing
CPU DOZE -+
If you want to refer to the exact behavior, please refer to the source code mwx_appcore.cpp
.
Callback invocation order when waking up from sleep
the_twelite.sleep()
↓ sleeping...
init_warmboot()
↓ (TWENET internal processing: Initialization 3)
wakeup()
↓ (TWENET internal processing: Initialization 4)
loop() <--+
↓ | Event processing, behavior processing
CPU DOZE -+
If you want to refer to the exact behavior, please refer to the source code mwx_appcore.cpp
.
1 - setup()
Initialization process
Called at the beginning of code execution; write initialization code here.
TWENET initialization is also executed after the setup()
function finishes. Since many processes are designed to run after TWENET completes, please do not perform any operations other than initialization here.
The following points should be noted:
- You cannot execute sleep
the_twenet.sleep()
. If you want to sleep immediately after initialization, write the initial sleep process inside the begin()
function. - The
delay()
function is replaced by the process described below. In this case, the parameter ms
does not specify milliseconds.
static inline void delay(uint32_t ms) {
volatile uint32_t ct = ms * 4096;
while (ct > 0) {
--ct;
}
}
2 - begin()
Initialization process (after TWENET initialization)
Called only once just before the first call of the loop()
function. Since TWENET initialization is complete, there is no need to consider constraints like those in setup()
.
Mainly used in the following situations:
- Displaying the startup message
- Writing test code
- Transitioning to sleep immediately after startup
- Processing that is problematic in
setup()
(wireless packet processing, timer operation, etc.)
This callback function definition is optional.
3 - loop()
Loop processing
This is the main loop of the application. After the loop ends, the CPU transitions to DOZE mode and waits for the next interrupt with low power consumption.
In Act, most processing is written inside this loop.
Defining the callback function is optional.
4 - wakeup()
Processing after waking from sleep
Called before transitioning to loop()
after waking from sleep, this function includes procedures for initialization after waking and branching processes according to the wake-up state.
If there are only processes such as sensor readings and no processing in loop()
, you can execute sleep again within this function.
This callback function definition is optional.
5 - init_coldboot()
Initialization process (before peripheral initialization)
Called at the re-initialization of code execution, before peripheral API and initialization have been performed.
This callback function definition is optional.
6 - init_warmboot()
Process after waking from sleep (before peripheral initialization)
Called again after waking from sleep, before the peripheral API is initialized.
This function can detect the cause of interrupts.
This callback function definition is optional.
7 - on_rx_packet()
Processing upon packet reception
Describes the process when a received packet is received.
void on_rx_packet(mwx::packet_rx& pkt, bool_t &b_handled)
When a wireless packet is received, this function is called from within the MWX library with the data stored in pkt
as packet_rx
. If this function is not defined in the application, a weak function that does nothing will be linked.
If true is set to b_handled
within this function, it notifies the MWX library that the received packet has been processed within the application. When marked as processed, unnecessary processing is suppressed (the processing of the_twelite.receiver
is not performed).
When using
Behaviors, please use the callback functions within the behavior.
the_twelite.receiver
is not recommended.
Previously, processing using the_twelite.receiver
was intended to be written inside loop()
, but due to the queuing delay processing, packet loss can occur in principle, and the code tends to become complicated. Therefore, on_rx_packet()
was added.
8 - on_tx_comp()
Processing upon packet transmission completion
Describes the processing performed when the transmission is completed.
void on_tx_comp(mwx::packet_ev_tx& ev, bool_t &b_handled)
This function is called within the MWX library when the wireless packet transmission is finished, with data stored in ev
as packet_ev_tx
. If this function is not defined in the application, a do-nothing weak function is linked.
ev.u8CbId
is the ID at transmission, and ev.bStatus
is a flag indicating transmission success (1) or failure (0).
If true is set to b_handled
within this function, it informs the MWX library that the received packet has been processed within the application. When marked as processed, unnecessary processing is suppressed (event callback functions are not called for the_twelite.app
, .board
, or .settings
).