I have written a Wear application for the Fossil Gen 6 smartwatch which extracts photoplethysmogram (PPG) data from an onboard sensor and updates the value on the screen continuously. Here is my onSensorChanged
method, which recognizes events from the PPG sensor and updates the TextView
object accordingly. I also attempt to write each datum to a CSV file using a FileWriter
object.
@Override
public void onSensorChanged(SensorEvent event) {
// On event from PPG sensor, update text on screen and
// write to CSV file.
if (event.sensor.getType() == 65572) {
sensorData = event.values[0];
String dataString = Float.toString(sensorData);
textView.setText(dataString);
try {
writer.write(dataString);
} catch (IOException e) {
e.printStackTrace();
}
}
}
The file writer is declared at the top of the MainActivity
:
private FileWriter writer;
And is defined in the onResume
method:
protected void onResume() {
super.onResume();
try {
writer = new FileWriter("data.csv",true);
} catch (IOException e) {
e.printStackTrace();
}
}
What I am not sure how to do is actually have this file available to write to, whether it should be stored on the watch or on the paired phone somehow, and how I can ultimately retrieve the CSV data on my PC for analysis in MATLAB, etc. (Is there a better way to be doing this?) Thanks!