Skip to content

Commit 5f8022e

Browse files
committed
AccelerometerClient: Re-initialize sensor indices after late EC connection
If the EC driver wasn't available during Initialize(), the sensor indices would still be the default values (lid=0, base=1) and never be updated. This would cause the driver to read from the wrong sensor. Add a flag to keep track of whether the indeces were checked already and initialize them if they weren't when reading sensor data. Signed-off-by: Daniel Schaefer <dhs@frame.work>
1 parent c42a5da commit 5f8022e

2 files changed

Lines changed: 21 additions & 1 deletion

File tree

FrameworkSensors/AccelerometerClient.cpp

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ AccelerometerDevice::Initialize(
170170
// Sensible defaults - applies to most devices
171171
m_LidSensorIndex = 0;
172172
m_BaseSensor = 1;
173+
m_SensorIndicesInitialized = FALSE;
173174
Context->m_CrosEcHandle = INVALID_HANDLE_VALUE;
174175

175176
// Make sure we have a handle to the EC driver
@@ -196,6 +197,7 @@ AccelerometerDevice::Initialize(
196197
Status = STATUS_NOT_FOUND;
197198
goto Exit;
198199
}
200+
m_SensorIndicesInitialized = TRUE;
199201
}
200202

201203
//
@@ -534,7 +536,24 @@ AccelerometerDevice::GetData(
534536
return STATUS_INVALID_HANDLE;
535537
}
536538

537-
// TODO: Might want to check if sensor indeces are initialized
539+
// Initialize sensor indices if not done during Initialize() (EC wasn't available then)
540+
if (!m_SensorIndicesInitialized) {
541+
UINT8 SensorCount = 0;
542+
Status = CrosEcGetMotionSensorCount(Handle, &SensorCount);
543+
if (NT_SUCCESS(Status) && SensorCount > 0) {
544+
Status = CrosEcGetAccelIndeces(Handle, &m_LidSensorIndex, &m_BaseSensor, SensorCount);
545+
if (NT_SUCCESS(Status)) {
546+
m_SensorIndicesInitialized = TRUE;
547+
TraceInformation("%!FUNC! Late-initialized sensor indices: Lid=%d, Base=%d", m_LidSensorIndex, m_BaseSensor);
548+
} else {
549+
TraceError("%!FUNC! Failed to get accelerometer indices: %!STATUS!", Status);
550+
return Status;
551+
}
552+
} else {
553+
TraceError("%!FUNC! Failed to get sensor count or no sensors available");
554+
return STATUS_DEVICE_NOT_READY;
555+
}
556+
}
538557

539558
UINT8 acc_status = 0;
540559
CrosEcReadMemU8(Handle, EC_MEMMAP_ACC_STATUS, &acc_status);

FrameworkSensors/Clients.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@ typedef class _AccelerometerDevice : public _ComboDevice
223223
AccelerometerSample m_LastSample;
224224
UINT8 m_LidSensorIndex;
225225
UINT8 m_BaseSensor;
226+
BOOLEAN m_SensorIndicesInitialized;
226227

227228
public:
228229

0 commit comments

Comments
 (0)