Skip to content

Commit 24d9eae

Browse files
committed
Accelerometer: Use motionsense HC to get number of sensors
If no sensors available, abort AccelerometerClient. Next step is to find which sensor is at which index. Signed-off-by: Daniel Schaefer <dhs@frame.work>
1 parent 3e9849f commit 24d9eae

2 files changed

Lines changed: 56 additions & 0 deletions

File tree

FrameworkSensors/AccelerometerClient.cpp

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,35 @@ typedef enum
3838
ACCELEROMETER_DATA_COUNT
3939
} ACCELEROMETER_DATA_INDEX;
4040

41+
UINT8 CrosEcGetMotionSensorCount(HANDLE Handle)
42+
{
43+
EC_REQUEST_MOTION_SENSE_DUMP req{};
44+
EC_RESPONSE_MOTION_SENSE_DUMP res{};
45+
46+
if (Handle == INVALID_HANDLE_VALUE) {
47+
TraceError("%!FUNC! Handle is invalid");
48+
return 0;
49+
}
50+
51+
req.Cmd = 0;
52+
req.MaxSensorCount = 0;
53+
if (0 == CrosEcSendCommand(
54+
Handle,
55+
EC_CMD_MOTION_SENSE,
56+
1,
57+
&req,
58+
sizeof(req),
59+
&res,
60+
sizeof(res)
61+
)) {
62+
TraceError("%!FUNC! EC_CMD_MOTION_SENSE_DUMP failed");
63+
return 0;
64+
}
65+
66+
return res.SensorCount;
67+
}
68+
69+
4170
//------------------------------------------------------------------------------
4271
// Function: Initialize
4372
//
@@ -57,6 +86,8 @@ AccelerometerDevice::Initialize(
5786
)
5887
{
5988
NTSTATUS Status = STATUS_SUCCESS;
89+
UINT8 SensorCount = 0;
90+
PComboDevice Context = GetContextFromSensorInstance(SensorInstance);
6091

6192
SENSOR_FunctionEnter();
6293

@@ -67,6 +98,15 @@ AccelerometerDevice::Initialize(
6798
m_SensorInstance = SensorInstance;
6899
m_Started = FALSE;
69100

101+
SensorCount = CrosEcGetMotionSensorCount(Context->m_CrosEcHandle);
102+
TraceInformation("%!FUNC! Found %d Sensors on this device", SensorCount);
103+
if (SensorCount == 0)
104+
{
105+
TraceError("%!FUNC! No Sensors available. Not initializing AccelerometerClient");
106+
Status = STATUS_NOT_FOUND;
107+
goto Exit;
108+
}
109+
70110
//
71111
// Create Lock
72112
//

FrameworkSensors/EcCommunication.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ NTSTATUS ConnectToEc(
4949
_Inout_ HANDLE* Handle
5050
);
5151

52+
#define EC_CMD_MOTION_SENSE 0x002B
5253
#define EC_CMD_RGBKBD_SET_COLOR 0x013A
5354
#define EC_CMD_RGBKBD 0x013B
5455

@@ -93,6 +94,21 @@ typedef struct {
9394
Rgb Colors[CROS_EC_CMD_MAX_KEY_COUNT];
9495
} EC_REQUEST_RGB_KBD_SET_COLOR;
9596

97+
typedef struct {
98+
// Dump = 0
99+
UINT8 Cmd;
100+
UINT8 MaxSensorCount;
101+
} EC_REQUEST_MOTION_SENSE_DUMP;
102+
103+
typedef struct {
104+
UINT8 MaxSensorCount;
105+
UINT8 SensorCount;
106+
// Need to allocate extra data if you care about this field.
107+
// Right now I only care about the count.
108+
// If this field is not there, the EC just truncates the response.
109+
// UINT8 Sensors[];
110+
} EC_RESPONSE_MOTION_SENSE_DUMP;
111+
96112
#include <poppack.h>
97113

98114
int CrosEcSendCommand(

0 commit comments

Comments
 (0)