fossasia / pslab-python

Python Library for PSLab Desktop: https://pslab.io
GNU General Public License v3.0
1.62k stars 226 forks source link

Simplified the I2C API #139

Closed nkpro2000sr closed 3 years ago

nkpro2000sr commented 3 years ago

closes #136

changes

  1. I2C -> I2CMaster and I2CSlave

added methods

  1. simple_read_byte() simple_read_int() simple_read_long()
  2. read_bulk_byte() read_bulk_int() read_bulk_long()
nkpro2000sr commented 3 years ago

@bessman

I added tests for I2CMaster and I2CSlave except I2CSlave.capture .

because it throws error on mocked handler.

Error [total_int_samples = self.total_bytes / 2](https://github.com/fossasia/pslab-python/blob/57425d06512c6422d30a1c5135d6ed678aa44045/PSL/Peripherals.py#L382) which is float, so [self.H.__sendInt__(total_int_samples % DATA_SPLITTING)](https://github.com/fossasia/pslab-python/blob/57425d06512c6422d30a1c5135d6ed678aa44045/PSL/Peripherals.py#L408) throws not a integer error.

also it is little difficult for me to understand. so i didn't touched it.

bessman commented 3 years ago

Thank you!

Regarding the error, previous versions of Handler accepted floats and just rounded then to the closest integer before transmission, but that behavior could lead to unexpected results so it was removed. This is a leftover from that which wasn't found and fixed yet. You can fix it by changing the operator to integer division (//).

Other than that, the old I2C class should raise a DeprecationWarning on initialization. You can also add # nosec to the lines codacy complains about. That's not good practice, of course, but acceptable in this case since the class is being deprecated.

nkpro2000sr commented 3 years ago

@bessman may i change I2CSlave.simpleRead and I2CSlave.readBulk to I2CSlave.simple_read and I2CSlave.read_bulk, according to PEP8 naming standards.

bessman commented 3 years ago

Please do!

bessman commented 3 years ago

I'm not sure why # nosec isn't suppressing the codacy warnings here. I'll look into it.

Edit: The warning comes from pylint, not bandit, that's why. So # nosec should be # pylint: disable=arguments-differ instead. My bad!

nkpro2000sr commented 3 years ago

@bessman can you please add hacktoberfest-accepted label to this pr, if doing so doesn't violates codeheat rules.

bessman commented 3 years ago

Sure! I'm not familiar with codeheat's rules, but I don't see why it should be a problem.