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

Proposed implementation for device scanning #14

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions I2C.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,35 @@ void I2C::scan()
timeOutDelay = tempTime;
}

bool I2C::scanFor(uint8_t addr)
{
uint16_t tempTime = timeOutDelay;
timeOut(80);

returnStatus = 0;
returnStatus = _start();
if (!returnStatus)
{
returnStatus = _sendAddress(SLA_W(addr));
}
if (returnStatus)
{
if (returnStatus == 1)
{
timeOutDelay = tempTime;
return false;
}
}
else
{
return true;
}
_stop();

timeOutDelay = tempTime;
return false;
}

uint8_t I2C::available()
{
return (bytesAvailable);
Expand Down
1 change: 1 addition & 0 deletions I2C.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ class I2C
void setSpeed(uint8_t);
void pullup(uint8_t);
void scan();
bool scanFor(uint8_t addr);
uint8_t available();
uint8_t receive();
uint8_t write(uint8_t, uint8_t);
Expand Down