Skip to content

Update samples using I2c to work on Windows#528

Merged
krwq merged 1 commit intodotnet:masterfrom
krwq:use-i2c-create
Jun 27, 2019
Merged

Update samples using I2c to work on Windows#528
krwq merged 1 commit intodotnet:masterfrom
krwq:use-i2c-create

Conversation

@krwq
Copy link
Member

@krwq krwq commented Jun 25, 2019

Fixes: #498

This won't build until we get new package version

This incorporates changes done here: #505

@krwq krwq requested review from joperezr and shaggygi June 25, 2019 23:39
Copy link
Contributor

@shaggygi shaggygi left a comment

Choose a reason for hiding this comment

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

LGTM. You beat me to it 😄

@krwq
Copy link
Member Author

krwq commented Jun 26, 2019

@shaggygi I'll leave you SPI 😄

@krwq krwq closed this Jun 26, 2019
@krwq krwq reopened this Jun 26, 2019
@joperezr
Copy link
Member

/azp run

@azure-pipelines
Copy link

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);
Copy link
Member

Choose a reason for hiding this comment

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

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.

Copy link
Contributor

Choose a reason for hiding this comment

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

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.

Copy link
Member Author

Choose a reason for hiding this comment

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

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

Copy link
Member Author

Choose a reason for hiding this comment

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

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

@joperezr
Copy link
Member

How did you find all these places? Did you just do a search on all places where we were doing a new UnixI2cDevice( or new WindowsI2cDevice ?

@krwq
Copy link
Member Author

krwq commented Jun 26, 2019

@joperezr almost. I searched for UnixI2cDevice and WindowsI2cDevice (no new) in src/devices and samples and manually reviewed the code if it needs some more adjustments. Find & replace covers 90% though

@joperezr
Copy link
Member

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?

@shaggygi
Copy link
Contributor

Yes, I was just looking at DeviceApiTester and will update those, as well with var or I2cDevice/SpiDevice

@krwq
Copy link
Member Author

krwq commented Jun 26, 2019

@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

@shaggygi
Copy link
Contributor

@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>

@joperezr
Copy link
Member

@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 msbuild System.Device.Gpio.csproj /t:rebuild /bl:msbuild.binlog on a developer command prompt which will generate a file called msbuild.binlog.

@shaggygi
Copy link
Contributor

@joperezr Does this work? Just remove the .zip.
msbuild.binlog.zip

@joperezr
Copy link
Member

Does this work? Just remove the .zip.

mmm that is very weird, does this repro if you are on a clean master? try doing:

git pull
git reset --hard
git clean -fdx
build.cmd

This will get latest changes, remove all pending changes, clean up your enlistment and run build again.

@krwq
Copy link
Member Author

krwq commented Jun 26, 2019

also if you cancelled build during restore it might be worth to clean nuget cache ($HOME/.nuget or %userprofile%\.nuget)

@krwq krwq merged commit 3007425 into dotnet:master Jun 27, 2019
@shaggygi
Copy link
Contributor

git pull
git reset --hard
git clean -fdx
build.cmd

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

@github-actions github-actions bot locked and limited conversation to collaborators Dec 13, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SenseHat does not create appropriate I2C devices

3 participants