void VDIP::processNXT(portConfig *portConfigBuffer) { char *name; char *btAddress; long freeMemory; extern BT bt; if (myEEPROM2.getResetStatus() == (byte) 0){ if(nxtQueryDevice(this,portConfigBuffer->usbDev,&name,&btAddress,&freeMemory)){ bt.setRemoteAddress(btAddress); delay(100); myEEPROM2.setResetStatus(1); delay(1000); software_Reset(); // increments the "status" so that the ChapR knows it has been reset } } }
// // processDisk() - called when a disk is discovered and properly located // on P2. This routine does everything that the Chapr can // do with a flash drive, like update the name of the Chapr. // void VDIP::processDisk(portConfig *portConfigBuffer) { char buf[BIGENOUGH]; // check that it's in port two (beep annoyingly otherwise) if(portConfigBuffer->port == 1) { // read through VDIP stuff looking for a text file with the name, personality etc. // PLEASE NOTE -- FILE NAMES MUST BE FEWER THAN 8 CHARACTERS // get the new name of the ChapR if(readFile("name.txt", buf, BIGENOUGH)){ if (buf[EEPROM_NAMELENGTH - 1] == '\0'){ myEEPROM.setName(buf); } } // get the new personality if(readFile("person.txt", buf, BIGENOUGH)){ byte newNum = (byte) atoi(buf); if (newNum > 0 && newNum <= EEPROM_LASTPERSON){ myEEPROM.setPersonality(newNum); } } // get the power-down timeout if(readFile("timeout.txt", buf, BIGENOUGH)){ byte newNum = (byte) atoi(buf); if (newNum >= 0 && newNum <= EEPROM_MAXTIMEOUT){ myEEPROM.setTimeout(newNum); } } // get the lag time if(readFile("lag.txt", buf, BIGENOUGH)){ byte newNum = (byte) atoi(buf); if (newNum >= 0 && newNum <= EEPROM_MAXLAG){ myEEPROM.setSpeed(newNum); } } // get the user mode if(readFile("mode.txt", buf, BIGENOUGH)){ byte newNum = (byte) atoi(buf); if (newNum >= 0 && newNum <= EEPROM_MAXMODE){ myEEPROM.setMode(newNum); } } // allows user to determine number of seconds in autonomous, teleOp and endgame (ChapR3 of EEPROM) // zero for either mode skips the mode if(readFile("mConfig.txt",buf, BIGENOUGH)){ char *ptr = buf; for (int i = 0; i < 3; i++){ switch(i){ case 0: myEEPROM.setAutoLen(atoi(ptr));break; case 1: myEEPROM.setTeleLen(atoi(ptr));break; case 2: myEEPROM.setEndLen(atoi(ptr));break; } while (*ptr != '\r' && *ptr != '\0' && *ptr != '\n'){ ptr++; } while (*ptr == '\r' && *ptr == '\n'){ ptr++; } if (*ptr == '\0'){ break; } } } // contains the settings for the digital I/O pins (for FRC, aka ChapR3 of EEPROM) if (readFile("dgtlIn.txt", buf, BIGENOUGH)){ byte newNum = 0; for (int i = 0, ptr = 0; i < 8; i++){ byte bit = (buf[ptr] == '1')?1:0; newNum |= bit<<i; while (buf[ptr] != '\r' && buf[ptr] != '\0' && buf[ptr] != '\n'){ ptr++; } while (buf[ptr] == '\r' || buf[ptr] == '\n'){ ptr++; } if (buf[ptr] == '\0'){ break; } } myEEPROM.setDigitalInputs(newNum); } // contains the 4 analog inputs (for FRC, aka ChapR3 of EEPROM) if (readFile("analogIn.txt", buf, BIGENOUGH)){ char *ptr = buf; for (int i = 0; i < 4; i++){ double value = atof(ptr); if (value > 0 && value <= 5) { value = (value*1023)/5; // TODO - translate to labview preferences here switch(i) { case 0: myEEPROM.setAnalogInput1(value); break; case 1: myEEPROM.setAnalogInput2(value); break; case 2: myEEPROM.setAnalogInput3(value); break; case 3: myEEPROM.setAnalogInput4(value); break; } } while (*ptr != '\r' && *ptr != '\0' && *ptr != '\n'){ ptr++; } while (*ptr == '\r' || *ptr == '\n'){ ptr++; } if (*ptr == '\0'){ break; } } } // get a target bluetooth connection name/ID AND connect if it is there // this MAY need to be changed to do the connection AFTER getting // done with the flash drive. Note that this data IS NOT stored in // the EEPROM - instead, it is just used as the current paired device // and will be reset (like normal) whenever a new pairing is done. extern BT bt; if(readFile("targetID.txt", buf, BIGENOUGH,true)){ if (bt.addressFilter(buf,BIGENOUGH)) { // useful address? bt.setRemoteAddress(buf); delay(100); } } // TODO: make target.txt work - it should take a NAME and find the BT ID for it if(readFile("target.txt", buf, BIGENOUGH,true)){ // Serial.print("target: \""); // Serial.print(buf); // Serial.println("\""); // if(bt.nameToAddress(buf)) { // bt.setRemoteAddress(buf); // delay(100); // } } // the confirm beep indicates that all files that existed were read // it doesn't confirm that all data was cool beeper.confirm(); } else { // the disk was put in the wrong USB port! beeper.icky(); } }