Ejemplo n.º 1
0
 public void Light(LightColor color1, LightColor color2)
 {
     Off();
     switch (color1)
     {
         case LightColor.Green:
             Green = true;
             break;
         case LightColor.Yellow:
             Yellow = true;
             break;
         case LightColor.Red:
             Red = true;
             break;
     }
     switch (color2)
     {
         case LightColor.Green:
             Green = true;
             break;
         case LightColor.Yellow:
             Yellow = true;
             break;
         case LightColor.Red:
             Red = true;
             break;
     }
 }
Ejemplo n.º 2
0
        public Vector3 GetColor(LightColor color)
        {
            var idx = (int)color;
            if (idx < 0 || idx >= 18)
                return Vector3.Zero;

            return mColors[idx];
        }
Ejemplo n.º 3
0
 public void ChangeColor(LightColor color)
 {
     if (color != _lastColor)
     {
         SetColor(color);
         Thread.Sleep(FLASH_LENGTH);
         SetColor(_lastColor);
         Thread.Sleep(FLASH_LENGTH);
         SetColor(color);
         _lastColor = color;
     }
 }
Ejemplo n.º 4
0
 public Light(int x, int y, LightCircuit circuit, LightColor color, LightShape shape)
 {
     Assembly assembly = Assembly.GetExecutingAssembly();
       string lightName = Enum.GetName(color.GetType(), color).ToLower();
       string resourceOn = string.Format("JamesAllen.XmasLights.Images.{0}_on.png", lightName);
       string resourceOff = string.Format("JamesAllen.XmasLights.Images.{0}_off.png", lightName);
       Stream streamOn = assembly.GetManifestResourceStream(resourceOn);
       Stream streamOff = assembly.GetManifestResourceStream(resourceOff);
       imageOn = (Image)Bitmap.FromStream(streamOn);
       imageOff = (Image)Bitmap.FromStream(streamOff);
       this.position = new Point(x, y);
       this.circuit = circuit;
       this.color = color;
       this.shape = shape;
 }
 public void SetFlash(LightColor color)
 {
     if (color == LightColor.Off)
     {
         throw new ArgumentException("LightColor.Off is invalid");
     }
     LightControlRequest request = new LightControlRequest()
     {
         Color = color,
         Flash = true
     };
     lock (this.outstandingRequestLock)
     {
         outstandingRequest = request;
         outstandingRequestExist.Set();
         TraceVerbose.Trace("SetFlash({0}): request queued.", color);
     }
 }
Ejemplo n.º 6
0
        void HandleLights()
        {
            if (greenLight == null || redLight == null) InitializeLights();

            if (core == null || MapView.MapIsEnabled)
            {
                litLight = LightColor.NEITHER;
            }
            else
            {
                bool somethingEnabled = false;
                if (vessel.GetMasterMechJeb() == core)
                {
                    foreach (DisplayModule display in core.GetComputerModules<DisplayModule>())
                    {
                        if (display is MechJebModuleMenu) continue;
                        if (display.enabled && display.showInCurrentScene)
                        {
                            somethingEnabled = true;
                        }
                    }
                }

                litLight = (somethingEnabled ? LightColor.GREEN : LightColor.RED);
            }

            switch (litLight)
            {
                case LightColor.GREEN:
                    if (!greenLight.enabled) TurnOnLight(LightColor.GREEN);
                    if (redLight.enabled) TurnOffLight(LightColor.RED);
                    break;

                case LightColor.RED:
                    if (greenLight.enabled) TurnOffLight(LightColor.GREEN);
                    if (!redLight.enabled) TurnOnLight(LightColor.RED);
                    break;

                case LightColor.NEITHER:
                    if (greenLight.enabled) TurnOffLight(LightColor.GREEN);
                    if (redLight.enabled) TurnOffLight(LightColor.RED);
                    break;
            }
        }
Ejemplo n.º 7
0
 private void OnSequenceChange(LightColor light, SoundType sound)
 {
     if (SequenceChange != null)
         SequenceChange(this, new SequenceChangeEventArgs() { Light = light, Sound = sound });
 }
Ejemplo n.º 8
0
    void handleLights()
    {
        bool somethingEnabled = false;
        foreach (ComputerModule module in core.modules)
        {
            if (module.enabled) somethingEnabled = true;
        }

        if (MapView.MapIsEnabled) litLight = LightColor.NEITHER;
        else litLight = (somethingEnabled ? LightColor.GREEN : LightColor.RED);

        switch (litLight)
        {
            case LightColor.GREEN:
                if (!greenLight.enabled) turnOnLight(LightColor.GREEN);
                if (redLight.enabled) turnOffLight(LightColor.RED);
                break;

            case LightColor.RED:
                if (greenLight.enabled) turnOffLight(LightColor.GREEN);
                if (!redLight.enabled) turnOnLight(LightColor.RED);
                break;

            case LightColor.NEITHER:
                if (greenLight.enabled) turnOffLight(LightColor.GREEN);
                if (redLight.enabled) turnOffLight(LightColor.RED);
                break;
        }
    }
        /// <summary>
        /// Helper to convert our 'public-facing' color enum to the Delcom light.
        /// Delcom light has two versions, one supports yellow nad the other suports blue.
        /// Although Delcom document is vague, distributed DelcomDLL.h has only a single entry BLUELED = 2.
        /// We observe that each device picks either blue or yellow for this value.
        /// </summary>
        /// <param name="inputColor"></param>
        /// <returns></returns>
        private DelcomLightColor ConvertColor(LightColor inputColor)
        {
            DelcomLightColor result;

            switch (inputColor)
            {
                case LightColor.Red:
                    result = DelcomLightColor.Red;
                    break;

                case LightColor.Green:
                    result = DelcomLightColor.Green;
                    break;

                case LightColor.Yellow:
                    result = DelcomLightColor.Blue;
                    break;

                default:
                    throw new ArgumentException("Unexpected inputColor");
            }

            return result;
        }
