Ejemplo n.º 1
0
        public MainWindowController(string productVersion, EventHandler quitHandler)
        {
            id = -1;//Add drop down for selecting a single or all devices for settings control
            disposables = new List<IDisposable>();
            controlColor = new Color16Bit(new Utility.HslColor(0, 0, 0.5).ToRgbColor());

            AttachObserver((LogMsgObserver)(LoggerHelper.GetInstance()));//attach logger
            // Create Manager instances
            connectionManager = new ConnectionManager(VID, PID);
            settingsManager = new SettingsManager();
            extensionManager = new ExtensionManager();
            preOutputProcessor = new PreOutputProcessor();
            whiteBalController = new WhiteBalanceWindowController(settingsManager);
            pollingWindowController = new PollingAreaWindowController();
            disposables.Add(pollingWindowController);
            // Attach event observers
            connectionManager.AttachObserver((ConnectionEventObserver)settingsManager);
            connectionManager.AttachObserver((ConnectionEventObserver)extensionManager);
            connectionManager.AttachObserver((ConnectionEventObserver)whiteBalController);
            connectionManager.AttachObserver((ConnectionEventObserver)pollingWindowController);
            connectionManager.AttachObserver((ConnectionEventObserver)this);
            preOutputProcessor.AttachObserver((AntumbraColorObserver)connectionManager);
            extensionManager.AttachObserver((AntumbraColorObserver)preOutputProcessor);
            settingsManager.AttachObserver((ConfigurationObserver)extensionManager);
            settingsManager.AttachObserver((ConfigurationObserver)preOutputProcessor);
            settingsManager.AttachObserver((ConfigurationObserver)this);
            pollingWindowController.PollingAreaUpdatedEvent += new PollingAreaWindowController.PollingAreaUpdated(UpdatePollingSelection);
            // Find devices
            connectionManager.UpdateDeviceConnections();
            settingsManager.UpdateBoundingBox();

            AttachObserver((GlowCommandObserver)extensionManager);
            pollingWindowController.AttachObserver((GlowCommandObserver)this);

            SystemEvents.SessionSwitch += new SessionSwitchEventHandler(SystemEvents_SessionSwitch);
            SystemEvents.PowerModeChanged += new PowerModeChangedEventHandler(PowerModeChanged);
            this.window = new MainWindow();
            this.window.closeBtn_ClickEvent += new EventHandler(closeBtnClicked);
            this.window.colorWheel_ColorChangedEvent += new EventHandler(colorWheelColorChanged);
            this.window.brightnessTrackBar_ScrollEvent += new EventHandler(brightnessValueChanged);
            this.window.hsvBtn_ClickEvent += new EventHandler(hsvBtnClicked);
            this.window.sinBtn_ClickEvent += new EventHandler(sinBtnClicked);
            this.window.neonBtn_ClickEvent += new EventHandler(neonBtnClicked);
            this.window.mirrorBtn_ClickEvent += new EventHandler(mirrorBtnClicked);
            this.window.augmentBtn_ClickEvent += new EventHandler(augmentBtnClicked);
            this.window.smoothBtn_ClickEvent += new EventHandler(smoothBtnClicked);
            this.window.gameBtn_ClickEvent += new EventHandler(gameBtnClicked);
            this.window.mainWindow_MouseDownEvent += new System.Windows.Forms.MouseEventHandler(mouseDownEvent);
            this.window.quitBtn_ClickEvent += new EventHandler(quitBtnClicked);
            this.quitEventHandler += quitHandler;
            this.window.setPollingBtn_ClickEvent += new EventHandler(setPollingBtnClickHandler);
            this.window.onOffValueChanged += new EventHandler(OnOffValueChangedHandler);
            this.window.whiteBalanceBtn_ClickEvent += new EventHandler(whiteBalanceBtnClicked);
            this.window.throttleBar_ValueChange += new EventHandler(throttleBarValueChanged);
        }
