Revisions
-
ckundo created this gist
Dec 16, 2010 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,53 @@ package earthquake_detector; import java.util.Map; import com.buglabs.bug.module.gps.pub.IPositionProvider; 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. * * @author kgilmer * */ public class AccelerometerSampleFilter implements ISyncFilter { private float lx, ly, lz; private final IPositionProvider positionProvider; public AccelerometerSampleFilter(IPositionProvider positionProvider) { this.positionProvider = positionProvider; lx = 0; ly = 0; lz = 0; } @Override public boolean synchronize(Map model, Object[] keys) { boolean retVal = false; float ac[] = (float []) model.get(Activator.KEY_ACCELERATION); if (ac == null) { return false; } if (deviates(lx, ac[0], 1) || deviates(ly, ac[1], 1) || deviates(lz, ac[2], 1)) { //Add our current location in since we'll be sending event data to the server. model.put(Activator.KEY_LOCATION, Monitor.positionAsArray(positionProvider.getPosition())); retVal = true; } lx = ac[0]; ly = ac[1]; lz = ac[2]; return retVal; } private boolean deviates(float src, float target, float delta) { return Math.abs(src - target) > delta; } }