示例#1
0
        public void ConnectRefreshButtonClick(object sender, RoutedEventArgs e)
        {
            //Open serial port
            if (this.GUI.ComPort.Text != null)
            {
                LEDStrahlerSerial.Open(this.GUI.ComPort.Text);
            }

            //Ping for devices
            LEDStrahlerSerial.PingRequest(out List <uint> UUIDs);

            //Setup new device list
            List <LEDStrahler> DeviceList = new List <LEDStrahler>();

            foreach (uint UUID in UUIDs)
            {
                DeviceList.Add(new LEDStrahler(UUID));
            }
            this.GUI.DeviceList = DeviceList;

            //Read all temperatures once
            foreach (LEDStrahler Strahler in this.GUI.DeviceList)
            {
                LEDStrahlerSerial.GetTemperature(Strahler);
            }

            this.GUI.DeviceGrid.IsEnabled = true;
        }
示例#2
0
        public static bool Open(string Port)
        {
            bool retVal = false;

            LEDStrahlerSerial.ThreadDispatcher.Invoke(new Action(() => retVal = LEDStrahlerSerial.OpenInternal(Port)));
            return(retVal);
        }
示例#3
0
        private static string WriteRead(string Text, int TimeoutMilliseconds, bool Wait = false)
        {
            string retVal = "";

            LEDStrahlerSerial.ThreadDispatcher.Invoke(new Action(() => retVal = LEDStrahlerSerial.WriteReadInternal(Text, TimeoutMilliseconds, Wait)));
            return(retVal);
        }
示例#4
0
 public void GetTemperatureButtonClick(object sender, RoutedEventArgs e)
 {
     foreach (LEDStrahler Strahler in this.GUI.DeviceList)
     {
         LEDStrahlerSerial.GetTemperature(Strahler);
     }
 }
示例#5
0
        public static void GetTemperature(LEDStrahler Strahler)
        {
            string Ret = LEDStrahlerSerial.WriteRead("G" + (int)Commands.GetTemperature + " " + Strahler.UUID, 200);

            if ((Ret.Length >= 6) && (Ret.StartsWith("T: ") == true) && (double.TryParse(Ret.Substring(3), NumberStyles.Number, CultureInfo.InvariantCulture, out double Temp) == true))
            {
                Strahler.Temperature = Temp;
            }
            else
            {
                Strahler.Temperature = 0.0;
            }
        }
示例#6
0
        private static bool OpenInternal(string Port)
        {
            LEDStrahlerSerial.CloseInternal();

            lock (InterfaceLock)
            {
                try
                {
                    LEDStrahlerSerial.Serial.PortName = Port;
                    LEDStrahlerSerial.Serial.Open();
                }
                catch
                {
                    return(false);
                }
                return(true);
            }
        }
示例#7
0
        public static void PingRequest(out List <uint> UUIDs)
        {
            UUIDs = new List <uint>();

            string Ret = LEDStrahlerSerial.WriteRead("G" + (int)Commands.PingRequest, 1100, true);

            if ((Ret.Length >= 4) && (Ret.StartsWith("P: ") == true) && (Ret.Contains("\n") == true))
            {
                var Strahler = new List <string>(Ret.Replace("P: ", "").Split('\n'));
                Strahler.RemoveAt(Strahler.Count - 1); //Last element is either an empty string or corrupted data
                foreach (string ID in Strahler)
                {
                    if (uint.TryParse(ID, out uint UUID) == true)
                    {
                        if (UUIDs.Contains(UUID) == false)
                        {
                            UUIDs.Add(UUID);
                        }
                    }
                }
            }
        }
示例#8
0
        public LEDStrahlerBackend(MainWindow _gui)
        {
            this.GUI = _gui;

            //Link shutdown event
            this.GUI.Closing += new CancelEventHandler(this.GUIClosing);

            //Get available serial ports
            this.UpdateCOMPortList();

            //Get available audio devices
            this.UpdateAudioDeviceList();

            //Connect serial port to all GroupControls
            LEDStrahlerSerial.StartDispatcher();

            //Link Buttons
            this.GUI.ConnectRefreshButton.Click += this.ConnectRefreshButtonClick;
            this.GUI.GetTemperatureButton.Click += this.GetTemperatureButtonClick;

            //Link config tab
            this.GUI.GUITabs.SelectionChanged += this.TabSelectionChanged;

            //Link key up/down
            this.GUI.Control.KeyDown += this.Control_KeyDown;
            this.GUI.Control.KeyUp   += this.Control_KeyUp;

            //Empty list of pressed keys
            this.PressedKeys.Clear();

            //Start timer for LJ stuff
            this.LJ_Timer.Interval = new TimeSpan(100000); //10ms interval
            this.LJ_Timer.Tick    += new EventHandler(this.TimerTick);
            this.LJ_Timer.Start();

            //Start timer for music control stuff
            this.Music_Timer = new Timer(new TimerCallback(this.MusicControlThread), null, 1000, 100);
        }
