Esempio n. 1
0
        internal void RaiseKeyDoublePress(byte index)
        {
            OptimusMiniPluginWorkerBase lPlugin = _Plugins[MapKeyIndex(index)];

            if (lPlugin != null)
            {
                ThreadPool.QueueUserWorkItem(new WaitCallback(lPlugin.OnKeyDoublePress));
            }

            if (OnKeyDoublePress != null)
            {
                OnKeyDoublePress(this, index);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Removes plugin from specified key.
        /// </summary>
        /// <param name="index">0-based index of key.</param>
        /// <returns>0 if successful, otherwise an error code.</returns>
        public int RemovePlugin(byte index)
        {
            if (_Plugins[index] != null)
            {
                OptimusMiniPluginWorkerBase lCurrentPlugin = _Plugins[index];
                _Plugins[index] = null;

                // Tell plugin to stop working

                // Terminate
                lCurrentPlugin.Terminate();
            }

            return(0);
        }
Esempio n. 3
0
        /// <summary>
        /// Assigns passed plugin to specified key.
        /// </summary>
        /// <param name="index">0-based index of key.</param>
        /// <param name="plugin">Plugin to assign.</param>
        /// <returns>0 if successful, otherwise an error code.</returns>
        public int AddPlugin(byte index, OptimusMiniPluginWorkerBase plugin, OptimusMiniSettingsList settings)
        {
            // ----- If there's already a plugin assigned remove it
            RemovePlugin(index);


            // ----- Add new plugin
            _Plugins[index] = plugin;
            plugin.Initialize(settings);
            plugin.Repaint();


            // ----- Result
            return(0);
        }
Esempio n. 4
0
        private void ProcessUpdates()
        {
            try
            {
                _UpdateThreadExit = false;

                while (_Connection.GetConnectionState() && !_UpdateThreadExit)
                {
                    // ----- Check if user is idle
                    if (_IdleTime != 0 && Win32Library.GetUserIdleTime() > _IdleTime)
                    {
                        if (!_IsIdle)
                        {
                            _Connection.SwitchOff();
                            _IsIdle = true;
                        }
                    }
                    else
                    {
                        if (_IsIdle)
                        {
                            _Connection.SwitchOn();
                            _Connection.ShowAll();
                            _Connection.SetBrightness(_Brightness);
                            _IsIdle = false;
                        }
                    }


                    // ----- Update plugins
                    for (byte i = 0; i < 3; i++)
                    {
                        // Update plugins
                        OptimusMiniPluginWorkerBase lPlugin = _Plugins[i];
                        if (lPlugin != null)
                        {
                            // Check for updated images
                            if (lPlugin._Bitmap != null)
                            {
                                Bitmap lBitmap = lPlugin._Bitmap;
                                lPlugin._Bitmap = null;

                                _LastImage[i] = lBitmap.Clone(new Rectangle(0, 0, 96, 96), PixelFormat.Format24bppRgb);
                                RotateImage(lBitmap);
                                _Connection.SetImage(MapKeyIndex(i), lBitmap);
                                lBitmap.Dispose();
                            }

                            // Start update
                            if (lPlugin.IsNextUpdateDue())
                            {
                                ThreadPool.QueueUserWorkItem(new WaitCallback(lPlugin.Update));
                                //lPlugin.Update(null);
                            }
                        }


                        // ----- Update key state
                        byte lKeyState = _Connection.GetKeyState();
                        _KeyState[0].Update((lKeyState & 1) == 1);
                        _KeyState[1].Update((lKeyState & 2) == 2);
                        _KeyState[2].Update((lKeyState & 4) == 4);
                    }

                    Thread.Sleep(10);
                }

                _UpdateThreadExit = true;
                Terminate();
            }
            catch (ThreadAbortException)
            {
            }
        }