private void comboMode_SelectedIndexChanged(object sender, EventArgs e) { EModes newMode; try { newMode = (EModes)Enum.Parse(typeof(EModes), comboMode.SelectedItem.ToString()); } catch { return; } if (mMode == newMode) { return; } mMode = newMode; try { if (mWorker != null) { mWorker.CancelAsync(); mWorker.Dispose(); } } catch { } finally { mWorker = null; } panelParam.Controls.Clear(); Effects.EffectBase effect = Effects.EffectBase.GetEffect(mMode); if (effect == null) { return; } effect.Dock = DockStyle.Fill; panelParam.Controls.Add(effect); previewPanel.Visible = effect.IsAnimation; if (effect.IsAnimation) { mWorker = new BackgroundWorker(); mWorker.WorkerSupportsCancellation = true; mWorker.DoWork += MWorker_DoWork; mWorker.RunWorkerCompleted += MWorker_RunWorkerCompleted; mWorker.RunWorkerAsync(new object[] { this, effect }); } else { if (mCtrl != null) { mCtrl.RequestMode(0, 0, 0); } Thread.Sleep(10); effect.Init(this); effect.Work(this); } Settings.Instance.Mode = mMode; }
public static Effects.EffectBase GetEffect(EModes nMode) { if (Settings.Instance == null) { return(null); } switch (nMode) { case EModes.Static: return(new Effects.Static(Settings.Instance.Static)); case EModes.Strobing: return(new Effects.Strobing(Settings.Instance.Strobing)); case EModes.Breathing: return(new Effects.Breathing(Settings.Instance.Breathing)); case EModes.ColorCycle: return(new Effects.ColorCycle(Settings.Instance.ColorCycle)); case EModes.BreathingCycle: return(new Effects.BreathingCycle(Settings.Instance.BreathingCycle)); case EModes.ScreenGrab: return(new Effects.ScreenGrab(Settings.Instance.ScreenGrab)); default: return(null); } }
private void Form1_Load(object sender, EventArgs e) { try { Settings.Load(); } catch (Exception ex) { MessageBox.Show("Error loading configuration:" + Environment.NewLine + ex.ToString(), "Error Loading Configuration", MessageBoxButtons.OK, MessageBoxIcon.Error); } cmbPort.Items.AddRange(Arduino.Controller.AvailablePorts); if (cmbPort.Items.Contains(Settings.Instance.ComPort.ToString())) { cmbPort.SelectedItem = Settings.Instance.ComPort.ToString(); } else if (cmbPort.Items.Count > 0) { cmbPort.SelectedIndex = cmbBaud.Items.Count - 1; } cmbBaud.Items.AddRange(Arduino.Controller.AvailableBaudRates.Select(x => x.ToString()).ToArray()); if (cmbBaud.Items.Contains(Settings.Instance.BaudRate.ToString())) { cmbBaud.SelectedItem = Settings.Instance.BaudRate.ToString(); } else if (cmbBaud.Items.Count > 0) { cmbBaud.SelectedIndex = cmbBaud.Items.Count - 1; } Brightness = Settings.Instance.Brightness; numBrightness.Value = Brightness; slideBrightness.Value = (float)Brightness / 2.55f; Color = Settings.Instance.Color; Task.Factory.StartNew(() => { btnConnect_Click(null, null); EModes initMode = Settings.Instance.Mode; timerHeartBeat.Start(); mCtrl.RequestMode(0, 0, 0); Thread.Sleep(1000); mCtrl.RequestBrightness(255); Thread.Sleep(1000); mCtrl.RequestColor(Color.Orange); BeginInvoke(new Action(() => { comboMode.Items.AddRange(Enum.GetNames(typeof(EModes))); if (comboMode.Items.Contains(initMode.ToString())) { comboMode.SelectedIndex = comboMode.Items.IndexOf(initMode.ToString()); } } ) ); } ); #if !DEBUG if (HideOnLaunch) { Task.Factory.StartNew(() => { Thread.Sleep(500); Invoke(new MethodInvoker(Hide)); }); } #endif }