Update samples using I2c to work on Windows#528
Conversation
shaggygi
left a comment
There was a problem hiding this comment.
LGTM. You beat me to it 😄
|
@shaggygi I'll leave you SPI 😄 |
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
| UnixI2cDevice device = new UnixI2cDevice(settings); | ||
| // get I2cDevice (in Win10) | ||
| //Windows10I2cDevice device = new Windows10I2cDevice(settings); | ||
| I2cDevice device = I2cDevice.Create(settings); |
There was a problem hiding this comment.
Just as a comment, now that we have I2cDevice.Create method, we might want to think again how most bindings take a I2cDevice as part of their constructor, such that insted they would just create a new one inside their class. There were only two reasons to have it passed in: support for windows/unix (which we no longer need) and in order to allow passing in a device that is not a Unix or Windows I2c device, but instead something that implementes the II2cDevice interface, like a I2C extender.
There was a problem hiding this comment.
Could the guidance be to pass in I2cDevice? or SpiDevice? similar to IGpioController. As you mentioned, I could see other flavors (i. e. GpioI2cDevice, GpioSpiDevice) in the future.
Inside the binding constructor, have something like...
_i2cDevice = I2cDevice ?? I2cDevice.Create(settings);
_spiDevice = SpiDevice ?? SpiDevice.Create(settings);Also, with guidance showing the nullable types to pass... could hopefully trigger binding devs to code the binding API with the new C# 8 feature.
There was a problem hiding this comment.
I'd refrain from that for now unless it covers 95% of the cases. Example thing what I did for SenseHat:
- Lsm9Ds1AccelerometerAndGyroscope doesn't know anything about I2C addresses
- SenseHatAccelerometerAndGyroscope thin wrapper on top of Lsm9Ds1AccelerometerAndGyroscope which only defaults I2C address since it's constant in context of SenseHat
Ideally I think we should create an issue and set up guidelines for this but I think this is non-issue at this point and regardless of this issue we need at least one constructor which takes already existing I2cDevice object.
I don't personally like default value as the ownership is not immediately obvious. Having two classes one which always default and one which never does makes stuff much clearer
There was a problem hiding this comment.
I'd prefer if we made this non-nullable and create second implementation like DefaultXyzDevice which just inherits, creates I2cDevice and disposes of it. This way you got covered 90% of the cases and advanced usage
|
How did you find all these places? Did you just do a search on all places where we were doing a |
|
@joperezr almost. I searched for |
|
Why only src/devices? should we do it on the root as well in case we were doing this in the tools or root samples? |
|
Yes, I was just looking at DeviceApiTester and will update those, as well with |
|
@joperezr I meant root samples when I said samples. Reason was to avoid the hits from the implementation of I2cDevice itself which I didn't expect to have anything useful anyway |
|
@krwq @joperezr I get local build errors now with the following package added in System.Device.Gpio.csproj. All projects build in iot directory after I remove it. Thoughts? <PackageReference Include="Microsoft.DotNet.GenAPI" Version="$(MicrosoftDotNetGenApiPackageVersion)">
<PrivateAssets>all</PrivateAssets>
</PackageReference> |
|
@shaggygi do you mind sharing a binlog of the error you are seeing so that I can take a better look? In order to produce one, just run |
|
@joperezr Does this work? Just remove the .zip. |
mmm that is very weird, does this repro if you are on a clean master? try doing: This will get latest changes, remove all pending changes, clean up your enlistment and run build again. |
|
also if you cancelled build during restore it might be worth to clean nuget cache ( |
This appears to have fix the error. One thing I noticed was a version of preview6 of something (in the output text) where this has preview5. Not sure if was SDK, runtime, etc. 😕 Thx |
Fixes: #498
This won't build until we get new package version
This incorporates changes done here: #505