10. Introduction Definition Sensors measure a physical phenomenon or a physical interaction Sensor Types Ambient Light Sensors (ALS) Accelerometers Location Sensors GPS, Wi-Fi /cell tower triangulation, IP Geolocation Proximity Sensors Temperature Sensors Biometric Sensor* Others (Human presence, RFID)
11. Limitations of Sensors Today Sensors are integrated as vertical solutions Applications need to know sensor hardware specifics Limited adoption and scope Sensors are exposed as virtual COM ports Exclusive application access Not secure Proprietary data formats (NMEA, others)
12. Sensor Platform Overview Unified Driver Model for all types of sensors Physical sensors (e.g., GPS devices, Light Sensors) Logical sensor (e.g., Wi-Fi triangulation resolver) Standard APIs for accessing sensors COM-based Sensor API Works with drivers using the sensor class extension Benefits Implements native support for sensor and location devices on Windows No need to target vendor-specific APIs or to know hardware specifics Consistent interface for all sensor types Privacy and security
13. Sensor Platform Architecture Application Application Location and Other Sensors Control Panel Sensor API User System Sensor class extension UMDF sensor driver Sensor device This is a partial diagram of the Sensor and Location Platform, showing only sensor-related parts
21. Sensor API Architecture COM-based API (includes Sensorsapi.h and Sensors.h) Consists of these main interfaces: ISensorManager Sensor enumeration, attachment event, request permissions ISensor Get and set properties, get report, events (new report, detachment, state change, custom) and more ISensorDataReport Get sensor data report data fields
23. Sensors Explained Enumerated via category and type GUIDs Category represents what is being sensed (for example, environment, location, motion, electrical systems) Type represents how it is being sensed (for example, by thermometer, GPS, accelerometer, voltage) Properties Read-only (such as model) or read-write (such as report interval). Sensors may have custom properties Data Get (sensor-specific) data report object synchronously (not recommended) or asynchronously (events) Events State change, leave (detach), data updated, custom State Is sensor working properly? Do you have access?
24. Enumerating Sensors #include <sensorsapi.h> #include <sensors.h> HRESULT hr; CComPtr<ISensorManager> pSensorManager; pSensorManager.CoCreateInstance(CLSID_SensorManager); CComPtr<ISensorCollection> pALSCollection; CComPtr<ISensor> pALSSensor; // Get all the ALS sensors on the system pSensorManager->GetSensorsByType(SENSOR_TYPE_AMBIENT_LIGHT, &pALSCollection); hr = pSensorManager->RequestPermissions( 0, // Owner window pALSCollection, // Collection of sensors requiring permissions TRUE); // Modal flag if(SUCCEEDED(hr)) { pALSCollection->GetAt(0, &pALSSensor); }
25. Getting Current Light Level STDMETHODIMP CALSEventSink::OnDataUpdated( ISensor* pSensor, ISensorDataReport* pNewData) { PROPVARIANT lightLevel; PropVariantInit(&lightLevel); // Get the sensor reading from the ISensorDataReport object pNewData->GetSensorValue(SENSOR_DATA_TYPE_LIGHT_LEVEL_LUX, &lightLevel); // Extract the float value from the PROPVARIANT object float luxValue = V_FLOAT(lightLevel); // Normalize the light sensor data double lightNormalized = ::pow(luxValue, 0.4) / 100.0; // Handle UI changes based on the normalized LUX data // which ranges from 0.0 - 1.0 for a lux range of // 0 lux to 100,000 lux, this method represents such a // handler that would be implemented in your application UpdateUI(lightNormalized); PropVariantClear(&lightLevel); return S_OK; }
43. Location-Awareness Opportunities Useful local information Location based search for points of interest Mapping/navigation based on current location PC recovery service Social networking: Where are my friends and family? Others…
44. Location Platform API Overview The Windows 7 Location API is built on top of the Sensor API COM-based API (includes Locationapi.h) It is a high-level abstraction Leverages sensors which provide location information Some sensors (location providers) may be logical Ex: Wi-Fi hotspot triangulation
45. Location Platform Architecture Gadget or script Application Application Location API Location IDispatch Interface Sensor API User Location and Other Sensors Control Panel System Sensor class extension Sensor class extension UMDF sensor driver UMDF sensor driver Sensor device Logical location sensor (Triangulation)
48. Types of Location Data Geographic data (ILatLongReport) Latitude, longitude, altitude, associated error required Most common format Best format for precise location Can reverse geo-code later Civic address (ICivicAddressReport) Zip code, country required Most human readable Best for ‘rough’ location estimates, street directions Demo…