Ejemplo n.º 2
0
        public void NewColorAvail(Color16Bit newCol, int id, long index)
        {
            OutputSettings settings;
            if(!AllDeviceSettings.TryGetValue(id, out settings)) {
                Log("OutputSettings for device not found! Color sent plain. ID: " + id);
                NewColorAvailEvent(newCol, id, index);
                return;
            }

            if(index == long.MinValue) {
                OutputIndexes.Remove(id);
            }

            long prevIndex;
            if(!OutputIndexes.TryGetValue(id, out prevIndex)) {
                OutputIndexes[id] = index;
            } else if(prevIndex >= index) {
                // Invalid index
                Log("Color recieved out of order! Color BLOCKED! Target ID: " + id +
                    " with index " + index + " and last index " + prevIndex);
                return;

            }
            // Either first run or valid index
            int red = newCol.red;
            int green = newCol.green;
            int blue = newCol.blue;
            // White balance
            if(newCol.GetAvgBrightness() > settings.whiteBalanceMin) {
                red += settings.redBias;
                green += settings.greenBias;
                blue += settings.blueBias;
            }
            newCol = Color16Bit.FunnelIntoColor(red, green, blue);
            // Scale brightness
            try {
                newCol.ScaleColor(settings.MaxBrightness);
            } catch(ArgumentException ex) {
                Log(ex.Message + '\n' + ex.StackTrace);
            }
            NewColorAvailEvent(newCol, id, index);
        }
Ejemplo n.º 3
0
 public void colorWheelColorChanged(object sender, EventArgs args)
 {
     if(sender is Utility.HslColor) {
         Utility.HslColor col = (Utility.HslColor)sender;
         Color16Bit manualColor = new Color16Bit(col.ToRgbColor());
         NewGlowCmdAvailEvent(new StopAndSendColorCommand(-1, manualColor));
     }
 }
Ejemplo n.º 4
0
 /// <summary>
 /// Target of the independent driver task.
 /// </summary>
 private void target()
 {
     double i = 0;
     while (running) {
         double value = Math.Abs(Math.Sin(i) * UInt16.MaxValue);
         ushort v = Convert.ToUInt16(value);
         Color16Bit result = new Color16Bit(v, v, v);
         if(NewColorAvailEvent != null)
             NewColorAvailEvent(result, deviceId, index++);
         if (v == 0)
             Thread.Sleep(this.stepSleep * 39);
         Thread.Sleep(this.stepSleep);
         i += .03;
     }
 }
 public StopAndSendColorCommand(int id, Color16Bit newColor)
     : base(id)
 {
     this.newColor = newColor;
 }
Ejemplo n.º 6
0
 public abstract Color16Bit Filter(Color16Bit origColor);
Ejemplo n.º 7
0
 private void Target()
 {
     List<Color16Bit> colors = new List<Color16Bit>();
     colors.Add(new Color16Bit(Color.Red));
     colors.Add(new Color16Bit(Color.Teal));
     colors.Add(new Color16Bit(Color.Blue));
     colors.Add(new Color16Bit(Color.Yellow));
     colors.Add(new Color16Bit(Color.Green));
     colors.Add(new Color16Bit(Color.Purple));
     int index = 0;
     Color16Bit prev = new Color16Bit();
     while (running) {
         Color16Bit newColor = colors[index];
         FadeFromTo(prev, newColor);
         prev = newColor;
         index += 1;
         if (index == colors.Count)
             index = 0;//wrap around
     }
 }
Ejemplo n.º 8
0
 /// <summary>
 /// Filter and announce a new NewColorAvailEvent
 /// </summary>
 /// <param name="newColor"></param>
 /// <param name="id"></param>
 /// <param name="index"></param>
 public void NewColorAvail(Color16Bit newColor, int id, long index)
 {
     _prevIndex = index;
     if(NewColorAvailEvent != null) {
         if(Extensions.ActiveFilters.Count > 0) {
             long r = 0, g = 0, b = 0;
             int i;
             for(i = 0; i < Extensions.ActiveFilters.Count; i += 1) {
                 r += newColor.red;
                 g += newColor.green;
                 b += newColor.blue;
             }
             newColor = new Color16Bit(Convert.ToUInt16(r / i), Convert.ToUInt16(g / i), Convert.ToUInt16(b / i));
         }
         NewColorAvailEvent(newColor, id, index);
     }
 }
