Skip to content

Commit 26e95e3

Browse files
committed
Automatic reporting report one encoder at the time (best performences)
1 parent 72aec53 commit 26e95e3

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

utility/EncoderFirmata.cpp

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,11 @@ void EncoderFirmata::report()
147147
{
148148
if (autoReport)
149149
{
150-
reportPositions();
150+
byte encoder;
151+
for(encoder=0; encoder<MAX_ENCODERS; encoder++)
152+
{
153+
reportPosition(encoder);
154+
}
151155
}
152156
}
153157

@@ -199,7 +203,17 @@ void EncoderFirmata::reportPositions()
199203
byte encoder;
200204
for(encoder=0; encoder<MAX_ENCODERS; encoder++)
201205
{
202-
reportPosition(encoder);
206+
if (isEncoderAttached(encoderNum))
207+
{
208+
signed long position = encoders[encoder]->read();
209+
long absValue = abs(position);
210+
Firmata.write(encoder);
211+
Firmata.write(position >= 0 ? 0x00 : 0x01);
212+
Firmata.write((byte)absValue & 0x7F);
213+
Firmata.write((byte)(absValue >> 7) & 0x7F);
214+
Firmata.write((byte)(absValue >> 14) & 0x7F);
215+
Firmata.write((byte)(absValue >> 21) & 0x7F);
216+
}
203217
}
204218
Firmata.write(END_SYSEX);
205219
}

0 commit comments

Comments
 (0)