Putting it all together - acquiring data
It is time to put everything together and start acquiring data. By now, we have implemented:
- Two sensor listeners to listen to the new values
- The listener to know when the sensor is connected to the board
Let us glue all the pieces and make our app work. Open MainActivity.java
again and in the onCreate
method add the following lines:
callback = new BMX280Callback(); sensorManager.registerDynamicSensorCallback(callback); try { mySensorDriver = new Bmx280SensorDriver(BoardPins.getSDAPin()); mySensorDriver.registerTemperatureSensor(); mySensorDriver.registerPressureSensor(); } catch(Throwable t) { t.printStackTrace(); }
Where mySensorDriver
is an instance of Bmx280SensorDriver
that handles the communication details to the BMP280/BME280. Notice that as we described in the previous chapter, to make the app independent from the board we did not directly use the SDA pin identification, but we have used a method to retrieve the pin name according to the...