Ejemplo n.º 9
0
 private void FadeFromTo(Color16Bit col1, Color16Bit col2)
 {
     for (double frac = 0; frac <= 1; frac += .001) {
         if (!running)
             return;//cancel fade, we've been stopped
         Color16Bit newColor = Mixer.MixColorPercIn(col2, col1, frac);
         SendColor(newColor);
         Thread.Sleep(this.stepSleep);
     }
 }
Ejemplo n.º 10
0
 private void SendColor(Color16Bit newColor)
 {
     if (NewColorAvailEvent != null)
         NewColorAvailEvent(newColor, deviceId, index++);
 }
Ejemplo n.º 11
0
        public void SoftSendColor(Color16Bit newColor, int id) {
            if(id == -1) {
                for(int i = 0; i < Instances.Count; i += 1) {
                    SoftSendColor(newColor, id);
                }
                return;
            }

            ExtensionInstance Instance = Instances[id];
            if(!Instance.running) {
                if(NewColorAvailEvent != null) {
                    NewColorAvailEvent(newColor, id, Instance.prevIndex);
                }
            }
        }
Ejemplo n.º 12
0
        public void StopAndSendColor(Color16Bit newColor, int id) {
            if(id == -1) {
                for(int i = 0; i < Instances.Count; i += 1) {
                    StopAndSendColor(newColor, i);
                }
                return;
            }

            ExtensionInstance Instance = Instances[id];
            Instance.Stop();
            if(NewColorAvailEvent != null) {
                NewColorAvailEvent(newColor, id, Instance.prevIndex);
            }
        }
Ejemplo n.º 13
0
 /// <summary>
 /// Handle a NewColorAvail event
 /// </summary>
 /// <param name="newColor"></param>
 /// <param name="id"></param>
 /// <param name="index"></param>
 public void NewColorAvail(Color16Bit newColor, int id, long index) {
     if(NewColorAvailEvent != null) {
         try {
             NewColorAvailEvent(newColor, id, index);
         } catch(ArgumentException ex) {
             Log(ex.Message + '\n' + ex.StackTrace);
         }
     }
 }
Ejemplo n.º 14
0
 public void NewColorAvail(Color16Bit newColor, int id, long index)
 {
     sendColor(newColor, id);
 }
Ejemplo n.º 15
0
 public override Color16Bit Filter(Color16Bit origColor)
 {
     HslColor hsl = new HslColor(origColor.ToRGBColor());
     if (hsl.L > (1.0 - (double)Properties.Settings.Default.amountToLighten))
         hsl.L = 1.0;
     else
         hsl.L += (double)Properties.Settings.Default.amountToLighten;
     return new Color16Bit(hsl.ToRgbColor());
 }
Ejemplo n.º 16
0
 public override Color16Bit Filter(Color16Bit origColor)
 {
     // Too dark to saturate with good results
     if (origColor.red < 5000 && origColor.green < 5000 && origColor.blue < 5000)
         return origColor;
     HslColor boringHSL = new HslColor(origColor.ToRGBColor());
     double satAmnt = (double)Properties.Settings.Default.saturationAmount;
     double diff = Math.Abs(.5 - boringHSL.L);
     int dir = boringHSL.L > .5 ? -1 : 1;
     if (diff < satAmnt)
         boringHSL.L = .5;
     else
         boringHSL.L += dir * satAmnt;
     return new Color16Bit(boringHSL.ToRgbColor());
 }
 void AntumbraColorObserver.NewColorAvail(Color16Bit newCol, int id, long index)
 {
     if(NewColorAvailEvent != null)
         NewColorAvailEvent(newCol, id, index);//pass it up
 }