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

Commit 61d50e3

Browse files
author
Andrew
authored
Merge pull request #13 from anmenaga/SPICmdlet
SPI cmdlet
2 parents c3fcc28 + 4114be3 commit 61d50e3

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed

src/Microsoft.PowerShell.IoT/Microsoft.PowerShell.IoT.cs

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,22 @@ public GpioPinData(int id, SignalLevel value, Unosquare.RaspberryIO.Gpio.GpioPin
8383
this.Value = value;
8484
this.PinInfo = pinInfo;
8585
}
86+
}
87+
88+
public class SPIData
89+
{
90+
public uint Channel { get; set; }
91+
public uint Frequency { get; set; }
92+
public byte[] Data { get; set; }
93+
public byte[] Responce { get; set; }
94+
95+
public SPIData(uint channel, uint frequency, byte[] data, byte[] responce)
96+
{
97+
this.Channel = channel;
98+
this.Frequency = frequency;
99+
this.Data = data;
100+
this.Responce = responce;
101+
}
86102
}
87103

88104
[Cmdlet(VerbsCommon.Get, "I2CDevice")]
@@ -276,4 +292,51 @@ protected override void ProcessRecord()
276292
}
277293
}
278294
}
295+
296+
[Cmdlet(VerbsCommunications.Send, "SPIData")]
297+
public class SendSPIData : Cmdlet
298+
{
299+
[Parameter(Mandatory = true, ValueFromPipeline = true, ValueFromPipelineByPropertyName = true, Position = 0)]
300+
public byte[] Data { get; set; }
301+
302+
[Parameter(Mandatory = false, ValueFromPipelineByPropertyName = true, Position = 1)]
303+
public uint Channel { get; set; }
304+
305+
[Parameter(Mandatory = false, ValueFromPipelineByPropertyName = true, Position = 2)]
306+
public uint Frequency { get; set; }
307+
308+
[Parameter(Mandatory = false, ValueFromPipelineByPropertyName = true)]
309+
public SwitchParameter Raw { get; set; }
310+
311+
public SendSPIData()
312+
{
313+
this.Channel = 0;
314+
this.Frequency = Unosquare.RaspberryIO.Gpio.SpiChannel.MinFrequency;
315+
}
316+
317+
protected override void ProcessRecord()
318+
{
319+
var spiChannel = Unosquare.RaspberryIO.Pi.Spi.Channel0;
320+
if (this.Channel == 1)
321+
{
322+
spiChannel = Unosquare.RaspberryIO.Pi.Spi.Channel1;
323+
Unosquare.RaspberryIO.Pi.Spi.Channel1Frequency = (int)this.Frequency;
324+
}
325+
else
326+
{
327+
Unosquare.RaspberryIO.Pi.Spi.Channel0Frequency = (int)this.Frequency;
328+
};
329+
330+
var responce = spiChannel.SendReceive(this.Data);
331+
if (this.Raw)
332+
{
333+
WriteObject(responce);
334+
}
335+
else
336+
{
337+
SPIData spiData = new SPIData(this.Channel, this.Frequency, this.Data, responce);
338+
WriteObject(spiData);
339+
}
340+
}
341+
}
279342
}

0 commit comments

Comments
 (0)