Commit 626fdcae authored by Loris's avatar Loris
Browse files

u

parent 532193df
...@@ -25,7 +25,8 @@ android { ...@@ -25,7 +25,8 @@ android {
dependencies { dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar']) implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'co.nstant.in:cbor:0.9' implementation 'co.nstant.in:cbor:0.9'
// implementation 'com.upokecenter:cbor:4.2.0'
implementation 'com.android.support:appcompat-v7:28.0.0' implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3' implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.android.support:design:28.0.0' implementation 'com.android.support:design:28.0.0'
......
...@@ -3,6 +3,7 @@ package de.tonifetzer.sensorrecorder; ...@@ -3,6 +3,7 @@ package de.tonifetzer.sensorrecorder;
import android.app.ProgressDialog; import android.app.ProgressDialog;
import android.content.Context; import android.content.Context;
import android.graphics.Color; import android.graphics.Color;
import android.hardware.Sensor;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.support.annotation.RequiresApi; import android.support.annotation.RequiresApi;
...@@ -17,7 +18,10 @@ import android.widget.Toast; ...@@ -17,7 +18,10 @@ import android.widget.Toast;
import android.widget.ToggleButton; import android.widget.ToggleButton;
import java.io.File; import java.io.File;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List;
import co.nstant.in.cbor.CborException; import co.nstant.in.cbor.CborException;
import de.tonifetzer.sensorrecorder.sender.Sender; import de.tonifetzer.sensorrecorder.sender.Sender;
...@@ -81,8 +85,6 @@ public class MainActivity extends AppCompatActivity { ...@@ -81,8 +85,6 @@ public class MainActivity extends AppCompatActivity {
recButton = findViewById(R.id.toggleButton); recButton = findViewById(R.id.toggleButton);
txtViewFilename = findViewById(R.id.textViewFilename); txtViewFilename = findViewById(R.id.textViewFilename);
//set the listener //set the listener
phoneSensors.setListener(new MySensor.SensorListener(){ phoneSensors.setListener(new MySensor.SensorListener(){
@Override public void onData(final String csv) {} @Override public void onData(final String csv) {}
...@@ -153,9 +155,16 @@ public class MainActivity extends AppCompatActivity { ...@@ -153,9 +155,16 @@ public class MainActivity extends AppCompatActivity {
phoneSensors.onResume(this); phoneSensors.onResume(this);
Log.d(TAG, "startRecording: User " + dataLogger.getAndroidUser()); Log.d(TAG, "startRecording: User " + dataLogger.getAndroidUser());
Log.d(TAG, "startRecording: Position " + dataLogger.getAndroidPosition()); Log.d(TAG, "startRecording: Position " + dataLogger.getAndroidPosition());
dataLogger.start(phoneSensors.getAll()); /*dataLogger.start(phoneSensors.getAll());*/
List all = new ArrayList<Sensor>();
all.add(phoneSensors.getAccelero());
all.add(phoneSensors.getGyro());
all.add(phoneSensors.getLinear());
dataLogger.start(all);
String path = dataLogger.getFile().getAbsolutePath(); String path = dataLogger.getFile().getAbsolutePath();
txtViewFilename.setText(path.substring(path.length()-17)); txtViewFilename.setText(path.substring(path.length()-17));
// all = new ArrayList<Sensor>();
} }
private void stopRecording() throws CborException { private void stopRecording() throws CborException {
...@@ -182,7 +191,7 @@ public class MainActivity extends AppCompatActivity { ...@@ -182,7 +191,7 @@ public class MainActivity extends AppCompatActivity {
public void fileSend() throws Exception { public void fileSend() throws Exception {
for (File f : dataLogger.getFolder().getFolder().listFiles()) { for (File f : dataLogger.getFolder().getFolder().listFiles()) {
Log.d("FileSend", "startRecording: " + f); // Log.d("FileSend", "startRecording: " + f);
sender.upload(f, progressDialog); sender.upload(f, progressDialog);
} }
} }
......
...@@ -146,10 +146,10 @@ public final class Logger { ...@@ -146,10 +146,10 @@ public final class Logger {
synchronized (this) { synchronized (this) {
cborEncoder.encode(cborBuilder.build()); cborEncoder.encode(cborBuilder.build());
data = baos.toByteArray(); data = baos.toByteArray();
Log.d("baos", "flush: " + data.toString()); // Log.d("baos", "flush: " + data.toString());
// data = sb.toString().getBytes(); // fetch data to write // data = sb.toString().getBytes(); // fetch data to write
// sb.setLength(0); // reset the buffer // sb.setLength(0); // reset the buffer
cborBuilder = new CborBuilder(); // cborBuilder = new CborBuilder();
} }
// write // write
......
...@@ -25,7 +25,9 @@ import co.nstant.in.cbor.CborException; ...@@ -25,7 +25,9 @@ import co.nstant.in.cbor.CborException;
public class PhoneSensors extends MySensor implements SensorEventListener{ public class PhoneSensors extends MySensor implements SensorEventListener{
private SensorManager sensorManager; private SensorManager sensorManager;
private List<Sensor> all; private Sensor accelero;
private Sensor gyro;
private Sensor linear;
private int DELAY = 10000; // 100Hz in µs private int DELAY = 10000; // 100Hz in µs
...@@ -36,7 +38,10 @@ public class PhoneSensors extends MySensor implements SensorEventListener{ ...@@ -36,7 +38,10 @@ public class PhoneSensors extends MySensor implements SensorEventListener{
sensorManager = (SensorManager) act.getSystemService(Context.SENSOR_SERVICE); sensorManager = (SensorManager) act.getSystemService(Context.SENSOR_SERVICE);
// try to get each sensor // try to get each sensor
all = sensorManager.getSensorList(Sensor.TYPE_ALL); //all = sensorManager.getSensorList(Sensor.TYPE_ALL);
accelero = sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
gyro = sensorManager.getDefaultSensor(Sensor.TYPE_GYROSCOPE);
linear = sensorManager.getDefaultSensor(Sensor.TYPE_LINEAR_ACCELERATION);
// dump sensor-vendor info to file // dump sensor-vendor info to file
// dumpVendors(act); // dumpVendors(act);
...@@ -63,9 +68,12 @@ public class PhoneSensors extends MySensor implements SensorEventListener{ ...@@ -63,9 +68,12 @@ public class PhoneSensors extends MySensor implements SensorEventListener{
sb.append(NL); sb.append(NL);
// construct sensor details // construct sensor details
for (Sensor s: all) { /*for (Sensor s: all) {
dumpSensor(sb, s); dumpSensor(sb, s);
} }*/
dumpSensor(sb, accelero);
dumpSensor(sb, gyro);
dumpSensor(sb, linear);
// write // write
fos.write(sb.toString().getBytes()); fos.write(sb.toString().getBytes());
fos.close(); fos.close();
...@@ -101,7 +109,7 @@ public class PhoneSensors extends MySensor implements SensorEventListener{ ...@@ -101,7 +109,7 @@ public class PhoneSensors extends MySensor implements SensorEventListener{
public void onSensorChanged(SensorEvent event) { public void onSensorChanged(SensorEvent event) {
long now = System.currentTimeMillis(); long now = System.currentTimeMillis();
Log.d("PhoneSensors", "onSensorChanged: " + event.sensor.getType()); // Log.d("PhoneSensors", "onSensorChanged: " + event.sensor.getType());
try { try {
if (event.values.length == 1) { if (event.values.length == 1) {
...@@ -129,9 +137,12 @@ public class PhoneSensors extends MySensor implements SensorEventListener{ ...@@ -129,9 +137,12 @@ public class PhoneSensors extends MySensor implements SensorEventListener{
@Override @Override
public void onResume(final Activity act) { public void onResume(final Activity act) {
// attach as listener to each of the available sensors // attach as listener to each of the available sensors
for (Sensor s: all) { /*for (Sensor s: all) {
registerIfPresent(s, DELAY); registerIfPresent(s, DELAY);
} }*/
registerIfPresent(accelero, DELAY);
registerIfPresent(gyro, DELAY);
registerIfPresent(linear, DELAY);
} }
@RequiresApi(api = Build.VERSION_CODES.KITKAT) @RequiresApi(api = Build.VERSION_CODES.KITKAT)
...@@ -150,8 +161,20 @@ public class PhoneSensors extends MySensor implements SensorEventListener{ ...@@ -150,8 +161,20 @@ public class PhoneSensors extends MySensor implements SensorEventListener{
sensorManager.unregisterListener(this); sensorManager.unregisterListener(this);
} }
public List<Sensor> getAll() { /* public List<Sensor> getAll() {
return all; return all;
}*/
public Sensor getAccelero() {
return accelero;
}
public Sensor getGyro() {
return gyro;
}
public Sensor getLinear() {
return linear;
} }
} }
2020/07/28 10:09:41 Micro started
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment