summaryrefslogtreecommitdiff
path: root/sensors/SensorsComboDriver/Clients.h
blob: a8992fa7cfbe9fae6f662520cb904c722f099ef2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
// Copyright (C) Microsoft Corporation, All Rights Reserved
//
// Abstract:
//
//  This module contains the type definitions for the client
//  driver's device callback class.
//
// Environment:
//
//  Windows User-Mode Driver Framework (WUDF)

#pragma once

#include <windows.h>
#include <wdf.h>
#include <cmath>
#include <timeapi.h>

#include "SensorsTrace.h"
#include <SensorsCx.h>
#include <SensorsUtils.h>

//
// CLX Callbacks
//
EVT_SENSOR_DRIVER_START_SENSOR               OnStart;
EVT_SENSOR_DRIVER_STOP_SENSOR                OnStop;
EVT_SENSOR_DRIVER_GET_SUPPORTED_DATA_FIELDS  OnGetSupportedDataFields;
EVT_SENSOR_DRIVER_GET_PROPERTIES             OnGetProperties;
EVT_SENSOR_DRIVER_GET_DATA_FIELD_PROPERTIES  OnGetDataFieldProperties;
EVT_SENSOR_DRIVER_GET_DATA_INTERVAL          OnGetDataInterval;
EVT_SENSOR_DRIVER_SET_DATA_INTERVAL          OnSetDataInterval;
EVT_SENSOR_DRIVER_GET_DATA_THRESHOLDS        OnGetDataThresholds;
EVT_SENSOR_DRIVER_SET_DATA_THRESHOLDS        OnSetDataThresholds;
EVT_SENSOR_DRIVER_DEVICE_IO_CONTROL          OnIoControl;
EVT_SENSOR_DRIVER_START_SENSOR_HISTORY       OnStartHistory;
EVT_SENSOR_DRIVER_STOP_SENSOR_HISTORY        OnStopHistory;
EVT_SENSOR_DRIVER_CLEAR_SENSOR_HISTORY       OnClearHistory;
EVT_SENSOR_DRIVER_START_HISTORY_RETRIEVAL    OnStartHistoryRetrieval;
EVT_SENSOR_DRIVER_CANCEL_HISTORY_RETRIEVAL   OnCancelHistoryRetrieval;
EVT_SENSOR_DRIVER_ENABLE_WAKE                OnEnableWake;
EVT_SENSOR_DRIVER_DISABLE_WAKE               OnDisableWake;

EVT_WDF_TIMER                                OnTimerExpire;


/*++
Routine Description:
    Critical section lock/unlock to protect shared context
Return Value:
    None
--*/
#define Lock(lock)      { WdfWaitLockAcquire(lock, NULL); }
#define Unlock(lock)    { WdfWaitLockRelease(lock); }

#define SENSORV2_POOL_TAG_COMBO           '2bmC'

//
// Sensor Enumeration Properties
//
typedef enum
{
    SENSOR_TYPE_GUID = 0,
    SENSOR_MANUFACTURER,
    SENSOR_MODEL,
    SENSOR_CONNECTION_TYPE,
    SENSOR_PERSISTENT_UNIQUEID,
    SENSOR_ISPRIMARY,
    SENSOR_ENUMERATION_PROPERTIES_COUNT
} SENSOR_ENUMERATION_PROPERTIES_INDEX;

enum class SensorConnectionType : ULONG
{
    Integrated = 0,
    Attached = 1,
    External = 2
};

//
// Data-field Properties
//
typedef enum
{
    SENSOR_RESOLUTION = 0,
    SENSOR_MIN_RANGE,
    SENSOR_MAX_RANGE,
    SENSOR_DATA_FIELD_PROPERTY_COUNT
} SENSOR_DATA_FIELD_PROPERTY_INDEX;

//
// Sensor Common Properties
//
typedef enum
{
    SENSOR_COMMON_PROPERTY_STATE = 0,
    SENSOR_COMMON_PROPERTY_MIN_INTERVAL,
    SENSOR_COMMON_PROPERTY_MAX_DATAFIELDSIZE,
    SENSOR_COMMON_PROPERTY_TYPE,
    SENSOR_COMMON_PROPERTY_COUNT
} SENSOR_COMMON_PROPERTIES_INDEX;



