Exemplo n.º 1
0
        public void AddButtonLightMapping(ButtonEnum button, bool lightOnHold, int intensity)
        {
            int buttonEquivalent    = (int)button;
            ControllerLEDEnum light = (ControllerLEDEnum)GetLightForButton(button);

            AddButtonLightMapping(button, light, lightOnHold, intensity);
        }
        /// <summary>
        /// Retrieves the LED state from the internal buffer.  This does not return the actual
        /// intensity from the controller itself.  But, if this is the only library accessing
        /// the device, you can assume that the LED state is the same as what's in the buffer.
        /// </summary>
        /// <param name="LightId"></param>
        /// <returns></returns>
        public int GetLEDState(ControllerLEDEnum LightId)
        {
            int hexPos  = ((int)LightId) % 2;
            int bytePos = (((int)LightId) - hexPos) / 2;

            return((((int)rawLEDData[bytePos]) & ((hexPos == 1)?0xF0:0x0F)) / ((hexPos == 1)?0x10:0x01));
        }
Exemplo n.º 3
0
        //trying to make this method multi-threaded, will return to this later.
        public void flashLED(ControllerLEDEnum LightId, int numberOfTimes)
        {
            FlashLEDParams inputParams  = new FlashLEDParams(LightId, numberOfTimes);
            Thread         workerThread = new Thread(this.flashLED_worker);

            //workerThread.Start(inputParams);
            flashLED_helper(LightId, numberOfTimes);
        }
Exemplo n.º 4
0
        //used when creating thread
        private void flashLED_worker(object input)
        {
            FlashLEDParams    parameters    = (FlashLEDParams)input;
            int               numberOfTimes = parameters.numberOfTimes;
            ControllerLEDEnum LightId       = parameters.LightId;

            flashLED_helper(LightId, numberOfTimes);
        }
Exemplo n.º 5
0
            int lightLevel = 0; // index of lightState; 0 == lowest
            public FlashingLight(ButtonEnum b, List <Tuple <int, int> > ls, int i)
            {
                this.light       = controller.GetLightForButton(b);
                this.button      = b;
                this.lightStates = ls;
                this.iterations  = i;

                this.duration = this.lightStates[0].Item2;
                controller.SetLEDState(this.light, this.lightStates[0].Item1);
            }
Exemplo n.º 6
0
 public void AddButtonLightMapping(ButtonEnum button, ControllerLEDEnum LED, bool lightOnHold, int intensity)
 {
     /*if (!ButtonLights.ContainsKey(button))
      *  ButtonLights.Add((int)button, new LightProperties(LED, lightOnHold, intensity));
      * else*/
     if (ButtonLights.Contains((int)button))
     {
         ButtonLights.Remove((int)button);//to save on later garbage collection
     }
     ButtonLights[(int)button] = new LightProperties(LED, lightOnHold, intensity);
 }
Exemplo n.º 7
0
        /// <summary>
        /// lights 5 times...just as a sanity check to make sure I coded all of the enumerator values for the LED's :-)
        /// </summary>
        public void TestLEDs(int frequency)
        {
            for (int j = 0; j < frequency; j++)
            {
                for (int intensity = 0; intensity <= 0x0f; intensity++)
                {
                    foreach (string value in Enum.GetNames(typeof(ControllerLEDEnum)))
                    {
                        ControllerLEDEnum LightId = (ControllerLEDEnum)Enum.Parse(typeof(ControllerLEDEnum), value);

                        int hexPos  = ((int)LightId) % 2;
                        int bytePos = (((int)LightId) - hexPos) / 2;

                        if (intensity > 0x0f)
                        {
                            intensity = 0x0f;
                        }

                        rawLEDData[bytePos] &= (byte)((hexPos == 1)?0x0F:0xF0);
                        rawLEDData[bytePos] += (byte)(intensity * ((hexPos == 1)?0x10:0x01));
                    }

                    RefreshLEDState();
                }
                for (int intensity = 0x0f; intensity >= 0; intensity--)
                {
                    foreach (string value in Enum.GetNames(typeof(ControllerLEDEnum)))
                    {
                        ControllerLEDEnum LightId = (ControllerLEDEnum)Enum.Parse(typeof(ControllerLEDEnum), value);

                        int hexPos  = ((int)LightId) % 2;
                        int bytePos = (((int)LightId) - hexPos) / 2;

                        if (intensity > 0x0f)
                        {
                            intensity = 0x0f;
                        }

                        rawLEDData[bytePos] &= (byte)((hexPos == 1)?0x0F:0xF0);
                        rawLEDData[bytePos] += (byte)(intensity * ((hexPos == 1)?0x10:0x01));
                    }

                    RefreshLEDState();
                }
            }
            if (updateGearLights)
            {
                GearLightsRefresh(GearLever);
            }
            RefreshLEDState();
        }
