Skip to content

Add I2C General Call Commands #10

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

Merged
merged 1 commit into from
May 10, 2021

Conversation

codenio
Copy link
Contributor

@codenio codenio commented May 6, 2021

This PR address #9 ,

  • Adds _general_call static methods for executing different general calls to MCP4728
  • Adds reset, wakeup and soft_update general call static methods

Thoughts and Comments..?

@jposada202020
Copy link
Contributor

@codenio that was quick, questions:
Sorry not to mention that the CI will probably fail as we use pylint and Black to verify our code and sphinx for the documentation
please see. https://learn.adafruit.com/improve-your-code-with-pylint
Also question why you are putting the functions in the CV class, we only use this one as a constructor to implement options for the registers and others.
I will let run the CI and see what happens : Thanks

@jposada202020
Copy link
Contributor

@codenio I will take a look at the datasheet tonight, and try to test moving your functions to the main class, also a good practice is to have a test code, that way we could test the same things and compare results. Thanks...

@codenio
Copy link
Contributor Author

codenio commented May 7, 2021

Sorry not to mention that the CI will probably fail as we use pylint and Black to verify our code and sphinx for the documentation
please see. https://learn.adafruit.com/improve-your-code-with-pylint

Thanks for prompt response. adding the same in contribution guidelines would help new contributors.

Will make those suggested changes and update this PR

@jposada202020
Copy link
Contributor

You are right, actually it is the guide, https://learn.adafruit.com/creating-and-sharing-a-circuitpython-library/overview. We are working on putting some automatic "guidelines" in the CI built. But, thank you, your suggestion is noted.

@codenio
Copy link
Contributor Author

codenio commented May 7, 2021

try to test moving your functions to the main class,

I guess it is in main class "MCP4728", could you check the same..?

also a good practice is to have a test code, that way we could test the same things and compare results. Thanks...

test code you mean, example code to test it on actual hardware..?
I can add the example code but I do not have an MCP4728 BoB with me, any help in testing this code is appriciated

Thanks
codenio

@jposada202020
Copy link
Contributor

You are right, just to verify that the new features introduced with your Pr are working, I Do have the hardware so I could test :)

@codenio codenio force-pushed the feature/general_call branch from 1b10160 to 0e8af0b Compare May 7, 2021 03:00
@codenio
Copy link
Contributor Author

codenio commented May 7, 2021

The following changes were made

  • changed newly added functions as class methods (instead of static methods)
  • added example file to test the reset function
  • used Pre-commit to lint the code

will modify the implementation to improve readability and get back

@codenio codenio force-pushed the feature/general_call branch from 0e8af0b to 7a41d0a Compare May 7, 2021 03:18
@codenio
Copy link
Contributor Author

codenio commented May 7, 2021

All changes done. hope this could be reviewed and merged. Thanks for the prompt responses and suggestions.

@jposada202020
Copy link
Contributor

@codenio just to let you know, that I took a briefly look at the changes and test some of the new features, it works. will take some time later to give my official review. Thanks for your contribution

Copy link
Contributor

@jposada202020 jposada202020 left a comment

Choose a reason for hiding this comment

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

Thanks just that minor comment regarding the coyright mention, also we need to include this new example in the examples.rst file, following the standard provides, this allows the autodocs to build the readthedocs documentation

I have testes this with a modified script provided, using the internal function _read_registers() to see changes.

Modified Test Code

import board
import adafruit_mcp4728

i2c = board.I2C()  # uses board.SCL and board.SDA
mcp4728 = adafruit_mcp4728.MCP4728(i2c)
print(mcp4728._read_registers())
mcp4728.channel_a.value = 65535  # Voltage = VDD
mcp4728.channel_b.value = int(65535 / 2)  # VDD/2
mcp4728.channel_c.value = int(65535 / 4)  # VDD/4
mcp4728.channel_d.value = 0  # 0V

mcp4728.save_settings()  # save current voltages into EEPROM
print(mcp4728._read_registers())
mcp4728.channel_a.value = 0  # Modify output
mcp4728.channel_b.value = 0  # Modify output
mcp4728.channel_c.value = 0  # Modify output
mcp4728.channel_d.value = 65535  # Modify output

print(mcp4728._read_registers())
mcp4728.reset()  # reset MCP4728
print(mcp4728._read_registers())

Results

Adafruit CircuitPython 6.2.0 on 2021-04-05; Adafruit Feather RP2040 with rp2040
>>> import mcp4728_generaltest
[(6, False, False, 0), (2047, False, False, 0), (1023, False, False, 0), (0, False, False, 0)]
[(4095, False, False, 0), (2047, False, False, 0), (1023, False, False, 0), (0, False, False, 0)]
[(4095, False, False, 0), (2047, False, False, 0), (1023, False, False, 0), (0, False, False, 0)]
[(6, False, False, 0), (2047, False, False, 0), (1023, False, False, 0), (0, False, False, 0)]
>>> 

