- close #6 - verbindung klappt und macht was sie soll. sonderfälle fehlen halt noch wie verbindung kackt ab etc.
- ref #8 mal einen filewriter geschrieben, welcher die sensordaten rausschreiben soll. - viele kleine sachen
This commit is contained in:
@@ -86,6 +86,8 @@ public class Estimator implements SensorEventListener {
|
||||
mAccelerometerWindowBuffer.add(new AccelerometerData(System.currentTimeMillis(), se.values[0], se.values[1], se.values[2]));
|
||||
}
|
||||
|
||||
//TODO: get also gyro and write stuff into file
|
||||
|
||||
// mSensorUpdateFlag = false;
|
||||
//}
|
||||
}
|
||||
|
||||
@@ -41,6 +41,10 @@ public class MainActivity extends WearableActivity implements WorkerFragment.OnF
|
||||
|
||||
// connection to phone stuff
|
||||
private static final String START_ACTIVITY_PATH = "/start-activity";
|
||||
private static final String START_RECORD_PATH = "/start-record";
|
||||
private static final String STOP_RECORD_PATH = "/stop-record";
|
||||
private static final String UPDATE_PATH = "/update";
|
||||
|
||||
public static final String TAG = "DataLayerListenerService";
|
||||
private GoogleApiClient mGoogleApiClient;
|
||||
private Node mNode;
|
||||
@@ -85,6 +89,10 @@ public class MainActivity extends WearableActivity implements WorkerFragment.OnF
|
||||
args.putInt("bpm", mCroller.getProgress());
|
||||
worker.setArguments(args);
|
||||
|
||||
//send data to phone, that we start to record
|
||||
String curProgress = Integer.toString(mCroller.getProgress());
|
||||
sendMessage(START_RECORD_PATH + ":" + curProgress + ":" + curProgress);
|
||||
|
||||
//setter
|
||||
worker.setCrollerWorker(mCroller);
|
||||
worker.setTextViewWorker(mTextView);
|
||||
@@ -103,6 +111,9 @@ public class MainActivity extends WearableActivity implements WorkerFragment.OnF
|
||||
mCroller.setBackCircleColor(Color.parseColor("#158b69"));
|
||||
mTextView.setTextColor(Color.parseColor("#158b69"));
|
||||
mCroller.setProgress(mMetronomBpm);
|
||||
|
||||
//send data to phone, that we stopped to record
|
||||
sendMessage(STOP_RECORD_PATH);
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -163,6 +174,10 @@ public class MainActivity extends WearableActivity implements WorkerFragment.OnF
|
||||
mCroller.interruptMainCircleColorAnimated();
|
||||
mCroller.interruptBackCircleAnimated();
|
||||
}
|
||||
else {
|
||||
mCroller.setBackCircleColor(Color.parseColor("#cccccc"));
|
||||
mCroller.setMainCircleColor(Color.parseColor("#ffffff"));
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
@@ -252,8 +267,18 @@ public class MainActivity extends WearableActivity implements WorkerFragment.OnF
|
||||
@Override
|
||||
public void onProgressChanged(int progress) {
|
||||
// use the progress
|
||||
mTextView.setText(String.valueOf(progress));
|
||||
sendMessage(Integer.toString(progress));
|
||||
String curProgress = Integer.toString(progress);
|
||||
String metronomBpm = Integer.toString(mMetronomBpm);;
|
||||
mTextView.setText(curProgress);
|
||||
|
||||
//TODO: too many messages? or just because of thread?
|
||||
if(mModeRecord){
|
||||
sendMessage(START_RECORD_PATH + ":" + metronomBpm + ":" + curProgress);
|
||||
}
|
||||
else {
|
||||
sendMessage(UPDATE_PATH + ":" + metronomBpm + ":" + curProgress);
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
@@ -274,8 +299,10 @@ public class MainActivity extends WearableActivity implements WorkerFragment.OnF
|
||||
|
||||
private void sendMessage(String Key) {
|
||||
|
||||
//TODO: sammel key's und schicke nur die hälfte
|
||||
|
||||
if (mNode != null && mGoogleApiClient!= null && mGoogleApiClient.isConnected()) {
|
||||
Log.d(TAG, "-- " + mGoogleApiClient.isConnected());
|
||||
//Log.d(TAG, "-- " + mGoogleApiClient.isConnected());
|
||||
Wearable.MessageApi.sendMessage(
|
||||
mGoogleApiClient, mNode.getId(), Key, new byte[0]).setResultCallback(
|
||||
|
||||
@@ -283,7 +310,7 @@ public class MainActivity extends WearableActivity implements WorkerFragment.OnF
|
||||
@Override
|
||||
public void onResult(MessageApi.SendMessageResult sendMessageResult) {
|
||||
|
||||
Log.d(TAG, "--- " + sendMessageResult.getStatus().getStatusCode());
|
||||
//Log.d(TAG, "-- " + sendMessageResult.getStatus().getStatusCode());
|
||||
if (!sendMessageResult.getStatus().isSuccess()) {
|
||||
Log.e(TAG, "Failed to send message with status code: "
|
||||
+ sendMessageResult.getStatus().getStatusCode());
|
||||
@@ -316,7 +343,6 @@ public class MainActivity extends WearableActivity implements WorkerFragment.OnF
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onFragmentStopped(Vector<Double> bpmList) {
|
||||
|
||||
@@ -332,19 +358,12 @@ public class MainActivity extends WearableActivity implements WorkerFragment.OnF
|
||||
super.onStart();
|
||||
if (!mResolvingError) {
|
||||
mGoogleApiClient.connect();
|
||||
|
||||
//TODO. mGoogleApiClient.disconnect(); implementieren in onPause()
|
||||
}
|
||||
|
||||
|
||||
//start app on phone
|
||||
//TODO: bissle cleverer machen. starten und auf antwort warten. falls er sagt "bin schon an" nicht mehr senden
|
||||
// ansonsten nochmal versuchen.bzw. auch von anderen stellen (bei click etc) aufrufen.
|
||||
|
||||
|
||||
|
||||
|
||||
//TODO: disconnect or own class for this stuff
|
||||
}
|
||||
|
||||
//TODO: rename this! onTapBPMNewEstimation or something like that
|
||||
@Override
|
||||
public void onNewEstimation(int bpm) {
|
||||
mTapBpmEstimation = bpm;
|
||||
@@ -363,6 +382,7 @@ public class MainActivity extends WearableActivity implements WorkerFragment.OnF
|
||||
}
|
||||
}
|
||||
|
||||
//TODO: rename this! onTapBPMFinished or something like that
|
||||
@Override
|
||||
public void onFinished() {
|
||||
|
||||
@@ -387,13 +407,16 @@ public class MainActivity extends WearableActivity implements WorkerFragment.OnF
|
||||
public void onConnected(@Nullable Bundle bundle) {
|
||||
resolveNode();
|
||||
|
||||
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
while(mNode == null){
|
||||
|
||||
try {
|
||||
Thread.sleep(1000L);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
sendMessage(START_ACTIVITY_PATH);
|
||||
}
|
||||
@@ -403,12 +426,12 @@ public class MainActivity extends WearableActivity implements WorkerFragment.OnF
|
||||
|
||||
@Override
|
||||
public void onConnectionSuspended(int i) {
|
||||
|
||||
//TODO: implement this
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {
|
||||
|
||||
//TODO: implement this
|
||||
}
|
||||
|
||||
private void resolveNode() {
|
||||
|
||||
@@ -61,7 +61,6 @@ public class WorkerFragment extends Fragment implements Metronome.OnMetronomeLis
|
||||
//mBpmThread = new Thread(mEstimator, "estThread");
|
||||
mBpmList = new Vector<Double>();
|
||||
|
||||
|
||||
// init metronome and listener
|
||||
mMetronome = new Metronome(getArguments().getInt("bpm"));
|
||||
mMetronome.add(this);
|
||||
@@ -69,7 +68,6 @@ public class WorkerFragment extends Fragment implements Metronome.OnMetronomeLis
|
||||
|
||||
mVibrator = (Vibrator) this.getActivity().getSystemService(Context.VIBRATOR_SERVICE);
|
||||
|
||||
|
||||
//keep screen always on
|
||||
this.getActivity().getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
package de.tonifetzer.conductorswatch.utilities;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Created by toni on 20/12/17.
|
||||
*/
|
||||
|
||||
public class FileWriter {
|
||||
|
||||
private String mFilename;
|
||||
|
||||
private ByteArrayOutputStream mByteStream;
|
||||
private DataOutputStream mDataStream;
|
||||
|
||||
FileWriter(String filename){
|
||||
mFilename = filename;
|
||||
mByteStream = new ByteArrayOutputStream();
|
||||
mDataStream = new DataOutputStream(mByteStream);
|
||||
}
|
||||
|
||||
public void writeDouble(double data){
|
||||
try {
|
||||
mDataStream.writeDouble(data);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void writeString(String data){
|
||||
try {
|
||||
mDataStream.writeChars(data);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void writeInt(int data){
|
||||
try {
|
||||
mDataStream.writeInt(data);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public byte[] getByteArray(){
|
||||
return mByteStream.toByteArray();
|
||||
}
|
||||
|
||||
public String getFilename(){
|
||||
return mFilename;
|
||||
}
|
||||
|
||||
public void reset(){
|
||||
mByteStream.reset();
|
||||
}
|
||||
|
||||
public void close(){
|
||||
try {
|
||||
mByteStream.close();
|
||||
mDataStream.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -33,5 +33,6 @@ public class MovingFilter {
|
||||
|
||||
public void clear(){
|
||||
mSamples.clear();
|
||||
mTotal = 0d;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user