SlideShare a Scribd company logo
 
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	
  ·∙	
  sqeinfo@sqe.com	
  ·∙	
  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.	
  
Introductions
Twitter @lgleasain
Github lgleasain
www.lancegleason.com
www.polyglotprogrammincinc.com
lgleason@polyglotprogramminginc.com
The Software Developers Guide to Prototyping Wearable Devices
The Software Developers Guide to Prototyping Wearable Devices
The Software Developers Guide to Prototyping Wearable Devices
http://www.polyglotprogramminginc.com/purr-
programming-2-0/
The Software Developers Guide to Prototyping Wearable Devices
Software
Options
Pros
•Extensible
•Common Pinouts
Cons
• Impossible to create a at
scale prototype
• Many extensions overkill for
wearables
Pros
• Inexpensive
• Available GPS Module
• Low Power
• Aduino Based
• Lots of Support
Cons
• No easy way to integrate Bluetooth
or Wifi
• Requires a physical connection to
get data
• Things like an accelerometer require
a separate component
The Software Developers Guide to Prototyping Wearable Devices
The Software Developers Guide to Prototyping Wearable Devices
Features
• Bluetooth Support
• Robust API for Android and IOS
• Built in Sensors (temperature,
accelerometer etc.)
• Built in support for rechargeable
batteries
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
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
Cons
• Really Small
• Tough to write custom drivers
• Proprietary
Bluetooth
• Same Frequency range as
2.4 Gigahertz Wifi
• 79 Channels VS 13
• Less Throughput
Bluetooth LE
• Always off
• Less Throughput
• Often lower transmit power
• Designed for low data low power
Applications
IOS
• IPad 3rd Generation or better
• Iphone 4S or greater
Android
• Bluetooth 4.0 supported radio
• Android 4.3 or greater
The Software Developers Guide to Prototyping Wearable Devices
repositories {
ivy {
url "http://ivyrep.mbientlab.com"
layout "gradle"
}
}
compile 'com.mbientlab:metawear:1.5.3'
Include the Repo
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<service
android:name="com.mbientlab.metawear.api.MetaWearBleService" />
<!-- Other application info -->
</application>
Update The Manifest
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) { }
}
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
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));
}
@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();
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
.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
The Software Developers Guide to Prototyping Wearable Devices
Example Code Available at
https://github.com/lgleasain/Metawear-Android-SOS
Twitter @lgleasain
Github lgleasain
www.lancegleason.com
www.polyglotprogrammincinc.com
lgleason@polyglotprogramminginc.com

More Related Content

PPTX
Log Monitoring Simplified - Get the best out of Graylog2 & Icinga 2
PDF
Open source IoT gateway: Tale of Eclipse Kura, Apache Camel and Rhiot
PDF
FIWARE Tech Summit - Building Your Own IoT Agent
PDF
Building Open Source IoT Cloud
PDF
Resin.io overview (2016 July)
PPTX
Web servers for the Internet of Things
PPTX
Icinga @ OSMC 2014
PDF
Reactive web
Log Monitoring Simplified - Get the best out of Graylog2 & Icinga 2
Open source IoT gateway: Tale of Eclipse Kura, Apache Camel and Rhiot
FIWARE Tech Summit - Building Your Own IoT Agent
Building Open Source IoT Cloud
Resin.io overview (2016 July)
Web servers for the Internet of Things
Icinga @ OSMC 2014
Reactive web

What's hot (18)