示例#9
0
        private void UpdateCOMPortList()
        {
            var PortList = LEDStrahlerSerial.ListPorts();

            PortList.Sort();

            if (PortList.SequenceEqual(this.GUI.ComPortList) == false)
            {
                string SelectedPort = this.GUI.ComPort.Text;
                if ((PortList.Count != 0) && (PortList.Contains(SelectedPort)))
                {
                    this.GUI.ComPortList           = PortList;
                    this.GUI.ComPort.SelectedIndex = PortList.IndexOf(SelectedPort);
                }
                else
                {
                    this.GUI.ComPortList = PortList;
                    if (PortList.Count != 0)
                    {
                        this.GUI.ComPort.SelectedIndex = 0;
                    }
                }
            }
        }
示例#10
0
 public static void FadeValue(LEDStrahler Strahler, ushort Period, ushort Hue, ushort Saturation, ushort ValueMin, ushort ValueMax)
 {
     LEDStrahlerSerial.Write("G" + (int)Commands.FadeValue + " 0 " + Period + " " + Hue + " " + Saturation + " " + ValueMax + " " + ValueMin + " " + Strahler.UUID);
 }
示例#11
0
 public static void FadeValue(byte GroupID, ushort Period, ushort Hue, ushort Saturation, ushort ValueMin, ushort ValueMax)
 {
     LEDStrahlerSerial.Write("G" + (int)Commands.FadeValue + " " + GroupID + " " + Period + " " + Hue + " " + Saturation + " " + ValueMax + " " + ValueMin);
 }
示例#12
0
 public static void StrobeHSV(LEDStrahler Strahler, byte Period, byte Count, ushort Hue, ushort Saturation, ushort Value)
 {
     LEDStrahlerSerial.Write("G" + (int)Commands.StrobeHSV + " 0 " + Period + " " + Count + " " + Hue + " " + Saturation + " " + Value + " " + Strahler.UUID);
 }
示例#13
0
 public static void StrobeRGBW(LEDStrahler Strahler, byte Period, byte Count, ushort Red, ushort Green, ushort Blue, ushort White)
 {
     LEDStrahlerSerial.Write("G" + (int)Commands.StrobeRGBW + " 0 " + Period + " " + Count + " " + Red + " " + Green + " " + Blue + " " + White + " " + Strahler.UUID);
 }
示例#14
0
 public static void StrobeRGB(byte GroupID, byte Period, byte Count, ushort Red, ushort Green, ushort Blue)
 {
     LEDStrahlerSerial.Write("G" + (int)Commands.StrobeRGB + " " + GroupID + " " + Period + " " + Count + " " + Red + " " + Green + " " + Blue);
 }
示例#15
0
 public static void SetHSV(LEDStrahler Strahler, ushort Hue, ushort Saturation, ushort Value)
 {
     LEDStrahlerSerial.Write("G" + (int)Commands.SetHSV + " 0 " + Hue + " " + Saturation + " " + Value + " " + Strahler.UUID);
 }
示例#16
0
 public static void SetHSV(byte GroupID, ushort Hue, ushort Saturation, ushort Value)
 {
     LEDStrahlerSerial.Write("G" + (int)Commands.SetHSV + " " + GroupID + " " + Hue + " " + Saturation + " " + Value);
 }
示例#17
0
 public static void SetRGBW(LEDStrahler Strahler, ushort Red, ushort Green, ushort Blue, ushort White)
 {
     LEDStrahlerSerial.Write("G" + (int)Commands.SetRGBW + " 0 " + Red + " " + Green + " " + Blue + " " + White + " " + Strahler.UUID);
 }
示例#18
0
 public static void SetRGBW(byte GroupID, ushort Red, ushort Green, ushort Blue, ushort White)
 {
     LEDStrahlerSerial.Write("G" + (int)Commands.SetRGBW + " " + GroupID + " " + Red + " " + Green + " " + Blue + " " + White);
 }
