Skip to content

Add RealTimeClock - Mcp7941xDriver.#98

Merged
stefanhaustein merged 4 commits intoPi4J:mainfrom
mores:mcp7941x
Dec 6, 2025
Merged

Add RealTimeClock - Mcp7941xDriver.#98
stefanhaustein merged 4 commits intoPi4J:mainfrom
mores:mcp7941x

Conversation

@mores
Copy link
Contributor

@mores mores commented Nov 28, 2025

No description provided.

i2c.writeRegister(YEAR, (byte) decToBcd(localDateTime.getYear() - 2000));
}

public static int bcdToDec(int bcd) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you make this private for now, too?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

}

private static int decToBcd(int val) {
return ((val / 10) << 4) | (val % 10);
Copy link
Collaborator

@stefanhaustein stefanhaustein Nov 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a comment that this is limited to two digits (0..99) here and above

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should make it generic (although it's not needed here)

if (val < 0) {
  throw new IllegalArgumentException();
}
int result = 0;
while (val > 0) {
  result = (result << 4) | (val % 10)
  val /= 10
}
return result 

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Half done.
The above logic breaks the code.

@stefanhaustein stefanhaustein self-requested a review December 6, 2025 13:37
@stefanhaustein stefanhaustein merged commit 0c622f4 into Pi4J:main Dec 6, 2025
1 check passed
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

Successfully merging this pull request may close these issues.

2 participants