Ejemplo n.º 10
0
 public ColorLight(LightColor light, SoundType sound, object ellipse)
 {
     Light = light;
     Sound = sound;
     Ellispe = ellipse;
 }
 public void SetSolid(LightColor color)
 {
 }
Ejemplo n.º 12
0
        void TurnOffLight(LightColor which)
        {
            switch (which)
            {
                case LightColor.GREEN:
                    if (greenLightTransform != null)
                    {
                        greenLightTransform.renderer.material.shader = originalLensShader;
                        greenLightTransform.renderer.material.color = originalLensColor;
                        greenLight.enabled = false;
                    }
                    break;

                case LightColor.RED:
                    if (redLightTransform != null)
                    {
                        redLightTransform.renderer.material.shader = originalLensShader;
                        redLightTransform.renderer.material.color = originalLensColor;
                        redLight.enabled = false;
                    }
                    break;
            }
        }
Ejemplo n.º 13
0
        Vector3 ToRgb(LightColor colorType, ref LightDataEntry e)
        {
            var ret = new Vector3();
            switch(colorType)
            {
                case LightColor.Ambient:
                    ToRgb(e.globalAmbient, ref ret);
                    break;

                case LightColor.Diffuse:
                    ToRgb(e.globalDiffuse, ref ret);
                    break;

                case LightColor.Top:
                    ToRgb(e.skyColor0, ref ret);
                    break;

                case LightColor.Middle:
                    ToRgb(e.skyColor1, ref ret);
                    break;

                case LightColor.MiddleLower:
                    ToRgb(e.skyColor2, ref ret);
                    break;

                case LightColor.Lower:
                    ToRgb(e.skyColor3, ref ret);
                    break;

                case LightColor.Horizon:
                    ToRgb(e.skyColor4, ref ret);
                    break;

                case LightColor.Fog:
                    ToRgb(e.fogColor, ref ret);
                    break;

                case LightColor.Sun:
                    ToRgb(e.sunColor, ref ret);
                    break;

                case LightColor.Halo:
                    ToRgb(e.haloColor, ref ret);
                    break;

                case LightColor.Cloud:
                    ToRgb(e.cloudColor, ref ret);
                    break;

                default:
                    throw new ArgumentException("Invalid light type");
            }

            return ret;
        }
Ejemplo n.º 14
0
 /// <summary>
 /// Change the color of a group of lights.
 /// </summary>
 /// <remarks>
 /// This will automatically turn on the group of lights.
 /// </remarks>
 /// <param name="group">Group id.</param>
 /// <param name="color">Color.</param>
 public void SetLightColor(int group, LightColor color) {
     SetLightState(group, true);
     SendCommand(new byte[] { 0x40, (byte) color });
 }
Ejemplo n.º 15
0
        private void TurnOffLight(LightColor which)
        {
            switch (which)
            {
                case LightColor.GREEN:
                    if (greenLightTransform != null)
                    {
                        greenLightRenderer.material.SetColor(emissionId, Color.black);
                        greenLight.enabled = false;
                    }
                    break;

                case LightColor.RED:
                    if (redLightTransform != null)
                    {
                        redLightRenderer.material.SetColor(emissionId, Color.black);
                        redLight.enabled = false;
                    }
                    break;
            }
        }
Ejemplo n.º 16
0
        public Vector3 GetColorForTime(LightColor table, uint time)
        {
            var idx = (int)table;
            time %= 2880;

            if (idx < 0 || idx >= 18)
                return Vector3.Zero;

            var timeValues = mTimeTables[idx];
            var colorValues = mColorTables[idx];
            if (timeValues.Count == 0)
                return Vector3.Zero;

            if (timeValues[0] > time)
                time = timeValues[0];

            if (timeValues.Count == 1)
                return colorValues[0];

            var v1 = Vector3.Zero;
            var v2 = Vector3.Zero;

            uint t1 = 0;
            uint t2 = 0;

            for (var i = 0; i < timeValues.Count; ++i)
            {
                if (i + 1 >= timeValues.Count)
                {
                    v1 = colorValues[i];
                    v2 = colorValues[0];
                    t1 = timeValues[i];
                    t2 = timeValues[0] + 2880;
                    break;
                }

                var ts = timeValues[i];
                var te = timeValues[i + 1];
                if (ts <= time && te >= time)
                {
                    t1 = ts;
                    t2 = te;
                    v1 = colorValues[i];
                    v2 = colorValues[i + 1];
                    break;
                }
            }

            var diff = t2 - t1;
            if (diff == 0)
                return v1;

            var sat = (time - t1) / (float)diff;
            return (1 - sat) * v1 + sat * v2;
        }