示例#19
0
 public static void Close()
 {
     LEDStrahlerSerial.ThreadDispatcher.Invoke(new Action(() => LEDStrahlerSerial.Close()));
 }
示例#20
0
 public void GUIClosing(object sender, CancelEventArgs e)
 {
     LEDStrahlerSerial.ShutdownDispatcher();
 }
示例#21
0
 private static void Write(string Text)
 {
     LEDStrahlerSerial.ThreadDispatcher.BeginInvoke(new Action(() => LEDStrahlerSerial.WriteInternal(Text)));
 }
示例#22
0
        private void HandleLJMode(List <LEDStrahler> StrahlerListe)
        {
            List <Key> PressedKeysClone = new List <Key>(this.PressedKeys); //Copy list

            this.UpdateLJBaseColorsList(StrahlerListe);

            //Reset handlers
            this.LJresetHandlers();

            foreach (Key Taste in PressedKeysClone)
            {
                switch (Taste)
                {
                case Key.Q:     //Set fixed color
                    this.LJSetConstantColor(0.0);
                    break;

                case Key.W:     //Set fixed color
                    this.LJSetConstantColor(36.0);
                    break;

                case Key.E:     //Set fixed color
                    this.LJSetConstantColor(72.0);
                    break;

                case Key.R:     //Set fixed color
                    this.LJSetConstantColor(108.0);
                    break;

                case Key.T:     //Set fixed color
                    this.LJSetConstantColor(144.0);
                    break;

                case Key.Z:     //Set fixed color
                    this.LJSetConstantColor(180.0);
                    break;

                case Key.U:     //Set fixed color
                    this.LJSetConstantColor(216.0);
                    break;

                case Key.I:     //Set fixed color
                    this.LJSetConstantColor(252.0);
                    break;

                case Key.O:     //Set fixed color
                    this.LJSetConstantColor(288.0);
                    break;

                case Key.P:     //Set fixed color
                    this.LJSetConstantColor(324.0);
                    break;

                case Key.A:     //Set color fading
                    this.LJFadeHue(5000);
                    break;

                case Key.S:     //Set color fading
                    this.LJFadeHue(10000);
                    break;

                case Key.D:     //Set color fading
                    this.LJFadeHue(20000);
                    break;

                case Key.F:     //Set color fading
                    this.LJFadeHue(30000);
                    break;

                case Key.G:
                    this.LJhandleValue = this.LJhandleLEDoff;
                    break;

                case Key.H:
                    this.LJSetStrobeSaturation(50);
                    break;

                case Key.J:
                    this.LJSetStrobeSaturation(100);
                    break;

                case Key.K:     //Set value strobing
                    this.LJSetStrobeValue(50);
                    break;

                case Key.L:     //Set value strobing
                    this.LJSetStrobeValue(100);
                    break;

                case Key.Y:
                    this.LJFadeUniform = false;
                    break;

                case Key.X:
                    this.LJFadeUniform = true;
                    break;

                case Key.C:
                    this.LJStrobeUniform = false;
                    break;

                case Key.V:
                    this.LJStrobeUniform = true;
                    break;

                case Key.B:
                    this.LJSetUniform = false;
                    break;

                case Key.N:
                    this.LJSetUniform = true;
                    break;

                case Key.M:
                    break;

                default:
                    try
                    {
                        this.PressedKeys.Remove(Taste);
                    }
                    catch
                    {
                        //Do nothing in case of failure
                    }
                    break;
                }
            }

            //Handle fading and strobing
            this.LJhandleHue();
            this.LJhandleSaturation();
            this.LJhandleValue();

            //Actually write stuff
            //Currently only implemented in broadcast mode
            if (this.LJUpdateLEDs == true)
            {
                ushort Hue        = (ushort)(65535.0 * this.LJBaseColors[0].H / 360.0);
                ushort Saturation = (ushort)(65535.0 * this.LJBaseColors[0].S);
                ushort Value      = (ushort)(65535.0 * this.LJBaseColors[0].V * (double)this.GUI.GroupControls[0].Backend.GetBrightnessScale());
                LEDStrahlerSerial.SetHSV(0, Hue, Saturation, Value);
            }
        }
示例#23
0
 public static void SetGroup(byte GroupID, uint UUID)
 {
     LEDStrahlerSerial.Write("G" + (int)Commands.SetGroup + " " + UUID + " " + GroupID);
 }