PPTX
Software for the Internet of Things
PDF
Getting started on IoT with AWS and NodeMCU for less than 5€
PPTX
Io t basic-exercises
PDF
Learn Evothings Studio along with ESP8266
PDF
Lightning Fast Monitoring against Lightning Fast Outages
PDF
OSMC 2021 | Thola – A tool for monitoring and provisioning network devices
PDF
MoniTutor
PPTX
Programming for the Internet of Things
PPTX
Splunk Modular Inputs / JMS Messaging Module Input
PPTX
Afpified Monitoring with Icinga2
PPTX
Icinga Camp Kuala Lumpur 2015 Opening By Eric Lippmann
PDF
Blynk presentation
PDF
FIWARE Global Summit - Building Your Own IoT Agent
PDF
Introduction to Oberon HomeKit SDKs
PPTX
Windows 10 IoT-Core to Azure IoT Suite
PDF
FIWARE Global Summit - Connecting to IoT
PDF
Elixir Programming Language 101
PPTX
Internet of Things 101 - Part II
Software for the Internet of Things
Getting started on IoT with AWS and NodeMCU for less than 5€
Io t basic-exercises
Learn Evothings Studio along with ESP8266
Lightning Fast Monitoring against Lightning Fast Outages
OSMC 2021 | Thola – A tool for monitoring and provisioning network devices
MoniTutor
Programming for the Internet of Things
Splunk Modular Inputs / JMS Messaging Module Input
Afpified Monitoring with Icinga2
Icinga Camp Kuala Lumpur 2015 Opening By Eric Lippmann
Blynk presentation
FIWARE Global Summit - Building Your Own IoT Agent
Introduction to Oberon HomeKit SDKs
Windows 10 IoT-Core to Azure IoT Suite
FIWARE Global Summit - Connecting to IoT
Elixir Programming Language 101
Internet of Things 101 - Part II
Ad

Viewers also liked (20)

PPT
Мысль №11
PPTX
Контакт центр – ефективний інструмент керування містом
PDF
Khao sat Hanh Vi Lua Tuoi Teen Viet Nam 2012 by FTA
PPTX
Personajes
PPTX
Использование социальных медиа как инструмент продвижения гостиничного бизнеса
PPTX
Cycles of a film
PPT
Del Off al On y viceversa. Verdades y mitos del Comercio Electrónico
PPT
О Погорєлов "Ефективні комунікації під час громадського моніторингу публічних...
PPT
Ver. Caffé
DOCX
La resistencia aeróbica
PDF
数字时代阅读报告 第五期 2011年3月号
PPTX
Praktijkonderzoek als competentie
PPTX
InDesign Experiments
PDF
Эффективный SMM или почему 100 лайков не означает 100 клиентов
DOC
Мысль вслух №1
PPTX
Comparativos
PPT
PDF
Marine corps intelligence activity romania country handbook
PDF
Ciutats 2.0 - Citymarketing
PPTX
The power of social media uwo
Мысль №11
Контакт центр – ефективний інструмент керування містом
Khao sat Hanh Vi Lua Tuoi Teen Viet Nam 2012 by FTA
Personajes
Использование социальных медиа как инструмент продвижения гостиничного бизнеса
Cycles of a film
Del Off al On y viceversa. Verdades y mitos del Comercio Electrónico
О Погорєлов "Ефективні комунікації під час громадського моніторингу публічних...
Ver. Caffé
La resistencia aeróbica
数字时代阅读报告 第五期 2011年3月号
Praktijkonderzoek als competentie
InDesign Experiments
Эффективный SMM или почему 100 лайков не означает 100 клиентов
Мысль вслух №1
Comparativos
Marine corps intelligence activity romania country handbook
Ciutats 2.0 - Citymarketing
The power of social media uwo
Ad

Similar to The Software Developers Guide to Prototyping Wearable Devices (20)

