Settings

Developers can use the ISettings module to configure ble pereferences and retrieve general board information. You can combine preference changes with the Macro module to make them permanent.

import com.mbientlab.metawear.module.Settings;

final Settings settings = board.getModule(Settings.class);

Ble Advertising

Advertising parameters control how the Bluetooth LE radio sends its adversiting packets and are configured with the EditBleAdConfig function. You can configure parameters such as the device name, timeout, tx power, and scan response.

import com.mbientlab.metawear.module.Settings;

settings.EditBleAdConfig(name: "AntiWare", timeout: 100, interval: 1024, txPower: -4);

Check out these posts from the Nordic Developer Zone if you are unsure of what these parameters do:

Connection Parameters

Bluetooth LE connection parameters control how the ble devices communicate with each other. Configuring thes parameters is done with the EditBleAdConfig function. A more detailed explanation on connection parameters can be found on the Nordic Developer Zone:

// change min conn interval to 100ms,
// max conn interval to 1024ms
settings.EditBleAdConfig(minConnInterval: 100f, maxConnInterval: 1024);

Battery State

Battery state is defined as a forced data producer and represented by the BatteryState class. Unlike reading the battery characteristc with the MetaWearBoard class, reading the battery state with the Settings module lets you use the battery data with the route API.

await settings.Battery.AddRouteAsync(source => source.Stream(data =>
    Console.WriteLine("battery = " + data.Value<BatteryState>()))
);
settings.Battery.Read();

Handling Disconnects

The board can be programmed to react to a disconnect by registering an IObserver with the onDisconnectAsync function.

await settings.OnDisconnectAsync(() => {
    ILed led = metawear.GetModule<ILed>();
    led.EditPattern(Color.Red, Pattern.Solid, count: 2);
    led.Play();
});

Power Status

Firmware v1.3.2 exposes battery charging and power status notifications which provides information on when the battery is charging / not charging and when a power source is attached / removed, respectively. The data is interpreted as a byte or boolean with 1 (true) signifying battery charging / power source attached, and 0 (false) meaning battery not charging / power source removed. Not all boards support this feature and a null pointer will be returned if PowerStatus or ChargeStatus is called on an unsupported board.

await settings.PowerStatus.AddRouteAsync(source =>
    source.Stream(data => Console.WriteLine("Power source state changed: " + data.Value<byte>()))
);

In addition to the data route system, you can directly read the current statuses independent of the data route API by calling ReadAsync.

Console.WriteLine("Current charge status = " + await settings.ChargeStatus.ReadAsync());