Index: src/add-ons/kernel/drivers/joystick/usb_joy/driver.h
===================================================================
--- src/add-ons/kernel/drivers/joystick/usb_joy/driver.h	(revision 41021)
+++ src/add-ons/kernel/drivers/joystick/usb_joy/driver.h	(working copy)
@@ -77,7 +77,7 @@
 	void *buffer;
 	bool buffer_valid;
 
-	const usb_device *dev;
+	usb_device dev;
 	int number;
 
 	bool active;
@@ -107,7 +107,7 @@
 /* devmgmt.c */
 
 my_device_info *
-create_device (const usb_device *dev, const usb_interface_info *ii);
+create_device (usb_device dev, const usb_interface_info *ii);
 
 void 
 remove_device (my_device_info *my_dev);
Index: src/add-ons/kernel/drivers/joystick/usb_joy/devmgmt.c
===================================================================
--- src/add-ons/kernel/drivers/joystick/usb_joy/devmgmt.c	(revision 41021)
+++ src/add-ons/kernel/drivers/joystick/usb_joy/devmgmt.c	(working copy)
@@ -12,7 +12,7 @@
 static int device_number = 0;
 
 my_device_info *create_device (
-	const usb_device *dev, 
+	usb_device dev, 
 	const usb_interface_info *ii)
 {
 	my_device_info *my_dev = NULL;
@@ -21,7 +21,7 @@
 	sem_id sem;
 	char	area_name [32];
 
-	assert (usb != NULL && dev != NULL);
+	assert (usb != NULL);
 
 	number = device_number++;
 
Index: src/add-ons/kernel/drivers/joystick/usb_joy/driver.c
===================================================================
--- src/add-ons/kernel/drivers/joystick/usb_joy/driver.c	(revision 41021)
+++ src/add-ons/kernel/drivers/joystick/usb_joy/driver.c	(working copy)
@@ -36,7 +36,7 @@
 _EXPORT int32	api_version = B_CUR_DRIVER_API_VERSION;
 
 const char *my_driver_name = "usb_joy";
-const char *my_base_name = "joystick/usb/";
+const char *my_base_name = "joystick/usb_haiku/";
 
 usb_module_info *usb;
 
@@ -154,7 +154,7 @@
 
 static void usb_callback (
 	void *cookie, 
-	uint32 status, 
+	status_t status, 
 	void *data, 
 	uint32 actual_len)
 {
@@ -215,7 +215,7 @@
 */
 
 static status_t my_device_added (
-	const usb_device *dev, 
+	usb_device dev, 
 	void **cookie)
 {
 	my_device_info *my_dev;
@@ -225,12 +225,13 @@
 	status_t st;
 	usb_hid_descriptor *hid_desc;
 	uint8 *rep_desc = NULL;
+	report_insn *reallocated_insns = NULL;
 	size_t desc_len, actual;
 	decomp_item *items;
 	size_t num_items;
 	int i, ifno, fd, report_id;
 
-	assert (dev != NULL && cookie != NULL);
+	assert (cookie != NULL);
 	DPRINTF_INFO ((MY_ID "device_added()\n"));
 
 	dev_desc = usb->get_device_descriptor (dev);
@@ -353,7 +354,8 @@
 	parse_report_descriptor (items, num_items, my_dev->insns, 
 		&my_dev->num_insns, &my_dev->total_report_size, &report_id);
 	free (items);
-	realloc (my_dev->insns, sizeof (report_insn) * my_dev->num_insns);
+	reallocated_insns = realloc (my_dev->insns, sizeof (report_insn) * my_dev->num_insns);
+	my_dev->insns = reallocated_insns;
 	DPRINTF_INFO ((MY_ID "%d items, %d insns, %d bytes\n", 
 		(int)num_items, (int)my_dev->num_insns, (int)my_dev->total_report_size));
 
@@ -661,8 +663,9 @@
 			my_dev->insns, my_dev->num_insns, 
 			my_dev->prod_info, my_dev->flags, &joy_data);
 	}
-
-	if (cookie->enhanced && *num_bytes >= sizeof (extended_joystick))
+	
+	// always work in enhanced mode, the joystick caller will handle legacy mode
+	if (*num_bytes >= sizeof (extended_joystick))
 	{
 		/* enhanced mode */
 		joy_data.timestamp = my_dev->timestamp;
@@ -671,22 +674,6 @@
 		err = B_OK;
 	}
 
-	if (!cookie->enhanced && *num_bytes >= sizeof (joystick))
-	{
-		/* standard mode */
-		joystick std_joy_data;
-
-		std_joy_data.timestamp = my_dev->timestamp;
-		std_joy_data.horizontal = joy_data.axes [0];
-		std_joy_data.vertical   = joy_data.axes [1];
-		/* false if pressed */
-		std_joy_data.button1 = (joy_data.buttons & 1) ? false : true;
-		std_joy_data.button2 = (joy_data.buttons & 2) ? false : true;
-		memcpy (buf, &std_joy_data, sizeof (joystick));
-		*num_bytes = sizeof (joystick);
-		err = B_OK;
-	}
-
 	return err;
 }
 
