Skip to content

Commit 0e3a973

Browse files
move bytesToRead from config to serialRead. remove temp logging
1 parent 7e7118c commit 0e3a973

File tree

2 files changed

+21
-22
lines changed

2 files changed

+21
-22
lines changed

examples/StandardFirmata/StandardFirmata.ino

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
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;
7575
Stream *swSerial3 = NULL;
7676

7777
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;
8080

8181
/* i2c data */
8282
struct i2c_device_info {
@@ -102,8 +102,6 @@ byte servoCount = 0;
102102

103103
boolean isResetting = false;
104104

105-
int memCheckCounter = 0;
106-
char buffer[20];
107105

108106
/* utility functions */
109107
void 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
}

utility/serialUtils.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,17 @@
2020
#define HW_SERIAL1 0x01
2121
#define HW_SERIAL2 0x02
2222
#define HW_SERIAL3 0x03
23+
// extensible up to 0x07
2324

2425
#define SW_SERIAL0 0x08
2526
#define SW_SERIAL1 0x09
2627
#define SW_SERIAL2 0x0A
2728
#define SW_SERIAL3 0x0B
29+
// extensible up to 0x0F
2830

2931
#define SERIAL_PORT_ID_MASK 0x0F
3032
#define MAX_SERIAL_PORTS 8
33+
#define SERIAL_READ_ARR_LEN 12
3134

3235
// map configuration query response resolution value to serial pin type
3336
#define RES_RX1 0x02

0 commit comments

Comments
 (0)