Polling GPIO in background on Android
I'm seeking an architectural advice from the developer(s) who engineered Android API.
What I'm planning to do is to connect sensor to GPIO pins which will measure some values. Now I want to constantly poll those values in Android application.
What I have in mind:
1. When app is launched, start Service, call it SensorService
2. From SensorService, bind to MetaWearBleService, register broadcast receiver.
3. Schedule polling by calling GPIO.readDigitalInput
4.Receive value with callback
So basically I want to get values from GPIO in background all the time. Is this how you would do it? I'm a bit confused by the necessity of binding from one Service to another, since this is not a common pattern in Android development(AFAIK).
Thanks in advance!
This discussion has been closed.
Comments
@Override
public void onServiceConnected(ComponentName componentName,
IBinder service) {
mwService= ((MetaWearBleService.LocalBinder) service).getService();
mwService.useLocalBroadcasterManager(true);
LocalBroadcastManager.getInstance(mwService).registerReceiver(
MetaWearBleService.getMetaWearBroadcastReceiver(),
MetaWearBleService.getMetaWearIntentFilter());
}
- Use the Timer controller to setup periodic notifications
- Have Event controller listen for timer notifications
- Record the gpio read command you want to execute
- Start the timer
There is a post about the Event system on the MbientLab blog (http://projects.mbientlab.com/285/).