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

pins.i2cReadNumber() should not return 0 when the device is not connected/answered #2411

Open
dynamis opened this issue Sep 2, 2019 · 0 comments

Comments

@dynamis
Copy link

dynamis commented Sep 2, 2019

Is your feature request related to a problem? Please describe.
pins.i2cReadNumber() will return 0 (without any error) even when the target device (specified with address parameter) is not connected or it have some trouble and cannot answer correctly or any other errors.

We cannot detect the disconnection nor internal error of the devices with current API set.

Describe the solution you'd like
It should indicate the problem about the device with

  • throw exception
  • return null

when we cannot read the value from the target i2c device.

Describe alternatives you've considered
If we can detect I2C devices (#1780), we'll detect it and then read/write to the devices. But event when the device is connected and worked correctly for the first time, i2c devices sometimes will stop working with some internal errors (not so rare case). To indicate it, i2cReadNumber() should throw exception or at least should return null or some valued which clearly indicated the error.

Additional context
note: pins have only read/write i2c APIs: i2cReadNumber() and i2cWriteNumber()

https://makecode.microbit.org/reference/pins
https://makecode.microbit.org/reference/pins/i2c-read-number
https://makecode.microbit.org/reference/pins/i2c-write-number

implementations of them:
https://github.com/microsoft/pxt-microbit/blob/master/libs/core/pins.ts#L21

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants