Macro

The Macro class programs MetaWear commands to the on-board flash memory, which can either be executed on boot or at a later time.

Recording a Macro

To record a macro, call the record method. The method takes in a Macro.CodeBlock that encapsulates the MetaWear commands to program. By default, the code block will execute on boot. To disable exec on boot, override the execOnBoot method to return false.

The record method returns an AsyncOperation that holds an ID referencing the macro, which can be used with the execute method. The normal execute function will alert the caller of when the macro has finished executing whereas the silentExecute variant will only execute the commands.

import com.mbientlab.metawear.module.Led;
import com.mbientlab.metawear.module.Macro;

// Turn on the LED on boot
final Led ledModule= mwBoard.getModule(Led.class);
final Macro macroModule= mwBoard.getModul(Macro.class);
macroModule.record(new Macro.CodeBlock() {
    @Override
    public void commands() {
        ledModule.configureColorChannel(Led.ColorChannel.BLUE)
            .setRiseTime((short) 0).setPulseDuration((short) 1000)
            .setRepeatCount((byte) 5).setHighTime((short) 500)
            .setHighIntensity((byte) 16).setLowIntensity((byte) 16)
            .commit();
        ledModule.play(false);
    }
});

Erasing Macros

Erasing macros is done with the eraseMacro method. The erase operation will not occur until you disconnect from the board.

macroModule.eraseMacros();
mwBoard.disconnect();