27 #define PRECALIBRATED 1
29 static int Joy_inited = 0;
44 static int Joy_last_x_reading = 0;
45 static int Joy_last_y_reading = 0;
104 EXECUTION_STATE last_exectution_state = 0;
105 uint last_ssav_time = 0;
112 last_exectution_state = SetThreadExecutionState(ES_CONTINUOUS | ES_DISPLAY_REQUIRED | ES_SYSTEM_REQUIRED);
115 SystemParametersInfo(SPI_GETSCREENSAVETIMEOUT, 0, &last_ssav_time, 0);
116 SystemParametersInfo(SPI_SETSCREENSAVETIMEOUT, 0, NULL, 0);
121 bi = &joy_buttons[
i];
136 memset(&ji, 0,
sizeof(ji));
137 ji.dwSize =
sizeof(ji);
139 ji.dwFlags = JOY_RETURNALL;
147 if (rs == JOYERR_NOERROR) {
148 joy_state = ji.dwButtons;
156 state = joy_state & (1<<
i);
162 if (ji.dwPOV == JOY_POVBACKWARD)
167 if (ji.dwPOV == JOY_POVFORWARD)
172 if (ji.dwPOV == JOY_POVLEFT)
177 if (ji.dwPOV == JOY_POVRIGHT)
189 if (state != joy_buttons[i].actual_state) {
201 if ( joy_buttons[i].state ) {
209 if (joy_buttons[i].state) {
222 last_exectution_state = SetThreadExecutionState(last_exectution_state);
225 SystemParametersInfo(SPI_SETSCREENSAVETIMEOUT, last_ssav_time, NULL, 0);
253 mprintf((
"Joy end thread wait timeout!\n" ));
282 if (JOYERR_NOERROR == joyGetDevCaps (j, &JoyCaps,
sizeof(JoyCaps))) {
287 if (JoyCaps.wCaps & JOYCAPS_HASZ)
289 if (JoyCaps.wCaps & JOYCAPS_HASR)
291 if (JoyCaps.wCaps & JOYCAPS_HASU)
293 if (JoyCaps.wCaps & JOYCAPS_HASV)
303 DCF(joytest,
"Test joystick")
307 dc_printf(
"Real-time test of the joystick's X and Y axes. Readings are taken from the joystick and directly");
308 dc_printf(
"spewed to a popup window. Press ESC to abort the test.\n");
310 dc_printf(
"First pair of readings are the raw values as reported by the OS's input library. Second pair of");
311 dc_printf(
"readings are what the engine uses for controls\n");
326 mprintf((
"X=%5d Y=%5d Calibrated X=%6d Y=%6d\n", axis[0], axis[1], x, y));
332 DCF(joytest2,
"Test joystick (extended)")
336 dc_printf(
"Real-time test of the joystick's X, Y, Z, Rx, Ry, and Rz axes. Readings are taken from the joystick");
337 dc_printf(
"and directly spewed to a popup window. Press ESC to abort the test.");
339 dc_printf(
"First set of readings are the raw values as reported by the OS's input library. Second set of");
340 dc_printf(
"readings are what the engine uses for controls\n");
357 mprintf((
"X=%5d Y=%5d Z=%5d Rx=%5d Ry=%5d Rz=%5d Cal X=%6d Y=%6d Z=%6d R=%6d\n", axis[0], axis[1], axis[2], axis[3], axis[4], axis[5], x, y, z, r));
384 mprintf((
"No joystick driver detected\n"));
388 InitializeCriticalSection(&
joy_lock);
394 memset(&ji, 0,
sizeof(ji));
395 ji.dwSize =
sizeof(ji);
396 ji.dwFlags = JOY_RETURNALL;
401 for (count=0; count<20; count++) {
403 if (rs == JOYERR_NOERROR)
407 if (rs == JOYERR_NOERROR) {
421 SetThreadPriority(
joy_thread, THREAD_PRIORITY_HIGHEST);
430 for (i=0; i<4; i++) {
440 for (i=0; i<4; i++) {
466 mprintf((
"Move stick to upper-left and hit button\n" ));
474 mprintf((
"Move stick to lower-right and hit button\n" ));
482 mprintf((
"Move stick to center and hit button\n" ));
492 int joy_get_pos_old(
int * x,
int * y )
503 memset(&ji, 0,
sizeof(ji));
504 ji.dwSize =
sizeof(ji);
510 ji.dwFlags = JOY_RETURNALL;
512 ji.dwFlags = JOY_CAL_READXYONLY;
520 if (rs == JOYERR_NOERROR) {
528 *x = (ji.dwXpos - 32768) * 2;
536 *y = (ji.dwYpos - 32768) * 2;
603 tmp = joy_buttons[btn].
state;
651 bi = &joy_buttons[btn];
691 for ( i = 0; i < 4; i++) {
711 for (i=0; i<4; i++) {
740 for (i=0; i<num_axes; i++)
751 memset(&ji, 0,
sizeof(ji));
752 ji.dwSize =
sizeof(ji);
755 ji.dwFlags = JOY_RETURNALL;
757 ji.dwFlags = JOY_RETURNRAWDATA;
762 ji.dwFlags |= JOY_RETURNV;
764 ji.dwFlags |= JOY_RETURNU;
766 ji.dwFlags |= JOY_RETURNR;
768 ji.dwFlags |= JOY_RETURNZ;
770 ji.dwFlags |= JOY_RETURNY;
772 ji.dwFlags |= JOY_RETURNX;
788 if (rs != JOYERR_NOERROR)
885 return (
int) ((
unsigned int) raw * (
unsigned int)
F1_0 / (
unsigned int) rng);
900 int x, d, dead_zone, rng;
914 if (raw < -dead_zone) {
916 d = -raw - dead_zone;
918 }
else if (raw > dead_zone) {
931 percent = (
float) d / (
float) rng;
936 x = (
int) ((
float)
F1_0 * percent);
981 Joy_last_x_reading = *
x;
984 Joy_last_x_reading = *
y;
992 static int old_joy_x = 0;
993 static int old_joy_y = 0;
1000 *dx = Joy_last_x_reading - old_joy_x;
1001 *dy = Joy_last_y_reading - old_joy_y;
1003 old_joy_x = Joy_last_x_reading;
1004 old_joy_y = Joy_last_y_reading;
1020 Di_joy_guid_valid = 1;
1021 nprintf((
"Joystick",
" (Selected joystick)\n"));
1126 mprintf((
"DirectInputCreate() failed!\n" ));
1130 Di_joy_guid_valid = 0;
1133 mprintf((
"EnumDevice() failed!\n" ));
1137 if (!Di_joy_guid_valid) {
1138 mprintf((
"Correct joystick not found.\n" ));
1142 hr = Di_joystick_obj->CreateDevice(Di_joy_guid, &pdev, NULL);
1144 mprintf((
"CreateDevice() failed!\n" ));
1150 mprintf((
"SetDataFormat() failed!\n" ));
1152 mprintf((
" (reason: DIERR_ACQUIRED)\n" ));
1155 mprintf((
" (reason: DIERR_INVALIDPARAM)\n" ));
1158 mprintf((
" (reason: DIERR_NOTINITIALIZED)\n" ));
1166 mprintf((
"SetCooperativeLevel() failed!\n" ));
1168 mprintf((
" (reason: DIERR_ACQUIRED)\n" ));
1171 mprintf((
" (reason: DIERR_INVALIDPARAM)\n" ));
1174 mprintf((
" (reason: DIERR_NOTINITIALIZED)\n" ));
1186 Di_joystick->Acquire();
1190 nprintf((
"Joystick",
"DirectInput initialization of joystick succeeded\n"));
1200 Di_joystick->Unacquire();
1202 Di_joystick->Release();
1207 if (Di_joystick_obj) {
1208 Di_joystick_obj->Release();
1209 Di_joystick_obj = NULL;
1229 hr = Di_joystick->Poll();
1237 hr = Di_joystick->Acquire();
1244 memset(&joy_state, 0,
sizeof(joy_state));
1248 hr = Di_joystick->GetDeviceState(
sizeof(joy_state), &joy_state);
1256 hr = Di_joystick->Acquire();
1262 if (SUCCEEDED(hr)) {
1266 axis[5] = joy_state.
lRy;
1270 axis[4] = joy_state.
lRx;
1274 axis[3] = joy_state.
lRz;
1278 axis[2] = joy_state.
lZ;
1282 axis[1] = joy_state.
lY;
1286 axis[0] = joy_state.
lX;
int axis_max[JOY_NUM_AXES]
DWORD joy_process(DWORD lparam)
uint os_config_read_uint(const char *section, const char *name, uint default_value)
int axis_center[JOY_NUM_AXES]
int joy_up_count(int btn)
HANDLE Joy_tell_thread_to_end_event
int joy_get_pos(int *x, int *y, int *z, int *rx)
int joy_get_unscaled_reading(int raw, int axn)
struct joy_button_info joy_button_info
SDL_mutex * CRITICAL_SECTION
void joy_get_delta(int *dx, int *dy)
GLenum GLuint GLenum GLsizei const GLchar * buf
int axis_min[JOY_NUM_AXES]
void joy_get_cal_vals(int *axis_min, int *axis_center, int *axis_max)
int joy_get_scaled_reading(int raw, int axn)
CHAR tszInstanceName[MAX_PATH]
typedef int(SCP_EXT_CALLCONV *SCPDLL_PFVERSION)(SCPDLL_Version *)
GLdouble GLdouble GLdouble r
CRITICAL_SECTION joy_lock
int joystick_read_raw_axis(int num_axes, int *axis)
void joy_get_caps(int max)
sprintf(buf,"(%f,%f,%f)", v3->xyz.x, v3->xyz.y, v3->xyz.z)
int joystick_read_raw_axis_di(int num_axes, int *axis)
bool dc_optional_string_either(const char *str1, const char *str2)
Searches for an optional string and it's alias.
GLint GLint GLint GLint GLint x
for(int idx=0;idx< i;idx++)
BOOL CALLBACK joy_di_enum(LPCDIDEVICEINSTANCE lpddi, LPVOID pvRef)
float joy_down_time(int btn)
typedef float(SCP_EXT_CALLCONV *SCPTRACKIR_PFFLOATVOID)()
CHAR tszProductName[MAX_PATH]
#define JOY_TOTAL_BUTTONS
void joy_set_cal_vals(int *axis_min, int *axis_center, int *axis_max)
An overhauled/updated debug console to allow monitoring, testing, and general debugging of new featur...
ubyte keyd_pressed[NUM_KEYS]
joy_button_info joy_buttons[JOY_TOTAL_BUTTONS]
int joy_down_count(int btn, int reset_count)
void dc_printf(const char *format,...)
Prints the given char string to the debug console.
HANDLE Joy_thread_says_its_done_event
int axis_valid[JOY_NUM_AXES]
int timer_get_milliseconds()
DCF(joytest,"Test joystick")