@@ -735,8 +722,8 @@
 			the joystick product may be connected
 		*/
 		assert (arg != NULL);
-		if (!cookie->enhanced &&
-			strstr (((joystick_module_info*)arg)->device_name, "USB") != NULL)	/* XXX */
+		if (!cookie->enhanced)// &&
+			//strstr (((joystick_module_info*)arg)->device_name, "USB") != NULL)	/* XXX */
 		{
 			cookie->joy_mod_info = *(joystick_module_info *)arg;
 
@@ -744,6 +731,7 @@
 
 			/* set actual # of controls detected */
 			/* this will be returned in B_JOYSTICK_GET_DEVICE_MODULE */
+			cookie->joy_mod_info.num_sticks = 1;
 			cookie->joy_mod_info.num_axes = my_dev->num_axes;
 			cookie->joy_mod_info.num_hats = my_dev->num_hats;
 			cookie->joy_mod_info.num_buttons = my_dev->num_buttons;
Index: src/kits/device/Joystick.cpp
===================================================================
--- src/kits/device/Joystick.cpp	(revision 41021)
+++ src/kits/device/Joystick.cpp	(working copy)
@@ -4,6 +4,7 @@
  * Distributed under the terms of the MIT License.
  */
 
+#include "JoystickTweaker.h"
 
 #include <List.h>
 #include "Joystick.h"
@@ -19,6 +20,7 @@
 #include <String.h>
 #include <Debug.h>
 
+#define JOYSTICK_READ 'jrea'
 
 #if DEBUG
 static FILE *sLogFile = NULL;
@@ -43,20 +45,26 @@
 
 #define CALLED() LOG("%s\n", __PRETTY_FUNCTION__)
 
-#include "JoystickTweaker.h"
-
-
 BJoystick::BJoystick()
 	:
+	horizontal(0),
+	vertical(0),
+	button1(0),
+	button2(0),
 	fBeBoxMode(false),
 	ffd(-1),
-	fDevices(new BList),
-	fJoystickInfo(new _joystick_info())
+	fDevices(NULL),
+	fJoystickInfo(new _joystick_info()),
+	fDevName(0)
 {
 #if DEBUG
 	sLogFile = fopen("/var/log/libdevice.log", "a");
 #endif
-	//ScanDevices();
+
+	memset(&fJoystickInfo->module_info, 0,
+		sizeof(_joystick_module_info));
+	memset(&fJoystickInfo->sticks, 0,
+		sizeof(fJoystickInfo->sticks));
 }
 
 
@@ -65,10 +73,13 @@
 	if (ffd >= 0)
 		close(ffd);
 
-	for (int32 count = fDevices->CountItems() - 1; count >= 0; count--) {
-		free(fDevices->RemoveItem(count));
+	if(fDevices)
+	{
+		for (int32 count = fDevices->CountItems() - 1; count >= 0; count--)
+			free(fDevices->RemoveItem(count));
 	}
 
+	free(fDevName);
 	delete fDevices;
 	delete fJoystickInfo;
 }
@@ -98,7 +109,7 @@
 		snprintf(buf, 64, DEVICEPATH"/%s", portName);
 	else
 		snprintf(buf, 64, "%s", portName);
-
+	
 	if (ffd >= 0)
 		close(ffd);
 
@@ -118,10 +129,11 @@
 		_BJoystickTweaker jt(*this);
 		jt.GetInfo(fJoystickInfo, portName);
 
-		LOG("ioctl - %d\n", fJoystickInfo->num_buttons);
-		ioctl(ffd, B_JOYSTICK_SET_DEVICE_MODULE, fJoystickInfo);
-		ioctl(ffd, B_JOYSTICK_GET_DEVICE_MODULE, fJoystickInfo);
-		LOG("ioctl - %d\n", fJoystickInfo->num_buttons);
+		int result = ioctl(ffd, B_JOYSTICK_SET_DEVICE_MODULE, &fJoystickInfo->module_info);
+		LOG("ioctl B_JOYSTICK_SET_DEVICE_MODULE: %d\n", result);
+		result = ioctl(ffd, B_JOYSTICK_GET_DEVICE_MODULE, &fJoystickInfo->module_info);
+		LOG("ioctl B_JOYSTICK_GET_DEVICE_MODULE: %d\n", result);
+		LOG("NumberOfButtons - %d\n", fJoystickInfo->module_info.num_buttons);
 
 		return ffd;
 	} else
