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

Need help #8

Open
NickAtGit opened this issue Feb 16, 2023 · 2 comments
Open

Need help #8

NickAtGit opened this issue Feb 16, 2023 · 2 comments

Comments

@NickAtGit
Copy link

Hey, great that you reverse engineered the Shimano bluetooth connection. I don't fully understand what you do here. Can you maybe explain more to me?

mainView.values[9] = ((value[3] << 8) | value[2]).toFloat()/10;

Thanks

@markdotai
Copy link
Owner

markdotai commented Feb 19, 2023

Hi :) It looks like NicholasRasi decoded & added that bit, but what it looks to be doing is:

  • The speed is stored using 2 bytes (in the array of bytes) and is a value in 100m/h.
  • So first to combine the 2 bytes to a single integer value it multiplies the top byte by 256 (i.e. the <<8) and then it adds the bottom byte to that value (using the bitwise "or" operation). (Each byte stores an unsigned number from 0 to 255).
  • It then converts the integer value to a floating point one so that it can be divided without losing precision, i.e. it will keep the fractional part after the division.
  • It then divides by 10 to convert from 100m/h to km/h. I guess for Shimano showing the speed to the nearest km/h was not enough, and they wanted to give 1 decimal point of precision.

@NickAtGit
Copy link
Author

Great, thanks for the explanation!

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