Skip to content

Instantly share code, notes, and snippets.

@ckundo
Created December 16, 2010 19:01
Show Gist options
  • Save ckundo/743800 to your computer and use it in GitHub Desktop.
Save ckundo/743800 to your computer and use it in GitHub Desktop.
package earthquake_detector;
import java.util.Map;
import com.buglabs.bug.swarm.connector.pub.ISyncFilter;
/**
* Given a previous sample and the current sample, determine if the difference is great enough to pass data to the server.
*
*/
public class AccelerometerSampleFilter implements ISyncFilter {
private float lx, ly, lz;
public AccelerometerSampleFilter() {
lx = 0;
ly = 0;
lz = 0;
}
@Override
public boolean synchronize(Map model, Object[] keys) {
boolean retVal = false;
float nx = (Float) model.get("x");
float ny = (Float) model.get("y");
float nz = (Float) model.get("z");
if (deviates(lx, nx, 1) || deviates(ly, ny, 1) || deviates(lz, nz, 1)) {
retVal = true;
}
lx = nx;
ly = ny;
lz = nz;
return retVal;
}
private boolean deviates(float src, float target, float delta) {
return Math.abs(src - target) > delta;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment