private void SetTouchUpListener(Canvas c, RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, float dX, float dY, int actionState, bool isCurrentlyActive) { recyclerView.SetOnTouchListener(new OnTouchListener((v, e) => { if (e.Action == MotionEventActions.Up) { base.OnChildDraw(c, recyclerView, viewHolder, 0F, dY, actionState, isCurrentlyActive); recyclerView.SetOnTouchListener(new OnTouchListener((v, e) => { })); } SetItemsClickable(recyclerView, true); swipeBack = false; if (_buttonsActions != null && buttonInstance != null && buttonInstance.Contains(e.GetX(), e.GetY())) { if (buttonShowedState == ButtonsState.LEFT_VISIBLE) { _buttonsActions.OnLeftClicked(viewHolder.AdapterPosition); } else if (buttonShowedState == ButtonsState.RIGHT_VISIBLE) { _buttonsActions.OnRightClicked(viewHolder.AdapterPosition); } } buttonShowedState = ButtonsState.GONE; currentItemViewHolder = null; })); }
private void ToggleButtons(ButtonsState state) { Button startButton = stopwatchLayout.FindViewById <Button>(Resource.Id.startButton); Button stopButton = stopwatchLayout.FindViewById <Button>(Resource.Id.stopButton); Button pauseButton = stopwatchLayout.FindViewById <Button>(Resource.Id.pauseButton); if (state == ButtonsState.Start) { startButton.Enabled = false; pauseButton.Enabled = true; stopButton.Enabled = true; } else if (state == ButtonsState.Pause) { startButton.Enabled = false; pauseButton.Enabled = true; stopButton.Enabled = false; } else if (state == ButtonsState.End) { startButton.Enabled = true; pauseButton.Enabled = false; stopButton.Enabled = false; } }
public void InitializeButtons(params string[] buttonNames) { for (var i = 0; i < buttonNames.Length; i++) { _buttonStates[buttonNames[i]] = new ButtonsState(buttonNames[i]); } }
private void InvalidateButtons(ButtonsState state) { switch (state) { case ButtonsState.Paused: pauseButton.Text = "RESUME"; startButton.Enabled = false; break; case ButtonsState.Resumed: pauseButton.Text = "PAUSE"; startButton.Enabled = false; break; case ButtonsState.Started: startButton.Enabled = false; break; case ButtonsState.Stopped: startButton.Enabled = true; break; default: break; } stopButton.Enabled = !startButton.Enabled; pauseButton.Enabled = !startButton.Enabled; saveButton.Enabled = startButton.Enabled; loadFileButton.Enabled = startButton.Enabled; removeDuplicatesButton.Enabled = startButton.Enabled; detailsButton.Enabled = startButton.Enabled; }
private void OnRecycleViewTouch( View.TouchEventArgs args, Canvas c, RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, float dX, float dY, int actionState, bool isCurrentlyActive) { _swipeBack = args.Event.Action == MotionEventActions.Cancel || args.Event.Action == MotionEventActions.Up; if (_swipeBack) { if (dX < -_buttonWidth) { _buttonShowedState = ButtonsState.RIGHT_VISIBLE; } else if (dX > _buttonWidth) { _buttonShowedState = ButtonsState.LEFT_VISIBLE; } if (_buttonShowedState != ButtonsState.GONE) { SetTouchDownListener(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive); SetItemsClickable(recyclerView, false); } } args.Handled = false; }
private void OnMouseDoubleClick(object sender, MouseEventArgs e) { var btn = GetMouseButton(e.Button); state.Buttons |= btn; var bs = new ButtonsState { CursorPoint = Cursor.Position.ToWindowPoint(), PointV2 = control.PointToClient(Cursor.Position).ToNumericsV2(), Condition = ButtonStates.Pressed, }; state.ButtonsStates[btn] = bs; InvokeSubscribers((s, ev) => s.OnMouseDoubleDown(ev)); }
private void OnRecyclerViewTouchUp( View.TouchEventArgs args, Canvas c, RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, float dX, float dY, int actionState, bool isCurrentlyActive) { if (args.Event.Action == MotionEventActions.Up) { base.OnChildDraw(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive); recyclerView.SetOnTouchListener(new TouchListener((view, motionEvent) => false)); SetItemsClickable(recyclerView, true); _swipeBack = false; _buttonShowedState = ButtonsState.GONE; } args.Handled = false; }
private void OnMouseUp(object sender, MouseEventArgs e) { var btn = GetMouseButton(e.Button); //state.Buttons ^= btn; state.Buttons &= ~btn; var bs = new ButtonsState { CursorPoint = new WindowPoint(), PointV2 = Vector2.Zero, Condition = ButtonStates.Released }; state.ButtonsStates[btn] = bs; if (btn == GeneralMouseButtons.None) { ReleaseCapture(); } InvokeSubscribers((s, ev) => s.OnMouseUp(ev)); }
private void SetTouchListener(Canvas c, RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, float dX, float dY, int actionState, bool isCurrentlyActive) { recyclerView.SetOnTouchListener(new OnTouchListener((v, e) => { swipeBack = e.Action == MotionEventActions.Cancel || e.Action == MotionEventActions.Up; if (swipeBack) { if (dX < -buttonWidth) { buttonShowedState = ButtonsState.RIGHT_VISIBLE; } else if (dX > buttonWidth) { buttonShowedState = ButtonsState.LEFT_VISIBLE; } if (buttonShowedState != ButtonsState.GONE) { SetTouchDownListener(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive); SetItemsClickable(recyclerView, false); } } })); }
/// <summary> /// Default constructor /// </summary> public StandardCalculatorViewModel() { #region Initialization currentData = new CurrentData(); buttonsState = new ButtonsState(); clearData = new ClearData(currentData, buttonsState); numberFormation = new NumberFormation(currentData, buttonsState, clearData); expressionFormation = new ExpressionFormation(currentData, buttonsState, clearData); memory = new Memory(); #endregion #region Create commands #region Commands for clearing data ClearCommand = new RelayCommand(() => { clearData.ClearAll(); UpdateMainProperties(); }); ClearEntryCommand = new RelayCommand(() => { clearData.ClearEntry(); UpdateMainProperties(); }); BackspaceCommand = new RelayCommand(() => { clearData.Backspace(); UpdateMainProperties(); }); #endregion #region Commands for basic math operations AdditionCommand = new RelayParameterizedCommand((obj) => { expressionFormation.SetBasicMathOperation(BasicMathOperations.Addition); UpdateMainProperties(); }, (obj) => NumberStandardization.NumberCheck(currentData.CurrentNumber)); SubtractionCommand = new RelayParameterizedCommand((obj) => { expressionFormation.SetBasicMathOperation(BasicMathOperations.Subtraction); UpdateMainProperties(); }, (obj) => NumberStandardization.NumberCheck(currentData.CurrentNumber)); MultiplyCommand = new RelayParameterizedCommand((obj) => { expressionFormation.SetBasicMathOperation(BasicMathOperations.Multiplication); UpdateMainProperties(); }, (obj) => NumberStandardization.NumberCheck(currentData.CurrentNumber)); DivisionCommand = new RelayParameterizedCommand((obj) => { expressionFormation.SetBasicMathOperation(BasicMathOperations.Division); UpdateMainProperties(); }, (obj) => NumberStandardization.NumberCheck(currentData.CurrentNumber)); ModuleDivisionCommand = new RelayParameterizedCommand((obj) => { expressionFormation.SetBasicMathOperation(BasicMathOperations.ModuleDivision); UpdateMainProperties(); }, (obj) => NumberStandardization.NumberCheck(currentData.CurrentNumber)); EqualCommand = new RelayParameterizedCommand((obj) => { expressionFormation.SetBasicMathOperation(BasicMathOperations.Equal); UpdateMainProperties(); }, (obj) => NumberStandardization.NumberCheck(currentData.CurrentNumber)); #endregion #region Number pad commands DigitZeroCommand = new RelayCommand(() => { numberFormation.AddDigit(Digits.Zero); UpdateMainProperties(); }); DigitOneCommand = new RelayCommand(() => { numberFormation.AddDigit(Digits.One); UpdateMainProperties(); }); DigitTwoCommand = new RelayCommand(() => { numberFormation.AddDigit(Digits.Two); UpdateMainProperties(); }); DigitThreeCommand = new RelayCommand(() => { numberFormation.AddDigit(Digits.Three); UpdateMainProperties(); }); DigitFourCommand = new RelayCommand(() => { numberFormation.AddDigit(Digits.Four); UpdateMainProperties(); }); DigitFiveCommand = new RelayCommand(() => { numberFormation.AddDigit(Digits.Five); UpdateMainProperties(); }); DigitSixCommand = new RelayCommand(() => { numberFormation.AddDigit(Digits.Six); UpdateMainProperties(); }); DigitSevenCommand = new RelayCommand(() => { numberFormation.AddDigit(Digits.Seven); UpdateMainProperties(); }); DigitEightCommand = new RelayCommand(() => { numberFormation.AddDigit(Digits.Eight); UpdateMainProperties(); }); DigitNineCommand = new RelayCommand(() => { numberFormation.AddDigit(Digits.Nine); UpdateMainProperties(); }); InvertNumberCommand = new RelayCommand(() => { numberFormation.InvertNumber(); UpdateMainProperties(); }); CommaCommand = new RelayCommand(() => { numberFormation.AddComma(); UpdateMainProperties(); }); #endregion #endregion }
/// <summary> /// Default constructor /// </summary> public StandardCalculatorViewModel() { #region Initialization currentData = new CurrentData(); buttonsState = new ButtonsState(); clearData = new ClearData(currentData, buttonsState); numberFormation = new NumberFormation(currentData, buttonsState, clearData); expressionFormation = new ExpressionFormation(currentData, buttonsState, clearData); memory = new Memory(); #endregion #region Create commands #region Commands for memory operations MemorySaveCommand = new RelayCommand(() => { memory.MemorySave(CurrentNumber); UpdateMainProperties(); }); MemoryClearCommand = new RelayCommand(() => { memory.MemoryClear(); UpdateMainProperties(); }); MemoryReadCommand = new RelayCommand(() => { memory.MemoryRead(CurrentNumber); UpdateMainProperties(); }); MemoryPlusCommand = new RelayCommand(() => { memory.MemoryPlus(CurrentNumber); UpdateMainProperties(); }); MemoryMinusCommand = new RelayCommand(() => { memory.MemoryMinus(CurrentNumber); UpdateMainProperties(); }); #endregion #region Commands for clearing data ClearCommand = new RelayCommand(() => { clearData.ClearAll(); UpdateMainProperties(); }); ClearEntryCommand = new RelayCommand(() => { clearData.ClearEntry(); UpdateMainProperties(); }); BackspaceCommand = new RelayCommand(() => { clearData.Backspace(); UpdateMainProperties(); }); #endregion #region Commands for basic math operations /// <summary> /// Adds a "+" operation to the current expression /// </summary> AdditionCommand = new RelayParameterizedCommand((obj) => { expressionFormation.SetBasicMathOperation(BasicMathOperations.Addition); UpdateMainProperties(); }, (obj) => NumberStandardization.NumberCheck(currentData.CurrentNumber)); /// <summary> /// Adds a "-" operation to the current expression /// </summary> SubtractionCommand = new RelayParameterizedCommand((obj) => { expressionFormation.SetBasicMathOperation(BasicMathOperations.Subtraction); UpdateMainProperties(); }, (obj) => NumberStandardization.NumberCheck(currentData.CurrentNumber)); /// <summary> /// Adds a "*" operation to the current expression /// </summary> MultiplyCommand = new RelayParameterizedCommand((obj) => { expressionFormation.SetBasicMathOperation(BasicMathOperations.Multiply); UpdateMainProperties(); }, (obj) => NumberStandardization.NumberCheck(currentData.CurrentNumber)); /// <summary> /// Adds a "/" operation to the current expression /// </summary> DivisionCommand = new RelayParameterizedCommand((obj) => { expressionFormation.SetBasicMathOperation(BasicMathOperations.Division); UpdateMainProperties(); }); /// <summary> /// Adds a "%" operation to the current expression /// </summary> ModuleDivisionCommand = new RelayParameterizedCommand((obj) => { expressionFormation.SetBasicMathOperation(BasicMathOperations.ModuleDivision); UpdateMainProperties(); }, (obj) => NumberStandardization.NumberCheck(currentData.CurrentNumber)); /// <summary> /// Adds a "=" operation to the current expression /// </summary> EqualCommand = new RelayParameterizedCommand((obj) => { expressionFormation.SetBasicMathOperation(BasicMathOperations.Equal); UpdateMainProperties(); }, (obj) => NumberStandardization.NumberCheck(currentData.CurrentNumber)); #endregion #region Commands for math operations /// <summary> /// Adds a "1/x" operation to the current expression /// </summary> PartOfTheWholeCommand = new RelayParameterizedCommand((obj) => { expressionFormation.SetBasicMathOperation(BasicMathOperations.PartOfTheWhole); UpdateMainProperties(); }, (obj) => NumberStandardization.NumberCheck(currentData.CurrentNumber)); /// <summary> /// Adds a "x²" operation to the current expression /// </summary> SqrCommand = new RelayParameterizedCommand((obj) => { expressionFormation.SetBasicMathOperation(BasicMathOperations.Sqr); UpdateMainProperties(); }, (obj) => NumberStandardization.NumberCheck(currentData.CurrentNumber)); /// <summary> /// Adds a "√x" operation to the current expression /// </summary> SqrtCommand = new RelayParameterizedCommand((obj) => { expressionFormation.SetBasicMathOperation(BasicMathOperations.Sqrt); UpdateMainProperties(); }, (obj) => NumberStandardization.NumberCheck(currentData.CurrentNumber)); #endregion #region Number pad commands DigitZeroCommand = new RelayCommand(() => { numberFormation.AddDigit(Digits.Zero); UpdateMainProperties(); }); DigitOneCommand = new RelayCommand(() => { numberFormation.AddDigit(Digits.One); UpdateMainProperties(); }); DigitTwoCommand = new RelayCommand(() => { numberFormation.AddDigit(Digits.Two); UpdateMainProperties(); }); DigitThreeCommand = new RelayCommand(() => { numberFormation.AddDigit(Digits.Three); UpdateMainProperties(); }); DigitFourCommand = new RelayCommand(() => { numberFormation.AddDigit(Digits.Four); UpdateMainProperties(); }); DigitFiveCommand = new RelayCommand(() => { numberFormation.AddDigit(Digits.Five); UpdateMainProperties(); }); DigitSixCommand = new RelayCommand(() => { numberFormation.AddDigit(Digits.Six); UpdateMainProperties(); }); DigitSevenCommand = new RelayCommand(() => { numberFormation.AddDigit(Digits.Seven); UpdateMainProperties(); }); DigitEightCommand = new RelayCommand(() => { numberFormation.AddDigit(Digits.Eight); UpdateMainProperties(); }); DigitNineCommand = new RelayCommand(() => { numberFormation.AddDigit(Digits.Nine); UpdateMainProperties(); }); InvertNumberCommand = new RelayCommand(() => { numberFormation.InvertNumber(); UpdateMainProperties(); }); CommaCommand = new RelayCommand(() => { numberFormation.AddComma(); UpdateMainProperties(); }); #endregion #endregion }
/// <summary> /// Default constructor /// </summary> public StandardCalculatorViewModel() { #region Initialization currentData = new CurrentData(); buttonsState = new ButtonsState(); clearData = new ClearData(currentData, buttonsState); numberFormation = new NumberFormation(currentData, buttonsState, clearData); expressionFormation = new ExpressionFormation(currentData, buttonsState, clearData); memory = new Memory(); #endregion #region Create commands #region Commands for memory operations MemoryClearCommand = new RelayParameterizedCommand((obj) => { memory.MemoryClear(); }, (obj) => MemoryBtnLockCondition()); MemoryReadCommand = new RelayParameterizedCommand((obj) => { if (buttonsState.EqualBtnPressed) { clearData.ClearAll(); } else if (buttonsState.AdditionalOperationBtnPressed) { currentData.CurrentExpression = clearData.ClearLastAdditionalOperation(currentData.CurrentExpression); buttonsState.AdditionalOperationBtnPressed_Change(false); } currentData.CurrentNumber = memory.CurrentValue.ToString(); buttonsState.NumberPadBtnPressed_Change(true); UpdateMainProperties(); }, (obj) => MemoryBtnLockCondition()); MemoryPlusCommand = new RelayParameterizedCommand((obj) => { memory.MemoryPlus(CurrentNumber); }, (obj) => NumberStandardization.NumberCheck(currentData.CurrentNumber)); MemoryMinusCommand = new RelayParameterizedCommand((obj) => { memory.MemoryMinus(CurrentNumber); }, (obj) => NumberStandardization.NumberCheck(currentData.CurrentNumber)); MemorySaveCommand = new RelayParameterizedCommand((obj) => { memory.MemorySave(CurrentNumber); }, (obj) => NumberStandardization.NumberCheck(currentData.CurrentNumber)); MemoryStorageCommand = new RelayParameterizedCommand((obj) => { System.Windows.MessageBox.Show(memory.CurrentValue.ToString()); }, (obj) => MemoryBtnLockCondition()); #endregion #region Commands for clearing data ClearCommand = new RelayCommand(() => { clearData.ClearAll(); UpdateMainProperties(); }); ClearEntryCommand = new RelayCommand(() => { clearData.ClearEntry(); UpdateMainProperties(); }); BackspaceCommand = new RelayCommand(() => { clearData.Backspace(); UpdateMainProperties(); }); #endregion #region Commands for additional operations FindPercentageCommand = new RelayParameterizedCommand((obj) => { expressionFormation.FindPercentage(); UpdateMainProperties(); }, (obj) => NumberStandardization.NumberCheck(currentData.CurrentNumber)); PartOfTheWholeCommand = new RelayParameterizedCommand((obj) => { expressionFormation.SetAdditionalOperation(AdditionalOperations.PartOfTheWhole); UpdateMainProperties(); }, (obj) => NumberStandardization.NumberCheck(currentData.CurrentNumber)); SqrCommand = new RelayParameterizedCommand((obj) => { expressionFormation.SetAdditionalOperation(AdditionalOperations.Exponentiation); UpdateMainProperties(); }, (obj) => NumberStandardization.NumberCheck(currentData.CurrentNumber)); SqrtCommand = new RelayParameterizedCommand((obj) => { expressionFormation.SetAdditionalOperation(AdditionalOperations.RootExtraction); UpdateMainProperties(); }, (obj) => NumberStandardization.NumberCheck(currentData.CurrentNumber)); #endregion #region Commands for basic math operations AdditionCommand = new RelayParameterizedCommand((obj) => { expressionFormation.SetBasicMathOperation(BasicMathOperations.Addition); UpdateMainProperties(); }, (obj) => NumberStandardization.NumberCheck(currentData.CurrentNumber)); SubtractionCommand = new RelayParameterizedCommand((obj) => { expressionFormation.SetBasicMathOperation(BasicMathOperations.Subtraction); UpdateMainProperties(); }, (obj) => NumberStandardization.NumberCheck(currentData.CurrentNumber)); MultiplyCommand = new RelayParameterizedCommand((obj) => { expressionFormation.SetBasicMathOperation(BasicMathOperations.Multiplication); UpdateMainProperties(); }, (obj) => NumberStandardization.NumberCheck(currentData.CurrentNumber)); DivisionCommand = new RelayParameterizedCommand((obj) => { expressionFormation.SetBasicMathOperation(BasicMathOperations.Division); UpdateMainProperties(); }, (obj) => NumberStandardization.NumberCheck(currentData.CurrentNumber)); EqualCommand = new RelayParameterizedCommand((obj) => { expressionFormation.SetBasicMathOperation(BasicMathOperations.Equal); UpdateMainProperties(); }, (obj) => NumberStandardization.NumberCheck(currentData.CurrentNumber)); #endregion #region Number pad commands DigitZeroCommand = new RelayCommand(() => { numberFormation.AddDigit(Digits.Zero); UpdateMainProperties(); }); DigitOneCommand = new RelayCommand(() => { numberFormation.AddDigit(Digits.One); UpdateMainProperties(); }); DigitTwoCommand = new RelayCommand(() => { numberFormation.AddDigit(Digits.Two); UpdateMainProperties(); }); DigitThreeCommand = new RelayCommand(() => { numberFormation.AddDigit(Digits.Three); UpdateMainProperties(); }); DigitFourCommand = new RelayCommand(() => { numberFormation.AddDigit(Digits.Four); UpdateMainProperties(); }); DigitFiveCommand = new RelayCommand(() => { numberFormation.AddDigit(Digits.Five); UpdateMainProperties(); }); DigitSixCommand = new RelayCommand(() => { numberFormation.AddDigit(Digits.Six); UpdateMainProperties(); }); DigitSevenCommand = new RelayCommand(() => { numberFormation.AddDigit(Digits.Seven); UpdateMainProperties(); }); DigitEightCommand = new RelayCommand(() => { numberFormation.AddDigit(Digits.Eight); UpdateMainProperties(); }); DigitNineCommand = new RelayCommand(() => { numberFormation.AddDigit(Digits.Nine); UpdateMainProperties(); }); InvertNumberCommand = new RelayCommand(() => { numberFormation.InvertNumber(); UpdateMainProperties(); }); CommaCommand = new RelayCommand(() => { numberFormation.AddComma(); UpdateMainProperties(); }); #endregion #endregion }
/// <summary> /// Return the buttons state of the device, it uses a sort of small cache to reduce memory consumption. /// </summary> /// <returns></returns> public ButtonsState GetState() { EnsureAttached(); Interop.Buttons buttons = Interop.Buttons.None; uint result = MethodsWrapper.ReadSoftButtons(openByTypeContext.device, ref buttons); switch (result) { case (uint)Errors.ERROR_SUCCESS: break; case (uint)Errors.ERROR_SERVICE_NOT_ACTIVE: throw new DeviceException(result, "Lglcd.Initialize() has not been called yet"); case (uint)Errors.ERROR_INVALID_PARAMETER: throw new DeviceException(result, "Device handle is invalid"); case (uint)Errors.ERROR_DEVICE_NOT_CONNECTED: // Not connected means it has been usb-removed, that's why I don't use "detached" throw new DeviceException(result, "Device not connected"); default: throw new DeviceException(result, "Problems getting device buttons state"); } if ((uint)buttons != m_LastButtonsState) { m_LastButtonsState = (uint)buttons; m_ButtonsState = new ButtonsState(m_LastButtonsState); } return m_ButtonsState; }
private void InternalStartListening() { while (_keepListenieng) { if (_numberOfLedPackets[0] > 0) { if (_blinkLeds) { ledPacketToSend[0] = 170; // NEW_PACKET ledPacketToSend[1] = 238; // LED_SEQUENCE ledPacketToSend[2] = 01; // LED_ACCORDING_TO_CLOCK ledPacketToSend[3] = 99; // CRC_START Port.Write(ledPacketToSend, 0, 4); _numberOfLedPackets[0]--; } } if (_numberOfLedPackets[1] > 0) { if (_blinkLeds == false) { ledPacketToSend[0] = 170; // NEW_PACKET ledPacketToSend[1] = 238; // LED_SEQUENCE ledPacketToSend[2] = 0; // LED_NO_LEDS ledPacketToSend[3] = 99; // CRC_START Port.Write(ledPacketToSend, 0, 4); _numberOfLedPackets[1]--; } } Port.BaseStream.Flush(); // Wait for packet start byte if (Port.ReadByte() != 0xAA) { continue; } var command = Port.ReadByte(); if (command == 0xAC) { var axisX = ReadFloat(); var tempHorizontalAxis = ReadFloat(); var axisZ = ReadFloat(); var crc = (byte)Port.ReadByte(); if (crc == 99) { HorizontalAxis = tempHorizontalAxis; } } else if (command == 0x38) { var tempButtons = new ButtonsState { BreakButtonDown = Port.ReadByte() != 0, Button1Down = Port.ReadByte() != 0, Button2Down = Port.ReadByte() != 0, Button3Down = Port.ReadByte() != 0 }; var crc = (byte)Port.ReadByte(); if (crc == 99) { Buttons = tempButtons; } } } }
private void InternalStartListening() { while (_keepListenieng) { if (_numberOfLedPackets[0] > 0) { if (_blinkLeds) { ledPacketToSend[0] = 170; // NEW_PACKET ledPacketToSend[1] = 238; // LED_SEQUENCE ledPacketToSend[2] = 01; // LED_ACCORDING_TO_CLOCK ledPacketToSend[3] = 99; // CRC_START Port.Write(ledPacketToSend, 0, 4); _numberOfLedPackets[0]--; } } if (_numberOfLedPackets[1] > 0) { if (_blinkLeds == false) { ledPacketToSend[0] = 170; // NEW_PACKET ledPacketToSend[1] = 238; // LED_SEQUENCE ledPacketToSend[2] = 0; // LED_NO_LEDS ledPacketToSend[3] = 99; // CRC_START Port.Write(ledPacketToSend, 0, 4); _numberOfLedPackets[1]--; } } Port.BaseStream.Flush(); // Wait for packet start byte if (Port.ReadByte() != 0xAA) { continue; } var command = Port.ReadByte(); if (command == 0xAC) { var axisX = ReadFloat(); var tempHorizontalAxis = ReadFloat(); var axisZ = ReadFloat(); var crc = (byte) Port.ReadByte(); if (crc == 99) { HorizontalAxis = tempHorizontalAxis; } } else if (command == 0x38) { var tempButtons = new ButtonsState { BreakButtonDown = Port.ReadByte() != 0, Button1Down = Port.ReadByte() != 0, Button2Down = Port.ReadByte() != 0, Button3Down = Port.ReadByte() != 0 }; var crc = (byte) Port.ReadByte(); if (crc == 99) { Buttons = tempButtons; } } } }