//
// Base ---------------------------------------------------------------------
//
typedef class _ComboDevice
{
public:
    //
    // WDF
    //
    WDFDEVICE                   m_Device;
    SENSOROBJECT                m_SensorInstance;
    WDFWAITLOCK                 m_Lock;
    WDFTIMER                    m_Timer;

    //
    // Sensor Operation
    //
    BOOLEAN                     m_PoweredOn;
    BOOLEAN                     m_Started;
    ULONG                       m_IntervalMs;
    ULONG                       m_MinimumIntervalMs;
    BOOLEAN                     m_FirstSample;
    ULONG                       m_StartTime;
    ULONGLONG                   m_SampleCount;
    BOOLEAN                     m_WakeEnabled;

    //
    // Sensor Specific Properties
    //
    PSENSOR_COLLECTION_LIST     m_pEnumerationProperties;
    PSENSOR_COLLECTION_LIST     m_pProperties;
    PSENSOR_PROPERTY_LIST       m_pSupportedDataFields;
    PSENSOR_COLLECTION_LIST     m_pDataFieldProperties;
    PSENSOR_COLLECTION_LIST     m_pThresholds;
    PSENSOR_COLLECTION_LIST     m_pData;

public:
    //
    // Sensor specific functions
    //
    virtual NTSTATUS            Initialize(_In_ WDFDEVICE Device, _In_ SENSOROBJECT SensorObj) = NULL;
    virtual NTSTATUS            GetData()                                                      = NULL;
    virtual NTSTATUS            UpdateCachedThreshold()                                        = NULL;
    virtual NTSTATUS            EnableWake() { return STATUS_NOT_SUPPORTED; }
    virtual NTSTATUS            DisableWake() { return STATUS_NOT_SUPPORTED; }

    //
    // History functions - none of the sensors in this driver actually support history yet, this is for testing purpose now.
    //
    virtual NTSTATUS            StartHistory() { return STATUS_NOT_SUPPORTED; }
    virtual NTSTATUS            StopHistory() { return STATUS_NOT_SUPPORTED; }
    virtual NTSTATUS            ClearHistory() { return STATUS_NOT_SUPPORTED; }
    virtual NTSTATUS            StartHistoryRetrieval(_Inout_ PSENSOR_COLLECTION_LIST /*pHistoryBuffer*/, _In_ ULONG /*HistorySizeInBytes*/) { return STATUS_NOT_SUPPORTED; }
    virtual NTSTATUS            CancelHistoryRetrieval(_Out_ PULONG /*pBytesWritten*/) { return STATUS_NOT_SUPPORTED; }

} ComboDevice, *PComboDevice;

// Set up accessor function to retrieve device context
WDF_DECLARE_CONTEXT_TYPE_WITH_NAME(ComboDevice, GetContextFromSensorInstance);


//
// Ambient Light --------------------------------------------------------------
//
typedef class _AlsDevice : public _ComboDevice
{
private:
    // Internal struct used to store readings
    typedef struct _AlsData
    {
        FLOAT Lux;
        FLOAT Kelvins;
        FLOAT ChromaticityX;
        FLOAT ChromaticityY;
        BOOL IsValid;
    } AlsData, *PAlsData;

    // Internal struct used to store thresholds
    typedef struct _AlsThresholdData
    {
        FLOAT LuxPct;
        FLOAT LuxAbs;
        FLOAT KelvinsAbs;
        FLOAT ChromaticityXAbs;
        FLOAT ChromaticityYAbs;
    } AlsThresholdData;

private:

    AlsThresholdData            m_CachedThresholds;
    AlsData                     m_CachedData;
    AlsData                     m_LastSample;

public:

    NTSTATUS                    Initialize(_In_ WDFDEVICE Device, _In_ SENSOROBJECT SensorObj);
    NTSTATUS                    GetData();
    NTSTATUS                    UpdateCachedThreshold();

} AlsDevice, *PAlsDevice;



//
// Barometer --------------------------------------------------------------
//
typedef class _BarDevice : public _ComboDevice
{
private:

    FLOAT                       m_CachedThresholds;
    FLOAT                       m_CachedData;
    FLOAT                       m_LastSample;

public:

    NTSTATUS                    Initialize(_In_ WDFDEVICE Device, _In_ SENSOROBJECT SensorObj);
    NTSTATUS                    GetData();
    NTSTATUS                    UpdateCachedThreshold();

} BarDevice, *PBarDevice;



