internal async Task <bool> IsBrickButtonPressedAsyncInternal(BrickButton button) { Command c = new Command(CommandType.DirectReply, 1, 0); c.IsBrickButtonPressed(button, 0); await _brick.SendCommandAsyncInternal(c); return(false); }
private async Task PollSensorsAsync() { bool changed = false; const int responseSize = 11; int index = 0; Command c = new Command(CommandType.DirectReply, (8 * responseSize) + 6, 0); foreach (InputPort i in Enum.GetValues(typeof(InputPort))) { Port p = Ports[i]; index = p.Index * responseSize; c.GetTypeMode(p.InputPort, (byte)index, (byte)(index + 1)); c.ReadySI(p.InputPort, p.Mode, (byte)(index + 2)); c.ReadyRaw(p.InputPort, p.Mode, (byte)(index + 6)); c.ReadyPercent(p.InputPort, p.Mode, (byte)(index + 10)); } index += responseSize; c.IsBrickButtonPressed(BrickButton.Back, (byte)(index + 0)); c.IsBrickButtonPressed(BrickButton.Left, (byte)(index + 1)); c.IsBrickButtonPressed(BrickButton.Up, (byte)(index + 2)); c.IsBrickButtonPressed(BrickButton.Right, (byte)(index + 3)); c.IsBrickButtonPressed(BrickButton.Down, (byte)(index + 4)); c.IsBrickButtonPressed(BrickButton.Enter, (byte)(index + 5)); await SendCommandAsyncInternal(c); if (c.Response.Data == null) { return; } foreach (InputPort i in Enum.GetValues(typeof(InputPort))) { Port p = Ports[i]; int type = c.Response.Data[(p.Index * responseSize) + 0]; byte mode = c.Response.Data[(p.Index * responseSize) + 1]; float siValue = BitConverter.ToSingle(c.Response.Data, (p.Index * responseSize) + 2); int rawValue = BitConverter.ToInt32(c.Response.Data, (p.Index * responseSize) + 6); byte percentValue = c.Response.Data[(p.Index * responseSize) + 10]; if ((byte)p.Type != type || Math.Abs(p.SIValue - siValue) > 0.01f || p.RawValue != rawValue || p.PercentValue != percentValue) { changed = true; } if (Enum.IsDefined(typeof(DeviceType), type)) { p.Type = (DeviceType)type; } else { p.Type = DeviceType.Unknown; } p.SIValue = siValue; p.RawValue = rawValue; p.PercentValue = percentValue; } if (Buttons.Back != (c.Response.Data[index + 0] == 1) || Buttons.Left != (c.Response.Data[index + 1] == 1) || Buttons.Up != (c.Response.Data[index + 2] == 1) || Buttons.Right != (c.Response.Data[index + 3] == 1) || Buttons.Down != (c.Response.Data[index + 4] == 1) || Buttons.Enter != (c.Response.Data[index + 5] == 1) ) { changed = true; } Buttons.Back = (c.Response.Data[index + 0] == 1); Buttons.Left = (c.Response.Data[index + 1] == 1); Buttons.Up = (c.Response.Data[index + 2] == 1); Buttons.Right = (c.Response.Data[index + 3] == 1); Buttons.Down = (c.Response.Data[index + 4] == 1); Buttons.Enter = (c.Response.Data[index + 5] == 1); if (changed || _alwaysSendEvents) { OnBrickChanged(new BrickChangedEventArgs { Ports = this.Ports, Buttons = this.Buttons }); } }
private async Task PollSensorsAsync() { bool changed = false; const int responseSize = 11; int index = 0; Command c = new Command(CommandType.DirectReply, (8 * responseSize) + 6, 0); foreach(InputPort i in Enum.GetValues(typeof(InputPort))) { Port p = Ports[i]; index = p.Index * responseSize; c.GetTypeMode(p.InputPort, (byte)index, (byte)(index+1)); c.ReadySI(p.InputPort, p.Mode, (byte)(index+2)); c.ReadyRaw(p.InputPort, p.Mode, (byte)(index+6)); c.ReadyPercent(p.InputPort, p.Mode, (byte)(index+10)); } index += responseSize; c.IsBrickButtonPressed(BrickButton.Back, (byte)(index+0)); c.IsBrickButtonPressed(BrickButton.Left, (byte)(index+1)); c.IsBrickButtonPressed(BrickButton.Up, (byte)(index+2)); c.IsBrickButtonPressed(BrickButton.Right, (byte)(index+3)); c.IsBrickButtonPressed(BrickButton.Down, (byte)(index+4)); c.IsBrickButtonPressed(BrickButton.Enter, (byte)(index+5)); await SendCommandAsyncInternal(c); if(c.Response.Data == null) return; foreach(InputPort i in Enum.GetValues(typeof(InputPort))) { Port p = Ports[i]; int type = c.Response.Data[(p.Index * responseSize)+0]; byte mode = c.Response.Data[(p.Index * responseSize)+1]; float siValue = BitConverter.ToSingle(c.Response.Data, (p.Index * responseSize)+2); int rawValue = BitConverter.ToInt32(c.Response.Data, (p.Index * responseSize)+6); byte percentValue = c.Response.Data[(p.Index * responseSize)+10]; if((byte)p.Type != type || Math.Abs(p.SIValue - siValue) > 0.01f || p.RawValue != rawValue || p.PercentValue != percentValue) changed = true; if(Enum.IsDefined(typeof(DeviceType), type)) p.Type = (DeviceType)type; else p.Type = DeviceType.Unknown; p.SIValue = siValue; p.RawValue = rawValue; p.PercentValue = percentValue; } if( Buttons.Back != (c.Response.Data[index+0] == 1) || Buttons.Left != (c.Response.Data[index+1] == 1) || Buttons.Up != (c.Response.Data[index+2] == 1) || Buttons.Right != (c.Response.Data[index+3] == 1) || Buttons.Down != (c.Response.Data[index+4] == 1) || Buttons.Enter != (c.Response.Data[index+5] == 1) ) changed = true; Buttons.Back = (c.Response.Data[index+0] == 1); Buttons.Left = (c.Response.Data[index+1] == 1); Buttons.Up = (c.Response.Data[index+2] == 1); Buttons.Right = (c.Response.Data[index+3] == 1); Buttons.Down = (c.Response.Data[index+4] == 1); Buttons.Enter = (c.Response.Data[index+5] == 1); if(changed || _alwaysSendEvents) OnBrickChanged(new BrickChangedEventArgs { Ports = this.Ports, Buttons = this.Buttons }); }
internal async Task<bool> IsBrickButtonPressedAsyncInternal(BrickButton button) { Command c = new Command(CommandType.DirectReply, 1, 0); c.IsBrickButtonPressed(button, 0); await _brick.SendCommandAsyncInternal(c); return false; }