/// <summary> /// Checks the button state based on the raw data returned, and if it has, the ButtonStateChanged event is raised /// </summary> /// <param name="buf">Raw data buffer retrieved from the controller</param> private void CheckStateChanged(byte[] buf) { ButtonEnum[] values = (ButtonEnum[])Enum.GetValues(typeof(ButtonEnum)); ButtonState[] stateChangedArray = new ButtonState[values.Length]; for (int i = 0; i < values.Length; i++) { ButtonMasks.ButtonMask mask = ButtonMasks.MaskList[(int)values[i]]; ButtonState state = new ButtonState(); state.button = (ButtonEnum)values[i]; state.currentState = ((buf[mask.bytePos] & mask.maskValue) > 0); state.changed = isStateChanged(buf, mask.bytePos, mask.maskValue); stateChangedArray[(int)values[i]] = state; } if ((stateChangedArray.Length > 0) && (this.ButtonStateChanged != null)) { ButtonStateChanged(stateChangedArray); } }
/// <summary> /// Checks the button state based on the raw data returned, and if it has, the ButtonStateChanged event is raised /// </summary> /// <param name="buf">Raw data buffer retrieved from the controller</param> private void CheckStateChanged(byte[] buf) { ButtonEnum[] values = (ButtonEnum[])Enum.GetValues(typeof(ButtonEnum)); stateChangedArray = new ButtonState[values.Length]; bool updateLights = false; for (int i = 0; i < values.Length; i++) { ButtonMasks.ButtonMask mask = ButtonMasks.MaskList[(int)values[i]]; ButtonState state = new ButtonState(); state.button = (ButtonEnum)values[i]; state.currentState = ((buf[mask.bytePos] & mask.maskValue) > 0); state.changed = isStateChanged(buf, mask.bytePos, mask.maskValue); ButtonEnum currentButton = (ButtonEnum)(i); //only do something if button changed, and button was pressed and button is in hashtable if (state.changed) { if (updateGearLights && state.button == ButtonEnum.GearLeverStateChange) { GearLightsRefresh((int)unchecked ((sbyte)buf[25]));//copied this code from GearLever accessor, changed it since we need ot updateLights = true; } //check button - light mapping if (ButtonLights.ContainsKey(i)) { updateLights = true; LightProperties currentLightProperties = (LightProperties)(ButtonLights[i]); if (currentLightProperties.lightOnHold) { if (state.currentState) { SetLEDState(currentLightProperties.LED, currentLightProperties.intensity, false); } else { SetLEDState(currentLightProperties.LED, 0, false); } } else if (state.currentState) //only switch when button is pressed { int result = GetLEDState(currentLightProperties.LED); if (result > 0) //light is on { SetLEDState(currentLightProperties.LED, 0); //turn off } else { SetLEDState(currentLightProperties.LED, currentLightProperties.intensity); } } } if (ButtonKeys.ContainsKey(i)) { KeyProperties currentKeyProperties = (KeyProperties)(ButtonKeys[i]); if (currentKeyProperties.useModifier) { if (state.currentState)//button is pressed, then press key { InputSimulator.SimulateModifiedKeyStroke(currentKeyProperties.modifier, currentKeyProperties.keyCode1); } } else { if (currentKeyProperties.holdDown) //send separate down and up keypresses { if (state.currentState) { InputSimulator.SimulateKeyDown(currentKeyProperties.keyCode1); } else { InputSimulator.SimulateKeyUp(currentKeyProperties.keyCode1); } } else { if (state.currentState) { InputSimulator.SimulateKeyPress(currentKeyProperties.keyCode1); } } } } } stateChangedArray[(int)values[i]] = state; } if (updateLights) { RefreshLEDState(); } }
/// <summary> /// Checks if individual button state has changed /// </summary> /// <param name="buf">Int value of button enum</param> public bool GetButtonStateChanged(int button) { ButtonMasks.ButtonMask mask = ButtonMasks.MaskList[button]; return(isStateChanged(rawControlData, mask.bytePos, mask.maskValue)); }
/// <summary> /// Checks the individual button state /// </summary> /// <param name="buf">Int value of button enum</param> public bool GetButtonState(int button) { ButtonMasks.ButtonMask mask = ButtonMasks.MaskList[button]; return((rawControlData[mask.bytePos] & mask.maskValue) > 0); }