Ejemplo n.º 17
0
        void TurnOnLight(LightColor which)
        {
            switch (which)
            {
                case LightColor.GREEN:
                    if (greenLightTransform != null)
                    {
                        greenLightTransform.renderer.material.shader = lightShader;                        
                        greenLightTransform.renderer.material.color = Color.green;
                        greenLight.enabled = true;
                    }
                    break;

                case LightColor.RED:
                    if (redLightTransform != null)
                    {
                        redLightTransform.renderer.material.shader = lightShader;                        
                        redLightTransform.renderer.material.color = Color.red;
                        redLight.enabled = true;
                    }
                    break;
            }
        }
 public void SetSolid(LightColor color)
 {
     LightControlRequest request = new LightControlRequest()
     {
         Color = color,
         Flash = false
     };
     lock (this.outstandingRequestLock)
     {
         outstandingRequest = request;
         outstandingRequestExist.Set();
         TraceVerbose.Trace("SetSolid({0}): request queued.", color);
     }
 }
Ejemplo n.º 19
0
        public bool GetColorForTime(int time, LightColor colorType, ref Vector3 color)
        {
            if (mDataEntries.Count == 0)
                return false;

            if (mEntryArray.Length != mDataEntries.Count)
                mEntryArray = mDataEntries.ToArray();

            if (mEntryArray.Length == 1)
            {
                color = ToRgb(colorType, ref mEntryArray[0]);
                return true;
            }

            var maxTime = mEntryArray[mEntryArray.Length - 1].timeValues;
            if (maxTime == 0 || mEntryArray[0].timeValues > time)
            {
                color = ToRgb(colorType, ref mEntryArray[0]);
                return true;
            }

            time %= 2880;

            var eIndex1 = -1;
            var eIndex2 = -1;
            var hasLight = false;
            var t1 = 1u;
            var t2 = 1u;

            for (var i = 0; i < mEntryArray.Length; ++i)
            {
                if (i + 1 >= mEntryArray.Length)
                {
                    eIndex1 = i;
                    eIndex2 = 0;
                    hasLight = true;
                    t1 = mEntryArray[eIndex1].timeValues;
                    t2 = mEntryArray[eIndex2].timeValues + 2880;
                    break;
                }

                if (mEntryArray[i].timeValues > time || mEntryArray[i + 1].timeValues <= time) continue;

                eIndex1 = i;
                eIndex2 = i + 1;
                hasLight = true;
                t1 = mEntryArray[eIndex1].timeValues;
                t2 = mEntryArray[eIndex2].timeValues;
                break;
            }

            if (hasLight == false)
                return false;

            if (t1 >= t2)
            {
                color = ToRgb(colorType, ref mEntryArray[eIndex1]);
                return true;
            }

            var diff = t2 - t1;
            var sat = (time - t1) / (float)diff;
            var v1 = ToRgb(colorType, ref mEntryArray[eIndex1]);
            var v2 = ToRgb(colorType, ref mEntryArray[eIndex2]);
            color = v2 * sat + v1 * (1 - sat);

            return true;
        }
Ejemplo n.º 20
0
        private void SetColor(LightColor color)
        {
            var controlBytes = new byte[8];
            controlBytes[0] = 0x65;
            controlBytes[1] = 0x0C;
            controlBytes[2] = (byte)color; // This is the LED byte
            controlBytes[3] = 0xFF;

            _controller.HidSetFeature(controlBytes);
        }
Ejemplo n.º 21
0
        void TurnOnLight(LightColor which)
        {
            switch (which)
            {
                case LightColor.GREEN:
                    if (greenLightTransform != null)
                    {
                        greenLightTransform.renderer.material.shader = Shader.Find("Self-Illumin/Specular");
                        greenLightTransform.renderer.material.color = Color.green;
                        greenLight.enabled = true;
                    }
                    break;

                case LightColor.RED:
                    if (redLightTransform != null)
                    {
                        redLightTransform.renderer.material.shader = Shader.Find("Self-Illumin/Specular");
                        redLightTransform.renderer.material.color = Color.red;
                        redLight.enabled = true;
                    }
                    break;
            }
        }
Ejemplo n.º 22
0
 public void Light(LightColor color1, LightColor color2)
 {
     StartCommand(string.Format("{0} {1}", color1, color2));
 }
Ejemplo n.º 23
0
 public void Light(LightColor color)
 {
     StartCommand(color.ToString());
 }
 public void SetFlash(LightColor color)
 {
 }