-
-
Save mbientlab/316f5ec0d9a1549527d4725a988ea37c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you Eric