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

u

parent 532193df
......@@ -26,6 +26,7 @@ android {
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
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.constraint:constraint-layout:1.1.3'
implementation 'com.android.support:design:28.0.0'
......
......@@ -3,6 +3,7 @@ package de.tonifetzer.sensorrecorder;
import android.app.ProgressDialog;
import android.content.Context;
import android.graphics.Color;
import android.hardware.Sensor;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.RequiresApi;
......@@ -17,7 +18,10 @@ import android.widget.Toast;
import android.widget.ToggleButton;
import java.io.File;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import co.nstant.in.cbor.CborException;
import de.tonifetzer.sensorrecorder.sender.Sender;
......@@ -81,8 +85,6 @@ public class MainActivity extends AppCompatActivity {
recButton = findViewById(R.id.toggleButton);
txtViewFilename = findViewById(R.id.textViewFilename);
//set the listener
phoneSensors.setListener(new MySensor.SensorListener(){
@Override public void onData(final String csv) {}
......@@ -153,9 +155,16 @@ public class MainActivity extends AppCompatActivity {
phoneSensors.onResume(this);
Log.d(TAG, "startRecording: User " + dataLogger.getAndroidUser());
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();
txtViewFilename.setText(path.substring(path.length()-17));
// all = new ArrayList<Sensor>();
}
private void stopRecording() throws CborException {
......@@ -182,7 +191,7 @@ public class MainActivity extends AppCompatActivity {
public void fileSend() throws Exception {
for (File f : dataLogger.getFolder().getFolder().listFiles()) {
Log.d("FileSend", "startRecording: " + f);
// Log.d("FileSend", "startRecording: " + f);
sender.upload(f, progressDialog);
}
}
......
......@@ -146,10 +146,10 @@ public final class Logger {
synchronized (this) {
cborEncoder.encode(cborBuilder.build());
data = baos.toByteArray();
Log.d("baos", "flush: " + data.toString());
// Log.d("baos", "flush: " + data.toString());
// data = sb.toString().getBytes(); // fetch data to write
// sb.setLength(0); // reset the buffer
cborBuilder = new CborBuilder();
// cborBuilder = new CborBuilder();
}
// write
......
......@@ -25,7 +25,9 @@ import co.nstant.in.cbor.CborException;
public class PhoneSensors extends MySensor implements SensorEventListener{
private SensorManager sensorManager;
private List<Sensor> all;
private Sensor accelero;
private Sensor gyro;
private Sensor linear;
private int DELAY = 10000; // 100Hz in µs
......@@ -36,7 +38,10 @@ public class PhoneSensors extends MySensor implements SensorEventListener{
sensorManager = (SensorManager) act.getSystemService(Context.SENSOR_SERVICE);
// 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
// dumpVendors(act);
......@@ -63,9 +68,12 @@ public class PhoneSensors extends MySensor implements SensorEventListener{
sb.append(NL);
// construct sensor details
for (Sensor s: all) {
/*for (Sensor s: all) {
dumpSensor(sb, s);
}
}*/
dumpSensor(sb, accelero);
dumpSensor(sb, gyro);
dumpSensor(sb, linear);
// write
fos.write(sb.toString().getBytes());
fos.close();
......@@ -101,7 +109,7 @@ public class PhoneSensors extends MySensor implements SensorEventListener{
public void onSensorChanged(SensorEvent event) {
long now = System.currentTimeMillis();
Log.d("PhoneSensors", "onSensorChanged: " + event.sensor.getType());
// Log.d("PhoneSensors", "onSensorChanged: " + event.sensor.getType());
try {
if (event.values.length == 1) {
......@@ -129,9 +137,12 @@ public class PhoneSensors extends MySensor implements SensorEventListener{
@Override
public void onResume(final Activity act) {
// attach as listener to each of the available sensors
for (Sensor s: all) {
/*for (Sensor s: all) {
registerIfPresent(s, DELAY);
}
}*/
registerIfPresent(accelero, DELAY);
registerIfPresent(gyro, DELAY);
registerIfPresent(linear, DELAY);
}
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
......@@ -150,8 +161,20 @@ public class PhoneSensors extends MySensor implements SensorEventListener{
sensorManager.unregisterListener(this);
}
public List<Sensor> getAll() {
/* public List<Sensor> getAll() {
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