Principal Software Engineer Senior Program Manager Sensors Sensors Building Rich Contextually Aware Applications Using Sensors ID: 247769
Download Presentation The PPT/PDF document "Lisa Ong" is the property of its rightful owner. Permission is granted to download and print the materials on this web site for personal, non-commercial use only, and to display it on your personal computer provided you do not modify the materials and that you retain all copyright notices contained in the materials. By downloading content from our website, you accept the terms of this agreement.
Slide1Slide2
Lisa Ong Rinku SreedharPrincipal Software Engineer Senior Program ManagerSensors Sensors
Building Rich, Contextually Aware Applications Using Sensors
2-735Slide3
Promise of Context AwarenessWindows 10 Sensor APIs Demos
Agenda slideSlide4
Promise of Context AwarenessSet of facts about users
Reduce explicit interaction, more
responsive
Advanced inferences through machine learning
Running, working out
Running, late for a meeting
High altitude biking
Walking, Shopping
In car, Driving,
Stopped
SleepingSlide5
How Sensors enable Context AwarenessAre you near your device?
Are you driving? Or walking or biking?
Are you trying to track to a fitness goal?
Did you forget where you parked?Slide6
Introducing the Contextual Awareness Sensor APISlide7
WinRT
API
to detect proximity
state, distance and range
Supports Short and Long Range Sensors
Applications
Automatic display off during a phone call
Wake on approach
In pocket detection
Gestures
Proximity APISlide8
Proximity DemoSurface HubSlide9
Sensors API namespace
using
Windows.Devices.Sensors
;
Getting the default sensor (most sensor APIs only return
one
sensor on the system
)
Barometer
barometer =
Barometer.GetDefault();
Getting the sensor (when there are multiple sensors – e.g.: proximity and Custom Sensors)
DeviceWatcher
watcher =
DeviceInformation
.CreateWatcher
(
ProximitySensor
.GetDeviceSelector
());
watcher.Added
+=
OnProximitySensorAdded
;
. . . void OnProximitySensorAdded(DeviceWatcher sender, DeviceInformation device){ ProximitySensor sensor= ProximitySensor.FromId(device.Id);}
Intro to Sensors API Pattern using ProximitySlide10
Intro to Sensors API Pattern using Proximity
using
Windows.Devices.Sensors
;
Getting the current reading
ProximitySensorReading
reading =
sensor.
GetCurrentReading
();
bool
isDetected
=
reading.IsDetected
;
Subscribing to reading changes
sensor.
ReadingChanged
+=
ReadingChanged
;
void
ReadingChanged
(
ProximitySensor s, ProximitySensorReadingChangedEventArgs e){ ProximitySensorReading reading = e.Reading; bool isDetected = reading.isDetected}Slide11
API
to detect user’s motion context
Run, Walk, On bicycle, In vehicle, Fidgeting, Stationary, Idle, Unknown
Most
likely activity with confidence
30 day history
Typical Applications
Health
&
fitness tracking
Navigation, Maps,
S
afe driving
Power Saving
Activity Detection APISlide12
DemoMS Research Predestination Appusing Simulator Slide13
Using Activity Sensors and Background Triggers
Getting the current a
ctivity
var
reading =
await
activitySensor.
GetCurrentReadingAsync
();
Subscribing to activity changesactivitySensor.
ReadingChanged
+= new
TypedEventHandler
<ActivitySensor
,
ActivitySensorReadingChangedEventArgs
>(
ReadingChanged
);
Getting history of up to 30 days
DateTimeOffset
yesterday =
...
var history = await ActivitySensor.GetSystemHistoryAsync(yesterday);foreach (var entry in history) { ... }Using a background taskvar trigger = new Windows.ApplicationModel.Background.ActivitySensorTrigger(reportIntervalMs);
trigger.
SubscribedActivities
.
Add
(
ActivityType
.InVehicle
);
// .. register the trigger, etc..Slide14
API to detect users steps
Number
of steps – walking and running
Active
time spent walking and
running
30 day history
Typical Applications
Health & Fitness Tracking
– no fitness gadget required
Combine wearables and phone sensor data
Pedometer APISlide15
Using Pedometer APIGetting the
pedometer reading changes
pedometer.
ReadingChanged
+=
new
TypedEventHandler
<
Pedometer
,
PedometerReadingChangedEventArgs>(
ReadingChanged);
void
ReadingChanged
(
Pedometer
sender,
PedometerReadingChangedEventArgs
args
)
{
PedometerReading reading = args.Reading; if (reading.StepKind == PedometerStepKind.Walking) walkingSteps = reading.CumulativeSteps;}Getting pedometer step count historyvar history = await
Pedometer
.
GetSystemHistoryAsync
(yesterday);Slide16
Demo Pedometer on Desktop and MobileSlide17
Barometer API reports barometric station pressure
Altimeter API reports
relative altitude/ elevation
Typical Applications
Health & fitness
Floor
Sensing and Indoor Navigation
Weather
Forecasting
Barometer / Altimeter APISlide18
Using Barometer/Altimeter API
Same Sensor API patterns….
Barometer
barometer
=
Barometer
.GetDefault
();
BarometerReading
reading =
barometer.GetCurrentReading();
d
ouble
pressure =
reading.StationPressureInHectopascals
;
barometer.ReadingChanged
+= ...
Altimeter
altimeter
=
Altimeter
.GetDefault
();
AltimeterReading
altimeterReading = altimeter.GetCurrentReading();double altitudeChange = altimeterReading.AltitudeChangeInMeters;altimeter.ReadingChanged += ...Select a Report IntervalmySensor.ReportInterval = 500;Slide19
Add
a completely new Sensor
Examples: CO2 Sensor, UV Sensor,
Heart Rate Sensor…
Hardware
vendors can introduce new Sensor Types independent of Microsoft OS
releases
Simple, familiar API for reading sensor data
Custom Sensor APISlide20
Demo UV Custom sensors on IoTSlide21
Extensibility using Custom Sensors
Step 1: Driver defines and implements sensor IDs and keys
// Driver-defined IDs: UV sensor and UV level reading
Guid
UVSensorID
=
new
Guid
(
"4025a865-638c-43aa-a688-98580961eeae");
const
String
UVLevelKey =
"{74879888-a3cc-45c6-9ea9-058838256433} 1"
;
Step 2: App finds that custom sensor
const
selector =
CustomSensor
.
GetDeviceSelector
(
UVSensorID);watcher = Windows.Devices.Enumeration.DeviceInformation.CreateWatcher(selector);… and consumes its dataCustomSensorReading reading = sensor.GetCurrentReading();if (reading.Properties.ContainsKey(UVLevelKey)) float UVLevel = reading.Properties[
UVLevelKey
];
sensor.ReadingChanged
+= …Slide22
Buffers sensor samples to a batch Client specifies the report latency
accelerometer.ReportLatency
=
accelerometer.MaxBatchSize
*
desiredReportInterval
;
Typical Applications:
Power saving features
Background scenarios like Sleep and Activity monitoringSensor BatchingSlide23
Developer
Proposition
Reuse Existing
Android/ iOS
Code to Build
UWP Apps
Reusing Android Code – Sensors Supported
Activity Detection
Screen
Rotation Accelerometer Gyroscope
MagnetometerProximity Reusing
iOS Code – Sensors Supported Accelerometer
Gyroscope MagnetometerReusing Android and iOS app/code
Windows Bridges
‘Project Astoria’
(Java/C++)
‘Project Islandwood’
(Objective C/C++)Slide24
Lumia
SensorCore APIs – released in 2014 with Activity Tracking features on Lumia Phones
Windows 10 now supports these features on devices ranging from mobile, desktop, IOT
All future enhancement for Activity Detection and Pedometer features will be on the UWP APIs
Guidelines to developers :
For new app development – use UWP APIs
To target Legacy Lumia phones - use
SensorCore
APIs
(Note: Places and Track features of
SensorCore
is Out of Scope)
Lumia
SensorCore
APISlide25
Partner Demo MS HealthSlide26
Additional Tips to know
ReadingTransform
Rotates sensor data for you to a display orientation
1 line change to port apps from portrait-first devices to landscape-first devices (vice-versa)
Data is streamed consistently across platforms
UWP apps on multiple platforms get the same behavior for
ReportInterval
Using Simulator to build and Test your app
Download universal driver samples from
Github
to emulate new sensor types
Privacy
Users can control privacy via Privacy Settings Slide27
Attend Quick Start Challenge to start building Sensor appsUniversal driver samples
UWP SDK samplesAPI Reference
Related sessions:
Build 2014 Sensors Session:
Sensors Platform Enhancements in Windows
Build 2015 Sessions:
3-610 Compiling Objective-C Using the VS 2015 C++ code generation (that also builds Windows, SQL,
.Net
and Office2-702 “PROJECT ASTORIA“: Build great Windows apps with your Android code
Get StartedSlide28