Created
December 16, 2010 19:01
-
-
Save ckundo/743800 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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