Skip to content

Instantly share code, notes, and snippets.

@jamesmontemagno
Created April 12, 2014 21:04
Show Gist options
  • Save jamesmontemagno/10556784 to your computer and use it in GitHub Desktop.
Save jamesmontemagno/10556784 to your computer and use it in GitHub Desktop.
Sensor Changed Logic
private int stepCounter = 0;
private int counterSteps = 0;
private int stepDetector = 0;
public void OnSensorChanged (SensorEvent e)
{
switch (e.Sensor.Type) {
case SensorType.StepDetector:
stepDetector++;
break;
case SensorType.StepCounter:
//Since it will return the total number since we registered we need to subtract the initial amount
//for the current steps since we opened app
if (counterSteps < 1) {
// initial value
counterSteps = (int)e.Values [0];
}
// Calculate steps taken based on first counter value received.
stepCounter = (int)e.Values [0] - counterSteps;
break;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment