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

Improvements to detectMagnet() / getMagnetStrength() #19

Closed
sheffieldnikki opened this issue Jun 8, 2022 · 3 comments
Closed

Improvements to detectMagnet() / getMagnetStrength() #19

sheffieldnikki opened this issue Jun 8, 2022 · 3 comments
Assignees
Labels
enhancement New feature or request Seeed_Arduino_AS5600 Label for Seeed_Arduino_AS5600 UAY Unassigned yet

Comments

@sheffieldnikki
Copy link

sheffieldnikki commented Jun 8, 2022

Some suggested improvements to detectMagnet():

  1. Fix typo "examines MH bit" should be MD bit
  2. Comments inside function use // instead of /* */ for consistency with rest of library
  3. Added "Status bits: " to explain what the comment is about
  4. Removed comments about ML/MH bits which are not used
  5. Folded variable declarations/logic into fewer lines
  6. 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():

  1. Comments inside function use // instead of /* */ for consistency with rest of library
  2. Added "Status bits: " to explain what the comment is about
  3. Fixed typo "andexamins" and wrapped long comment to next line
  4. Fixed spelling "to weak/to strong"
  5. Folded variable declaration into fewer lines
  6. Removed detectMagnet() call which was not needed since we have just read the status register. Now twice as fast
  7. 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;
}
@Pillar1989
Copy link
Member

@sheffieldnick welcome to PR.

@sheffieldnikki
Copy link
Author

@Pillar1989 no PR, but you've got my code so you're welcome to merge it if you want.

Pillar1989 pushed a commit that referenced this issue Aug 25, 2022
Implement Issue "Improvements to detectMagnet() / getMagnetStrength()
#19 opened on 8 Jun by sheffieldnick
Implement Issue "Improvements to setOutPut()
#20 opened on 8 Jun by sheffieldnick"
@MatthewJeffson MatthewJeffson added UAY Unassigned yet Seeed_Arduino_AS5600 Label for Seeed_Arduino_AS5600 labels Oct 9, 2024
@Lesords Lesords self-assigned this Oct 14, 2024
@Lesords Lesords added the enhancement New feature or request label Oct 16, 2024
@Lesords
Copy link
Contributor

Lesords commented Nov 8, 2024

Hello,

I appreciate what you did.

Your suggested changes have been merged, so I will close this issue.

If you have other questions, please feel free to open it.

@Lesords Lesords closed this as completed Nov 8, 2024
@github-project-automation github-project-automation bot moved this from Todo to Done in Issues and PR Assemble Nov 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request Seeed_Arduino_AS5600 Label for Seeed_Arduino_AS5600 UAY Unassigned yet
Projects
Status: Done
Development

No branches or pull requests

4 participants