//
// Gyroscope ------------------------------------------------------------------
//
typedef class _GyrDevice : public _ComboDevice
{
private:

    VEC3D                       m_CachedThresholds;
    VEC3D                       m_CachedData;
    VEC3D                       m_LastSample;

public:

    NTSTATUS                    Initialize(_In_ WDFDEVICE Device, _In_ SENSOROBJECT SensorObj);
    NTSTATUS                    GetData();
    NTSTATUS                    UpdateCachedThreshold();

} GyrDevice, *PGyrDevice;



//
// Magnetometer ---------------------------------------------------------------
//
typedef struct _MagData
{
    VEC3D Axis;
    ULONG Accuracy;
} MagData, *PMagData;

typedef class _MagDevice : public _ComboDevice
{
private:

    VEC3D                       m_CachedThresholds;
    MagData                     m_CachedData;
    MagData                     m_LastSample;

public:

    NTSTATUS                    Initialize(_In_ WDFDEVICE Device, _In_ SENSOROBJECT SensorObj);
    NTSTATUS                    GetData();
    NTSTATUS                    UpdateCachedThreshold();

} MagDevice, *PMagDevice;



//
// Proximity ------------------------------------------------------------------
//
typedef struct
{
    BOOL Detected;
    ULONG DistanceMillimeters;
} PrxData, *PPrxData;

typedef class _PrxDevice : public _ComboDevice
{
private:

    PrxData                     m_CachedData;
    PrxData                     m_LastSample;

public:

    NTSTATUS                    Initialize(_In_ WDFDEVICE Device, _In_ SENSOROBJECT SensorObj);
    NTSTATUS                    GetData();
    NTSTATUS                    UpdateCachedThreshold();

} PrxDevice, *PPrxDevice;



//
// Relative Fusion ------------------------------------------------------------------
//
typedef class _RelativeFusionDevice : public _ComboDevice
{
private:

    QUATERNION                  m_CachedThresholds;
    QUATERNION                  m_CachedData;
    QUATERNION                  m_LastSample;

public:

    NTSTATUS                    Initialize(_In_ WDFDEVICE Device, _In_ SENSOROBJECT SensorObj);
    NTSTATUS                    GetData();
    NTSTATUS                    UpdateCachedThreshold();

} RelativeFusionDevice, *PRelativeFusionDevice;

//
// Linear Accelerometer --------------------------------------------------------------
//
typedef class _LinearAccelerometerDevice : public _ComboDevice
{
private:

    typedef struct _LinearAccelerometerSample
    {
        VEC3D   Axis;
        BOOL    Shake;
    } LinearAccelerometerSample, *PLinearAccelerometerSample;

    LinearAccelerometerSample                       m_CachedThresholds;
    LinearAccelerometerSample                       m_CachedData;
    LinearAccelerometerSample                       m_LastSample;

public:

    NTSTATUS                    Initialize(_In_ WDFDEVICE Device, _In_ SENSOROBJECT SensorObj);
    NTSTATUS                    GetData();
    NTSTATUS                    UpdateCachedThreshold();

} LinearAccelerometerDevice, *PLinearAccelerometerDevice;

//
// Gravity Vector --------------------------------------------------------------
//
typedef class _GravityVectorDevice : public _ComboDevice
{
private:

    VEC3D                       m_CachedThresholds;
    VEC3D                       m_CachedData;
    VEC3D                       m_LastSample;

public:

    NTSTATUS                    Initialize(_In_ WDFDEVICE Device, _In_ SENSOROBJECT SensorObj);
    NTSTATUS                    GetData();
    NTSTATUS                    UpdateCachedThreshold();

} GravityVectorDevice, *PGravityVectorDevice;

//
// Geomagnetic Orientation ------------------------------------------------------------------
//
typedef class _GeomagneticOrientationDevice : public _ComboDevice
{
private:

    typedef struct _GeomagneticOrientationSample
    {
        QUATERNION Quaternion;
        FLOAT RotationAngle_Degrees;
        FLOAT DeclinationAngle_Degrees;
    } GeomagneticOrientationSample, *PGeomagneticOrientationSample;

    GeomagneticOrientationSample                  m_CachedThresholds;
    GeomagneticOrientationSample                  m_CachedData;
    GeomagneticOrientationSample                  m_LastSample;

public:

    NTSTATUS                    Initialize(_In_ WDFDEVICE Device, _In_ SENSOROBJECT SensorObj);
    NTSTATUS                    GetData();
    NTSTATUS                    UpdateCachedThreshold();

} GeomagneticOrientationDevice, *PGeomagneticOrientationDevice;