Macro¶
The on-board flash memory can also be used to store MetaWear commands instead of sensor data.
A good example of this feature is to change the name of a device permanently so that is does not advertise as MetaWear.
Recorded commands can be executed any time after being programmed with the functions in macro.h header file.
Recording Commands¶
To record commands:
Call mbl_mw_macro_record to put the API in macro mode
Use the MetaWear commands that you want programmed
Exit macro mode with macroEndRecord
mbl_mw_macro_record(device.board, 1)
// COMMANDS TO RECORD GO HERE
device.macroEndRecord()
Macros can be set to run on boot by setting the exec_on_boot
parameter with a non-zero value.
mbl_mw_macro_record(board, 1) // ON BOOT
mbl_mw_macro_record(board, 0) // NOT ON BOOT
In this example, the LED will blink blue on boot:
// Record everything to startup macro
mbl_mw_macro_record(device.board, 1)
// Setup LED
mbl_mw_led_stop_and_clear(device.board)
// Success flash
var greenPattern = MblMwLedPattern(high_intensity: 31,
low_intensity: 0,
rise_time_ms: 100,
high_time_ms: 200,
fall_time_ms: 100,
pulse_duration_ms: 800,
delay_time_ms: 0,
repeat_count: 3)
mbl_mw_led_write_pattern(device.board, &greenPattern, MBL_MW_LED_COLOR_GREEN)
mbl_mw_led_play(device.board)
// Finish off this macro
device.macroEndRecord()
Erasing Macros¶
Erasing macros is done with the mbl_mw_macro_erase_all method. The erase operation will not occur until you disconnect from the board.
mbl_mw_macro_erase_all(board);