28

Running, working outRunning, late for a meetingHigh altitude bikingWalking, Shopping In car, Driving, Stopped Sleeping

Embed Size (px)

Citation preview

Page 1: Running, working outRunning, late for a meetingHigh altitude bikingWalking, Shopping In car, Driving, Stopped Sleeping
Page 2: Running, working outRunning, late for a meetingHigh altitude bikingWalking, Shopping In car, Driving, Stopped Sleeping

Lisa Ong Rinku SreedharPrincipal Software Engineer Senior Program ManagerSensors Sensors

Building Rich, Contextually Aware Applications Using Sensors

2-735

Page 3: Running, working outRunning, late for a meetingHigh altitude bikingWalking, Shopping In car, Driving, Stopped Sleeping

Promise of Context AwarenessWindows 10 Sensor APIs Demos

Agenda slide

Page 4: Running, working outRunning, late for a meetingHigh altitude bikingWalking, Shopping In car, Driving, Stopped Sleeping

Promise of Context Awareness

Set 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

Sleeping

Page 5: Running, working outRunning, late for a meetingHigh altitude bikingWalking, Shopping In car, Driving, Stopped Sleeping

How Sensors enable Context Awareness

Are 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?

Page 6: Running, working outRunning, late for a meetingHigh altitude bikingWalking, Shopping In car, Driving, Stopped Sleeping

Introducing the Contextual Awareness Sensor API

Page 7: Running, working outRunning, late for a meetingHigh altitude bikingWalking, Shopping In car, Driving, Stopped Sleeping

WinRT API to detect proximity state, distance and range

• Supports Short and Long Range Sensors

• ApplicationsAutomatic display off during a phone

callWake on approachIn pocket detection Gestures

Proximity API

Page 8: Running, working outRunning, late for a meetingHigh altitude bikingWalking, Shopping In car, Driving, Stopped Sleeping

Proximity DemoSurface Hub

Page 9: Running, working outRunning, late for a meetingHigh altitude bikingWalking, Shopping In car, Driving, Stopped Sleeping

Sensors API namespaceusing 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 Proximity

Page 10: Running, working outRunning, late for a meetingHigh altitude bikingWalking, Shopping In car, Driving, Stopped Sleeping

Intro to Sensors API Pattern using Proximity

using Windows.Devices.Sensors;

Getting the current readingProximitySensorReading reading = sensor.GetCurrentReading();bool isDetected = reading.IsDetected;

Subscribing to reading changessensor.ReadingChanged += ReadingChanged;

void ReadingChanged(ProximitySensor s, ProximitySensorReadingChangedEventArgs e){ ProximitySensorReading reading = e.Reading; bool isDetected = reading.isDetected}

Page 11: Running, working outRunning, late for a meetingHigh altitude bikingWalking, Shopping In car, Driving, Stopped Sleeping

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 ApplicationsHealth & fitness trackingNavigation, Maps, Safe

drivingPower Saving

Activity Detection API

Page 12: Running, working outRunning, late for a meetingHigh altitude bikingWalking, Shopping In car, Driving, Stopped Sleeping

DemoMS Research Predestination Appusing Simulator

Page 13: Running, working outRunning, late for a meetingHigh altitude bikingWalking, Shopping In car, Driving, Stopped Sleeping

Using Activity Sensors and Background Triggers

Getting the current activityvar reading = await activitySensor.GetCurrentReadingAsync();

Subscribing to activity changesactivitySensor.ReadingChanged += new TypedEventHandler<ActivitySensor, ActivitySensorReadingChangedEventArgs>(ReadingChanged);

Getting history of up to 30 daysDateTimeOffset 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..

Page 14: Running, working outRunning, late for a meetingHigh altitude bikingWalking, Shopping In car, Driving, Stopped Sleeping

API to detect users steps Number of steps – walking and running Active time spent walking and running 30 day history

Typical ApplicationsHealth & Fitness Tracking – no fitness gadget requiredCombine wearables and phone sensor data

