Skip to content
This repository has been archived by the owner on Jun 14, 2024. It is now read-only.

Set-i2cdevice overload to support arrays #35

Open
DanielSSilva opened this issue Apr 21, 2018 · 8 comments
Open

Set-i2cdevice overload to support arrays #35

DanielSSilva opened this issue Apr 21, 2018 · 8 comments

Comments

@DanielSSilva
Copy link
Contributor

I think it would be good to have an overload that would accept an array of registers and an array of values to be set on those registers, 'freeing' the developer to have the necessity to create a loop to iterate each array and set each value

@TylerLeonhardt
Copy link
Member

Thanks for this Daniel! Did you mean Set-I2CRegister?

@DanielSSilva
Copy link
Contributor Author

Oh yes... I wrote it from my memory 😅

@TylerLeonhardt
Copy link
Member

TylerLeonhardt commented Apr 21, 2018

This is the case of really bad documentation but this is already supported!

https://github.com/PowerShell/PowerShell-IoT/blob/master/src/Microsoft.PowerShell.IoT/Microsoft.PowerShell.IoT.cs#L185-L189

Device, Register and Data are ValueFromPipelineByPropertyName 😄

@TylerLeonhardt
Copy link
Member

So if you have a custom object array and pass that into Set-I2CRegister it should work:

$device = Get-I2CDevice -Id 0x44 -FriendlyName Foo

$arr = @(
[pscustomobject]@{
    Register = 0x12
    Data = @(1,2,3)
    Device = $device
},
[pscustomobject]@{
    Register = 0x77
    Data = @(2,3,4)
    Device = $device
})

$arr | Set-I2CRegister

Note: haven't tested that code ^ but I'm pretty sure it works.

@DanielSSilva
Copy link
Contributor Author

Oh I see... although it's only valid to set an array of values into a register, not a 1 to 1 relation, aka, 1 register 1 value. But this might only be useful in my case, i don't know...

@TylerLeonhardt
Copy link
Member

You want to do 1 value to many registers?

@DanielSSilva
Copy link
Contributor Author

No. I want an array of 5 registers and an array of 5 values and use register[i] value[i]. But then again, I don't have much experience to say that this would be a common situation on I2C protocol... Might only be useful in my case

@TylerLeonhardt
Copy link
Member

Wait I just realized that you said "not a 1 to 1 relation" to my example above.

My example above IS a 1 to 1 example.

You have an array of custom objects that contain a register and a value property. When you pipe the array into Set-I2CRegister it handles each item in the array one by one and each item in the array has a register and a value só that's a 1 register to 1 value operation.

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

No branches or pull requests

2 participants