Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
public class DeviceSetupActivityFragment extends Fragment implements ServiceConnection {
private long delay= 30000L;
private final Handler handler= new Handler();
private final MetaWearBoard.ConnectionStateHandler connHandler= new MetaWearBoard.ConnectionStateHandler() {
@Override
public void connected() {
try {
mwBoard.getModule(Logging.class).downloadLog(0.25f, new Logging.DownloadHandler() {
@Override
public void onProgressUpdate(int nEntriesLeft, int totalEntries) {
Log.i("starter", String.format(Locale.US, "Progress: %d/%d", nEntriesLeft, totalEntries));
if (nEntriesLeft == 0) {
mwBoard.disconnect();
}
}
});
} catch (UnsupportedModuleException e) {
e.printStackTrace();
}
}
@Override
public void disconnected() {
Log.i("starter", "Scheduling connect attempt in 30 seconds");
handler.postDelayed(new Runnable() {
@Override
public void run() {
mwBoard.connect();
}
}, delay);
}
@Override
public void failure(int status, Throwable error) {
Log.i("starter", "Scheduling connect attempt in 30 seconds");
handler.postDelayed(new Runnable() {
@Override
public void run() {
mwBoard.connect();
}
}, delay);
}
};
/**
* Called when the mwBoard field is ready to be used
*/
public void ready() {
try {
final Accelerometer acc = mwBoard.getModule(Accelerometer.class);
final Logging logging = mwBoard.getModule(Logging.class);
final Debug debug = mwBoard.getModule(Debug.class);
acc.routeData().fromAxes().process(new Rms()).log("rms_log").commit()
.onComplete(new AsyncOperation.CompletionHandler<RouteManager>() {
@Override
public void success(RouteManager result) {
result.setLogMessageHandler("rms_log", new RouteManager.MessageHandler() {
@Override
public void process(Message message) {
Log.i("starter", String.format(Locale.US, "%s: %.3f",
message.getTimestampAsString(), message.getData(Float.class)));
}
});
mwBoard.setConnectionStateHandler(connHandler);
logging.startLogging();
acc.setOutputDataRate(1.5625f);
acc.enableAxisSampling();
acc.start();
debug.disconnect();
}
});
} catch (UnsupportedModuleException e) {
Log.e("starter", "Error retrieving module", e);
}
}
}
@MVSQL

This comment has been minimized.

Copy link

@MVSQL MVSQL commented Jun 28, 2016

Thank you Eric

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment