From d9e17b5233129adb91c81fc3cc7327e44fe4646f Mon Sep 17 00:00:00 2001 From: Florian Jung Date: Sat, 5 Apr 2014 19:53:55 +0200 Subject: code cleanup --- main.c | 84 ++++++++++++++++++++++++++---------------------------------------- 1 file changed, 33 insertions(+), 51 deletions(-) diff --git a/main.c b/main.c index 8cb3146..ef9c55c 100644 --- a/main.c +++ b/main.c @@ -114,7 +114,6 @@ USB_PUBLIC uchar usbFunctionSetup(uchar data[8]) if ((rq->bmRequestType & USBRQ_TYPE_MASK) == USBRQ_TYPE_CLASS && (rq->bRequest == USBRQ_HID_GET_REPORT)) { - debug(32); // wValue: ReportType (highbyte), ReportID (lowbyte) usbMsgPtr = (void *)&reportBuffer; // we only have this one return sizeof(reportBuffer); @@ -300,8 +299,7 @@ char decode_byte(char* bufptr) int main (void) { - char rand=123; - unsigned char ltrig=0, rtrig=0; + unsigned char ltrig=0, rtrig=0; // only used for rumbling test. DDRC=0x00; PORTC=0x00; @@ -325,74 +323,61 @@ int main (void) sei(); debug(4); - int temp=5; int n_received; int toggle=0; - int count=0; int count2=0; int count3=0; while(1) { - toggle=~toggle; + wdt_reset(); + + + + // DEBUGGING CODE starts here + + toggle=~toggle; // debug mainloop duration debug(toggle); - count++; - if (count>=1500) count=0; - count2++; - if (count2>=512-ltrig) count2=0; + count2++; // debug rumble + if (count2>=256+ltrig) count2=0; count3++; if (count3>=25) count3=0; - wdt_reset(); + // DEBUGGING CODE ends here. + + + + // USB CODE starts here + usbPoll(); if(usbInterruptIsReady()) - { - usbSetInterrupt((void *)&reportBuffer, sizeof(reportBuffer)); -// debug(2); - } + // USB CODE ends here -/* temp++; - if (!(PIND & 0x08)) // check if uC is hung up - { - //PORTB=~(1 << ((temp>>9)%6)); - PORTB=~temp; - } - else if (!(PIND & 0x20)) // debug num_received - { - PORTB=~n_received>>3; - } - else if (!(PIND & 0x40)) // clear debug output - { - PORTB=~0x00; - } - else*/ - { - // decode "buffer" and write button states to PORTB + _delay_us(10); - //PORTB=~buffer[4]; - } - //debug(temp % 64); -// _delay_ms(0.3); - _delay_us(10); - char foo[] = { 0x40, 0x03, 0x00 }; - //char foo[] = { 0x40, 0x03, 0x02 }; + // GAMECUBE COMMUNICATION starts here + + char getid_msg=0x00; + send_recv_gc(&getid_msg, 1); // send get-id message; probably unneccessary. - if (count2<256 && count3