From 012eac6d8fc4e11d663994a7c62dc3f911454e9c Mon Sep 17 00:00:00 2001 From: Johannes Anderwald Date: Wed, 28 Dec 2011 11:36:05 +0000 Subject: [PATCH 1/1] [USB-BRINGUP] - Implement mouse move detection, wheel state detection svn path=/branches/usb-bringup/; revision=54772 --- drivers/hid/mouhid/mouhid.c | 56 ++++++++++++++++++++++++++++++-- drivers/hid/mouhid/mouhid.h | 65 ++++++++++++++++++++++++++++++++++++- 2 files changed, 118 insertions(+), 3 deletions(-) diff --git a/drivers/hid/mouhid/mouhid.c b/drivers/hid/mouhid/mouhid.c index 22ca98bd19b..504f103f736 100644 --- a/drivers/hid/mouhid/mouhid.c +++ b/drivers/hid/mouhid/mouhid.c @@ -28,6 +28,35 @@ static USHORT MouHid_ButtonUpFlags[] = MOUSE_BUTTON_5_UP }; +VOID +MouHid_GetButtonMove( + IN PDEVICE_OBJECT DeviceObject, + OUT PLONG LastX, + OUT PLONG LastY) +{ + PMOUHID_DEVICE_EXTENSION DeviceExtension; + NTSTATUS Status; + + /* get device extension */ + DeviceExtension = (PMOUHID_DEVICE_EXTENSION)DeviceObject->DeviceExtension; + + /* init result */ + *LastX = 0; + *LastY = 0; + + /* get scaled usage value x */ + Status = HidP_GetScaledUsageValue(HidP_Input, HID_USAGE_PAGE_GENERIC, HIDP_LINK_COLLECTION_UNSPECIFIED, HID_USAGE_GENERIC_X, (PLONG)&LastX, DeviceExtension->PreparsedData, DeviceExtension->Report, DeviceExtension->ReportLength); + /* FIXME handle error */ + ASSERT(Status == HIDP_STATUS_SUCCESS); + + /* get scaled usage value y */ + Status = HidP_GetScaledUsageValue(HidP_Input, HID_USAGE_PAGE_GENERIC, HIDP_LINK_COLLECTION_UNSPECIFIED, HID_USAGE_GENERIC_Y, (PLONG)&LastY, DeviceExtension->PreparsedData, DeviceExtension->Report, DeviceExtension->ReportLength); + /* FIXME handle error */ + ASSERT(Status == HIDP_STATUS_SUCCESS); + +} + + VOID MouHid_GetButtonFlags( IN PDEVICE_OBJECT DeviceObject, @@ -146,6 +175,9 @@ MouHid_ReadCompletion( { PMOUHID_DEVICE_EXTENSION DeviceExtension; USHORT ButtonFlags; + LONG UsageValue; + NTSTATUS Status; + LONG LastX, LastY; MOUSE_INPUT_DATA MouseInputData; /* get device extension */ @@ -154,14 +186,34 @@ MouHid_ReadCompletion( /* get mouse change flags */ MouHid_GetButtonFlags(DeviceObject, &ButtonFlags); - /* FIXME detect mouse move change */ - /* FIXME detect mouse wheel change */ + /* get mouse change */ + MouHid_GetButtonMove(DeviceObject, &LastX, &LastY); /* init input data */ RtlZeroMemory(&MouseInputData, sizeof(MOUSE_INPUT_DATA)); /* init input data */ MouseInputData.ButtonFlags = ButtonFlags; + MouseInputData.LastX = LastX; + MouseInputData.LastY = LastY; + + /* detect mouse wheel change */ + if (DeviceExtension->MouseIdentifier == WHEELMOUSE_HID_HARDWARE) + { + /* get usage */ + UsageValue = 0; + Status = HidP_GetScaledUsageValue(HidP_Input, HID_USAGE_PAGE_GENERIC, HIDP_LINK_COLLECTION_UNSPECIFIED, HID_USAGE_GENERIC_WHEEL, &UsageValue, DeviceExtension->PreparsedData, DeviceExtension->Report, DeviceExtension->ReportLength); + if (Status == HIDP_STATUS_SUCCESS) + { + /* store wheel status */ + MouseInputData.ButtonFlags |= MOUSE_WHEEL; + MouseInputData.ButtonData = (USHORT)UsageValue; /* FIXME */ + } + else + { + DPRINT1("[MOUHID] failed to get wheel status with %x\n", Status); + } + } /* dispatch mouse action */ MouHid_DispatchInputData(DeviceObject, &MouseInputData); diff --git a/drivers/hid/mouhid/mouhid.h b/drivers/hid/mouhid/mouhid.h index 0cd8320c2f0..39231f564f0 100644 --- a/drivers/hid/mouhid/mouhid.h +++ b/drivers/hid/mouhid/mouhid.h @@ -12,26 +12,89 @@ typedef struct { + // + // lower device object + // PDEVICE_OBJECT NextDeviceObject; + + // + // irp which is used for reading input reports + // PIRP Irp; + + // + // event + // KEVENT Event; + + // + // device object for class callback + // PDEVICE_OBJECT ClassDeviceObject; + + // + // class callback + // PVOID ClassService; + + // + // mouse type + // USHORT MouseIdentifier; + + // + // wheel usage page + // USHORT WheelUsagePage; + // + // usage list length + // USHORT UsageListLength; + + // + // current usage list length + // PUSAGE CurrentUsageList; + + // + // previous usage list + // PUSAGE PreviousUsageList; + + // + // removed usage item list + // PUSAGE BreakUsageList; + + // + // new item usage list + // PUSAGE MakeUsageList; + + // + // preparsed data + // PVOID PreparsedData; + // + // mdl for reading input report + // PMDL ReportMDL; + + // + // input report buffer + // PUCHAR Report; - ULONG ReportLength; + // + // input report length + // + ULONG ReportLength; + // + // file object the device is reading reports from + // PFILE_OBJECT FileObject; }MOUHID_DEVICE_EXTENSION, *PMOUHID_DEVICE_EXTENSION; -- 2.17.1