Releases: mbientlab/MetaWear-SDK-Android
API 2.0.0 Released
Version 2.0.0 completely revamps the API to enable users to write cleaner MetaWear code. Gone are the days of micro-managing callback functions, storing IDs, and registering BroadcastReceivers.
Features
- Adds a class dedicated to handling asynchronous tasks e.g. reading rssi values
- Adds a Java DSL to express what to do with sensor data
- Supports both MetaWar R and R+Gyro in the same library
- Older 1.X.X releaeses only work with MetaWear R
- Unifies streaming and logging data
- Executes asynchronous tasks on background threads
- Can be configured to execute tasks on the UI thread if desired
- Macro system refactored to simplify the programming of complex command chains
Breaking Changes
For users updating from beta 04, there are many breaking changes introduced after scrutinizing the code. Most of these changes were renaming methods and classes,and some class reorganization, which primarily affect the data routes.
Change List
- Reorganized the Message subclasses
- Removed RouteBuilder class
- Data routes are now created from their respective module classes
- Changed getModule function signature to include a checked exception
- For dealing with sensors not shared across all boards e.g. barometer and light sensor
- Renamed AsyncResult to AsyncOperation
- Renamed functions that modify settings to begin with "configure"
- Renamed config editor functions to begin with "set"
- Renamed processor StateEditor class to State
- Moved MetaWearBleService from the impl package to the main package
- Renamed Mode enum used by delta, threshold, and time processors to OutputMode
- Renamed Math processor class to Maths
- Avoids naming conflict with java.lang.Math
- URI scheme name is still math
- Renamed OutputType enum used by the pulse processor to OutputMode
- Renamed ActivityMonitor to ActivityHandler
- Renamed subscribe to stream
- Renamed assignProcessor and removeProcessor to subscribe and unsubscribe respectively
- Renamed assignLogProcessor to setLogMessageHandler
- Moved MessageProcessor class from DataSignal to RouteManager and renamed to MessageHandler
- Time processor constructor changed to first take in an OutputMode value
API v2.0.0 Beta Release 04
Beta release 04 irons out macro system, adds support for the accelerometer detection features on the MetaWear R board, and refactors several module classes. This update will have breaking changes from beta 03
Features
- Add support for configuring and interacting with tap, shake, orientation, and motion detection on the MetaWear R accelerometer
- Modified how macros are added to support programing data routes to the flash memory
- See below section about recording macros
- Expanded AsyncResult functionality
- Can directly access the result object without needing a CompletionHandler
- Added serialization of the MetaWear state
- Added callback function in DownloadHandler class to handle unknown entries received by the device
Breaking Changes
- Refactored the RouteManager class
- Removed getDataProcessor and getSubscription functions
- Added functions to attach log and subscriber processors
- Moved DataProcessor class into the module package and only allow it to be accessed through an ActivityMonitor
- Renamed MwrAccelAxisMessage and MwrAccelCombinedAxisMessage to Mma8452qAxisMessage and Mma8452qCombinedAxisMessage respectively
- Changed function signatures for subscribe and log to only take in a string value
- See below section about subscribers and loggers
- Replaced createTimer function with scheduleTask
- See below section about scheduling timer tasks
- Changed Logging module so users explicitly control the logger
Recording Macros
The Macro class, and subsequently recording macros, has changed in beta 04. The record function now takes in a CodeBlock object, which is used to wrap the MetaWear commands you want to write to the board. For example, to have the blue LED flash 5 times on boot:
final Led ledModule= mwBoard.getModule(Led.class);
mwBoard.getModule(Macro.class).record(new Macro.CodeBlock() {
@Override
public void commands() {
ledModule.writeChannelAttributes(Led.ColorChannel.BLUE)
.withRiseTime((short) 0).withPulseDuration((short) 1000)
.withRepeatCount((byte) 5).withHighTime((short) 500)
.withHighIntensity((byte) 16).withLowIntensity((byte) 16)
.commit();
ledModule.play(false);
}
})
Subscribers and Loggers
Adding subscribers and loggers have changed to support programming routes with the Macro module. Instead of passing in a MessageProcessor object when calling subscribe or log, you instead will pass in a key that identifies the subscriber/logger. When the route is committed, you can then attach a MessageProcessor by using the key passed into the subscribe or log functions. Keep in mind that keys must be uniquely named, though a subscriber and logger can share the same key.
final String gpioAdc0Key= "gpio_adc_0";
mwBoard.routeData().fromAnalogGpio((byte) 0, Gpio.AnalogReadMode.ADC).log(gpioAdc0Key)
.commit().onComplete(new CompletionHandler<RouteManager>() {
@Override
public void success(RouteManager result) {
result.attachLogProcessor(gpioAdc0Key, new DataSignal.MessageProcessor() {
@Override
public void process(final Message msg) {
Log.i("example", String.format("%d", msg.getData(Short.class)));
}
});
}
});
final String tempKey= "temperature";
mwBoard.routeData().fromTemperature().subscribe(tempKey)
.commit().onComplete(new CompletionHandler<RouteManager>() {
@Override
public void success(RouteManager result) {
result.attachProcessor(tempKey, new DataSignal.MessageProcessor() {
@Override
public void process(final Message msg) {
Log.i("example", String.format("%.3f", msg.getData(Float.class)));
}
});
}
});
Scheduling Timer Tasks
Since timers primarily used to schedule MetaWear tasks, scheduling tasks has been more integrated with the Timer module. Instead of setting timer parameters and scheduling tasks separately, this has all been taken care of in one function.
///< Schedules a gpio ADC read to occur every 500 ms, repeat indefinitely
mwBoard.getModule(Timer.class).scheduleTask(new Timer.Task() {
@Override
public void commands() {
mwBoard.getModule(Gpio.class).readAnalogIn((byte) 0, Gpio.AnalogReadMode.ADC);
}
}, 500, false);
API v2.0.0 Beta Release 03
Release beta.03 is a quick bug fix for beta.02.
API v2.0.0 Beta Release 02
The second v2.0.0 beta release adds support for the remaining MetaWear modules and enhances the functionality of the data routes. This release also introduces a breaking change to the DataSignal and Accelerometer classes.
Features
- Added support for the remaining modules: IBeacon, NeoPixel, Haptic, I2C, Maco, and Settings
- Added new features for data processors
- Added delta, sample, and threshold data processors
Breaking Changes
- Combined filter and transform functions into one process function
- Replaced DataFilter and DataTransformer interfaces with ProcessorConfig
- Changed function signature for onSignalActive callback function
- Function takes in a Map and MessageToken
- Accelerometer class separated into Mma8452qAccelerometer and Bmi160Accelerometer
- Accelerometer class is a generic class that maps the parameters to the appropriate configuration while the other two classes are for specific accelerometers on the R and Rgyro boards
Data Processor Features
The processors that are added in a route can be assigned a key and accessed at a later point in time. You can use the DataProcessor class to modify a processor's internal state or configuration. Data processors can be retrieved from a RouteManager or in an ActivityMonitor
final String procKey= "passthroughKey1";
mwBoard.routeData().fromTemperature()
///< Only allow 8 data samples through
.process(procKey, new Passthrough(Passthrough.Mode.COUNT, (short) 8))
.subscribe(new DataSignal.MessageProcessor() {
@Override
public void process(Message msg) {
Log.i("test", String.format("Passthrough temp: %.3f", msg.getData(Float.class)));
}
}).commit(new CompletionHandler<RouteManager>() {
@Override
public void success(final RouteManager result) {
mwBoard.routeData().fromSwitch().monitor(new DataSignal.ActivityMonitor() {
@Override
public void onSignalActive(Map<String, DataProcessor> processors, MessageToken signalData) {
///< When the button is pressed or release, set the passthrough filter state to allow
///< another 8 samples through
result.getDataProcessor(procKey).setState(new Passthrough.PassthroughStateEditor((short) 8));
///< Note that the processors function parameter contains named processors in the current route.
///< In this case, we want the processor from the temperature route, so we use its RouteManager
}
}).commit();
}
);
Bug fixes for 1.9.0
Version 1.9.3 fixes the attempted bug fix in v1.9.0 and removes the launcher icons from the resource directory.
Accelerometer Triggers
Version 1.9.0 adds triggers for tap, motion / free fall, and shake events and fixes two bugs with the API. Javadocs of the release are available on the MbientLab website (https://mbientlab.com/docs/metawear/android/1.9.0/).
Features
- Adds trigger definitions for tap, motion / free fall, and shake events
- Adds functions to convert logged data for aforementioned accelerometer events to objects
- Fixes NegativeArraySizeException when reading I2C data
- Fixes NullPointerException in the MetaWearBleService class
Code Changes
LoggingTrigger
- Added ACCELEROMETER_MOTION, ACCELEROMETER_SHAKE, and ACCELEROMETER_TAP entries to the enum
BytesInterpreter
- Added byteToMotionData, byteToShakeData, and byteToTapData functions
- These functions are converting data from logged tap, motion, and shake events
API v2.0.0 Beta Release 01
This is the first beta release of Android API v2.0.0. Version 2.0.0 has several new features to simplify tasks that would have resulted in callback hell e.g. setting up a data processing chain. The release is not compatible with previous APIs so you will need to overhaul your code to use this beta release. Instructions on integrating the library into your project are in the project's README the wiki has more details on v2.0.0 features. Sample code is provided in the example module.
Attached is the jar version of this release for users who require a direct download.
Major Changes
- Background MetaWear service no longer communicates to apps via a BroadcastReceiver. All asynchronous responses are executed in the background.
- UI tasks in callback functions need to be explicitly run on the UI thread
- Callbacks for receiving asynchronous responses (i.e. reading RSSI values) are replaced with the AsyncResult class.
- Java DSL to express how sensor data should be manipulated and routed.
- More details are on the project's wiki
- Encapsulate sensor data with Message class
- Renamed main package to com.mbientlab.metawear
Support for Custom Scan Response
Version 1.8.0 adds support for customizing the Bluetooth scan response. You can use this feature to turn your MetaWear into a beacon, such as a UriBeacon
Code Changes
Settings
- Added setScanResponse method
Small Feature Update
Version 1.7.0 adds a few minor features to the API and fixes some small bugs with the library. Check out the project's README for instructions on adding this release as a compile dependency.
Features
- Fixes a bug with the delay parameter in the startTimer method
- Older API used the parameter incorrectly which resulted in having to pass in the opposite boolean value
- Fixes bug with waitToClose method
- Added support for new operations in the MathBuilder class
- Added support for circular buffer mode for the Logging module
Code Changes
MathBuilder
Logging
- Added overloaded startLogging method which can enable circular buffer mode
Bug Fixes and Android Studio Migration
Version 1.6.21 fixes some bugs with v1.6.0 and addresses some compatibility issues with Android 5.0.1 (SDK 21). The project has been migrated to Android Studio 1.1.0. Check the project's README file for instructions on adding the the API as a dependency to a MetaWear project. Documentation for v1.6.21 is available on our docs page.
Features
- Fixes bug with temperature polling for firmware v1.x
- Fixed bug that allowed the same callback function to be registered multiple times
- Fixes compatibility issue with Android 5.0.1 (SDK 21)
- Migrated project to Android Studio
Code Changes
Temperature
- Used correct increment when converting between temperature and bytes for temperature sampling
- This change requires at minimum firmware v1.0.0
MetaWearBleService
- Changed non-zero status for a disconnect event to call the disconnected callback function rather than the receivedGattError function
- Bug occurs on Android 5.0.1 devices that has its BLE connection severed by the board (i.e. board resets)