@@ -144,6 +156,8 @@
 BJoystick::ScanDevices(bool useDisabled)
 {
 	CALLED();
+	if(!fDevices) fDevices = new BList();
+	
 	if (useDisabled) {
 		_BJoystickTweaker temp(*this);
 		temp.scan_including_disabled();
@@ -157,7 +171,7 @@
 	CALLED();
 
 	// Refresh devices list
-	ScanDevices(true);
+	if(!fDevices) ScanDevices(true);
 
 	int32 count = 0;
 	if (fDevices != NULL)
@@ -173,6 +187,9 @@
 {
 	CALLED();
 	BString *temp = NULL;
+	
+	if(!fDevices) ScanDevices(true);
+
 	if (fDevices != NULL && fDevices->CountItems() > n)
 		temp = static_cast<BString*>(fDevices->ItemAt(n));
 	else
@@ -203,7 +220,7 @@
 BJoystick::CountSticks()
 {
 	CALLED();
-	return fJoystickInfo->num_sticks;
+	return fJoystickInfo->module_info.num_sticks;
 }
 
 
@@ -211,7 +228,7 @@
 BJoystick::CountAxes()
 {
 	CALLED();
-	return fJoystickInfo->num_axes;
+	return fJoystickInfo->module_info.num_axes;
 }
 
 
@@ -219,7 +236,7 @@
 BJoystick::CountHats()
 {
 	CALLED();
-	return fJoystickInfo->num_hats;
+	return fJoystickInfo->module_info.num_hats;
 }
 
 
@@ -227,7 +244,7 @@
 BJoystick::CountButtons()
 {
 	CALLED();
-	return fJoystickInfo->num_buttons;
+	return fJoystickInfo->module_info.num_buttons;
 }
 
 
@@ -236,7 +253,8 @@
 {
 	CALLED();
 	if (fJoystickInfo != NULL && ffd >= 0) {
-		out_name->SetTo(fJoystickInfo->module_name);
+		out_name->SetTo(fJoystickInfo->module_info.module_name);
+		//out_name->SetTo("Module");
 		return B_OK;
 	} else
 		return B_ERROR;
@@ -249,7 +267,8 @@
 {
 	CALLED();
 	if (fJoystickInfo != NULL && ffd >= 0) {
-		out_name->SetTo(fJoystickInfo->controller_name);
+		//out_name->SetTo("Joystick");
+		out_name->SetTo(fJoystickInfo->module_info.device_name);
 		return B_OK;
 	} else
 		return B_ERROR;
@@ -280,9 +299,11 @@
 BJoystick::SetMaxLatency(bigtime_t max_latency)
 {
 	CALLED();
-	fJoystickInfo->max_latency = max_latency;
-	 //else B_ERROR (when?)
-	return B_OK;
+	if(ffd >= 0) {
+		return ioctl(ffd, B_JOYSTICK_SET_MAX_LATENCY,
+			&max_latency, sizeof(bigtime_t));
+	}
+	return B_ERROR;
 }
 
 //--------- not done -------------------
@@ -291,7 +312,10 @@
 BJoystick::GetAxisNameAt(int32 index, BString *out_name)
 {
 	CALLED();
-	return B_BAD_INDEX;
+	BString axisName = "Axis ";
+	axisName << index + 1;
+	out_name->SetTo(axisName);
+	return B_OK;
 }
 
 
@@ -299,7 +323,10 @@
 BJoystick::GetHatNameAt(int32 index, BString *out_name)
 {
 	CALLED();
-	return B_BAD_INDEX;
+	BString hatName = "Hat ";
+	hatName << index + 1;
+	out_name->SetTo(hatName);
+	return B_OK;
 }
 
 
@@ -307,7 +334,10 @@
 BJoystick::GetButtonNameAt(int32 index, BString *out_name)
 {
 	CALLED();
-	return B_BAD_INDEX;
+	BString buttonName = "Button ";
+	buttonName << index + 1;
+	out_name->SetTo(buttonName);
+	return B_OK;
 }
 
 
@@ -315,7 +345,12 @@
 BJoystick::GetAxisValues(int16 *out_values, int32 for_stick)
 {
 	CALLED();
-	return B_BAD_VALUE;
+	if(for_stick < 0 || for_stick >= fJoystickInfo->module_info.num_sticks)
+		return B_BAD_VALUE;
+		
+	memcpy(out_values, fJoystickInfo->sticks[0].axes,
+		fJoystickInfo->module_info.num_axes * sizeof(int16));
+	return B_OK;
 }
 
 
@@ -323,7 +358,12 @@
 BJoystick::GetHatValues(uint8 *out_hats, int32 for_stick)
 {
 	CALLED();
-	return B_BAD_VALUE;
+	if(for_stick < 0 || for_stick >= fJoystickInfo->module_info.num_sticks)
+		return B_BAD_VALUE;
+	
+	memcpy(out_hats, fJoystickInfo->sticks[0].hats,
+		fJoystickInfo->module_info.num_hats);
+	return B_OK;
 }
 
 
@@ -331,7 +371,10 @@
 BJoystick::ButtonValues(int32 for_stick)
 {
 	CALLED();
-	return 0;
+	if(for_stick < 0 || for_stick >= fJoystickInfo->module_info.num_sticks)
+		return B_BAD_VALUE;
+	
+	return fJoystickInfo->sticks[0].buttons;
 }
 
 
@@ -340,6 +383,19 @@
 {
 	CALLED();
 	if (ffd >= 0) {
+		// Always read in enhanced mode,  then assign legacy axes and buttons their values
+		extended_joystick joystick;
+		memset(&joystick, 0, sizeof(joystick));
+		
+		status_t length = read(ffd, &joystick, sizeof(extended_joystick));
+		if(length == sizeof(joystick)) fJoystickInfo->sticks[0] = joystick;
+		
+		// legacy mode buttons are true when 0
+		horizontal = fJoystickInfo->sticks[0].axes[0];
+		vertical = fJoystickInfo->sticks[0].axes[1];
+		button1 = !(fJoystickInfo->sticks[0].buttons & 1);
+		button2 = !(fJoystickInfo->sticks[0].buttons & 2);
+		//printf("hor: %d ver:%d buttons: %d\n", horizontal, vertical, fJoystickInfo->sticks[0].buttons);
 		return B_OK;
 	} else
 		return B_ERROR;
Index: src/kits/device/JoystickTweaker.cpp
===================================================================
--- src/kits/device/JoystickTweaker.cpp	(revision 41021)
+++ src/kits/device/JoystickTweaker.cpp	(working copy)
@@ -125,11 +125,11 @@
 }
 
 
-status_t
+_joystick_info *
 _BJoystickTweaker::get_info()
 {
 	CALLED();
-	return B_ERROR;
+	return fJoystick->fJoystickInfo;
 }
 
 
@@ -141,7 +141,6 @@
 	status_t err = B_ERROR;
 	BString str(JOYSTICKPATH);
 	str.Append(ref);
-
 	FILE *file = fopen(str.String(), "r");
 	if (file != NULL) {
 		char line [STRINGLENGTHCPY];
@@ -167,22 +166,22 @@
 
 	if (str.IFindFirst("module") != -1) {
 		str.RemoveFirst("module = ");
-		strlcpy(info->module_name, str.String(), STRINGLENGTHCPY);
+		strlcpy(info->module_info.module_name, str.String(), STRINGLENGTHCPY);
 	} else if (str.IFindFirst("gadget") != -1) {
 		str.RemoveFirst("gadget = ");
-		strlcpy(info->controller_name, str.String(), STRINGLENGTHCPY);
+		strlcpy(info->module_info.device_name, str.String(), STRINGLENGTHCPY);
 	} else if (str.IFindFirst("num_axes") != -1) {
 		str.RemoveFirst("num_axes = ");
-		info->num_axes = atoi(str.String());		
+		info->module_info.num_axes = atoi(str.String());		
 	} else if (str.IFindFirst("num_hats") != -1) {
 		str.RemoveFirst("num_hats = ");
-		info->num_hats = atoi(str.String());
+		info->module_info.num_hats = atoi(str.String());
 	} else if (str.IFindFirst("num_buttons") != -1) {
 		str.RemoveFirst("num_buttons = ");
-		info->num_buttons = atoi(str.String());
+		info->module_info.num_buttons = atoi(str.String());
 	} else if (str.IFindFirst("num_sticks") != -1) {
 		str.RemoveFirst("num_sticks = ");
-		info->num_sticks = atoi(str.String());
+		info->module_info.num_sticks = atoi(str.String());
 	} else {
 		LOG("Path = %s\n", str.String());
 	}
Index: headers/private/device/JoystickTweaker.h
===================================================================
--- headers/private/device/JoystickTweaker.h	(revision 41021)
+++ headers/private/device/JoystickTweaker.h	(working copy)
@@ -21,6 +21,16 @@
 class BJoystick;
 
 typedef struct _joystick_info {
+	_joystick_module_info module_info;
+	_extended_joystick sticks[4];
+	BList           name_axis;
+	BList           name_hat;
+	BList           name_button;
+	bool            calibration_enable;
+};
+
+#if 0
+typedef struct _joystick_info {
         char            module_name[64];
         char            controller_name[64];
         int16           num_axes;
@@ -34,6 +44,7 @@
         BList           name_button;
 //      BList           name_
 } joystick_info;
+#endif
 
 class _BJoystickTweaker {
 
@@ -47,7 +58,7 @@
 		// BeOS R5's joystick pref need these
 		status_t	save_config(const entry_ref * ref = NULL);
 		void		scan_including_disabled();
-		status_t	get_info();
+		_joystick_info *	get_info();
 		
 private:
 		void 		_BuildFromJoystickDesc(char *string, _joystick_info* info);
