Events

An event is an asynchronous notification from the MetaWear board represented in the C++ API by the MblMwEvent struct.

Recording Commands

The board can be programmed to execute MetaWear commands in response to an event firing. To start recording commands, call mbl_mw_event_record_commands. While in a recording state, all MetaWear functions called will instead be recorded on the board and executed when the event is fired.

To stop recording, call mbl_mw_event_end_record. This function is asynchronous and will alert the caller when it is completed via a callback function. If recording events was successful, MBL_MW_STATUS_OK will be passed into the callback function, otherwise MBL_MW_STATUS_ERROR_TIMEOUT is used.

#include "metawear/core/event.h"
#include "metawear/core/settings.h"

void setup_dc_event(MblMwMetaWearBoard* board) {
    MblMwLedPattern pattern;
    mbl_mw_led_load_preset_pattern(&pattern, MBL_MW_LED_PRESET_BLINK);
    pattern.repeat_count = 10;

    // Setup disconnect event to blink the blue led 10x when fired
    MblMwEvent* dc_event = mbl_mw_settings_get_disconnect_event(board);
    mbl_mw_event_record_commands(dc_event);
    mbl_mw_led_write_pattern(board, &pattern, MBL_MW_LED_COLOR_BLUE);
    mbl_mw_led_play(board);
    mbl_mw_event_end_record(dc_event, nullptr, [](void* context, MblMwEvent* event, int32_t status) {
        if (!status) {
            cout << "Error recording commands, status= " << status << endl;
        } else {
            cout << "Commands recorded" << endl;
        }
    });
}