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)); }
//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); }
//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); }
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); }
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); }
/// <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(); }
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); } } }
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); }
/// <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(); } }
public FlashLEDParams(ControllerLEDEnum a, int b) { LightId = a; numberOfTimes = b; }
public int intensity; //light intensity public LightProperties(ControllerLEDEnum a, bool b, int c) { LED = a; lightOnHold = b; intensity = c; }
/// <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); }