2020
2121 See file LICENSE.txt for further informations on licensing terms.
2222
23- Last updated by Jeff Hoefs: August 9th , 2015
23+ Last updated by Jeff Hoefs: October 3rd , 2015
2424*/
2525
2626#include < Servo.h>
@@ -75,8 +75,8 @@ Stream *swSerial2 = NULL;
7575Stream *swSerial3 = NULL ;
7676
7777byte reportSerial[MAX_SERIAL_PORTS];
78- int serialBytesToRead[12 ];
79- signed char serialIndex = - 1 ;
78+ int serialBytesToRead[SERIAL_READ_ARR_LEN ];
79+ signed char serialIndex;
8080
8181/* i2c data */
8282struct i2c_device_info {
@@ -102,8 +102,6 @@ byte servoCount = 0;
102102
103103boolean isResetting = false ;
104104
105- int memCheckCounter = 0 ;
106- char buffer[20 ];
107105
108106/* utility functions */
109107void wireWrite (byte data)
@@ -724,11 +722,9 @@ void sysexCallback(byte command, byte argc, byte *argv)
724722 byte txPin, rxPin;
725723 serial_pins pins;
726724
727- serialBytesToRead[portId] = (int )argv[4 ] | ((int )argv[5 ] << 7 );
728-
729- if (portId > 7 && argc > 6 ) {
730- rxPin = argv[6 ];
731- txPin = argv[7 ];
725+ if (portId > 7 && argc > 4 ) {
726+ rxPin = argv[4 ];
727+ txPin = argv[5 ];
732728 }
733729
734730 if (portId < 8 ) {
@@ -796,6 +792,14 @@ void sysexCallback(byte command, byte argc, byte *argv)
796792 if (serialIndex + 1 >= MAX_SERIAL_PORTS) {
797793 break ;
798794 }
795+
796+ if (argc > 2 ) {
797+ // maximum number of bytes to read from buffer per iteration of loop()
798+ serialBytesToRead[portId] = (int )argv[2 ] | ((int )argv[3 ] << 7 );
799+ } else {
800+ // read all available bytes per iteration of loop()
801+ serialBytesToRead[portId] = 0 ;
802+ }
799803 serialIndex++;
800804 reportSerial[serialIndex] = portId;
801805 } else if (argv[1 ] == SERIAL_STOP_READING) {
@@ -907,7 +911,11 @@ void systemResetCallback()
907911 }
908912 }
909913#endif
914+
910915 serialIndex = -1 ;
916+ for (byte i = 0 ; i < SERIAL_READ_ARR_LEN; i++) {
917+ serialBytesToRead[i] = 0 ;
918+ }
911919
912920 for (byte i = 0 ; i < TOTAL_PORTS; i++) {
913921 reportPINs[i] = false ; // by default, reporting off
@@ -1007,19 +1015,7 @@ void loop()
10071015 readAndReportData (query[i].addr , query[i].reg , query[i].bytes );
10081016 }
10091017 }
1010-
1011- // // check for memory leaks
1012- // // send memory reading approximately ever 10 seconds
1013- // // 526 * 19 (default sampling interval) = 9994 ms
1014- // // increase 526 for long running processes
1015- // if (memCheckCounter++ == 526) {
1016- // sprintf(buffer, "%u", freeMemory());
1017- // Firmata.sendString(buffer);
1018- // memCheckCounter = 0;
1019- // }
1020-
10211018 }
10221019
1023- // TODO - figure out best location to call this function.
10241020 checkSerial ();
10251021}
0 commit comments