Pedometer API

Click icon to add picture

Page 15: Running, working outRunning, late for a meetingHigh altitude bikingWalking, Shopping In car, Driving, Stopped Sleeping

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);

Page 16: Running, working outRunning, late for a meetingHigh altitude bikingWalking, Shopping In car, Driving, Stopped Sleeping

Demo Pedometer on Desktop and Mobile

Page 17: Running, working outRunning, late for a meetingHigh altitude bikingWalking, Shopping In car, Driving, Stopped Sleeping

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 API

Page 18: Running, working outRunning, late for a meetingHigh altitude bikingWalking, Shopping In car, Driving, Stopped Sleeping

Using Barometer/Altimeter APISame Sensor API patterns….

Barometer barometer = Barometer.GetDefault();BarometerReading reading = barometer.GetCurrentReading();

double pressure = reading.StationPressureInHectopascals;barometer.ReadingChanged += ...

Altimeter altimeter = Altimeter.GetDefault();AltimeterReading altimeterReading = altimeter.GetCurrentReading();

double altitudeChange = altimeterReading.AltitudeChangeInMeters;altimeter.ReadingChanged += ...

Select a Report Interval

mySensor.ReportInterval = 500;

Page 19: Running, working outRunning, late for a meetingHigh altitude bikingWalking, Shopping In car, Driving, Stopped Sleeping

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 API

Click icon to add picture

Page 20: Running, working outRunning, late for a meetingHigh altitude bikingWalking, Shopping In car, Driving, Stopped Sleeping

Demo UV Custom sensors on IoT

Page 21: Running, working outRunning, late for a meetingHigh altitude bikingWalking, Shopping In car, Driving, Stopped Sleeping

Extensibility using Custom SensorsStep 1: Driver defines and implements sensor IDs and keys

// Driver-defined IDs: UV sensor and UV level readingGuid 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 data

CustomSensorReading reading = sensor.GetCurrentReading();if (reading.Properties.ContainsKey(UVLevelKey))

float UVLevel = reading.Properties[UVLevelKey];

sensor.ReadingChanged += …

Page 22: Running, working outRunning, late for a meetingHigh altitude bikingWalking, Shopping In car, Driving, Stopped Sleeping

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 monitoring

Sensor Batching

Click icon to add picture

Page 23: Running, working outRunning, late for a meetingHigh altitude bikingWalking, Shopping In car, Driving, Stopped Sleeping

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 Magnetometer

Reusing Android and iOS app/code

Click icon to add picture

Windows Bridges

‘Project Astoria’ (Java/C++)

‘Project Islandwood’ (Objective C/C++)

Page 24: Running, working outRunning, late for a meetingHigh altitude bikingWalking, Shopping In car, Driving, Stopped Sleeping

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 API

Page 25: Running, working outRunning, late for a meetingHigh altitude bikingWalking, Shopping In car, Driving, Stopped Sleeping

Partner Demo MS Health

Page 26: Running, working outRunning, late for a meetingHigh altitude bikingWalking, Shopping In car, Driving, Stopped Sleeping

Additional Tips to knowReadingTransform• 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

Page 27: Running, working outRunning, late for a meetingHigh altitude bikingWalking, Shopping In car, Driving, Stopped Sleeping

• Attend Quick Start Challenge to start building Sensor apps

• Universal driver samples • UWP SDK samples• API Reference

Related sessions:Build 2014 Sensors Session: Sensors Platform Enhancements in WindowsBuild 2015 Sessions:1. 3-610 Compiling Objective-C Using the VS 2015 C++ code generation (that also builds Windows, SQL, .Net

and Office2. 2-702 “PROJECT ASTORIA“: Build great Windows apps with your Android code

Get Started

Page 28: Running, working outRunning, late for a meetingHigh altitude bikingWalking, Shopping In car, Driving, Stopped Sleeping

© 2015 Microsoft Corporation. All rights reserved.