Update of /cvsroot/pure-data/externals/hardware/arduino/Pd_firmware In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1657/Pd_firmware
Modified Files: Pd_firmware.pde Log Message:
- digital inputs are now only sent upon change - finished conversion to new Serial class API - upped baud rate to full speed: 115200
Index: Pd_firmware.pde =================================================================== RCS file: /cvsroot/pure-data/externals/hardware/arduino/Pd_firmware/Pd_firmware.pde,v retrieving revision 1.20 retrieving revision 1.21 diff -C2 -d -r1.20 -r1.21 *** Pd_firmware.pde 30 Oct 2006 05:44:00 -0000 1.20 --- Pd_firmware.pde 31 Oct 2006 00:39:07 -0000 1.21 *************** *** 48,54 **** */
! /* firmware version numbers. The protocol is still changing, so these version ! * numbers are important */ ! // cvs version: $Id $ #define MAJOR_VERSION 0 #define MINOR_VERSION 2 --- 48,57 ---- */
! /* cvs version: $Id$ */ ! ! /* Version numbers for the protocol. The protocol is still changing, so these ! * version numbers are important. This number can be queried so that host ! * software can test whether it will be compatible with the currently ! * installed firmware. */ #define MAJOR_VERSION 0 #define MINOR_VERSION 2 *************** *** 62,66 **** /* computer<->Arduino commands * -------------------- */ ! /* 128-129 // UNUSED */ #define SET_PIN_ZERO_TO_IN 130 // set digital pin 0 to INPUT #define SET_PIN_ONE_TO_IN 131 // set digital pin 1 to INPUT --- 65,69 ---- /* computer<->Arduino commands * -------------------- */ ! /* 128-129 // UNASSIGNED */ #define SET_PIN_ZERO_TO_IN 130 // set digital pin 0 to INPUT #define SET_PIN_ONE_TO_IN 131 // set digital pin 1 to INPUT *************** *** 77,84 **** #define SET_PIN_TWELVE_TO_IN 142 // set digital pin 12 to INPUT #define SET_PIN_THIRTEEN_TO_IN 143 // set digital pin 13 to INPUT ! /* 144-149 // UNUSED */ #define DISABLE_DIGITAL_INPUTS 150 // disable reporting of digital inputs #define ENABLE_DIGITAL_INPUTS 151 // enable reporting of digital inputs ! /* 152-159 // UNUSED */ #define ZERO_ANALOG_INS 160 // disable reporting on all analog ins #define ONE_ANALOG_IN 161 // enable reporting for 1 analog in (0) --- 80,87 ---- #define SET_PIN_TWELVE_TO_IN 142 // set digital pin 12 to INPUT #define SET_PIN_THIRTEEN_TO_IN 143 // set digital pin 13 to INPUT ! /* 144-149 // UNASSIGNED */ #define DISABLE_DIGITAL_INPUTS 150 // disable reporting of digital inputs #define ENABLE_DIGITAL_INPUTS 151 // enable reporting of digital inputs ! /* 152-159 // UNASSIGNED */ #define ZERO_ANALOG_INS 160 // disable reporting on all analog ins #define ONE_ANALOG_IN 161 // enable reporting for 1 analog in (0) *************** *** 91,95 **** #define EIGHT_ANALOG_INS 168 // enable reporting for 6 analog ins (0-7) #define NINE_ANALOG_INS 169 // enable reporting for 6 analog ins (0-8) ! /* 167-199 // UNUSED */ #define SET_PIN_ZERO_TO_OUT 200 // set digital pin 0 to OUTPUT #define SET_PIN_ONE_TO_OUT 201 // set digital pin 1 to OUTPUT --- 94,98 ---- #define EIGHT_ANALOG_INS 168 // enable reporting for 6 analog ins (0-7) #define NINE_ANALOG_INS 169 // enable reporting for 6 analog ins (0-8) ! /* 170-199 // UNASSIGNED */ #define SET_PIN_ZERO_TO_OUT 200 // set digital pin 0 to OUTPUT #define SET_PIN_ONE_TO_OUT 201 // set digital pin 1 to OUTPUT *************** *** 106,114 **** #define SET_PIN_TWELVE_TO_OUT 212 // set digital pin 12 to OUTPUT #define SET_PIN_THIRTEEN_TO_OUT 213 // set digital pin 13 to OUTPUT ! /* 214-228 // UNUSED */ #define OUTPUT_TO_DIGITAL_PINS 229 // next two bytes set digital output data ! /* 230-239 // UNUSED */ #define REPORT_VERSION 240 // return the firmware version ! /* 240-249 // UNUSED */ #define DISABLE_PWM 250 // next byte sets pin # to disable #define ENABLE_PWM 251 // next two bytes set pin # and duty cycle --- 109,117 ---- #define SET_PIN_TWELVE_TO_OUT 212 // set digital pin 12 to OUTPUT #define SET_PIN_THIRTEEN_TO_OUT 213 // set digital pin 13 to OUTPUT ! /* 214-228 // UNASSIGNED */ #define OUTPUT_TO_DIGITAL_PINS 229 // next two bytes set digital output data ! /* 230-239 // UNASSIGNED */ #define REPORT_VERSION 240 // return the firmware version ! /* 240-249 // UNASSIGNED */ #define DISABLE_PWM 250 // next byte sets pin # to disable #define ENABLE_PWM 251 // next two bytes set pin # and duty cycle *************** *** 116,120 **** #define ENABLE_SOFTWARE_PWM 253 // next two bytes set pin # and duty cycle #define SET_SOFTWARE_PWM_FREQ 254 // set master frequency for software PWMs ! /* 255 // UNUSED */
--- 119,123 ---- #define ENABLE_SOFTWARE_PWM 253 // next two bytes set pin # and duty cycle #define SET_SOFTWARE_PWM_FREQ 254 // set master frequency for software PWMs ! /* 255 // UNASSIGNED */
*************** *** 162,175 **** boolean firstInputByte = false;
/* this int serves as a bit-wise array to store pin status ! * 0 = INPUT, 1 = OUTPUT ! */ ! int digitalPinStatus;
/* this byte stores the status off whether PWM is on or not * bit 9 = PWM0, bit 10 = PWM1, bit 11 = PWM2 ! * the rest of the bits are unused and should remain 0 ! */ ! int pwmStatus;
boolean digitalInputsEnabled = true; --- 165,183 ---- boolean firstInputByte = false;
+ /* store the previously sent digital inputs to compare against the current + * digital inputs. If there is no change, do not transmit. */ + byte previousDigitalInputHighByte = 0; + byte previousDigitalInputLowByte = 0; + byte digitalInputHighByte = 0; + byte digitalInputLowByte = 0; + /* this int serves as a bit-wise array to store pin status ! * 0 = INPUT, 1 = OUTPUT */ ! int digitalPinStatus = 0;
/* this byte stores the status off whether PWM is on or not * bit 9 = PWM0, bit 10 = PWM1, bit 11 = PWM2 ! * the rest of the bits are unused and should remain 0 */ ! int pwmStatus = 0;
boolean digitalInputsEnabled = true; *************** *** 180,188 ****
// ------------------------------------------------------------------------- ! void transmitDigitalInput(byte startPin) { byte i; byte digitalPin; // byte digitalPinBit; ! byte transmitByte = 0; byte digitalData;
--- 188,196 ----
// ------------------------------------------------------------------------- ! byte transmitDigitalInput(byte startPin) { byte i; byte digitalPin; // byte digitalPinBit; ! byte returnByte = 0; byte digitalData;
*************** *** 199,206 **** if( !(digitalPinStatus & (1 << digitalPin)) ) { digitalData = (byte) digitalRead(digitalPin); ! transmitByte = transmitByte + ((1 << i) * digitalData); } } ! printByte(transmitByte); }
--- 207,214 ---- if( !(digitalPinStatus & (1 << digitalPin)) ) { digitalData = (byte) digitalRead(digitalPin); ! returnByte = returnByte + ((1 << i) * digitalData); } } ! return(returnByte); }
*************** *** 227,230 **** --- 235,239 ---- pinMode(pin,OUTPUT); } + // TODO: save status to EEPROM here, if changed }
*************** *** 372,378 **** break; case REPORT_VERSION: ! printByte(REPORT_VERSION); ! printByte(MAJOR_VERSION); ! printByte(MINOR_VERSION); break; } --- 381,387 ---- break; case REPORT_VERSION: ! Serial.print(REPORT_VERSION, BYTE); ! Serial.print(MAJOR_VERSION, BYTE); ! Serial.print(MINOR_VERSION, BYTE); break; } *************** *** 386,391 **** void setup() { byte i; ! ! // flash the pin 13 with the protocol minor version pinMode(13,OUTPUT); for(i-0; i<MINOR_VERSION; i++) { --- 395,406 ---- void setup() { byte i; ! ! // TODO: load state from EEPROM here ! ! /* TODO: send digital inputs here, if enabled, to set the initial state on the ! * host computer, since once in the loop(), the Arduino will only send data on ! * change. */ ! ! // flash the pin 13 with the protocol minor version (add major once > 0) pinMode(13,OUTPUT); for(i-0; i<MINOR_VERSION; i++) { *************** *** 393,402 **** delay(100); digitalWrite(13,0); ! delay(100); } - Serial.begin(19200); for(i=0; i<TOTAL_DIGITAL_PINS; ++i) { setPinMode(i,INPUT); } }
--- 408,417 ---- delay(100); digitalWrite(13,0); ! delay(200); } for(i=0; i<TOTAL_DIGITAL_PINS; ++i) { setPinMode(i,INPUT); } + Serial.begin(115200); }
*************** *** 407,414 **** // read all digital pins, in enabled if(digitalInputsEnabled) { ! printByte(ENABLE_DIGITAL_INPUTS); ! transmitDigitalInput(7); ! checkForInput(); ! transmitDigitalInput(0); checkForInput(); } --- 422,438 ---- // read all digital pins, in enabled if(digitalInputsEnabled) { ! digitalInputHighByte = transmitDigitalInput(7); ! checkForInput(); ! digitalInputLowByte = transmitDigitalInput(0); ! checkForInput(); ! // only send data if it has changed ! if( (digitalInputHighByte != previousDigitalInputHighByte) && ! (digitalInputLowByte != previousDigitalInputLowByte) ) { ! Serial.print(ENABLE_DIGITAL_INPUTS, BYTE); ! Serial.print(digitalInputHighByte, BYTE); ! Serial.print(digitalInputLowByte, BYTE); ! previousDigitalInputHighByte = digitalInputHighByte; ! previousDigitalInputLowByte = digitalInputLowByte; ! } checkForInput(); } *************** *** 417,425 **** for(analogPin=0; analogPin<analogInputsEnabled; ++analogPin) { analogData = analogRead(analogPin); ! // these two bytes get converted back into the whole number in Pd ! // the higher bits should be zeroed so that the 8th bit doesn't get set ! printByte(ONE_ANALOG_IN + analogPin); ! printByte(analogData >> 7); // bitshift the big stuff into the output byte ! printByte(analogData % 128); // mod by 32 for the small byte checkForInput(); } --- 441,449 ---- for(analogPin=0; analogPin<analogInputsEnabled; ++analogPin) { analogData = analogRead(analogPin); ! /* These two bytes get converted back into the whole number on host. ! Highest bits should be zeroed so the 8th bit doesn't get set */ ! Serial.print(ONE_ANALOG_IN + analogPin, BYTE); ! Serial.print(analogData >> 7, BYTE); // shift high bits into output byte ! Serial.print(analogData % 128, BYTE); // mod by 32 for the small byte checkForInput(); }