| 1 |
package com.ridelogger.listners; |
| 2 |
|
| 3 |
import com.ridelogger.RideService; |
| 4 |
|
| 5 |
/** |
| 6 |
* Base |
| 7 |
* @author Chet Henry |
| 8 |
* Base sensor class that has methods to time stamp are write to buffer |
| 9 |
*/ |
| 10 |
public class Base<T> |
| 11 |
{ |
| 12 |
public RideService context; |
| 13 |
|
| 14 |
public Base(RideService mContext) { |
| 15 |
context = mContext; |
| 16 |
} |
| 17 |
|
| 18 |
|
| 19 |
public void alterCurrentData(int key, float value) |
| 20 |
{ |
| 21 |
synchronized (context.currentValues) { |
| 22 |
context.currentValues[RideService.SECS] = getTs(); |
| 23 |
context.currentValues[key] = value; |
| 24 |
context.fileFormat.writeValues(); |
| 25 |
} |
| 26 |
} |
| 27 |
|
| 28 |
|
| 29 |
public void alterCurrentData(int[] keys, float[] values) |
| 30 |
{ |
| 31 |
synchronized (context.currentValues) { |
| 32 |
context.currentValues[RideService.SECS] = getTs(); |
| 33 |
|
| 34 |
int i = 0; |
| 35 |
for (int key : keys) { |
| 36 |
context.currentValues[key] = values[i]; |
| 37 |
i++; |
| 38 |
} |
| 39 |
|
| 40 |
context.fileFormat.writeValues(); |
| 41 |
} |
| 42 |
} |
| 43 |
|
| 44 |
|
| 45 |
//get current time stamp |
| 46 |
public float getTs() { |
| 47 |
return (float) ((System.currentTimeMillis() - context.startTime) / 1000.0); |
| 48 |
} |
| 49 |
|
| 50 |
|
| 51 |
//Clean up my listeners here |
| 52 |
public void onDestroy() {} |
| 53 |
|
| 54 |
//zero any of my values |
| 55 |
public void zeroReadings() {} |
| 56 |
} |
| 57 |
|
| 58 |
|