/// <summary> /// Opens connection to device and initializes the class. /// </summary> /// <param name="raiseEvent">Boolean whether to raise ConnectionStateChanged event or not.</param> /// <param name="clearImages">Boolean whether to clear images or not.</param> /// <returns>0 if successful, otherwise an error code.</returns> /// <remarks> /// Error codes: 0=successful, 1=device not found, 2=device not responding, 3=system is suspending /// </remarks> private int Init(bool raiseEvent, bool clearImages) { if (_IsConnected) { return(0); } if (_IsSuspending) { return(3); } _KeyState[0] = new OptimusMiniKeyState(this, 0); _KeyState[1] = new OptimusMiniKeyState(this, 1); _KeyState[2] = new OptimusMiniKeyState(this, 2); int lConnectionError; lConnectionError = _Connection.Init(); if (lConnectionError != 0) { return(lConnectionError); } _UpdateThread = new Thread(ProcessUpdates); _UpdateThread.Start(); if (clearImages) { ClearImage(0); ClearImage(1); ClearImage(2); } _Connection.SetBrightness(_Brightness); _Connection.SetGamma(_Gamma); _Connection.SwitchOn(); _Connection.ShowAll(); _IsConnected = true; if (raiseEvent) { RaiseConnectionStateChanged(true); } if (_Plugins[0] != null) { _Plugins[0].Repaint(); } if (_Plugins[1] != null) { _Plugins[1].Repaint(); } if (_Plugins[2] != null) { _Plugins[2].Repaint(); } return(0); }
/// <summary> /// Creates a new instance of the <see cref="OptimusMini" /> class and returns it. /// </summary> public OptimusMiniController() { _Plugins = new OptimusMiniPluginWorkerBase[3]; _KeyState = new OptimusMiniKeyState[3]; _KeyState[0] = new OptimusMiniKeyState(this, 0); _KeyState[1] = new OptimusMiniKeyState(this, 1); _KeyState[2] = new OptimusMiniKeyState(this, 2); _LastImage = new Bitmap[3]; _Connection = new OptimusMiniConnection(); _Brightness = OptimusMiniBrightness.Low; _Layout = OptimusMiniLayout.Right; _Gamma = 0.65f; _IdleTime = 300; //SystemEvents.PowerModeChanged += new PowerModeChangedEventHandler(PowerModeChanged); }