v1 Stable
Dependencies: F401RE-USBHost USBHostXpad mbed
Diff: main.cpp
- Revision:
- 5:32c8b316582a
- Parent:
- 3:52b2a7514406
- Child:
- 6:21365f733399
--- a/main.cpp Mon Dec 05 02:40:19 2016 +0000 +++ b/main.cpp Mon Dec 12 01:07:48 2016 +0000 @@ -7,7 +7,7 @@ DigitalOut myled(LED1); Serial pc(USBTX, USBRX); // tx, rx DigitalInOut data(PA_8); -//DigitalIn button(PC_13); // eventually code to set controls +DigitalIn button(PC_13); // eventually code to set controls /** @namespace AXYB @@ -104,7 +104,7 @@ @brief makes the range of the triggers 0 to 10 */ const float tN=0.03921568627;//(10/255) -const int DEADZONE = 8; +const int DEADZONE = 3; char reverse(char b) { @@ -116,7 +116,7 @@ extern "C" void my_wait_us_asm (int n); -struct __attribute__((packed)) N64ControllerData // all bits are in the correct order +struct __attribute__((packed)) N64ControllerData // all bits are in the correct order... except for the analog { unsigned int a : 1; // 1 bit wide unsigned int b : 1; @@ -149,18 +149,22 @@ bkStrtLCRC=(buttons&0x00f0)>>4; DPad=buttons&0x000f; + //pc.printf("AXYB: %u, XLBRB, %u, bkStrtLCRC %u, DPad, %u\r\n",AXYB,XLBRB,bkStrtLCRC,DPad); + + // normalize the analog stick values to be 80 max LSY=(char)((int)(stick_ly*sN)); LSX=(char)((int)(stick_lx*sN)); RSY=stick_ry*sN; RSX=stick_rx*sN; + // normalize the trigger values to be 10 max Lt=trigger_l*tN; Rt=trigger_r*tN; memset(&n64_data,0,4); // clear controller state // Owna's Controls - /*if(AXYB & 0x01) // a + if(AXYB & 0x01) // a { n64_data.a = 1; } @@ -187,7 +191,7 @@ if(XLBRB & 0x01) // left bumper { n64_data.l = 1; - }*/ + } // Supa's Controls /*if(AXYB & 0x01) // a @@ -236,7 +240,7 @@ }*/ // LD's Controls - if(AXYB & 0x01) // a + /*if(AXYB & 0x01) // a { n64_data.a = 1; } @@ -276,10 +280,60 @@ { n64_data.c_right = 1; } - if(Rt > 50) // Right trigger greater than threshold + if(Rt > 5) // Right trigger greater than threshold + { + n64_data.z = 1; + }*/ + + // JJ's Controls + /*if(AXYB & 0x01) // a + { + n64_data.a = 1; + } + if((AXYB >> 2) & 0x01) // x + { + n64_data.b = 1; + } + if((AXYB >> 3) & 0x01) // y + { + n64_data.c_left = 1; + } + if((AXYB >> 1) & 0x01) // b + { + n64_data.c_right = 1; + } + if(bkStrtLCRC & 0x01) // start + { + n64_data.start = 1; + } + if((XLBRB >> 1) & 0x01) // right bumper + { + n64_data.r = 1; + } + if(XLBRB & 0x01) // left bumper { n64_data.z = 1; } + if(DPad & 0x01) // DPad Up + { + n64_data.up = 1; + } + if(DPad & 0x02) // DPad Down + { + n64_data.down = 1; + } + if(DPad & 0x04) // DPad Left + { + n64_data.left = 1; + } + if(DPad & 0x08) // DPad Right + { + n64_data.right = 1; + } + if(Lt > 2 || Rt > 2) // Triggers greater than threshold + { + n64_data.z = 1; + }*/ // Generic analog stick if(LSX > DEADZONE) @@ -418,6 +472,8 @@ int main() { + //Timer t; + pc.printf("\r\nNow loaded! SystemCoreClock = %d Hz\r\n", SystemCoreClock); USBHostXpad xpad; @@ -425,12 +481,12 @@ pc.printf("Error: XBox controller not found.\n"); } - //int USBHostXpad::read (PAD pad) <-- try using this instead of callbacks xpad.attachEvent(onXpadEvent); xpad.led(USBHostXpad::LED1_ON); while(1) { + //t.start(); // Set pin mode to input data.input(); @@ -460,6 +516,10 @@ break; } __enable_irq(); // Enable Interrupts - //-------- DONE SENDING RESPOSE + //-------- DONE SENDING RESPOSE + + //t.stop(); + pc.printf("Time: %d\r\n",t.read_us()); + //t.reset(); } }