Update of /cvsroot/pure-data/externals/hardware/arduino/Pd_firmware
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv8575
Modified Files:
Makefile Pd_firmware.pde
Log Message:
got 'report analog ports' working, but the analog data reporting isn't working properly yet
Index: Makefile
===================================================================
RCS file: /cvsroot/pure-data/externals/hardware/arduino/Pd_firmware/Makefile,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** Makefile 1 Mar 2007 05:39:49 -0000 1.4
--- Makefile 5 Mar 2007 04:34:32 -0000 1.5
***************
*** 124,127 ****
--- 124,128 ----
# Default target.
all: build
+ echo 'close;' | /Applications/Pd-0.39.2-extended-RC1.app/Contents/Resources/bin/pdsend 34567 || true
say "press the button"
make upload
Index: Pd_firmware.pde
===================================================================
RCS file: /cvsroot/pure-data/externals/hardware/arduino/Pd_firmware/Pd_firmware.pde,v
retrieving revision 1.25
retrieving revision 1.26
diff -C2 -d -r1.25 -r1.26
*** Pd_firmware.pde 1 Mar 2007 05:39:49 -0000 1.25
--- Pd_firmware.pde 5 Mar 2007 04:34:32 -0000 1.26
***************
*** 42,50 ****
/*
- * TODO: debug hardware PWM
* TODO: add pulseOut functionality for servos
* TODO: add software PWM for servos, etc (servo.h or pulse.h)
- * TODO: redesign protocol to accomodate boards with more I/Os
- * TODO: add protocol version reporting
* TODO: add device type reporting (i.e. some firmwares will use the Firmata
* protocol, but will only support specific devices, like ultrasound
--- 42,47 ----
***************
*** 52,56 ****
* TODO: add "pinMode all 0/1" command
* TODO: try using PIND to get all digitalIns at once
- * TODO: add cycle markers to mark start of analog, digital, pulseIn, and PWM
* TODO: use Program Control to load stored profiles from EEPROM
*/
--- 49,52 ----
***************
*** 96,100 ****
/* -----------------------------------------------------------------------------
! * DATA MESSAGES */
/* two byte digital data format
--- 92,96 ----
/* -----------------------------------------------------------------------------
! * DATA MESSAGE FORMAT */
/* two byte digital data format
***************
*** 214,217 ****
--- 210,214 ----
byte waitForData = 0;
byte executeMultiByteCommand = 0; // command to execute after getting multi-byte data
+ byte multiByteChannel = 0; // channel data for multiByteCommands
byte storedInputData[MAX_DATA_BYTES] = {0,0}; // multi-byte data
***************
*** 221,226 ****
byte digitalInputLowByte = 0;
unsigned int digitalPinStatus = 65535;// bit-wise array to store pin status 0=INPUT, 1=OUTPUT
-
-
/* this byte stores the status off whether PWM is on or not
* bit 9 = PWM0, bit 10 = PWM1, bit 11 = PWM2
--- 218,221 ----
***************
*** 228,237 ****
int pwmStatus = 0;
! /* bit-wise array to store pin reporting */
! unsigned int analogPinsToReport = 65535;
!
! /* for reading analogIns */
! byte analogPin = 0;
! int analogData;
/* interrupt variables */
volatile int int_counter = 0; // ms counter for scheduling
--- 223,230 ----
int pwmStatus = 0;
! /* analog inputs */
! unsigned int analogPinsToReport = 0; // bit-wise array to store pin reporting
! int analogPin = 0; // counter for reading analog pins
! int analogData; // storage variable for data from analogRead()
/* interrupt variables */
volatile int int_counter = 0; // ms counter for scheduling
***************
*** 272,276 ****
*/
void processInput(int inputData) {
! int command, channel;
// a few commands have byte(s) of data following the command
--- 265,269 ----
*/
void processInput(int inputData) {
! int command;
// a few commands have byte(s) of data following the command
***************
*** 282,289 ****
switch(executeMultiByteCommand) {
case ANALOG_MESSAGE:
- channel = inputData & 0x0F; // get channel from command byte
break;
case DIGITAL_MESSAGE:
! outputDigitalBytes(storedInputData[1], storedInputData[0]); // (LSB, MSB)
break;
case SET_DIGITAL_PIN_MODE:
--- 275,281 ----
switch(executeMultiByteCommand) {
case ANALOG_MESSAGE:
break;
case DIGITAL_MESSAGE:
! outputDigitalBytes(storedInputData[1], storedInputData[0]); //(LSB, MSB)
break;
case SET_DIGITAL_PIN_MODE:
***************
*** 293,296 ****
--- 285,293 ----
break;
case REPORT_ANALOG_PIN:
+ setAnalogPinReporting(multiByteChannel,storedInputData[0]);
+ //Serial.print(multiByteChannel,BYTE);
+ //Serial.print(storedInputData[0],BYTE);
+ //Serial.print(analogPinsToReport,BYTE);
+ //Serial.print(analogPinsToReport & (1 << multiByteChannel),BYTE);
break;
case REPORT_DIGITAL_PORTS:
***************
*** 303,320 ****
if(inputData < 0xF0) {
command = inputData & 0xF0;
} else {
command = inputData;
}
! switch (inputData) {
case ANALOG_MESSAGE:
case DIGITAL_MESSAGE:
case SET_DIGITAL_PIN_MODE:
waitForData = 2; // two data bytes needed
! executeMultiByteCommand = inputData;
break;
case REPORT_ANALOG_PIN:
case REPORT_DIGITAL_PORTS:
waitForData = 1; // two data bytes needed
! executeMultiByteCommand = inputData;
break;
case SYSTEM_RESET:
--- 300,319 ----
if(inputData < 0xF0) {
command = inputData & 0xF0;
+ multiByteChannel = inputData & 0x0F;
} else {
command = inputData;
+ // commands in the 0xF* range don't use channel data
}
! switch (command) { // TODO: these needs to be switched to command
case ANALOG_MESSAGE:
case DIGITAL_MESSAGE:
case SET_DIGITAL_PIN_MODE:
waitForData = 2; // two data bytes needed
! executeMultiByteCommand = command;
break;
case REPORT_ANALOG_PIN:
case REPORT_DIGITAL_PORTS:
waitForData = 1; // two data bytes needed
! executeMultiByteCommand = command;
break;
case SYSTEM_RESET:
***************
*** 344,349 ****
// -----------------------------------------------------------------------------
! /* this function sets the pin mode to the correct state and sets the relevant
! * bits in the two bit-arrays that track Digital I/O and PWM status
*/
void setPinMode(byte pin, byte mode) {
--- 343,348 ----
// -----------------------------------------------------------------------------
! /* sets the pin mode to the correct state and sets the relevant bits in the
! * two bit-arrays that track Digital I/O and PWM status
*/
void setPinMode(byte pin, byte mode) {
***************
*** 367,370 ****
--- 366,381 ----
}
+ // -----------------------------------------------------------------------------
+ /* sets bits in a bit array (int) to toggle the reporting of the analogIns
+ */
+ void setAnalogPinReporting(byte pin, byte state) {
+ if(state == 0) {
+ analogPinsToReport = analogPinsToReport &~ (1 << pin);
+ }
+ else { // everything but 0 enables reporting of that pin
+ analogPinsToReport = analogPinsToReport | (1 << pin);
+ }
+ }
+
// =============================================================================
***************
*** 417,430 ****
// flash the pin 13 with the protocol minor version (add major once > 0)
pinMode(13,OUTPUT);
! pin13strobe(10,5,20); // separator, a quick burst
delay(500);
pin13strobe(MAJOR_VERSION, 200, 400);
delay(500);
! pin13strobe(10,5,20); // separator, a quick burst
delay(500);
pin13strobe(MINOR_VERSION, 200, 400);
delay(500);
! pin13strobe(10,5,20); // separator, a quick burst
! delay(1000);
printVersion();
--- 428,440 ----
// flash the pin 13 with the protocol minor version (add major once > 0)
pinMode(13,OUTPUT);
! pin13strobe(2,1,4); // separator, a quick burst
delay(500);
pin13strobe(MAJOR_VERSION, 200, 400);
delay(500);
! pin13strobe(2,1,4); // separator, a quick burst
delay(500);
pin13strobe(MINOR_VERSION, 200, 400);
delay(500);
! pin13strobe(2,1,4); // separator, a quick burst
printVersion();
***************
*** 441,448 ****
/* DIGITALREAD - as fast as possible, check for changes and output them to the
* FTDI buffer using serialWrite) */
-
// this should use _SFR_IO8()
! if(int_counter > 3) {
--- 451,457 ----
/* DIGITALREAD - as fast as possible, check for changes and output them to the
* FTDI buffer using serialWrite) */
// this should use _SFR_IO8()
! if(int_counter > 3) { // run this every 4ms
***************
*** 457,470 ****
/* ANALOGREAD - right after the event character, do all of the analogReads().
* These only need to be done every 4ms. */
! // for(analogPin=0;analogPin<TOTAL_ANALOG_PINS;analogPin++) {
! for(analogPin=0;analogPin<2;analogPin++) {
! //if( analogPinsToReport & (1 << analogPin) ) {
! analogData = analogRead(analogPin);
! Serial.print(ANALOG_MESSAGE + analogPin, BYTE);
! // These two bytes converted back into the 10-bit value on host
! Serial.print(analogData & 127, BYTE); // same as analogData % 128
! Serial.print(analogData >> 7, BYTE);
! analogPin = (analogPin++) % TOTAL_ANALOG_PINS;
! //}
}
int_counter = 0; // reset ms counter
--- 466,477 ----
/* ANALOGREAD - right after the event character, do all of the analogReads().
* These only need to be done every 4ms. */
! for(analogPin=0;analogPin<TOTAL_ANALOG_PINS;analogPin++) {
! if( analogPinsToReport & (1 << analogPin) ) {
! analogData = analogRead(analogPin);
! Serial.print(ANALOG_MESSAGE + analogPin, BYTE);
! // These two bytes converted back into the 10-bit value on host
! Serial.print(analogData % 128, BYTE);
! Serial.print(analogData >> 7, BYTE);
! }
}
int_counter = 0; // reset ms counter