Changes seems good to me

@codenio codenio force-pushed the feature/general_call branch from 7a41d0a to e235e1d Compare May 7, 2021 17:37
@jposada202020
Copy link
Contributor

@codenio sorry it was not my intention to try to imply that we needed to change the example as you made it. Just to clarify to folks how I did my tests and verify the changes. Your code was perfectly fine to begin with

@codenio
Copy link
Contributor Author

codenio commented May 7, 2021

not my intention to try to imply that we needed to change the example as you made it.

realised the same just now, will revert to previous version of the example.
BTW, do we need to expose _read_registers() ..? is it a valid feature..?

@jposada202020
Copy link
Contributor

No we are good, user will not need that feature, and if they needed they will use as we did :)

@jposada202020 jposada202020 added the enhancement New feature or request label May 7, 2021
@jposada202020 jposada202020 linked an issue May 7, 2021 that may be closed by this pull request
@codenio codenio force-pushed the feature/general_call branch from e235e1d to 76e6a70 Compare May 7, 2021 17:57
@jposada202020
Copy link
Contributor

you could correct the last one with this

General Call Example
------------------------------

@codenio
Copy link
Contributor Author

codenio commented May 7, 2021

you could correct the last one with this

General Call Example
------------------------------

is there way to check this before pushing..?

@jposada202020
Copy link
Contributor

jposada202020 commented May 7, 2021

Yes, there is, you could run the following command
sphinx-build -E -W -b html . _build/html
This will build the docs as the CI does

This Commit,
- Adds _general_call static methods for executing different general calls to MCP4728
- Adds reset, wakeup and soft_update general call static methods
- Updates examples.rst
@codenio codenio force-pushed the feature/general_call branch from 76e6a70 to b1caab2 Compare May 7, 2021 18:15
@codenio
Copy link
Contributor Author

codenio commented May 7, 2021

@jposada202020 , all these short debugging commands can be add into contribution guidelines =)

@jposada202020
Copy link
Contributor

@codenio :) I know, I am on it :), I open this discussion in the CircuitPython dev channel that by the way you are invited to participate, is open, for everyone is in the Adafruit discord channel under circuitpython-dev.

@jposada202020
Copy link
Contributor

Thanks to stick to the whole process, know we give folks a couple of days and then we could merge. Thanks :)

@codenio
Copy link
Contributor Author

codenio commented May 7, 2021

thanks for the prompt responses and guidance 👍

@jposada202020 jposada202020 merged commit 7f87f7f into adafruit:master May 10, 2021
adafruit-adabot added a commit to adafruit/Adafruit_CircuitPython_Bundle that referenced this pull request May 14, 2021
Updating https://github.com/adafruit/Adafruit_CircuitPython_BNO08X_RVC to 1.0.5 from 1.0.4:
  > Merge pull request adafruit/Adafruit_CircuitPython_BNO08x_RVC#3 from jposada202020/improxing_docs
  > "Increase duplicate code check threshold "

Updating https://github.com/adafruit/Adafruit_CircuitPython_CAP1188 to 1.3.0 from 1.2.7:
  > Merge pull request adafruit/Adafruit_CircuitPython_CAP1188#21 from jposada202020/separating_properties

Updating https://github.com/adafruit/Adafruit_CircuitPython_DisplayIO_SH1107 to 1.2.0 from 1.1.1:
  > Merge pull request adafruit/Adafruit_CircuitPython_DisplayIO_SH1107#5 from lesamouraipourpre/display_offset
  > "Increase duplicate code check threshold "

Updating https://github.com/adafruit/Adafruit_CircuitPython_EMC2101 to 1.1.8 from 1.1.7:
  > Merge pull request adafruit/Adafruit_CircuitPython_EMC2101#17 from jposada202020/correcting_typo

Updating https://github.com/adafruit/Adafruit_CircuitPython_LSM6DS to 4.2.0 from 4.1.5:
  > Merge pull request adafruit/Adafruit_CircuitPython_LSM6DS#41 from jposada202020/adding_temperature_property

Updating https://github.com/adafruit/Adafruit_CircuitPython_MCP4728 to 1.2.0 from 1.1.6:
  > Merge pull request adafruit/Adafruit_CircuitPython_MCP4728#10 from codenio/feature/general_call

Updating https://github.com/adafruit/Adafruit_CircuitPython_SI4713 to 1.3.0 from 1.2.6:
  > Merge pull request adafruit/Adafruit_CircuitPython_SI4713#18 from sheimers/master
  > "Increase duplicate code check threshold "
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add I2C General Call Commands
2 participants