Пример #1
0
        public void load()
        {
            loading = true;
            int intNumberOfDevices = TelldusAPI.tdGetNumberOfDevices();
            int dynamicHeight = 36;
            allLights.Clear();
            lights.Clear();
            lightProcess = new Thread(stoppedstate);
            for (int i = 0; i < intNumberOfDevices; i++)
            {
                int id = TelldusAPI.tdGetDeviceId(i);
                string name = TelldusAPI.tdGetNameString(id);
                int methods = TelldusAPI.tdMethods(id, TelldusAPI.TELLSTICK_TURNON | TelldusAPI.TELLSTICK_TURNOFF | TelldusAPI.TELLSTICK_DIM);
                int[] arr = new int[2] { id, methods };
                allLights.Add(arr);
                //Generate label, checkboxes and lines
                if (methods == 16 || methods == 17 || methods == 18 || methods == 19)
                    name = name + " [dimmable]";
                System.Windows.Forms.Label lbl = new System.Windows.Forms.Label();
                lbl.Location = new System.Drawing.Point(6, dynamicHeight + (i * 20));
                lbl.Name = "lblLight_" + id.ToString();
                lbl.Size = new System.Drawing.Size(165, 14);
                lbl.TabIndex = 7;
                lbl.Text = name;
                //
                // chkboxPlay
                //
                System.Windows.Forms.CheckBox chkboxPlay = new System.Windows.Forms.CheckBox();
                chkboxPlay.AutoSize = true;
                chkboxPlay.Location = new System.Drawing.Point(177, dynamicHeight + (i * 20));
                chkboxPlay.Name = "chkboxPlay" + id.ToString();
                chkboxPlay.Size = new System.Drawing.Size(15, 14);
                chkboxPlay.TabIndex = 1 + (i * 3);
                chkboxPlay.UseVisualStyleBackColor = true;
                chkboxPlay.CheckedChanged += new System.EventHandler(this.checkBoxChangedSave);
                //
                // chkboxPause
                //
                System.Windows.Forms.CheckBox chkboxPause = new System.Windows.Forms.CheckBox();
                chkboxPause.AutoSize = true;
                chkboxPause.Location = new System.Drawing.Point(213, dynamicHeight + (i * 20));
                chkboxPause.Name = "chkboxPause" + id.ToString();
                chkboxPause.Size = new System.Drawing.Size(15, 14);
                chkboxPause.TabIndex = 2 + (i * 3);
                chkboxPause.UseVisualStyleBackColor = true;
                chkboxPause.CheckedChanged += new System.EventHandler(this.checkBoxChangedSave);
                //
                // chkboxStop
                //
                System.Windows.Forms.CheckBox chkboxStop = new System.Windows.Forms.CheckBox();
                chkboxStop.AutoSize = true;
                chkboxStop.Location = new System.Drawing.Point(253, dynamicHeight + (i * 20));
                chkboxStop.Name = "chkboxStop" + id.ToString();
                chkboxStop.Size = new System.Drawing.Size(15, 14);
                chkboxStop.TabIndex = 3 + (i * 3);
                chkboxStop.UseVisualStyleBackColor = true;
                chkboxStop.CheckedChanged += new System.EventHandler(this.checkBoxChangedSave);

                this.groupBox1.Controls.Add(lbl);
                this.groupBox1.Controls.Add(chkboxPlay);
                this.groupBox1.Controls.Add(chkboxPause);
                this.groupBox1.Controls.Add(chkboxStop);
            }

            using (StreamReader sr = new StreamReader(System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + "\\" + "settings.ini"))
            {
                Version = sr.ReadLine();
                Ip = sr.ReadLine();
                if (Version == "10")
                {
                    Port = sr.ReadLine();
                    User = sr.ReadLine();
                    Password = sr.ReadLine();
                }
                else
                    Port = "9090";

                //
                // Read values for dimlevel. Telldus API requires values from 0 to 255.
                // Values in config is stored in values from 0 to 100. Therefore multiply by 2.55
                //

                try
                {
                    DimlevelPause = Convert.ToInt32(int.Parse(sr.ReadLine()) * 2.55);
                }
                catch
                {
                    DimlevelPause = Convert.ToInt32(50 * 2.55);
                }
                try
                {
                    DimlevelPlay = Convert.ToInt32(int.Parse(sr.ReadLine()) * 2.55);
                }
                catch
                {
                    DimlevelPlay = Convert.ToInt32(50 * 2.55);
                }
                try
                {
                    DimlevelStop = Convert.ToInt32(int.Parse(sr.ReadLine()) * 2.55);
                }
                catch
                {
                    DimlevelStop = Convert.ToInt32(50 * 2.55);
                }

                sr.Close();
            }

            using (StreamReader sr = new StreamReader(System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + "\\" + "lights.ini"))
            {
                while (sr.Peek() != -1)
                {
                    string tempLine = sr.ReadLine().Trim();
                    if (tempLine != "")
                    {
                        try
                        {
                            string[] line = tempLine.Split(',');
                            var play = this.Controls.Find("chkboxPlay" + line[0], true).FirstOrDefault();
                            var pause = this.Controls.Find("chkboxPause" + line[0], true).FirstOrDefault();
                            var stop = this.Controls.Find("chkboxStop" + line[0], true).FirstOrDefault();
                            if (play != null && pause != null && stop != null)
                            {
                                CheckBox checkPlay = play as CheckBox;
                                CheckBox checkPause = pause as CheckBox;
                                CheckBox checkStop = stop as CheckBox;
                                if (int.Parse(line[1]) == 1)
                                    checkPlay.Checked = true;
                                if (int.Parse(line[2]) == 1)
                                    checkPause.Checked = true;
                                if (int.Parse(line[3]) == 1)
                                    checkStop.Checked = true;
                            }
                        }
                        catch(Exception e)
                        {
                            MessageBox.Show(e.ToString());
                            MessageBox.Show("Failure while reading lights.ini, please edit lightsources");
                            load();
                            return;
                        }
                    }
                }
                sr.Close();
            }

            if (Ip == null || Port == null)
            {
                if (settingsread)
                {
                    this.Close();
                    return;
                }
                else
                {
                    Settings set = new Settings();
                    set.ShowDialog();
                    settingsread = true;
                    set.Dispose();
                    load();
                    return;
                }
            }
            else
            {
                if (Version == "10")
                {
                    Xbmc = new XbmcConnection(Ip, Convert.ToInt32(Port), User, Password);

                    UpdateTimerOne.Interval = 1000;
                    UpdateTimerOne.Tick += new EventHandler(UpdateTimerOne_Tick);
                    UpdateTimerOne.Start();
                    UpdateTimerLights.Interval = 1000;
                    UpdateTimerLights.Tick += new EventHandler(UpdateTimerLights_Tick);
                    UpdateTimerLights.Start();
                    UpdateTimerTen.Interval = 10000;
                    UpdateTimerTen.Tick += new EventHandler(UpdateTimerTen_Tick);
                    UpdateTimerTen.Start();

                    if (Xbmc.Status.IsConnected)
                    {
                        lblConnected.Text = "Connected";
                        lblConnected.ForeColor = System.Drawing.Color.Green;
                    }
                }
                else //Since not version 10, it must be 11 (Eden)!
                {
                    new Thread(eden).Start();
                    UpdateTimerLights.Interval = 1000;
                    UpdateTimerLights.Tick += new EventHandler(UpdateTimerLights_Tick);
                    UpdateTimerLights.Start();
                }

            }
            loading = false;
        }
Пример #2
0
 private void button4_Click(object sender, EventArgs e)
 {
     Settings set = new Settings();
     set.ShowDialog();
     load();
 }