/// <summary> /// Raises the BlinkStick disconnected event. /// </summary> /// <param name="device">Device which has been disconnected.</param> protected void OnBlinkStickDisconnected(BlinkStick device) { if (BlinkStickDisconnected != null) { BlinkStickDisconnected(this, new DeviceModifiedArgs(device)); } }
/// <summary> /// Helper for doing ad-hoc testing /// </summary> public static void Main() { // add code here #if false var bs = new BlinkStick(); bs.Verbosity = Verbosity.Debug; bs.Blink(Color.Red, 1000); #endif }
private static void ProcessBrightness(Arguments parsedArguments, BlinkStick stick) { if (parsedArguments.Has("brightness")) { string rawBrightness = parsedArguments["brightness"]; BlinkStick.Brightness brightness; if (Enum.TryParse(rawBrightness, true, out brightness)) { stick.SetBrightnessLimit(brightness); } } }
static void Main(string[] args) { var parsedArguments = new Arguments(args); using (var stick = new BlinkStick()) { HandleCtrlC(); ProcessVerbosity(parsedArguments, stick); ProcessDebug(parsedArguments, stick); ProcessBrightness(parsedArguments, stick); Color color = ProcessColor(parsedArguments); int? duration = ProcessDuration(parsedArguments); ProcessTools(parsedArguments, stick, color, duration); } }
/// <summary> /// Find all BlinkStick devices. /// </summary> /// <returns>An array of BlinkStick devices</returns> public static BlinkStick[] FindAll() { List <BlinkStick> result = new List <BlinkStick>(); HidDeviceLoader loader = new HidDeviceLoader(); foreach (HidDevice adevice in loader.GetDevices(VendorId, ProductId).ToArray()) { BlinkStick hid = new BlinkStick(); hid.device = adevice; result.Add(hid); } return(result.ToArray()); }
/// <summary> /// Start monitoring for added/removed BlinkStick devices. /// </summary> public void Start() { //Get the list of already connected BlinkSticks devices = new List <BlinkStick>(BlinkStick.FindAll()); if (UsbDeviceNotifier != null) { UsbDeviceNotifier.Enabled = true; } else if (winUsbDeviceMonitor != null) { winUsbDeviceMonitor.Enabled = true; } Monitoring = true; }
/// <summary> /// Raises the usb device changed event. /// </summary> protected void OnUsbDevicesChanged() { if (UsbDevicesChanged != null) { UsbDevicesChanged(this, new EventArgs()); } List <BlinkStick> newDevices = new List <BlinkStick>(); List <BlinkStick> scannedDevices = new List <BlinkStick>(BlinkStick.FindAll()); foreach (BlinkStick newDevice in scannedDevices) { Boolean found = false; for (int i = devices.Count - 1; i >= 0; i--) { if (devices[i].Serial == newDevice.Serial) { devices.RemoveAt(i); found = true; break; } } if (!found) { OnBlinkStickConnected(newDevice); } } foreach (BlinkStick device in devices) { OnBlinkStickDisconnected(device); } devices = scannedDevices; }
private static void Blink(BlinkStick stick, Color color, int duration) { stick.Blink(color, duration); }
private static void Test(BlinkStick stick) { stick.BlinkWait(Color.Red, 1000); stick.BlinkWait(Color.Blue, 1000); stick.BlinkWait(Color.Green, 1000); }
private static void ProcessVerbosity(Arguments parsedArguments, BlinkStick stick) { if (parsedArguments.Has("verbose")) { stick.Verbosity = Verbosity.Verbose; } }
private static void ProcessTools(Arguments parsedArguments, BlinkStick stick, Color color, int? duration) { if (parsedArguments.Has("test")) { Test(stick); } else if (parsedArguments.Has("random")) { RandomColors.Run(stick, KeepGoing); } else if (parsedArguments.Has("blink")) { const int defaultBlinkDuration = 1000; Blink(stick, color, duration ?? defaultBlinkDuration); } else if (parsedArguments.Has("mouseover")) { MouseOverColorTracker.Run(stick, KeepGoing); } else if (parsedArguments.Has("cpu")) { CpuMonitor.Run(stick, KeepGoing); } else if (parsedArguments.Has("memory")) { MemoryMonitor.Run(stick, KeepGoing); } else if (parsedArguments.Has("morse")) { string message = parsedArguments["morse"]; const int defaultDotLength = 200; MorseCodeFlasher.Run(stick, message, color, duration ?? defaultDotLength); } else { DisplayUsage(); } }
private static void ProcessDebug(Arguments parsedArguments, BlinkStick stick) { if (parsedArguments.Has("debug")) { stick.Verbosity = Verbosity.Debug; } }
/// <summary> /// Initializes a new instance of the <see cref="BlinkStickDotNet.DeviceModifiedArgs"/> class. /// </summary> /// <param name="device">Device passed as an argument</param> public DeviceModifiedArgs(BlinkStick device) { this.Device = device; }
/// <summary> /// Find all BlinkStick devices. /// </summary> /// <returns>An array of BlinkStick devices</returns> public static BlinkStick[] FindAll() { List<BlinkStick> result = new List<BlinkStick>(); HidDeviceLoader loader = new HidDeviceLoader(); foreach (HidDevice adevice in loader.GetDevices(VendorId, ProductId).ToArray()) { BlinkStick hid = new BlinkStick(); hid.device = adevice; result.Add(hid); } return result.ToArray(); }