Skip to content

Commit 62e39c4

Browse files
Merge pull request #327 from zfields/opt
Compiler optimizations for new classes
2 parents c78d0e2 + 94d007a commit 62e39c4

File tree

5 files changed

+17
-10
lines changed

5 files changed

+17
-10
lines changed

Firmata.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ class FirmataClass
111111

112112
/* private methods ------------------------------ */
113113
void strobeBlinkPin(byte pin, int count, int onInterval, int offInterval);
114-
friend void FirmataMarshaller::sendValueAsTwo7bitBytes(uint16_t value);
114+
friend void FirmataMarshaller::sendValueAsTwo7bitBytes(uint16_t value) const;
115115
};
116116

117117
extern FirmataClass Firmata;

FirmataMarshaller.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
#include <string.h>
2424
#endif
2525

26+
#include "FirmataConstants.h"
27+
2628
//******************************************************************************
2729
//* Support Functions
2830
//******************************************************************************
@@ -32,6 +34,7 @@
3234
* @param value The 16-bit value to be split and written separately.
3335
*/
3436
void FirmataMarshaller::sendValueAsTwo7bitBytes(uint16_t value)
37+
const
3538
{
3639
FirmataStream->write(value & 0x7F); // LSB
3740
FirmataStream->write(value >> 7 & 0x7F); // MSB
@@ -87,6 +90,7 @@ void FirmataMarshaller::end(void)
8790
* The maximum value is 14-bits (16384).
8891
*/
8992
void FirmataMarshaller::sendAnalog(uint8_t pin, uint16_t value)
93+
const
9094
{
9195
if ( (Stream *)NULL == FirmataStream ) { return; }
9296
// pin can only be 0-15, so chop higher bits
@@ -101,6 +105,7 @@ void FirmataMarshaller::sendAnalog(uint8_t pin, uint16_t value)
101105
* @param value The value of the pin.
102106
*/
103107
void FirmataMarshaller::sendDigital(uint8_t pin, uint16_t value)
108+
const
104109
{
105110
/* TODO add single pin digital messages to the protocol, this needs to
106111
* track the last digital data sent so that it can be sure to change just
@@ -129,6 +134,7 @@ void FirmataMarshaller::sendDigital(uint8_t pin, uint16_t value)
129134
* @param portData The value of the port. The value of each pin in the port is represented by a bit.
130135
*/
131136
void FirmataMarshaller::sendDigitalPort(uint8_t portNumber, uint16_t portData)
137+
const
132138
{
133139
if ( (Stream *)NULL == FirmataStream ) { return; }
134140
FirmataStream->write(DIGITAL_MESSAGE | (portNumber & 0xF));
@@ -144,6 +150,7 @@ void FirmataMarshaller::sendDigitalPort(uint8_t portNumber, uint16_t portData)
144150
* @param bytev A pointer to the array of data bytes to send in the message.
145151
*/
146152
void FirmataMarshaller::sendSysex(uint8_t command, size_t bytec, uint8_t *bytev)
153+
const
147154
{
148155
if ( (Stream *)NULL == FirmataStream ) { return; }
149156
size_t i;
@@ -160,6 +167,7 @@ void FirmataMarshaller::sendSysex(uint8_t command, size_t bytec, uint8_t *bytev)
160167
* @param string A pointer to the char string
161168
*/
162169
void FirmataMarshaller::sendString(const char *string)
170+
const
163171
{
164172
sendSysex(STRING_DATA, strlen(string), (uint8_t *)string);
165173
}

FirmataMarshaller.h

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@
2424

2525
#include <Stream.h>
2626

27-
#include "FirmataConstants.h"
28-
2927
class FirmataMarshaller
3028
{
3129
friend class FirmataClass;
@@ -38,15 +36,15 @@ class FirmataMarshaller
3836
void end();
3937

4038
/* serial send handling */
41-
void sendAnalog(uint8_t pin, uint16_t value);
42-
void sendDigital(uint8_t pin, uint16_t value);
43-
void sendDigitalPort(uint8_t portNumber, uint16_t portData);
44-
void sendString(const char *string);
45-
void sendSysex(uint8_t command, size_t bytec, uint8_t *bytev);
39+
void sendAnalog(uint8_t pin, uint16_t value) const;
40+
void sendDigital(uint8_t pin, uint16_t value) const;
41+
void sendDigitalPort(uint8_t portNumber, uint16_t portData) const;
42+
void sendString(const char *string) const;
43+
void sendSysex(uint8_t command, size_t bytec, uint8_t *bytev) const;
4644

4745
private:
4846
/* utility methods */
49-
void sendValueAsTwo7bitBytes(uint16_t value);
47+
void sendValueAsTwo7bitBytes(uint16_t value) const;
5048

5149
Stream *FirmataStream;
5250
};

FirmataParser.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ void FirmataParser::parse(uint8_t inputData)
192192
* @return Returns true if the parser is actively parsing data.
193193
*/
194194
bool FirmataParser::isParsingMessage(void)
195+
const
195196
{
196197
return (waitForData > 0 || parsingSysex);
197198
}

FirmataParser.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class FirmataParser
3838
FirmataParser();
3939
/* serial receive handling */
4040
void parse(uint8_t value);
41-
bool isParsingMessage(void);
41+
bool isParsingMessage(void) const;
4242
/* attach & detach callback functions to messages */
4343
void attach(uint8_t command, callbackFunction newFunction);
4444
void attach(uint8_t command, systemCallbackFunction newFunction);

0 commit comments

Comments
 (0)