Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getByte and getWord are switched #1

Open
yabberyabber opened this issue Feb 7, 2017 · 1 comment
Open

getByte and getWord are switched #1

yabberyabber opened this issue Feb 7, 2017 · 1 comment

Comments

@yabberyabber
Copy link

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

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!

@partounian
Copy link
Member

partounian commented Feb 8, 2017

Just as a note I'm not on the team anymore, but thank you for the contribution. Also, please open up a PR any time you make changes to a git repo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants