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

Add more i2c functions. #41

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open

Conversation

btsimonh
Copy link

I think these are all good now.
Have a review, but maybe wait to pull until I have added an example (will be servo control via PCA9685, illustrates many but not all of the i2c functions)?

Note the comments on returns with data:

general note about returns with data.
if using await fn(), you will get an array back [count, d0, d1, d2 ...]
if using fn(callback), you will get (err, count, d0, d1, d2 ...)

@btsimonh
Copy link
Author

ok, added the example, added stuff to readme.
I think it's ready for review :).

@btsimonh
Copy link
Author

btsimonh commented Feb 2, 2023

hold off on this for a while...
I've been using it to implement MPU6050 communication, and see a need for
1/ a few more functions which would make it easier to use, but depart from the raw interface (e.g. ability to read/write a word/long in BE format).
2/ the repetitive use of the i2c handle pushes me towards a 'class' like the gpio pin class which knows it's pigpio instance and i2c handle.... I'll look at adding this in addition to the raw functions, and maybe put the BE functions and other helpers in there?

br,
Simon

@btsimonh
Copy link
Author

ok, it's ready.

Note:
all block functions return an array of data the size of the data received.
e.g.

i2c.readI2cBlockData(reg, 10, (err, data)=>{
  // data will be 10 bytes in an array
});
let b = i2c.readI2cBlockData(reg, 10);
// b will be 10 bytes in an array

This is different to the original, which called back with (err, count, d0, d1, d2 ...) or returned async with [count, d0, d1, d2...]
I basically strip the count off, and make sure that both callback and promise return an array as the data element.

Please let me know your thoughts...

@btsimonh
Copy link
Author

Hi @guymcswain
I've pushed a complex and comprehensive MPU6050 driver based on this i2c implementation.
Would be great to have the PR accepted?

Also the script PR is not damaging...
br,
Simon

@btsimonh
Copy link
Author

also PCA9685-pigpio-client for servo control :)

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.

1 participant