Skip to content

Commit e8cd2c9

Browse files
Merge pull request #2 from FrameworkComputer/simple-device-orientation
Implement 3D Accelerometer with crosecbus
2 parents 2e189b0 + 07e1f89 commit e8cd2c9

40 files changed

Lines changed: 529 additions & 5418 deletions

.gitattributes

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
###############################################################################
2+
# Set default behavior to automatically normalize line endings.
3+
###############################################################################
4+
* text=auto
5+
6+
# Declare files that will always have CRLF line endings on checkout.
7+
*.appxmanifest text eol=crlf
8+
*.c text eol=crlf
9+
*.cpp text eol=crlf
10+
*.cs text eol=crlf
11+
*.csproj text eol=crlf
12+
*.css text eol=crlf
13+
*.def text eol=crlf
14+
*.filters text eol=crlf
15+
*.h text eol=crlf
16+
*.htm text eol=crlf
17+
*.html text eol=crlf
18+
*.idl text eol=crlf
19+
*.js text eol=crlf
20+
*.jsproj text eol=crlf
21+
*.rc text eol=crlf
22+
*.rgs text eol=crlf
23+
*.sln text eol=crlf
24+
*.vcxproj text eol=crlf
25+
*.xaml text eol=crlf
26+
27+
# Declare files that are encoded in UTF-16
28+
*.inf text diff working-tree-encoding=UTF-16LE-BOM eol=crlf
29+
*.inx text diff working-tree-encoding=UTF-16LE-BOM eol=crlf
30+
31+
###############################################################################
32+
# Set default behavior for command prompt diff.
33+
#
34+
# This is need for earlier builds of msysgit that does not have it on by
35+
# default for csharp files.
36+
# Note: This is only used by command line
37+
###############################################################################
38+
*.cs diff=csharp

.github/workflows/ci.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010
platform: [x64]
1111
runs-on: windows-2022
1212
# env:
13-
# Solution_Path: SensorsComboDriver\SensorsComboDriver.sln
13+
# Solution_Path: FrameworkSensors\FrameworkSensors.sln
1414
steps:
1515
- name: Check out repository code
1616
uses: actions/checkout@v4
@@ -21,8 +21,7 @@ jobs:
2121
# msbuild ${{ env.Solution_Path }} -p:Configuration:${{ env.Configuration }} -p:Platform:${{ env.Platform }}
2222
- name: Build solution
2323
run: |
24-
msbuild SensorsComboDriver\SensorsComboDriver.sln /property:Configuration=${{ env.Configuration }} /property:Platform=${{ env.Platform }}
25-
msbuild SimpleDeviceOrientationSensor\SimpleDeviceOrientationSensor.sln /property:Configuration=${{ env.Configuration }} /property:Platform=${{ env.Platform }}
24+
msbuild FrameworkSensors\FrameworkSensors.sln /property:Configuration=${{ env.Configuration }} /property:Platform=${{ env.Platform }}
2625
env:
2726
Configuration: ${{ matrix.configuration }}
2827
Platform: ${{ matrix.platform }}
Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
// Windows User-Mode Driver Framework (WUDF)
1010

1111
#include "Clients.h"
12+
#include "EcCommunication.h"
1213

1314
#include "AlsClient.tmh"
1415

@@ -165,7 +166,7 @@ AlsDevice::Initialize(
165166
&(m_pEnumerationProperties->List[SENSOR_TYPE_GUID].Value));
166167

