int main() { // // Disable the watchdog // WDTimerDisable(); xSysCtlClockSet32KhzFLLExt(); //48mhz from 32768khz external clock xSysTickPeriodSet(xSysCtlClockGet()/SYSTICKS_PER_SECOND); //1ms xSysTickIntEnable(); xSysTickEnable(); // End of SysTick init ulClockMS = xSysCtlClockGet() / (3 * 1000); pwmInit(); // Setup and configure rf radio RF24 radio = RF24(); rf24_init(radio); while (1) { // if there is data ready report_t gamepad_report; if (!getNRF24report(&radio, &gamepad_report)) { drive(&gamepad_report); // if (gamepad_report.reportid == 1) { // // Delay just a little bit to let the other unit // // make the transition to receiver // xSysCtlDelay(ulClockMS * 10); // // radio.stopListening(); // uint8_t response = 0; // radio.write(&response, sizeof(uint8_t)); // radio.startListening(); // } timeoutcounter = millis(); } else { if ((millis() - timeoutcounter) > TIMEOUT) { stopall(); xSysCtlDelay(ulClockMS * 10); } } } return 0; }
int main (){ HardwareInit(); RF24 radio = RF24(); // Radio pipe addresses for the 2 nodes to communicate. const uint64_t pipes[2] = { 0xF0F0F0F0BELL, 0xF0F0F0F0EFLL }; setup_watchdog(wdt_64ms); // // Setup and configure rf radio // radio.begin(); radio.setChannel(100); // optionally, increase the delay between retries & # of retries radio.setRetries(15,15); // optionally, reduce the payload size. seems to // improve reliability radio.setPayloadSize(sizeof(report_t)); radio.setDataRate(RF24_250KBPS); radio.openWritingPipe(pipes[0]); radio.openReadingPipe(1,pipes[1]); radio.startListening(); radio.stopListening(); //unsigned long pa = 0; uint8_t counter = 0; //check eeprom if (eeprom_read_byte(0)==EEPROM_MAGIC_NUMBER){ minx=(char)eeprom_read_byte((uint8_t*)1); maxx=(char)eeprom_read_byte((uint8_t*)2); miny=(char)eeprom_read_byte((uint8_t*)3); maxy=(char)eeprom_read_byte((uint8_t*)4); minrx=(char)eeprom_read_byte((uint8_t*)5); maxrx=(char)eeprom_read_byte((uint8_t*)6); minry=(char)eeprom_read_byte((uint8_t*)7); maxry=(char)eeprom_read_byte((uint8_t*)8); calibrated=true; #ifdef DEBUG print_string("read eeprom magic number"); char temp[100]; sprintf(temp,"minx:%d maxx:%d minry:%d maxry:%d \n",minx,maxx,minry,maxry); print_string(temp); _delay_ms(2000); #endif } while(1){ ReadController(); #ifdef DEBUG char temp[100]; print_string("before convert\n"); sprintf(temp,"hat:%u x:%d y:%d rx:%d ry:%d b1:%u b2:%u\n",reportBuffer.hat,(int8_t)reportBuffer.x,(int8_t)reportBuffer.y,(int8_t)reportBuffer.rx,(int8_t)reportBuffer.ry,reportBuffer.b1,reportBuffer.b2); print_string(temp); #endif convertAxes(); #ifdef DEBUG sprintf(temp,"hat:%u x:%d y:%d rx:%d ry:%d b1:%u b2:%u\n",reportBuffer.hat,(int8_t)reportBuffer.x,(int8_t)reportBuffer.y,(int8_t)reportBuffer.rx,(int8_t)reportBuffer.ry,reportBuffer.b1,reportBuffer.b2); print_string(temp); #endif //Calibration if(A_PRESSED && B_PRESSED && Z_PRESSED && L_PRESSED && R_PRESSED){ calibrate(); } counter=(counter+1)%20; sendData(counter==0,radio); do_sleep(); } //never reached return 0; }