PDF
Android wear SDK introduction
PDF
Droidcon Turin 2015 - Android wear sdk introduction
PDF
Bluetooth Low Energy In Android Java Your Guide To Programming The Internet O...
PDF
Demystifying Android's Bluetooth Low Energy at MCE^3 Conf
PDF
MCE^3 - Dariusz Seweryn, Paweł Urban - Demystifying Android's Bluetooth Low ...
PDF
Desert Code Camp 2014.2 Intro to Bluetooth Low Energy
PPT
Android wearpp
PDF
A Brief Introduction to Bluetooth Low Energy (BLE) on iOS
PPTX
Bluetooth World 2018 - Intro to Bluetooth Low Energy with Mbed OS
PPTX
Android App with Meatwear
PDF
GDG Mediterranean Dev Fest Code lab #DevFestMed15 da android ad android wear ...
PDF
Eddystone beacons demo
PDF
Practical Core Bluetooth in IoT & Wearable projects @ UIKonf 2016
PDF
Android Wear from zero to hero
DOCX
Assistive Technology_Research
PDF
Intel Curie Presentation
PDF
JAM805 - Beyond the Device
PPTX
Bluetooth Accessing Android for mca .pptx
PDF
UXperts 2012: Connectivity Beyond the Web (Android), Friedger Müffke
PDF
Da Arduino ad Android_ illumina il Natale con il BLE
Android wear SDK introduction
Droidcon Turin 2015 - Android wear sdk introduction
Bluetooth Low Energy In Android Java Your Guide To Programming The Internet O...
Demystifying Android's Bluetooth Low Energy at MCE^3 Conf
MCE^3 - Dariusz Seweryn, Paweł Urban - Demystifying Android's Bluetooth Low ...
Desert Code Camp 2014.2 Intro to Bluetooth Low Energy
Android wearpp
A Brief Introduction to Bluetooth Low Energy (BLE) on iOS
Bluetooth World 2018 - Intro to Bluetooth Low Energy with Mbed OS
Android App with Meatwear
GDG Mediterranean Dev Fest Code lab #DevFestMed15 da android ad android wear ...
Eddystone beacons demo
Practical Core Bluetooth in IoT & Wearable projects @ UIKonf 2016
Android Wear from zero to hero
Assistive Technology_Research
Intel Curie Presentation
JAM805 - Beyond the Device
Bluetooth Accessing Android for mca .pptx
UXperts 2012: Connectivity Beyond the Web (Android), Friedger Müffke
Da Arduino ad Android_ illumina il Natale con il BLE

More from TechWell (20)

PDF
Failing and Recovering
PDF
Instill a DevOps Testing Culture in Your Team and Organization
PDF
Test Design for Fully Automated Build Architecture
PDF
System-Level Test Automation: Ensuring a Good Start
PDF
Build Your Mobile App Quality and Test Strategy
PDF
Testing Transformation: The Art and Science for Success
PDF
Implement BDD with Cucumber and SpecFlow
PDF
Develop WebDriver Automated Tests—and Keep Your Sanity
PDF
Ma 15
PDF
Eliminate Cloud Waste with a Holistic DevOps Strategy
PDF
Transform Test Organizations for the New World of DevOps
PDF
The Fourth Constraint in Project Delivery—Leadership
PDF
Resolve the Contradiction of Specialists within Agile Teams
PDF
Pin the Tail on the Metric: A Field-Tested Agile Game
PDF
Agile Performance Holarchy (APH)—A Model for Scaling Agile Teams
PDF
A Business-First Approach to DevOps Implementation
PDF
Databases in a Continuous Integration/Delivery Process
PDF
Mobile Testing: What—and What Not—to Automate
PDF
Cultural Intelligence: A Key Skill for Success
PDF
Turn the Lights On: A Power Utility Company's Agile Transformation
Failing and Recovering
Instill a DevOps Testing Culture in Your Team and Organization
Test Design for Fully Automated Build Architecture
System-Level Test Automation: Ensuring a Good Start
Build Your Mobile App Quality and Test Strategy
Testing Transformation: The Art and Science for Success
Implement BDD with Cucumber and SpecFlow
Develop WebDriver Automated Tests—and Keep Your Sanity
Ma 15
Eliminate Cloud Waste with a Holistic DevOps Strategy
Transform Test Organizations for the New World of DevOps
The Fourth Constraint in Project Delivery—Leadership
Resolve the Contradiction of Specialists within Agile Teams
Pin the Tail on the Metric: A Field-Tested Agile Game
Agile Performance Holarchy (APH)—A Model for Scaling Agile Teams
A Business-First Approach to DevOps Implementation
Databases in a Continuous Integration/Delivery Process
Mobile Testing: What—and What Not—to Automate
Cultural Intelligence: A Key Skill for Success
Turn the Lights On: A Power Utility Company's Agile Transformation