167168
m_pEnumerationProperties->List[SENSOR_MANUFACTURER].Key = DEVPKEY_Sensor_Manufacturer;
168-
InitPropVariantFromString(L"Manufacturer name",
169+
InitPropVariantFromString(L"Framework Computer Inc",
169170
&(m_pEnumerationProperties->List[SENSOR_MANUFACTURER].Value));
170171

171172
m_pEnumerationProperties->List[SENSOR_MODEL].Key = DEVPKEY_Sensor_Model;
@@ -462,7 +463,6 @@ AlsDevice::Initialize(
462463
}
463464

464465

465-
466466
//------------------------------------------------------------------------------
467467
// Function: GetData
468468
//
@@ -478,6 +478,7 @@ AlsDevice::Initialize(
478478
//------------------------------------------------------------------------------
479479
NTSTATUS
480480
AlsDevice::GetData(
481+
_In_ HANDLE Handle
481482
)
482483
{
483484
BOOLEAN DataReady = FALSE;
@@ -486,6 +487,15 @@ AlsDevice::GetData(
486487

487488
SENSOR_FunctionEnter();
488489

490+
UINT8 als[4] = {0};
491+
CrosEcReadMemU8(Handle, EC_MEMMAP_ALS + 0, &als[0]);
492+
CrosEcReadMemU8(Handle, EC_MEMMAP_ALS + 1, &als[1]);
493+
CrosEcReadMemU8(Handle, EC_MEMMAP_ALS + 2, &als[2]);
494+
CrosEcReadMemU8(Handle, EC_MEMMAP_ALS + 3, &als[3]);
495+
m_CachedData.Lux = (float) (als[0] + (als[1] << 8) + (als[2] << 16) + (als[3] << 24));
496+
TraceInformation("Read ALS value %02x %02x %02x %02x (%f)\n",
497+
als[0], als[1], als[2], als[3], m_CachedData.Lux);
498+
489499
// new sample?
490500
if (m_FirstSample != FALSE)
491501
{
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ OnTimerExpire(
4747

4848
// Get data and push to clx
4949
Lock(pDevice->m_Lock);
50-
Status = pDevice->GetData();
50+
Status = pDevice->GetData(pDevice->m_CrosEcHandle);
5151
if (!NT_SUCCESS(Status) && Status != STATUS_DATA_NOT_ACCEPTED)
5252
{
5353
TraceError("COMBO %!FUNC! GetData Failed %!STATUS!", Status);
Lines changed: 15 additions & 146 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ typedef class _ComboDevice
126126
ULONG m_StartTime;
127127
ULONGLONG m_SampleCount;
128128
BOOLEAN m_WakeEnabled;
129+
HANDLE m_CrosEcHandle;
129130

130131
//
131132
// Sensor Specific Properties
@@ -142,7 +143,7 @@ typedef class _ComboDevice
142143
// Sensor specific functions
143144
//
144145
virtual NTSTATUS Initialize(_In_ WDFDEVICE Device, _In_ SENSOROBJECT SensorObj) = NULL;
145-
virtual NTSTATUS GetData() = NULL;
146+
virtual NTSTATUS GetData(_In_ HANDLE Handle) = NULL;
146147
virtual NTSTATUS UpdateCachedThreshold() = NULL;
147148
virtual NTSTATUS EnableWake() { return STATUS_NOT_SUPPORTED; }
148149
virtual NTSTATUS DisableWake() { return STATUS_NOT_SUPPORTED; }
@@ -197,127 +198,13 @@ typedef class _AlsDevice : public _ComboDevice
197198
public:
198199

199200
NTSTATUS Initialize(_In_ WDFDEVICE Device, _In_ SENSOROBJECT SensorObj);
200-
NTSTATUS GetData();
201+
NTSTATUS GetData(_In_ HANDLE Device);
201202
NTSTATUS UpdateCachedThreshold();
202203

203204
} AlsDevice, *PAlsDevice;
204205

205206

206207

207-
//
208-
// Barometer --------------------------------------------------------------
209-
//
210-
typedef class _BarDevice : public _ComboDevice
211-
{
212-
private:
213-
214-
FLOAT m_CachedThresholds;
215-
FLOAT m_CachedData;
216-
FLOAT m_LastSample;
217-
218-
public:
219-
220-
NTSTATUS Initialize(_In_ WDFDEVICE Device, _In_ SENSOROBJECT SensorObj);
221-
NTSTATUS GetData();
222-
NTSTATUS UpdateCachedThreshold();
223-
224-
} BarDevice, *PBarDevice;
225-
226-
227-
228-
//
229-
// Gyroscope ------------------------------------------------------------------
230-
//
231-
typedef class _GyrDevice : public _ComboDevice
232-
{
233-
private:
234-
235-
VEC3D m_CachedThresholds;
236-
VEC3D m_CachedData;
237-
VEC3D m_LastSample;
238-
239-
public:
240-
241-
NTSTATUS Initialize(_In_ WDFDEVICE Device, _In_ SENSOROBJECT SensorObj);
242-
NTSTATUS GetData();
243-
NTSTATUS UpdateCachedThreshold();
244-
245-
} GyrDevice, *PGyrDevice;
246-
247-
248-
249-
//
250-
// Magnetometer ---------------------------------------------------------------
251-
//
252-
typedef struct _MagData
253-
{
254-
VEC3D Axis;
255-
ULONG Accuracy;
256-
} MagData, *PMagData;
257-
258-
typedef class _MagDevice : public _ComboDevice
259-
{
260-
private:
261-
262-
VEC3D m_CachedThresholds;
263-
MagData m_CachedData;
264-
MagData m_LastSample;
265-
266-
public:
267-
268-
NTSTATUS Initialize(_In_ WDFDEVICE Device, _In_ SENSOROBJECT SensorObj);
269-
NTSTATUS GetData();
270-
NTSTATUS UpdateCachedThreshold();
271-
272-
} MagDevice, *PMagDevice;
273-
274-
275-
276-
//
277-
// Proximity ------------------------------------------------------------------
278-
//
279-
typedef struct
280-
{
281-
BOOL Detected;
282-
ULONG DistanceMillimeters;
283-
} PrxData, *PPrxData;
284-
285-
typedef class _PrxDevice : public _ComboDevice
286-
{
287-
private:
288-
289-
PrxData m_CachedData;
290-
PrxData m_LastSample;
291-
292-
public:
293-
294-
NTSTATUS Initialize(_In_ WDFDEVICE Device, _In_ SENSOROBJECT SensorObj);
295-
NTSTATUS GetData();
296-
NTSTATUS UpdateCachedThreshold();
297-
298-
} PrxDevice, *PPrxDevice;
299-
300-
301-
302-
//
303-
// Relative Fusion ------------------------------------------------------------------
304-
//
305-
typedef class _RelativeFusionDevice : public _ComboDevice
306-
{
307-
private:
308-
309-
QUATERNION m_CachedThresholds;
310-
QUATERNION m_CachedData;
311-
QUATERNION m_LastSample;
312-
313-
public:
314-
315-
NTSTATUS Initialize(_In_ WDFDEVICE Device, _In_ SENSOROBJECT SensorObj);
316-
NTSTATUS GetData();
317-
NTSTATUS UpdateCachedThreshold();
318-
319-
} RelativeFusionDevice, *PRelativeFusionDevice;
320-
321208
//
322209
// Linear Accelerometer --------------------------------------------------------------
323210
//
@@ -338,52 +225,34 @@ typedef class _LinearAccelerometerDevice : public _ComboDevice
338225
public:
339226

340227
NTSTATUS Initialize(_In_ WDFDEVICE Device, _In_ SENSOROBJECT SensorObj);
341-
NTSTATUS GetData();
228+
NTSTATUS GetData(_In_ HANDLE Device);
342229
NTSTATUS UpdateCachedThreshold();
343230

344231
} LinearAccelerometerDevice, *PLinearAccelerometerDevice;
345232

346-
//
347-
// Gravity Vector --------------------------------------------------------------
348-
//
349-
typedef class _GravityVectorDevice : public _ComboDevice
350-
{
351-
private:
352-
353-
VEC3D m_CachedThresholds;
354-
VEC3D m_CachedData;
355-
VEC3D m_LastSample;
356-
357-
public:
358233

359-
NTSTATUS Initialize(_In_ WDFDEVICE Device, _In_ SENSOROBJECT SensorObj);
360-
NTSTATUS GetData();
361-
NTSTATUS UpdateCachedThreshold();
362-
363-
} GravityVectorDevice, *PGravityVectorDevice;
364234

365235
//
366-
// Geomagnetic Orientation ------------------------------------------------------------------
236+
// Simple Device Orientation --------------------------------------------------
367237
//
368-
typedef class _GeomagneticOrientationDevice : public _ComboDevice
238+
typedef class _SimpleDeviceOrientationDevice : public _ComboDevice
369239
{
370240
private:
371241

372-
typedef struct _GeomagneticOrientationSample
242+
typedef struct _SimpleDeviceOrientationSample
373243
{
374-
QUATERNION Quaternion;
375-
FLOAT RotationAngle_Degrees;
376-
FLOAT DeclinationAngle_Degrees;
377-
} GeomagneticOrientationSample, *PGeomagneticOrientationSample;
244+
FLOAT X;
245+
BOOL Shake;
246+
} SimpleDeviceOrientationSample, *PSimpleDeviceOrientationSample;
378247

379-
GeomagneticOrientationSample m_CachedThresholds;
380-
GeomagneticOrientationSample m_CachedData;
381-
GeomagneticOrientationSample m_LastSample;
248+
SimpleDeviceOrientationSample m_CachedThresholds;
249+
SimpleDeviceOrientationSample m_CachedData;
250+
SimpleDeviceOrientationSample m_LastSample;
382251

383252
public:
384253

385254
NTSTATUS Initialize(_In_ WDFDEVICE Device, _In_ SENSOROBJECT SensorObj);
386-
NTSTATUS GetData();
255+
NTSTATUS GetData(_In_ HANDLE Device);
387256
NTSTATUS UpdateCachedThreshold();
388257

389-
} GeomagneticOrientationDevice, *PGeomagneticOrientationDevice;
258+
} SimpleDeviceOrientationDevice, *PSimpleDeviceOrientationDevice;

0 commit comments

Comments
 (0)