Last active
January 13, 2017 07:22
-
-
Save KazuyukiEguchi/ea5b608b86bafe5f101c37346fa31310 to your computer and use it in GitHub Desktop.
Raspberry Pi 3に、Rainbow HATを装着して、AndroidThingsのアプリを書いてみた ref: http://qiita.com/KazuyukiEguchi/items/748f9a9a340ddfbc2f22
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
compile 'com.google.android.things.contrib:driver-rainbowhat:0.1' |
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
@Override protected void onCreate(Bundle savedInstanceState) { | |
Log.d(TAG,"onCreate()"); | |
super.onCreate(savedInstanceState); | |
sensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE); | |
try { | |
mSensorDriver = new Bmx280SensorDriver(RainbowHat.BUS_SENSOR); | |
mSensorDriver.registerTemperatureSensor(); | |
mSensorDriver.registerPressureSensor(); | |
} catch (IOException e) { | |
Log.d(TAG,e.toString()); | |
} | |
} | |
@Override | |
protected void onResume() { | |
Log.d(TAG,"onResume()"); | |
super.onResume(); | |
List<Sensor> lists = sensorManager.getDynamicSensorList(Sensor.TYPE_ALL); | |
for(int i = 0 ; i< lists.size() ; i++) | |
{ | |
Log.d(TAG,"" + lists.get(i).toString()); | |
sensorManager.registerListener(onEvent2, lists.get(i), SensorManager.SENSOR_DELAY_NORMAL); | |
} | |
} | |
@Override | |
protected void onPause() { | |
Log.d(TAG,"onPause()"); | |
super.onPause(); | |
try { | |
if(mSensorDriver != null) { | |
mSensorDriver.unregisterTemperatureSensor(); | |
mSensorDriver.unregisterPressureSensor(); | |
mSensorDriver.close(); | |
} | |
sensorManager.unregisterListener(onEvent2); | |
} catch (IOException e) { | |
Log.d(TAG,e.toString()); | |
} | |
} | |
SensorEventListener onEvent2 = new SensorEventListener() { | |
@Override | |
public void onSensorChanged(SensorEvent sensorEvent) { | |
if(sensorEvent.sensor.getType() == Sensor.TYPE_AMBIENT_TEMPERATURE) { | |
Log.d(TAG, "TEMPERATURE=" + sensorEvent.values[0]); | |
} | |
else if(sensorEvent.sensor.getType() == Sensor.TYPE_PRESSURE) | |
{ | |
Log.d(TAG,"PRESSURE="+ sensorEvent.values[0]); | |
} | |
} | |
@Override | |
public void onAccuracyChanged(Sensor sensor, int i) { | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment