Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Software Developers Guide To Prototyping Wearables

Software Developers Guide To Prototyping Wearables

A overview of prototyping wearables as a software developer along with some examples using Android and Metawear

Lance Gleason

March 10, 2015
Tweet

More Decks by Lance Gleason

Other Decks in Technology

Transcript

  1. Cons • Impossible to create a at scale prototype •

    Many extensions overkill for wearables
  2. Cons • No easy way to integrate Bluetooth or Wifi

    • Requires a physical connection to get data • Things like an accelerometer require a separate component
  3. Features • Bluetooth Support • Robust API for Android and

    IOS • Built in Sensors (temperature, accelerometer etc.) • Built in support for rechargeable batteries
  4. Specs • ! Nordic Semiconductor nRF51822 BLE SoC • !

    2.4 GHz transceiver • ! ARM®Cortex™-M0 32 bit processor • ! 256 kB flash program memory • ! 16 kB RAM • ! 8/9/10 bit ADC
  5. Specs Continued • Accelerometer • Temperature Sensor • Push Button

    Switch • Bright LED • Driver for vibration motor • micro usb chargable • I2C bus, and support for 4 digital/analog and 4 digital pins
  6. Bluetooth LE • Always off • Less Throughput • Often

    lower transmit power • Designed for low data low power Applications
  7. repositories { ivy { url "http://ivyrep.mbientlab.com" layout "gradle" } }

    compile 'com.mbientlab:metawear:1.5.3' Include the Repo
  8. package com.example.metawear; import com.mbientlab.metawear.api.MetaWearBleService; import android.app.Activity; import android.content.ServiceConnection; public class

    ExampleActivity extends Activity implements ServiceConnection { private MetaWearBleService mwService= null; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //< 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) { } }
  9. public class ExampleActivity extends Activity implements ServiceConnection { @Override protected

    void onResume() { super.onResume(); registerReceiver(MetaWearBleService.getMetaWearBroadcastReceiver(), MetaWearBleService.getMetaWearIntentFilter()); } @Override protected void onPause() { super.onPause(); unregisterReceiver(MetaWearBleService.getMetaWearBroadcastReceiver()); } } Nofifications via Activity
  10. 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
  11. 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
  12. 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)); } @Override public void receivedRemoteRSSI(int rssi) { log.i("ExampleActivity", String.format("RSSI= %d dBm", rssi)); } }); //< 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();
  13. mwController.addModuleCallback(new MechanicalSwitch.Callbacks() { @Override public void pressed() { if (saviours

    != null && saviours.getCount() > 0) { Toast.makeText(getActivity(), "button pressed", Toast.LENGTH_SHORT).show(); sendText(true); } else { Toast.makeText(getActivity(), R.string.error_no_contact, Toast.LENGTH_SHORT).show(); } } }) Switch Callback
  14. .addModuleCallback(new Accelerometer.Callbacks() { @Override public void shakeDetected(MovementData moveData) { shakeCounts.getAndIncrement();

    if (!setTimerTask.get()) { resetTask= new TimerTask() { @Override public void run() { shakeCounts.set(0); setTimerTask.getAndSet(false); } }; timer.schedule(resetTask, RESET_DELAY); setTimerTask.getAndSet(true); } if (shakeCounts.get() == MAX_SHAKES) { resetTask.cancel(); setTimerTask.getAndSet(false); shakeCounts.getAndSet(0); if (saviours != null && saviours.getCount() > 0) { sendText(false); } else { Toast.makeText(getActivity(), R.string.error_no_contact, Toast.LENGTH_SHORT).show(); } } } }); Shake Callback