-
Notifications
You must be signed in to change notification settings - Fork 0
/
MinMaxFilter.java
36 lines (32 loc) · 1.35 KB
/
MinMaxFilter.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// Mediates between a sensor sample provider and the user to provide normalised values between the
// Min and Max values
// seen during a calibration phase. Only works with sample providers returning a single value.
public class MinMaxFilter extends SampleProvider {
private SampleProvider sp;
private float range = 1.0f;
private float offset = 0.0f;
MaxMinColorFIlter(SampleProvider _sp) { // The actual sensor object will be used to get un-normalised values.
sp = _sp;
}
public void calibrate() { // This function is called once and then it keeps getting values until ENTER is pressed
float samples = new float[1];
float highValue = 0.0f;
float LowValue = 1.0f
while (!Button.ENTER.isPressed()) {
sp.fetchSample(samples, 0);
highValue = Math.max(highValue, samples[0]);
lowValue = Math.min(lowValue, samples[0]);
}
offset = low_value;
range = highValue - lowValue; // Before returning it stores the range and offset values for future use.
}
public int sampleSize() {
return 1;
}
public void fetchSample(float[] sample, int index) {
sp.fetchSample(sample, index); // delegate the fetchSample call to the actual sensor
sample[index] = (sample[index] - offset) / range; // Adjust the result and put it into the
// returned array
return;
}
}