# Description: Dream Cheeky LED Powershell Sample Script
# Author: Greg Bray
# Date: 8/9/2012
# License: Apache 2.0

if(([appdomain]::currentdomain.getassemblies() | Where {$_ -match "DreamCheekyLED"}) -eq $null){
	Write-Host "Loading DreamCheekyLED Assembly"
	$assembly = [Reflection.Assembly]::LoadFile("C:\Git\dreamcheekyusb\DreamCheekyLED\bin\Debug\DreamCheekyLED.exe")
}

#List all USB devices with VID=0x1D34
#[HidLibrary.HidDevices]::Enumerate() | where { $_.Attributes.VendorHexId -eq "0x1D34" }| ft isConnected,isOpen,Description -AutoSize

#Initialize led object
if($led -eq $null){
	#$led = New-Object DreamCheekyUSB.DreamCheekyLED #Find default device
	#$led = New-Object DreamCheekyUSB.DreamCheekyLED -ArgumentList @(0x1D34,0x0004,0) #Specify VID,PID,DeviceIndex
	#Issues with calling the device path constructor from powershell. Error was New-Object : Index was outside the bounds of the array.
	#This finally worked:
	$argArray = New-Object string[] 1
	#$argArray[0] = '\\?\HID#\VID_1D34&PID_000D\8&19bdbd1&0&0000{745a17a0-74d3-11d0-b6fe-00a0c90f57da}'
    $argArray[0] = '\\?\hid#vid_1d34&PID_000A\7&FB3C668&0&0000{745a17a0-74d3-11d0-b6fe-00a0c90f57da}'
	$led = New-Object -TypeName DreamCheekyUSB.DreamCheekyLED (,$argArray)
	
}

#Run tests:
#$led.Test();
#start-sleep -Seconds 2
#$led.TestBlink();

#if($false){
$led.SetColor([System.Drawing.Color]::Red)
start-sleep -Seconds 1
#$led.SetColor([System.Drawing.Color]::Green)
#start-sleep -Seconds 1
#$led.SetColor([System.Drawing.Color]::Blue)
#start-sleep -Seconds 1
#}

$led.Off()