PowerShell / PowerShell-IoT

Interact with I2C, SPI & GPIO devices using PowerShell Core!
https://www.powershellgallery.com/packages/Microsoft.PowerShell.IoT
MIT License
129 stars 28 forks source link

Detect if I2C is enable and possibly enable it if user agrees #40

Open DanielSSilva opened 6 years ago

DanielSSilva commented 6 years ago

For what I've seen, enable the I2C "manually" seems quite easy, only requiring to edit:

If this is all that it takes, when the user imports this module, we can check if the i2c is already enabled and display a warning if it's not. Even better would be to prompt the user if he wants to enable it (avoiding the process of running sudo raspi-config and search for that).

Does this seems feasible/ make sense?

anmenaga commented 6 years ago

It would certainly be beneficial to have a PowerShell way of enabling I2C (and, as extension, other interfaces). Though doing this during module import may not be the best place because user may be wanting to use interface other than I2C. Currently with disabled I2C Get-I2CDevice will give Unable to open I2C device: No such file or directory error. At a minimum we need to improve this error message to something like "Unable to open I2C device; please enable I2C interface using ..." Ideally, I think, we should implement 2 cmdlets like: Enable/Disable-ArmInterface -I2C/-SPI/<others> and maybe add a call to them when Get-I2CDevice gets above-mentioned error.

TylerLeonhardt commented 6 years ago

We should also make sure these aren't pi specific (Or write them in an easy way to support other devices) since we do eventually want to support other devices.

DanielSSilva commented 6 years ago

@anmenaga I understand your point, although the idea was not to "prevent" the user from using the module, but to warn/alert him that I2C (or other interface) was not enabled. Although this could become annoying if the user frequently import this module but don't care about this interface (maybe this is what you mean). Don't know if this could be solved with a flag on the Import-Module (don't know if it's even possible, but doesn't really makes sense). The call as you referred would make sense in that way.

@tylerl0706 I'm not familiar with the other devices, but isn't this something specific for each device? Seems like it's a configuration that can vary from device do device (worst case, from OS to OS)

TylerLeonhardt commented 6 years ago

We can start with Pi specific commands :)