|
@@ -38,6 +38,7 @@ import uk.co.md87.android.common.Aggregator;
|
38
|
38
|
import uk.co.md87.android.common.ModelReader;
|
39
|
39
|
import uk.co.md87.android.common.accel.AccelReader;
|
40
|
40
|
import uk.co.md87.android.common.accel.AccelReaderFactory;
|
|
41
|
+import uk.co.md87.android.common.accel.Sampler;
|
41
|
42
|
|
42
|
43
|
/**
|
43
|
44
|
*
|
|
@@ -63,60 +64,36 @@ public class RecorderService extends Service {
|
63
|
64
|
|
64
|
65
|
};
|
65
|
66
|
|
66
|
|
- private final Runnable sampleRunnable = new Runnable() {
|
|
67
|
+ private final Runnable registerRunnable = new Runnable() {
|
67
|
68
|
|
68
|
69
|
public void run() {
|
69
|
|
- final float[] values = reader.getSample();
|
70
|
|
-
|
71
|
|
- data[nextSample * 2] = values[0];
|
72
|
|
- data[nextSample * 2 + 1] = values[1];
|
73
|
|
-
|
74
|
|
- if (++nextSample == 128) {
|
75
|
|
- float[] cache = new float[256];
|
76
|
|
- System.arraycopy(data, 0, cache, 0, 256);
|
77
|
|
- analyse(cache);
|
78
|
|
-
|
79
|
|
- reader.stopSampling();
|
80
|
|
- return;
|
81
|
|
- }
|
82
|
|
-
|
83
|
|
- handler.postDelayed(sampleRunnable, 50);
|
|
70
|
+ //Log.i(getClass().getName(), "Registering");
|
|
71
|
+ sampler.start();
|
|
72
|
+
|
|
73
|
+ handler.postDelayed(registerRunnable, 30000);
|
84
|
74
|
}
|
85
|
|
-
|
|
75
|
+
|
86
|
76
|
};
|
87
|
77
|
|
88
|
|
- private final Runnable registerRunnable = new Runnable() {
|
|
78
|
+ private final Runnable analyseRunnable = new Runnable() {
|
89
|
79
|
|
90
|
80
|
public void run() {
|
91
|
|
- //Log.i(getClass().getName(), "Registering");
|
92
|
|
- nextSample = 0;
|
93
|
|
-
|
94
|
|
- reader.startSampling();
|
95
|
|
-
|
96
|
|
- handler.postDelayed(sampleRunnable, 50);
|
97
|
|
- handler.postDelayed(registerRunnable, 30000);
|
|
81
|
+ final Intent intent = new Intent(RecorderService.this, ClassifierService.class);
|
|
82
|
+ intent.putExtra("data", sampler.getData());
|
|
83
|
+ startService(intent);
|
98
|
84
|
}
|
99
|
85
|
|
100
|
86
|
};
|
101
|
87
|
|
102
|
88
|
final Handler handler = new Handler();
|
103
|
89
|
|
104
|
|
- float[] data = new float[256];
|
105
|
|
- volatile int nextSample = 0;
|
106
|
|
-
|
107
|
90
|
boolean running;
|
108
|
91
|
final Aggregator aggregator = new Aggregator();
|
109
|
92
|
AccelReader reader;
|
|
93
|
+ Sampler sampler;
|
110
|
94
|
public static Map<Float[], String> model;
|
111
|
95
|
private final List<Classification> classifications = new ArrayList<Classification>();
|
112
|
96
|
|
113
|
|
- public void analyse(float[] data) {
|
114
|
|
- //Log.i(getClass().getName(), "Analysing");
|
115
|
|
- final Intent intent = new Intent(this, ClassifierService.class);
|
116
|
|
- intent.putExtra("data", data);
|
117
|
|
- startService(intent);
|
118
|
|
- }
|
119
|
|
-
|
120
|
97
|
@Override
|
121
|
98
|
public IBinder onBind(Intent arg0) {
|
122
|
99
|
return binder;
|
|
@@ -129,6 +106,7 @@ public class RecorderService extends Service {
|
129
|
106
|
running = true;
|
130
|
107
|
|
131
|
108
|
reader = new AccelReaderFactory().getReader(this);
|
|
109
|
+ sampler = new Sampler(handler, reader, analyseRunnable);
|
132
|
110
|
|
133
|
111
|
init();
|
134
|
112
|
}
|
|
@@ -162,10 +140,11 @@ public class RecorderService extends Service {
|
162
|
140
|
if (running) {
|
163
|
141
|
running = false;
|
164
|
142
|
|
165
|
|
- handler.removeCallbacks(sampleRunnable);
|
|
143
|
+ if (sampler != null) {
|
|
144
|
+ sampler.stop();
|
|
145
|
+ }
|
|
146
|
+
|
166
|
147
|
handler.removeCallbacks(registerRunnable);
|
167
|
|
-
|
168
|
|
- reader.stopSampling();
|
169
|
148
|
}
|
170
|
149
|
}
|
171
|
150
|
|