T3 Session 4/16/2015 11:00 AM "The Software Developers Guide to Prototyping Wearable Devices" Presented by: Lance Gleason Polyglot Programming Inc. Brought to you by: 340 Corporate Way, Suite 300, Orange Park, FL 32073 8882688770 9042780524 [email protected] www.sqe.com
29
Embed
The Software Developers Guide to Prototyping Wearable Devices
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
T3 Session 4/16/2015 11:00 AM
"The Software Developers Guide
to Prototyping Wearable
Devices"
Presented by:
Lance Gleason
Polyglot Programming Inc.
Brought to you by:
340 Corporate Way, Suite 300, Orange Park, FL 32073 888-‐268-‐8770 ·∙ 904-‐278-‐0524 ·∙ [email protected] ·∙ www.sqe.com
Lance Gleason
Polyglot Programming Inc. Lance Gleason has been a computer nut ever since his dad bought him a computer when he was a kid. After getting a BS and MS in Computer Science, he worked on a number of large projects as a Java developer and architect for companies like Kodak, CNN, and GE. These days he is the CEO and founder of Polyglot Programming LLC. which focuses on Ruby, mobile and wearable software development. Lance regularly speaks about Ruby/wearable development at conferences around the world and is the co-organizer of the Atlanta Sensors and Startups Meetup, Ruby DCamp ZA, and Rubyfuza (the only Ruby conference in Africa). He is known to practice interspecies pair (purr) programming with his orange tabby, Allie, and when he’s not writing code, you will find him diving with sharks, trekking through Chernobyl, sampling wine, cheering on the Springboks or perfecting his biltong recipe. Follow Lance on Twitter @lgleasain.
//< Bind the MetaWear service when the activity is created getApplicationContext().bindService(new Intent(this, MetaWearBleService.class), this, Context.BIND_AUTO_CREATE); }
@Override public void onDestroy() { super.onDestroy();
//< Unbind the service when the activity is destroyed getApplicationContext().unbindService(this); }
@Override public void onServiceConnected(ComponentName name, IBinder service) { //< Get a reference to the MetaWear service from the binder mwService= ((MetaWearBleService.LocalBinder) service).getService(); }
//< Don't need this callback method but we must implement it @Override public void onServiceDisconnected(ComponentName name) { } }
public class ExampleActivity extends Activity implements ServiceConnection { @Override protected void onResume() { super.onResume(); registerReceiver(MetaWearBleService.getMetaWearBroadcastReceiver(), MetaWearBleService.getMetaWearIntentFilter()); }
private final string MW_MAC_ADDRESS= "EC:2C:09:81:22:AC"; private MetaWearController mwCtrllr;
public void onServiceConnected(ComponentName name, IBinder service) { mwService= ((MetaWearBleService.LocalBinder) service).getService();
final BluetoothManager btManager= (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE); final mwBoard= btManager.getAdapter().getRemoteDevice(MW_MAC_ADDRESS) mwCtrllr= mwService.getMetaWearController(mwBoard); }
//< Connect to the board the object is controlling mwCtrllr.connect();
///< Close the Bluetooth connection mwCtrllr.close();
Instantiate and Connect
private DeviceCallbacks dCallbacks= new DeviceCallbacks() { @Override public void connected() { Log.i("ExampleActivity", "A Bluetooth LE connection has been established!"); } @Override public void disconnected() { Log.i("ExampleActivity", "Lost the Bluetooth LE connection!"); } }; ///< Register the callback, log message will appear when connected mwController.addDeviceCallback(dCallbacks); ///< Remove the callback, no feedback for when a ble connection is made mwController.removeDeviceCallback(dCallbacks);
Registering Callbacks
import com.mbientlab.metawear.api.characteristic;
//< Setup callback for receiving device information mwCtrllr.addDeviceCallback(new DeviceCallbacks() { @Override public void receivedGATTCharacteristic(GATTCharacteristic characteristic, byte[] data) { Log.i("ExampleActivity", String.format("%s= %s", characteristic.toString(), new String(data)); }
//< Read characteristics from the device information service //< GATT characteristics are from the DeviceInformation enum mwCtrllr.readDeviceInfo(); //< Read battery level from the battery service //< GATT characteristics are from the Battery enum mwCtrllr.readBatteryLevel(); //< Read RSSI value mwCtrllr.readRemoteRSSI();