Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Revision 5:eb93a4f91396, committed 2014-12-10
- Comitter:
- igor_m
- Date:
- Wed Dec 10 14:22:30 2014 +0000
- Parent:
- 4:fee2d61ad6bc
- Commit message:
- Initial Release
Changed in this revision
--- a/USBHID/usbhid.cpp Fri Sep 30 23:16:52 2011 +0000
+++ b/USBHID/usbhid.cpp Wed Dec 10 14:22:30 2014 +0000
@@ -397,26 +397,49 @@
unsigned char reportDescriptorJoystick[] = {
0x05, 0x01, // USAGE_PAGE (Generic Desktop)
- 0x09, 0x04, // USAGE (Joystick)
+ 0x09, 0x05, // USAGE (Game Pad)
0xa1, 0x01, // COLLECTION (Application)
0xa1, 0x00, // COLLECTION (Physical)
0x05, 0x09, // USAGE_PAGE (Button)
0x19, 0x01, // USAGE_MINIMUM (Button 1)
- 0x29, 0x10, // USAGE_MAXIMUM (Button 16)
+ 0x29, 0x05, // USAGE_MAXIMUM (Button 5)
0x15, 0x00, // LOGICAL_MINIMUM (0)
0x25, 0x01, // LOGICAL_MAXIMUM (1)
- 0x95, 0x10, // REPORT_COUNT (16)
+ 0x95, 0x05, // REPORT_COUNT (5)
0x75, 0x01, // REPORT_SIZE (1)
0x81, 0x02, // INPUT (Data,Var,Abs)
+ 0x75, 0x03, // REPORT_SIZE (3)
+ 0x95, 0x01, // REPORT_COUNT (1)
+ 0x81, 0x03, // INPUT (Cnst,Var,Abs)
+ 0x19, 0x06, // USAGE_MINIMUM (Button 6)
+ 0x29, 0x0c, // USAGE_MAXIMUM (Button 12)
+ 0x15, 0x00, // LOGICAL_MINIMUM (0)
+ 0x25, 0x01, // LOGICAL_MAXIMUM (1)
+ 0x95, 0x07, // REPORT_COUNT (7)
+ 0x75, 0x01, // REPORT_SIZE (1)
+ 0x81, 0x02, // INPUT (Data,Var,Abs)
+ 0x95, 0x01, // REPORT_COUNT (1)
+ 0x75, 0x01, // REPORT_SIZE (1)
+ 0x81, 0x03, // INPUT (Cnst,Var,Abs)
0x05, 0x01, // USAGE_PAGE (Generic Desktop)
0x09, 0x30, // USAGE (X)
0x09, 0x31, // USAGE (Y)
+ 0x09, 0x33, // USAGE (Rx)
+ 0x09, 0x34, // USAGE (Ry)
0x15, 0x81, // LOGICAL_MINIMUM (-127)
0x25, 0x7f, // LOGICAL_MAXIMUM (127)
0x75, 0x08, // REPORT_SIZE (8)
+ 0x95, 0x04, // REPORT_COUNT (4)
+ 0x81, 0x02, // INPUT (Data,Var,Abs)
+ 0x05, 0x01, // USAGE_PAGE (Generic Desktop)
+ 0x09, 0x36, // USAGE (Slider)
+ 0x09, 0x37, // USAGE (Dial)
+ 0x26, 0xff, 0x00, // LOGICAL_MAXIMUM (255)
+ 0x15, 0x00, // LOGICAL_MINIMUM (0)
+ 0x75, 0x08, // REPORT_SIZE (8)
0x95, 0x02, // REPORT_COUNT (2)
0x81, 0x02, // INPUT (Data,Var,Abs)
- 0xc0, // END_COLLECTION
+ 0xc0, // END_COLLECTION
0xc0 // END_COLLECTION
};
@@ -480,15 +503,19 @@
return true;
}
-bool USBJoystick::joystick(unsigned char buttons1, unsigned short buttons2, signed char x, signed char y) {
- unsigned char report[6] = {0, 0, 0, 0, 0, 0};
+bool USBJoystick::joystick(unsigned char buttons1, unsigned short buttons2, signed char x, signed char y, signed char cx, signed char cy, unsigned char L, unsigned char R) {
+ unsigned char report[9] = {0, 0, 0, 0, 0, 0, 0, 0};
report[0] = buttons1;
report[1] = buttons2;
report[2] = x ;
- report[3] = (-1)*y ;
+ report[3] = -y ;
+ report[4] = cx ;
+ report[5] = cy ;
+ report[6] = L ;
+ report[7] = R ;
- if (!sendInputReport(report, 4)) {
+ if (!sendInputReport(report, 8)) {
return false;
}
--- a/USBHID/usbhid.h Fri Sep 30 23:16:52 2011 +0000
+++ b/USBHID/usbhid.h Wed Dec 10 14:22:30 2014 +0000
@@ -45,7 +45,7 @@
{
public:
USBJoystick();
- bool joystick(unsigned char buttons1, unsigned short buttons2, signed char x, signed char y);
+ bool joystick(unsigned char buttons1, unsigned short buttons2, signed char x, signed char y, signed char cx, signed char cy, unsigned char L, unsigned char R);
protected:
virtual bool requestGetDescriptor(void);
private:
--- a/main.cpp Fri Sep 30 23:16:52 2011 +0000
+++ b/main.cpp Wed Dec 10 14:22:30 2014 +0000
@@ -112,8 +112,8 @@
#define WRITE_EEPROM 0x05
#define RESET_CONTROLLER 0xff
-#define T1 22 // Corresponds to 1 us
-#define T2 68 // Corresponds to 3 us
+#define T1 23 // Corresponds to 1 us
+#define T2 69 // Corresponds to 3 us
DigitalInOut inout(p14); // Connect controller here
// using 220 ohm pull-up
@@ -162,7 +162,7 @@
delay(60);
sample=inout.read();
if (sample)
- byte = byte | (1<<bit);
+ byte = byte | (128>>bit);
bit++;
}
@@ -170,21 +170,10 @@
}
}
- /* The for loop here is used to reverse the bits for the x and y values retured
- by the controller. I am not entirely sure of the format. I'm missing a bit
- somewhere.. Values don't range from -127..128. */
- /*
- x=y=0;
- for (i=0; i<=7; i++) {
- if (controls.array[2] & (1 << i))
- x=x | (1 << (7-i));
- if (controls.array[3] & (1 << i))
- y=y | (1 << (7-i));
- }
- data_array[2]=x;
- data_array[3]=y;
- */
- //data_array[2]= 5;
+data_array[2] -= 128;
+data_array[3] -= 128;
+data_array[4] -= 128;
+data_array[5] -= 128;
return n;
}
/* void send_byte(unsigned char byte) is used to send a single
@@ -266,17 +255,29 @@
cmd[0]=64;
send(cmd,3);
receive(controls.array, 8); // Start receiving bit stream
- //pc.printf("%3d %3d %d %d\n ", controls.array[0], controls.array[1], (int8_t)controls.array[2], (int8_t)controls.array[3]);
+ joystick.joystick(controls.array[0], controls.array[1],
+ controls.array[2], controls.array[3],
+ controls.array[4], controls.array[5],
+ controls.array[6], controls.array[7]
+ );
+
+
+ //pc.printf("%d\t%d\t", (uint8_t)controls.array[0],(uint8_t)controls.array[1]);
+ //pc.printf("%d\t%d\t%d\t%d\t%d\t%d", (int8_t)(controls.array[2]),(int8_t)controls.array[3],(int8_t)controls.array[4],(int8_t)controls.array[5],controls.array[6],controls.array[7]);
+ //pc.printf("\n");
- for (n=7; n>=0; n--){
- if (controls.array[2] & (1 << n))
+ //pc.printf("%3d %3d %d %d\n ", controls.array[0], controls.array[1], (int8_t)controls.array[2], (int8_t)controls.array[3]);
+/*
+ for (n=12; n<8; n++){
+ if (controls.array[2] & (128 >> n))
pc.printf("1");
else
pc.printf("0");
}
- //pc.printf("%d %d", (int8_t)(controls.array[2]^= (1 << 7)),controls.array[3]);
+ pc.printf("%d\t%d\t", (uint8_t)controls.array[0],(uint8_t)controls.array[1]);
+ pc.printf("%d\t%d\t%d\t%d\t%d\t%d", (int8_t)(controls.array[2]),(int8_t)controls.array[3],(int8_t)controls.array[4],(int8_t)controls.array[5],controls.array[6],controls.array[7]);
pc.printf("\n");
-/*
+
for (n=0; n<16; n++)
pc.printf("%d", (1 & ((uint16_t)controls.result[0] >> n)));
pc.printf(" ");
@@ -306,7 +307,7 @@
//pc.printf("%3d %3d %d %d\n ", controls.array[0], controls.array[1], (int8_t)controls.array[2], (int8_t)controls.array[3]);
//pc.printf("%d\n",controls.result_32);
- joystick.joystick(controls.array[0],controls.array[1], controls.array[2], controls.array[3]);
+ //joystick.joystick(controls.array[0],controls.array[1], controls.array[2], controls.array[3]);
}
}
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Wed Dec 10 14:22:30 2014 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/63bcd7ba4912 \ No newline at end of file
--- a/mbed.lib Fri Sep 30 23:16:52 2011 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -http://mbed.org/projects/libraries/svn/mbed/trunk@28 \ No newline at end of file