A model of the BlinkStick device itself
Inheritance: IDisposable
示例#1
0
 /// <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));
     }
 }
示例#2
0
 /// <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));
     }
 }
示例#3
0
 /// <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
 }
示例#4
0
        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);
                }
            }
        }
示例#5
0
        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());
        }
示例#7
0
        /// <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;
        }
示例#8
0
        /// <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;
        }
示例#9
0
 private static void Blink(BlinkStick stick, Color color, int duration)
 {
     stick.Blink(color, duration);
 }
示例#10
0
 private static void Test(BlinkStick stick)
 {
     stick.BlinkWait(Color.Red, 1000);
     stick.BlinkWait(Color.Blue, 1000);
     stick.BlinkWait(Color.Green, 1000);
 }
示例#11
0
 private static void ProcessVerbosity(Arguments parsedArguments, BlinkStick stick)
 {
     if (parsedArguments.Has("verbose"))
     {
         stick.Verbosity = Verbosity.Verbose;
     }
 }
示例#12
0
        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();
            }
        }
示例#13
0
 private static void ProcessDebug(Arguments parsedArguments, BlinkStick stick)
 {
     if (parsedArguments.Has("debug"))
     {
         stick.Verbosity = Verbosity.Debug;
     }
 }
示例#14
0
 /// <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;
 }
示例#15
0
        /// <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();
        }
示例#16
0
 /// <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;
 }