20
20
21
21
See file LICENSE.txt for further informations on licensing terms.
22
22
23
- Last updated by Jeff Hoefs: August 9th , 2015
23
+ Last updated by Jeff Hoefs: October 3rd , 2015
24
24
*/
25
25
26
26
#include < Servo.h>
@@ -75,8 +75,8 @@ Stream *swSerial2 = NULL;
75
75
Stream *swSerial3 = NULL ;
76
76
77
77
byte reportSerial[MAX_SERIAL_PORTS];
78
- int serialBytesToRead[12 ];
79
- signed char serialIndex = - 1 ;
78
+ int serialBytesToRead[SERIAL_READ_ARR_LEN ];
79
+ signed char serialIndex;
80
80
81
81
/* i2c data */
82
82
struct i2c_device_info {
@@ -102,8 +102,6 @@ byte servoCount = 0;
102
102
103
103
boolean isResetting = false ;
104
104
105
- int memCheckCounter = 0 ;
106
- char buffer[20 ];
107
105
108
106
/* utility functions */
109
107
void wireWrite (byte data)
@@ -724,11 +722,9 @@ void sysexCallback(byte command, byte argc, byte *argv)
724
722
byte txPin, rxPin;
725
723
serial_pins pins;
726
724
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 ];
732
728
}
733
729
734
730
if (portId < 8 ) {
@@ -796,6 +792,14 @@ void sysexCallback(byte command, byte argc, byte *argv)
796
792
if (serialIndex + 1 >= MAX_SERIAL_PORTS) {
797
793
break ;
798
794
}
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
+ }
799
803
serialIndex++;
800
804
reportSerial[serialIndex] = portId;
801
805
} else if (argv[1 ] == SERIAL_STOP_READING) {
@@ -907,7 +911,11 @@ void systemResetCallback()
907
911
}
908
912
}
909
913
#endif
914
+
910
915
serialIndex = -1 ;
916
+ for (byte i = 0 ; i < SERIAL_READ_ARR_LEN; i++) {
917
+ serialBytesToRead[i] = 0 ;
918
+ }
911
919
912
920
for (byte i = 0 ; i < TOTAL_PORTS; i++) {
913
921
reportPINs[i] = false ; // by default, reporting off
@@ -1007,19 +1015,7 @@ void loop()
1007
1015
readAndReportData (query[i].addr , query[i].reg , query[i].bytes );
1008
1016
}
1009
1017
}
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
-
1021
1018
}
1022
1019
1023
- // TODO - figure out best location to call this function.
1024
1020
checkSerial ();
1025
1021
}
0 commit comments