Last active
November 26, 2015 04:06
-
-
Save fregmented/5410cbd55722c8f5cda1 to your computer and use it in GitHub Desktop.
AllSensorSample.java
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
private boolean isAmbient_temp = false; | |
private boolean isMagnetic = false; | |
private HashMap<Integer, float[]> sensorValues = new HashMap<>(); | |
public void onSensorChanged(SensorEvent event) { | |
switch (event.sensor.getType()){ | |
case Sensor.TYPE_AMBIENT_TEMPERATURE: | |
// blah blah | |
sensorValues.put(Sensor.TYPE_AMBIENT_TEMPERATURE, event.values); | |
isAmbient_temp = true; | |
break; | |
case Sensor.TYPE_MAGNETIC_FIELD: | |
sensorValues.put(Sensor.TYPE_MAGNETIC_FIELD, event.values); | |
// blah blah | |
isMagnetic = true; | |
} | |
if(isAllSensorGeted()){ | |
// blah blah | |
String[] val = makeCSVArray(sensorValues); | |
csvWriter.writeNect(val); | |
} | |
} | |
private String[] makeCSVArray(HashMap<Integer, float[]> sensorValues){ | |
String[] val = new String[sensorValues.size()*3]; | |
Set key = sensorValues.keySet(); | |
int i = 0; | |
for(Object k : key){ | |
float[] v = sensorValues.get(k); | |
for(int j = 0; j < v.length; j++, i++){ | |
val[i] = Float.toString(v[j]); | |
} | |
} | |
return val; | |
} | |
private boolean isAllSensorGeted(){ | |
return isAmbient_temp && isMagnetic; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment