Skip to content

Commit

Permalink
Although the files on bin and obj are not required, I'm leaving them …
Browse files Browse the repository at this point in the history
…for now, because the required dll is on bin and I've not yet created a .gitignore
  • Loading branch information
DanielSSilva committed Jun 6, 2018
1 parent 914aecd commit 99138a3
Show file tree
Hide file tree
Showing 201 changed files with 3,423 additions and 21 deletions.
32 changes: 32 additions & 0 deletions examples/buttonPress.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
Import-Module ./../bin/Debug/netcoreapp2.0/linux-arm/publish/ws281xPowerShell.dll -Force
$LedStripSettings = [PSCustomObject]@{
NumberOfLeds = 21
Brightness = 50
Color = [System.Drawing.Color]::Green
Speed = "Fast"
}

while($true)
{
while((Get-GpioPin -Id 26 -PullMode PullUp).Value -eq 'High')
{

}
$held = 0
while((Get-GpioPin -Id 26 -PullMode PullUp).Value -eq 'Low' -AND $held -lt 10) #lt 10 because each time $held is incremented, 100ms have passed, after 10 iterations, 1 second passed
{
Start-Sleep -Milliseconds 100
++$held
}

if($held -lt 10) #realeased before 1s
{
$LedStripSettings | Set-LedAccrossStrip
}
else # it was pressed at least during 1 second ( might still be being pressed)
{
Write-Host "Button pressed for at least 1 second. "
Set-RainbowCycle -NumberOfLeds $LedStripSettings.NumberOfLeds -Brightness $LedStripSettings.Brightness -NumberOfCycles 1
Start-Sleep -Milliseconds 200
}
}
75 changes: 75 additions & 0 deletions src/CmdLets/Set/LedAccrossStripCmdLet.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Management.Automation; // PowerShell namespace.
using System.Threading;

namespace WS281x.CmdLets
{

[Cmdlet(VerbsCommon.Set, "LedAccrossStrip")]
public class LedAccrossStrip : Cmdlet
{
[Parameter(Mandatory = true, ValueFromPipeline = true, ValueFromPipelineByPropertyName = true, Position = 0)]
public int NumberOfLeds {get; set;}

[Parameter(Mandatory = true, ValueFromPipeline = true, ValueFromPipelineByPropertyName = true, Position = 1)]
public byte Brightness { get; set; }

[Parameter(Mandatory = true, ValueFromPipeline = true, ValueFromPipelineByPropertyName = true, Position = 2)]
public Color Color { get; set; }

[Parameter(Mandatory = false, ValueFromPipeline = true, ValueFromPipelineByPropertyName = true, Position = 5)]
[ValidateSet("Slow", "Medium","Fast")]
public string Speed { get; set; }

[Parameter(Mandatory = false)]
public SwitchParameter Invert {get;set;}

public int GpioPin {get; set;}

//* SPEED!!!!
private Dictionary<string,int> _speedTranslation;

public LedAccrossStrip()
{
Invert = false;
GpioPin = 18;

}

protected override void BeginProcessing()
{
_speedTranslation = new Dictionary<string,int>()
{
{"Slow", 300},
{"Medium", 125},
{"Fast", 50},
};
}

protected override void ProcessRecord()
{
Settings settings = Settings.CreateDefaultSettings();
settings.Channel = new Channel(NumberOfLeds, GpioPin, Brightness, Invert, StripType.WS2812_STRIP);
WS281x controller = new WS281x(settings);


for(int i = 0 ; i < NumberOfLeds ; ++i)
{
for(int j = 0 ; j < i ; ++j)
{
controller.SetLEDColor(j, Color.Empty);
}
controller.SetLEDColor(i,Color);
controller.Render();
Thread.Sleep(_speedTranslation[Speed]);
}
//"hack". turn the last led of
controller.SetLEDColor(NumberOfLeds-1,Color.Empty);
controller.Render();
//for some reason it has to be explicitly disposed
controller.Dispose();
}
}
}
48 changes: 27 additions & 21 deletions src/CmdLets/Set/RainbowCycleCmdLet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@ public class RainbowCycle : Cmdlet
public byte Brightness { get; set; }

[Parameter(Mandatory = false)]
public SwitchParameter Invert {get;set;}
public SwitchParameter Invert { get; set; }

[Parameter(Mandatory = false, ValueFromPipeline = true, ValueFromPipelineByPropertyName = true, Position = 2)]
public int NumberOfCycles { get; set ;}

[Parameter(Mandatory = false)]
public int GpioPin {get; set;}

private bool shouldAbort;
Expand All @@ -42,38 +44,42 @@ protected override void BeginProcessing()

protected override void ProcessRecord()
{
if(NumberOfCycles == 0)
{
NumberOfCycles = 1;
}

Settings settings = Settings.CreateDefaultSettings();
settings.Channel = new Channel(NumberOfLeds, GpioPin, Brightness, Invert, StripType.WS2812_STRIP);
WS281x controller = new WS281x(settings);
List<Color> colors = GetColors();
int currentColorIndex = 0;
while(!shouldAbort)

for(int iterations = 0 ; iterations < NumberOfCycles ; ++iterations)
{
Color currentColor = colors[currentColorIndex++];
for(int i = 0 ; i < NumberOfLeds ; ++i)
for(int colorCycle = 0; colorCycle < colors.Count; ++colorCycle)
{
//Iterate over all LEDs and display the current color
controller.SetLEDColor(i,currentColor);
controller.Render();
Thread.Sleep(25);

Color currentColor = colors[colorCycle];
for(int i = 0 ; i < NumberOfLeds ; ++i)
{
//Iterate over all LEDs and display the current color
controller.SetLEDColor(i,currentColor);
controller.Render();
Thread.Sleep(25);
}
}
if(currentColorIndex >= colors.Count)
{
currentColorIndex = 0;
}
}
}

private List<Color> GetColors() => new List<Color>()
{
Color.FromArgb(0x201000),
Color.FromArgb(0x202000),
Color.DarkRed,
Color.Red,
Color.Orange,
Color.Yellow,
Color.Green,
Color.FromArgb(0x002020),
Color.Blue,
Color.FromArgb(0x100010),
Color.FromArgb(0x200010)
Color.Lime,
Color.Cyan,
Color.Blue
};
}
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading

0 comments on commit 99138a3

Please sign in to comment.