Recently uploaded (20)

PPTX
ai tools demonstartion for schools and inter college
PPTX
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
PDF
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
PDF
Navsoft: AI-Powered Business Solutions & Custom Software Development
PDF
Adobe Illustrator 28.6 Crack My Vision of Vector Design
PDF
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
PDF
Odoo Companies in India – Driving Business Transformation.pdf
PPTX
Odoo POS Development Services by CandidRoot Solutions
PDF
wealthsignaloriginal-com-DS-text-... (1).pdf
PDF
PTS Company Brochure 2025 (1).pdf.......
PDF
Softaken Excel to vCard Converter Software.pdf
PPTX
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
PPTX
Introduction to Artificial Intelligence
PPTX
Operating system designcfffgfgggggggvggggggggg
PDF
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
PPTX
Essential Infomation Tech presentation.pptx
PDF
Nekopoi APK 2025 free lastest update
PPTX
Transform Your Business with a Software ERP System
PPTX
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 41
ai tools demonstartion for schools and inter college
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
Navsoft: AI-Powered Business Solutions & Custom Software Development
Adobe Illustrator 28.6 Crack My Vision of Vector Design
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
Odoo Companies in India – Driving Business Transformation.pdf
Odoo POS Development Services by CandidRoot Solutions
wealthsignaloriginal-com-DS-text-... (1).pdf
PTS Company Brochure 2025 (1).pdf.......
Softaken Excel to vCard Converter Software.pdf
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
Introduction to Artificial Intelligence
Operating system designcfffgfgggggggvggggggggg
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
Essential Infomation Tech presentation.pptx
Nekopoi APK 2025 free lastest update
Transform Your Business with a Software ERP System
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
Internet Downloader Manager (IDM) Crack 6.42 Build 41

The Software Developers Guide to Prototyping Wearable Devices

  • 1.   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  ·∙  sqeinfo@sqe.com  ·∙  www.sqe.com
  • 2. 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.  
  • 11. Cons • Impossible to create a at scale prototype • Many extensions overkill for wearables
  • 12. Pros • Inexpensive • Available GPS Module • Low Power • Aduino Based • Lots of Support Cons • No easy way to integrate Bluetooth or Wifi • Requires a physical connection to get data • Things like an accelerometer require a separate component
  • 15. Features • Bluetooth Support • Robust API for Android and IOS • Built in Sensors (temperature, accelerometer etc.) • Built in support for rechargeable batteries 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
  • 16. 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
  • 17. Cons • Really Small • Tough to write custom drivers • Proprietary
  • 18. Bluetooth • Same Frequency range as 2.4 Gigahertz Wifi • 79 Channels VS 13 • Less Throughput
  • 19. Bluetooth LE • Always off • Less Throughput • Often lower transmit power • Designed for low data low power Applications
  • 20. IOS • IPad 3rd Generation or better • Iphone 4S or greater
  • 21. Android • Bluetooth 4.0 supported radio • Android 4.3 or greater
  • 23. repositories { ivy { url "http://ivyrep.mbientlab.com" layout "gradle" } } compile 'com.mbientlab:metawear:1.5.3' Include the Repo <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <service android:name="com.mbientlab.metawear.api.MetaWearBleService" /> <!-- Other application info --> </application> Update The Manifest
  • 24. 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) { } } 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
  • 25. 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
  • 26. 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(); 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
  • 27. .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
  • 29. Example Code Available at https://github.com/lgleasain/Metawear-Android-SOS Twitter @lgleasain Github lgleasain www.lancegleason.com www.polyglotprogrammincinc.com lgleason@polyglotprogramminginc.com