You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As the code in Pixy_Lib is currently written, getWord returns a byte padded with 0's and getByte returns the first byte transmitted and disposes of the second byte. A byte is always 8 bits and on the pixy a word is 16 bits.
uint16_t Pixy::getWord()
{
unsigned char buffer[2] = {0, 0};
i2c->ReadOnly(2, buffer);
return (buffer[1] << 8) | buffer[0]; //shift buffer[1] by 8 bits and add( | is bitwise or) buffer[0] to it
}
uint8_t Pixy::getByte()
{
unsigned char buffer[1] = {0};
i2c->ReadOnly(1, buffer);
return buffer[0];
}
The above code is corrected.
As a side note, i2c->ReadOnly might fail. If it does, it will return true. If you run into any trouble you should try checking the return value of the ReadOnly calls and reporting any errors you see.
Thanks for making this code public it was helpful to reference!
The text was updated successfully, but these errors were encountered:
As the code in Pixy_Lib is currently written, getWord returns a byte padded with 0's and getByte returns the first byte transmitted and disposes of the second byte. A byte is always 8 bits and on the pixy a word is 16 bits.
https://github.com/Robodox-599/Pixy/blob/master/C%2B%2B/Pixy_Lib/Pixy.cpp#L90
The above code is corrected.
As a side note, i2c->ReadOnly might fail. If it does, it will return
true
. If you run into any trouble you should try checking the return value of the ReadOnly calls and reporting any errors you see.Thanks for making this code public it was helpful to reference!
The text was updated successfully, but these errors were encountered: