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

Commit cda7aaf

Browse files
committed
feedback
1 parent 96a27bb commit cda7aaf

13 files changed

+34
-39
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,10 @@ _NOTE: If you'd rather not use the script, simply copy the `out/Microsoft.PowerS
127127

128128
#### Running
129129

130-
First, you must run pwsh with sudo:
130+
Start PowerShell:
131131

132132
```powershell
133-
sudo pwsh
133+
pwsh
134134
```
135135

136136
If you have the `Microsoft.PowerShell.IoT` module in your PSModulePath:

src/Microsoft.PowerShell.IoT/Gpio/Get/GetGpioPin.cs

+4-13
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
[Cmdlet(VerbsCommon.Get, "GpioPin")]
77
public class GetGpioPin : GpioCmdletBase
88
{
9-
[Parameter(Mandatory = false, ValueFromPipeline = true, ValueFromPipelineByPropertyName = true, Position = 0)]
9+
[Parameter(Mandatory = true, ValueFromPipeline = true, ValueFromPipelineByPropertyName = true, Position = 0)]
1010
public int[] Id { get; set; }
1111

1212
[Parameter(Mandatory = false, ValueFromPipelineByPropertyName = true, Position = 1)]
@@ -22,6 +22,7 @@ protected override void ProcessRecord()
2222
if ((this.Id == null) || (this.Id.Length <= 0))
2323
{
2424
// TODO: this is "gpio readall" functionality
25+
// do not forget to change Id param to Mandatory = false when this is implemented
2526
}
2627
else
2728
{
@@ -43,17 +44,7 @@ protected override void ProcessRecord()
4344
{
4445
SignalLevel slResult = SignalLevel.Low;
4546

46-
if (this.GpioController.IsPinOpen(pinId))
47-
{
48-
if (this.GpioController.GetPinMode(pinId) != mode)
49-
{
50-
this.GpioController.SetPinMode(pinId, mode);
51-
}
52-
}
53-
else
54-
{
55-
this.GpioController.OpenPin(pinId, mode);
56-
}
47+
this.EnsureOpenPin(pinId, mode);
5748

5849
if (this.GpioController.Read(pinId) == PinValue.High)
5950
{
@@ -78,4 +69,4 @@ public enum PullMode
7869
Off = 0,
7970
PullDown = 1,
8071
PullUp = 2
81-
}
72+
}

src/Microsoft.PowerShell.IoT/Gpio/GpioCmdletBase.cs

+16-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,21 @@ protected GpioController GpioController
2020
StaticGpioController = value;
2121
}
2222
}
23+
24+
protected void EnsureOpenPin(int pinId, PinMode mode)
25+
{
26+
if (this.GpioController.IsPinOpen(pinId))
27+
{
28+
if (this.GpioController.GetPinMode(pinId) != mode)
29+
{
30+
this.GpioController.SetPinMode(pinId, mode);
31+
}
32+
}
33+
else
34+
{
35+
this.GpioController.OpenPin(pinId, mode);
36+
}
37+
}
2338
}
2439

2540
[Cmdlet(VerbsCommon.Clear, "GpioResources")]
@@ -33,4 +48,4 @@ protected override void ProcessRecord()
3348
GpioCmdletBase.StaticGpioController = null;
3449
}
3550
}
36-
}
51+
}

src/Microsoft.PowerShell.IoT/Gpio/GpioPinData.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ public enum SignalLevel
1414
{
1515
Low = 0,
1616
High = 1
17-
}
17+
}

src/Microsoft.PowerShell.IoT/Gpio/Set/SetGpioPin.cs

+2-12
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,7 @@ protected override void ProcessRecord()
2020
{
2121
foreach (int pinId in this.Id)
2222
{
23-
if (this.GpioController.IsPinOpen(pinId))
24-
{
25-
if (this.GpioController.GetPinMode(pinId) != PinMode.Output)
26-
{
27-
this.GpioController.SetPinMode(pinId, PinMode.Output);
28-
}
29-
}
30-
else
31-
{
32-
this.GpioController.OpenPin(pinId, PinMode.Output);
33-
}
23+
this.EnsureOpenPin(pinId, PinMode.Output);
3424

3525
if(this.Value == SignalLevel.Low)
3626
{
@@ -49,4 +39,4 @@ protected override void ProcessRecord()
4939
}
5040
}
5141
}
52-
}
42+
}

src/Microsoft.PowerShell.IoT/I2c/Get/GetI2cDevice.cs

+1-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ public class GetI2CDevice : Cmdlet
1717
public GetI2CDevice()
1818
{
1919
this.FriendlyName = string.Empty;
20-
this.Id = 0;
2120
this.BusId = 1;
2221
}
2322

@@ -27,4 +26,4 @@ protected override void ProcessRecord()
2726
I2cDevice device = I2cDevice.Create(settings);
2827
WriteObject(new I2CDevice(device, this.Id, this.FriendlyName, this.BusId));
2928
}
30-
}
29+
}

src/Microsoft.PowerShell.IoT/I2c/Get/GetI2cRegister.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,4 @@ protected override void ProcessRecord()
5959
}
6060
}
6161
}
62-
}
62+
}

src/Microsoft.PowerShell.IoT/I2c/I2cDevice.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,4 @@ public override string ToString()
2525
return this.FriendlyName;
2626
}
2727
}
28-
}
28+
}

src/Microsoft.PowerShell.IoT/I2c/I2cRegisterData.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@ public I2CDeviceRegisterData()
2020
: this(null, 0)
2121
{
2222
}
23-
}
23+
}

src/Microsoft.PowerShell.IoT/I2c/Set/SetI2cRegister.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,4 @@ protected override void ProcessRecord()
2626
WriteObject(result);
2727
}
2828
}
29-
}
29+
}

src/Microsoft.PowerShell.IoT/Microsoft.PowerShell.IoT.csproj

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>netcoreapp3.1</TargetFramework>
4+
<TargetFramework>netstandard2.0</TargetFramework>
55
<Version>0.2.0.0</Version>
66
<Authors>Microsoft Corporation</Authors>
77
<Company>Microsoft Corporation</Company>
@@ -17,7 +17,7 @@
1717

1818
<ItemGroup>
1919
<PackageReference Include="System.Device.Gpio" Version="1.0.0" />
20-
<PackageReference Include="System.Management.Automation" Version="7.0.0" />
20+
<PackageReference Include="PowerShellStandard.Library" Version="7.0.0-preview.1" />
2121
</ItemGroup>
2222

2323
</Project>

src/Microsoft.PowerShell.IoT/SPI/SPIData.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ public SPIData(int busId, int chipSelectLine, int frequency, byte[] data, byte[]
1414
this.Data = data;
1515
this.Response = response;
1616
}
17-
}
17+
}

src/Microsoft.PowerShell.IoT/SPI/Send/SendSPIData.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,4 @@ protected override void ProcessRecord()
4949
}
5050
}
5151
}
52-
}
52+
}

0 commit comments

Comments
 (0)