Exemplo n.º 8
0
 private void flashLED_helper(ControllerLEDEnum LightId, int numberOfTimes)
 {
     for (int j = 0; j < numberOfTimes; j++)
     {
         for (int intensity = 0; intensity <= 0x0f; intensity++)
         {
             SetLEDState(LightId, intensity, true);
         }
         for (int intensity = 0x0f; intensity >= 0; intensity--)
         {
             SetLEDState(LightId, intensity, true);
         }
     }
 }
Exemplo n.º 9
0
            public FlashingLight(ButtonEnum b, int ll, int ld, int hl, int hd, int i)
            {
                this.light       = controller.GetLightForButton(b);
                this.button      = b;
                this.lightStates = new List <Tuple <int, int> >()
                {
                    new Tuple <int, int>(ll, ld),
                    new Tuple <int, int>(hl, hd)
                };
                this.iterations = i;

                this.duration = this.lightStates[0].Item2;
                controller.SetLEDState(this.light, this.lightStates[0].Item1);
            }
Exemplo n.º 10
0
        /// <summary>
        /// Sets the intensity of the specified LED in the buffer, but gives the option on whether you want
        /// to send the buffer to the controller.  This can be useful for updating multiple LED's at the
        /// same time, but not waiting for the LED buffer to transfer to the device after each call.
        /// </summary>
        /// <param name="LightId">A ControllerLEDEnum value that specifies which LED to modify</param>
        /// <param name="Intensity">The intensity of the LED, ranging from 0 to 15</param>
        /// <param name="refreshState">A boolean value indicating whether to refresh the buffer on the device.</param>
        public void SetLEDState(ControllerLEDEnum LightId, int Intensity, bool refreshState)
        {
            int hexPos  = ((int)LightId) % 2;
            int bytePos = (((int)LightId) - hexPos) / 2;

            if (Intensity > 0x0f)
            {
                Intensity = 0x0f;
            }

            // Erase the byte position, and set the light intensity
            rawLEDData[bytePos] &= (byte)((hexPos == 1)?0x0F:0xF0);
            rawLEDData[bytePos] += (byte)(Intensity * ((hexPos == 1)?0x10:0x01));

            if (refreshState)
            {
                RefreshLEDState();
            }
        }
Exemplo n.º 11
0
 public FlashLEDParams(ControllerLEDEnum a, int b)
 {
     LightId       = a;
     numberOfTimes = b;
 }
Exemplo n.º 12
0
 public int               intensity;   //light intensity
 public LightProperties(ControllerLEDEnum a, bool b, int c)
 {
     LED         = a;
     lightOnHold = b;
     intensity   = c;
 }
Exemplo n.º 13
0
 /// <summary>
 /// Sets the intensity of the specified LED in the buffer, and sends the buffer to the controller.
 /// </summary>
 /// <param name="LightId">A ControllerLEDEnum value that specifies which LED to modify</param>
 /// <param name="Intensity">The intensity of the LED, ranging from 0 to 15</param>
 public void SetLEDState(ControllerLEDEnum LightId, int Intensity)
 {
     SetLEDState(LightId, Intensity, true);
 }