public IPCValue RegisterAddress(string address, string group, bool persistent = false) { IPCValue value = null; try { if (!IPCTools.IsReadAddress(address)) { Log.Logger.Error($"RegisterValue: Not an Read-Address! [{address}]"); return(value); } if (currentValues.ContainsKey(address)) { value = currentValues[address]; currentRegistrations[address]++; Log.Logger.Debug($"RegisterValue: Added Registration for Address {address}, Registrations: {currentRegistrations[address]}"); } else { if (IPCTools.rxOffset.IsMatch(address)) { value = new IPCValueOffset(address, group); } else { value = new IPCValueLvar(address); } currentValues.Add(address, value); currentRegistrations.Add(address, 1); if (persistent) { persistentValues.Add(address); } Log.Logger.Debug($"RegisterValue: Added Address {address}, Persistent: {persistent}"); } } catch { Log.Logger.Error($"RegisterValue: Exception while registering Address {address}"); } if (value == null) { Log.Logger.Error($"RegisterValue: Null Reference for Address {address}"); } return(value); }
public static bool RunButtonDown(IPCManager ipcManager, IModelSwitch switchSettings) { if (IPCTools.IsVjoyAddress(switchSettings.AddressAction, switchSettings.ActionType) && !IPCTools.IsVjoyToggle(switchSettings.AddressAction, switchSettings.ActionType)) { return(IPCTools.VjoyClearSet(ipcManager, switchSettings.AddressAction, false)); } else if (IPCTools.IsWriteAddress(switchSettings.AddressAction, (ActionSwitchType)switchSettings.ActionType)) { return(true); } else { return(false); } }
public static bool RunButtonUp(IPCManager ipcManager, bool longPress, string lastState, string lastStateLong, IModelSwitch switchSettings, out string[] newValues) { bool result = false; newValues = new string[2]; newValues[0] = lastState; newValues[1] = lastStateLong; if (IPCTools.IsVjoyAddress(switchSettings.AddressAction, switchSettings.ActionType) && !IPCTools.IsVjoyToggle(switchSettings.AddressAction, switchSettings.ActionType)) { result = IPCTools.VjoyClearSet(ipcManager, switchSettings.AddressAction, true); } else if (!longPress) { string newValue = ToggleValue(lastState, switchSettings.SwitchOffState, switchSettings.SwitchOnState); result = IPCTools.RunAction(ipcManager, switchSettings.AddressAction, (ActionSwitchType)switchSettings.ActionType, newValue, switchSettings.UseControlDelay); if (result) { newValues[0] = newValue; } } else if (longPress && switchSettings.HasLongPress) { if (IPCTools.IsVjoyAddress(switchSettings.AddressActionLong, switchSettings.ActionTypeLong) && IPCTools.IsVjoyToggle(switchSettings.AddressActionLong, switchSettings.ActionTypeLong)) { result = IPCTools.VjoyToggle(ipcManager, switchSettings.AddressActionLong); } else if (IPCTools.IsWriteAddress(switchSettings.AddressActionLong, (ActionSwitchType)switchSettings.ActionTypeLong) && !IPCTools.IsVjoyAddress(switchSettings.AddressActionLong, switchSettings.ActionTypeLong)) { string newValue = ToggleValue(lastStateLong, switchSettings.SwitchOffStateLong, switchSettings.SwitchOnStateLong); result = IPCTools.RunAction(ipcManager, switchSettings.AddressActionLong, (ActionSwitchType)switchSettings.ActionTypeLong, newValue, switchSettings.UseControlDelay); if (result) { newValues[1] = newValue; } } } return(result); }
public virtual void RegisterAction() { if (!BaseSettings.SwitchOnCurrentValue && IsActionReadable(BaseSettings.ActionType) && IPCTools.IsReadAddress(BaseSettings.AddressAction)) { ValueManager.RegisterValue(ID.SwitchState, BaseSettings.AddressAction); } else if (!BaseSettings.SwitchOnCurrentValue) { ValueManager.SetVariable(ID.SwitchState, BaseSettings.SwitchOffState); } if (BaseSettings.HasLongPress && !BaseSettings.SwitchOnCurrentValue && IsActionReadable(BaseSettings.ActionTypeLong) && IPCTools.IsReadAddress(BaseSettings.AddressActionLong)) { ValueManager.RegisterValue(ID.SwitchStateLong, BaseSettings.AddressActionLong); } else if (BaseSettings.HasLongPress && !BaseSettings.SwitchOnCurrentValue) { ValueManager.SetVariable(ID.SwitchStateLong, BaseSettings.SwitchOffStateLong); } }