Comments inside function use // instead of // for consistency with rest of library
Added "Status bits: " to explain what the comment is about
Removed comments about ML/MH bits which are not used
Folded variable declarations/logic into fewer lines
Terminate description comment with period, for consistency with rest of library
/*******************************************************
Method: detectMagnet
In: none
Out: 1 if magnet is detected, 0 if not
Description: reads status register and examines the
MD bit.
*******************************************************/
int AMS_5600::detectMagnet()
{
// Status bits: 0 0 MD ML MH 0 0 0
// MD high = magnet detected
int magStatus = readOneByte(_addr_status);
return (magStatus & 0x20) ? 1 : 0;
}
Some suggested improvements to getMagnetStrength():
Comments inside function use // instead of // for consistency with rest of library
Added "Status bits: " to explain what the comment is about
Fixed typo "andexamins" and wrapped long comment to next line
Fixed spelling "to weak/to strong"
Folded variable declaration into fewer lines
Removed detectMagnet() call which was not needed since we have just read the status register. Now twice as fast
Terminate description comment with period, for consistency with rest of library
/*******************************************************
Method: getMagnetStrength
In: none
Out: 0 if magnet not detected
1 if magnet is too weak
2 if magnet is just right
3 if magnet is too strong
Description: reads status register and examines the
MH,ML,MD bits.
*******************************************************/
int AMS_5600::getMagnetStrength()
{
int retVal = 0; // no magnet
// Status bits: 0 0 MD ML MH 0 0 0
// MD high = magnet detected
// ML high = AGC maximum overflow, magnet too weak
// MH high = AGC minimum overflow, magnet too strong
int magStatus = readOneByte(_addr_status);
if (magStatus & 0x20) {
retVal = 2; // magnet detected
if (magStatus & 0x10)
retVal = 1; // too weak
else if (magStatus & 0x08)
retVal = 3; // too strong
}
return retVal;
}
Some suggested improvements to detectMagnet():
Some suggested improvements to getMagnetStrength():