[PATCH 3/5] programs/joystick: Command line options for setting axes range
Lucas Fialho Zawacki
lfzawacki at gmail.com
Fri May 18 08:50:48 CDT 2012
From: Lucas Fialho Zawacki <lfzawacki at gmail.com>
---
programs/joystick/main.c | 36 +++++++++++++++++++++++++++++++-----
1 file changed, 31 insertions(+), 5 deletions(-)
diff --git a/programs/joystick/main.c b/programs/joystick/main.c
index 357388d..5cf6266 100644
--- a/programs/joystick/main.c
+++ b/programs/joystick/main.c
@@ -43,6 +43,8 @@ struct JoystickData {
int num_joysticks;
int cur_joystick;
int poll_time;
+ int axes_max;
+ int axes_min;
};
/* Printing Functions */
@@ -78,9 +80,23 @@ static BOOL CALLBACK EnumObjectsCallback(const DIDEVICEOBJECTINSTANCEA *instance
{
struct JoystickData *data = context;
struct Joystick *joystick = &data->joysticks[data->cur_joystick];
+ DIPROPRANGE propRange;
if (instance->dwType & DIDFT_BUTTON) joystick->num_buttons += 1;
- if (instance->dwType & DIDFT_AXIS) joystick->num_axes += 1;
+
+ if (instance->dwType & DIDFT_AXIS) {
+ joystick->num_axes += 1;
+
+ /* Set axis range */
+ propRange.diph.dwSize = sizeof(DIPROPRANGE);
+ propRange.diph.dwHeaderSize = sizeof(DIPROPHEADER);
+ propRange.diph.dwHow = DIPH_BYID;
+ propRange.diph.dwObj = instance->dwType;
+ propRange.lMin = data->axes_min;
+ propRange.lMax = data->axes_max;
+
+ IDirectInputDevice_SetProperty(joystick->device, DIPROP_RANGE, &propRange.diph);
+ }
return DIENUM_CONTINUE;
}
@@ -173,8 +189,8 @@ static void WaitForInput(const struct JoystickData* data, int chosen)
static void ProcessCmdLine(struct JoystickData *params, LPSTR lpCmdLine)
{
int i, j, buffer_index;
- /* Options are { 'poll' } */
- char options[] = { 'p' };
+ /* Options are { 'poll', 'max-range', 'min-range' } */
+ char options[] = { 'p', 'a', 'i' };
char buffer[32];
char command;
@@ -214,6 +230,16 @@ static void ProcessCmdLine(struct JoystickData *params, LPSTR lpCmdLine)
if (strlen(buffer) == 0) goto invalid;
params->poll_time = atoi(buffer);
break;
+
+ case 'a':
+ if (strlen(buffer) == 0) goto invalid;
+ params->axes_max = atoi(buffer);
+ break;
+
+ case 'i':
+ if (strlen(buffer) == 0) goto invalid;
+ params->axes_min = atoi(buffer);
+ break;
}
}
}
@@ -229,8 +255,8 @@ static void ProcessCmdLine(struct JoystickData *params, LPSTR lpCmdLine)
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrev, LPSTR szCmdLine, int nShow)
{
/* Structure with the data and settings for the application */
- /* data is: lpdi, joy[], num_joy, cur_joy, poll_time */
- struct JoystickData data = { NULL, NULL, 0, 0, 0 };
+ /* data is: lpdi, joy[], num_joy, cur_joy, poll_time, axes_max, axes_min */
+ struct JoystickData data = { NULL, NULL, 0, 0, 0, 1000, -1000 };
HRESULT hr;
/* Get settings from the command line */
--
1.7.9.5
More information about the wine-patches
mailing list