affddbe829a41ffdb64513953fa449b5e803b3b0
[des2015.git] / mart / ev3 / ex2 / nl / ru / des / sensors / SuperSensor.java
1 package nl.ru.des.sensors;
2
3 import lejos.robotics.SampleProvider;
4
5 public abstract class SuperSensor {
6 public static final long SAMPLETIME = 50;
7
8 private long lastSampleTaken;
9 private SampleProvider sampleProvider;
10
11 protected float[] samples;
12
13 public SuperSensor(SampleProvider sampleProvider){
14 this.sampleProvider = sampleProvider;
15 this.samples = new float[sampleProvider.sampleSize()];
16 this.lastSampleTaken = System.currentTimeMillis()-SAMPLETIME;
17 }
18
19 public void fetchSample(){
20 fetchSample(false);
21 }
22
23 public void fetchSample(boolean always){
24 if(always || System.currentTimeMillis()-lastSampleTaken > SAMPLETIME){
25 lastSampleTaken = System.currentTimeMillis();
26 sampleProvider.fetchSample(samples, 0);
27 }
28 }
29 }