.. highlight:: java Settings ======== Developers can use the `ISettings `_ module to configure ble pereferences and retrieve general board information. You can combine preference changes with the :doc:`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: * https://devzone.nordicsemi.com/question/53348/advertising-interval-and-advertising-timeout/?answer=53385#post-id-53385 * https://devzone.nordicsemi.com/question/39731/range-of-values-for-tx-power/?answer=39733#post-id-39733 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: * https://devzone.nordicsemi.com/question/60/what-is-connection-parameters/ :: // 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())) ); 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(); 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())) ); 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());