Skip to content

Commit

Permalink
added calls to listen() for better behavior with multiple instances
Browse files Browse the repository at this point in the history
  • Loading branch information
kevin-pololu committed May 10, 2013
1 parent b300ac6 commit 61f727a
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions PololuQik/PololuQik.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,23 @@ void PololuQik::init(long speed /* = 9600 */)

char PololuQik::getFirmwareVersion()
{
listen();
write(QIK_GET_FIRMWARE_VERSION);
while (available() < 1);
return read();
}

byte PololuQik::getErrors()
{
listen();
write(QIK_GET_ERROR_BYTE);
while (available() < 1);
return read();
}

byte PololuQik::getConfigurationParameter(byte parameter)
{
listen();
cmd[0] = QIK_GET_CONFIGURATION_PARAMETER;
cmd[1] = parameter;
write(cmd, 2);
Expand All @@ -45,6 +48,7 @@ byte PololuQik::getConfigurationParameter(byte parameter)

byte PololuQik::setConfigurationParameter(byte parameter, byte value)
{
listen();
cmd[0] = QIK_SET_CONFIGURATION_PARAMETER;
cmd[1] = parameter;
cmd[2] = value;
Expand Down Expand Up @@ -165,13 +169,15 @@ void PololuQik2s12v10::setBrakes(unsigned char m0Brake, unsigned char m1Brake)

unsigned char PololuQik2s12v10::getM0Current()
{
listen();
write(QIK_2S12V10_GET_MOTOR_M0_CURRENT);
while (available() < 1);
return read();
}

unsigned char PololuQik2s12v10::getM1Current()
{
listen();
write(QIK_2S12V10_GET_MOTOR_M1_CURRENT);
while (available() < 1);
return read();
Expand All @@ -189,13 +195,15 @@ unsigned int PololuQik2s12v10::getM1CurrentMilliamps()

unsigned char PololuQik2s12v10::getM0Speed()
{
listen();
write(QIK_2S12V10_GET_MOTOR_M0_SPEED);
while (available() < 1);
return read();
}

unsigned char PololuQik2s12v10::getM1Speed()
{
listen();
write(QIK_2S12V10_GET_MOTOR_M1_SPEED);
while (available() < 1);
return read();
Expand Down

0 comments on commit 61f727a

Please sign in to comment.