public void HandleKeyDown([NotNull] WirelessNetworkAddress source, RemoteKey key, [CanBeNull] TimeSpan? sensorTime) { Guard.NotNull(source, nameof(source)); KeyCategory keyCategory = GetCategoryForKey(key); if (keyCategory != KeyCategory.CommandOnly && HasModifierDownThatMatchesEntryState(source)) { int digit = GetDigitForKey(key); if (numberEntryState.AppendToNumber(digit)) { // ReSharper disable once PossibleInvalidOperationException // Reason: Call to AppendToNumber() above guarantees that value is not null. int number = numberEntryState.Number.Value; if (number > 0) { bool isCurrentCompetitor = numberEntryState.Mode == NumberEntryMode.EnteringCurrentCompetitor; var args = new CompetitorNumberSelectionEventArgs(number, isCurrentCompetitor); NotifyDigitReceived?.Invoke(this, args); } } } if (keyCategory == KeyCategory.CommandOnly || (keyCategory == KeyCategory.DigitAndCommand && modifierStatePerDevice.IsEmpty(source))) { NotifyUnknownAction?.Invoke(this, new UnknownDeviceActionEventArgs(source, sensorTime, key)); } }
/// <summary> /// Siganl receiver message handler /// </summary> /// <param name="sender">Invoker of the event</param> /// <param name="e">Event arguments</param> private void OnNewMessage(object sender, SignalReceiverEventArgs e) { if (e != null && e.Signal != null) { _received = e.Signal.RemoteKey; } }
/// <summary> /// Sends WinLIRC.NET sigal for the Remote Key to the outbound communication channel /// </summary> /// <param name="remoteKey">WinLIRC.NET remote key</param> public static void Send(RemoteKey remoteKey) { try { new Signal(remoteKey, string.Empty, string.Empty, string.Empty, 0).Send(); } catch (Exception e) { throw new ApplicationException("Cannot send signal", e); } }
public static void ShouldBeKeyUpFor([NotNull] this EventArgsWithName<RemoteKeyTracker> eventArgsWithName, [NotNull] WirelessNetworkAddress source, RemoteKey key) { Guard.NotNull(eventArgsWithName, nameof(eventArgsWithName)); Guard.NotNull(source, nameof(source)); eventArgsWithName.Name.Should().Be("KeyUp"); eventArgsWithName.EventArgs.Should().BeOfType<RemoteKeyEventArgs>(); var remoteKeyModifierEventArgs = (RemoteKeyEventArgs) eventArgsWithName.EventArgs; remoteKeyModifierEventArgs.Source.Should().Be(source); remoteKeyModifierEventArgs.Key.Should().Be(key); }
/// <summary> /// Initializs stringified WinLIRC.NET signal /// </summary> /// <param name="remoteKey">WinLIRC.NET remote rey</param> /// <param name="remoteName">WinLIRC remote name</param> /// <param name="keyName">WinLIRC remote Key name</param> /// <param name="keyCode">WinLIRC remote Key code</param> /// <param name="repeatCount">WinLIRC remote repeat count</param> public Signal(RemoteKey remoteKey, string remoteName, string keyName, string keyCode, int repeatCount) { try { RemoteKey = remoteKey; RemoteName = remoteName; KeyName = keyName; KeyCode = KeyCode; RepeatCount = repeatCount; } catch (Exception e) { throw new ApplicationException("Cannot initialize a signal", e); } }
/// <summary> /// Gets stringified version of WinLIRC.NET signal /// </summary> /// <returns>Stringified version of WinLIRC.NET signal</returns> public override string ToString() { string result = "[Unknown]"; try { result = string.Format("RemoteKey={0}|RemoteName={1}|KeyName={2}|KeyCode={3}|RepeatCount={4}", RemoteKey.ToString(), RemoteName, KeyName, KeyCode, RepeatCount); } catch (Exception e) { throw new ApplicationException("Cannot format signal", e); } return(result); }
private void OnRemoteKeyPress(object sender, EventArgs e) { try { Button b = sender as Button; if (b != null && b.Tag != null) { RemoteKey key = (RemoteKey)Enum.Parse(typeof(RemoteKey), b.Tag.ToString()); Program.Transmitter.Send(new Signal(key, string.Empty, string.Empty, string.Empty, 0)); } } catch (Exception err) { MessageBox.Show(err.Message); } }
public void Execute() { _sent = (RemoteKey) new Random().Next(25); _transmitter.Send(new Signal(_sent, string.Empty, string.Empty, string.Empty, 0)); Thread t = new Thread(new ThreadStart(CheckSignal)); t.Start(); t.Join(new TimeSpan(0, 0, 10)); if (t != null && t.ThreadState == ThreadState.Running) { t.Abort(); throw new ApplicationException("Transmitter and receiver signal mismatch!"); } }
private void AdaptForKeyWithOptionalSensorTime([NotNull] WirelessNetworkAddress source, RemoteKey key, [CanBeNull] TimeSpan? sensorTime) { if (KeyToCommandLookupTable.ContainsKey(key)) { DeviceCommand command = KeyToCommandLookupTable[key]; if (RunComposition.IsInRoleKeypad(source)) { CommandReceived?.Invoke(this, new DeviceCommandEventArgs(source, command)); } } else { if (sensorTime != null) { if (key == RemoteKey.PassStart && RunComposition.IsInRoleStartTimer(source)) { GatePassed?.Invoke(this, new GatePassageEventArgs(source, sensorTime, GatePassage.PassStart)); } else if (key == RemoteKey.Key2OrPassIntermediate) { if (RunComposition.IsInRoleIntermediateTimer1(source)) { GatePassed?.Invoke(this, new GatePassageEventArgs(source, sensorTime, GatePassage.PassIntermediate1)); } else if (RunComposition.IsInRoleIntermediateTimer2(source)) { GatePassed?.Invoke(this, new GatePassageEventArgs(source, sensorTime, GatePassage.PassIntermediate2)); } else if (RunComposition.IsInRoleIntermediateTimer3(source)) { GatePassed?.Invoke(this, new GatePassageEventArgs(source, sensorTime, GatePassage.PassIntermediate3)); } } else if (key == RemoteKey.PassFinish && RunComposition.IsInRoleFinishTimer(source)) { GatePassed?.Invoke(this, new GatePassageEventArgs(source, sensorTime, GatePassage.PassFinish)); } } } }
/// <summary> /// Process a key request from the remote control. Warning: This command may change or be disabled in the future. /// </summary> /// <param name="key">Name of the key to be simulated.</param> /// <param name="hold">Simulate key being pressed, released, or both.</param> /// <param name="clientAddress">Identifies the server or client. 0 for server and mac address(hexstring without colons) for clients</param> /// <param name="callback">Defaults to "jsonp"</param> /// <param name="wrapper"></param> /// <returns>RemoteKeyPress</returns> public RemoteKeyPress ProcessKey(RemoteKey key, RemoteKeyAction hold, string clientAddress = "0", string callback = null, string wrapper = null) { var req = new RestRequest("remote/processKey"); req.AddParameter("key", key.GetDescription()); req.AddParameter("hold", hold.GetDescription()); if (!string.IsNullOrWhiteSpace(clientAddress)) { req.AddParameter("clientAddr", clientAddress); } if (!string.IsNullOrWhiteSpace(callback)) { req.AddParameter("callback", callback); } if (!string.IsNullOrWhiteSpace(wrapper)) { req.AddParameter("wrapper", wrapper); } return(Server.MakeRequest <RemoteKeyPress>(req)); }
public static void ShouldBeKeyUpFor(this EventArgsWithName <RemoteKeyTracker> eventArgsWithName, WirelessNetworkAddress source, RemoteKey key) { Guard.NotNull(eventArgsWithName, nameof(eventArgsWithName)); Guard.NotNull(source, nameof(source)); eventArgsWithName.Name.Should().Be("KeyUp"); eventArgsWithName.EventArgs.Should().BeOfType <RemoteKeyEventArgs>(); var remoteKeyModifierEventArgs = (RemoteKeyEventArgs)eventArgsWithName.EventArgs; remoteKeyModifierEventArgs.Source.Should().Be(source); remoteKeyModifierEventArgs.Key.Should().Be(key); }
public RemoteKeyEventArgs(WirelessNetworkAddress source, RemoteKey key, TimeSpan?sensorTime) : base(source, sensorTime) { Key = key; }
public abstract void Press(RemoteKey key);
public RemoteKeyEventArgs([NotNull] WirelessNetworkAddress source, RemoteKey key, [CanBeNull] TimeSpan? sensorTime) : base(source, sensorTime) { Key = key; }
private static int GetDigitForKey(RemoteKey key) { switch (key) { case RemoteKey.Key1OrPlaySoundA: return 1; case RemoteKey.Key2OrPassIntermediate: return 2; case RemoteKey.Key3OrToggleElimination: return 3; case RemoteKey.Key4: return 4; case RemoteKey.Key5OrDecreaseRefusals: return 5; case RemoteKey.Key6OrIncreaseRefusals: return 6; case RemoteKey.Key7: return 7; case RemoteKey.Key8OrDecreaseFaults: return 8; case RemoteKey.Key9OrIncreaseFaults: return 9; case RemoteKey.Key0OrMuteSound: return 0; default: throw new InvalidOperationException($"Key {key} has no numeric value."); } }
private static KeyCategory GetCategoryForKey(RemoteKey key) { switch (key) { case RemoteKey.Key4: case RemoteKey.Key7: return KeyCategory.DigitOnly; case RemoteKey.Key1OrPlaySoundA: case RemoteKey.Key2OrPassIntermediate: case RemoteKey.Key3OrToggleElimination: case RemoteKey.Key5OrDecreaseRefusals: case RemoteKey.Key6OrIncreaseRefusals: case RemoteKey.Key8OrDecreaseFaults: case RemoteKey.Key9OrIncreaseFaults: case RemoteKey.Key0OrMuteSound: return KeyCategory.DigitAndCommand; case RemoteKey.PassFinish: case RemoteKey.PassStart: case RemoteKey.ResetRun: case RemoteKey.Ready: return KeyCategory.CommandOnly; default: throw ExceptionFactory.CreateNotSupportedExceptionFor(key); } }