void socket_ConnectionChange(object sender, GenericSocketStatusChageEventArgs e) { StatusFeedback.FireUpdate(); ConnectedFeedback.FireUpdate(); if (e.Client.IsConnected) { // Tasks on connect } else { // Cleanup items from this session } }
void ParseBytes(byte[] bytes) { if (bytes[0] == 0x22) { // Power on if (bytes[1] == 0x00) { _PowerIsOn = true; PowerIsOnFeedback.FireUpdate(); } // Power off else if (bytes[1] == 0x01) { _PowerIsOn = false; PowerIsOnFeedback.FireUpdate(); } } // Running Status else if (bytes[0] == 0x20 && bytes[1] == 0x85 && bytes[4] == 0x10) { var operationStates = new Dictionary <int, string> { { 0x00, "Standby" }, { 0x04, "Power On" }, { 0x05, "Cooling" }, { 0x06, "Standby (error)" }, { 0x0f, "Standby (power saving" }, { 0x10, "Network Standby" }, { 0xff, "Not supported" } }; var newPowerIsOn = bytes[7] == 0x01; if (newPowerIsOn != _PowerIsOn) { _PowerIsOn = newPowerIsOn; PowerIsOnFeedback.FireUpdate(); } Debug.Console(2, this, "PowerIsOn={0}\rCooling={1}\rPowering on/off={2}\rStatus={3}", _PowerIsOn, bytes[8] == 0x01, bytes[9] == 0x01, operationStates[bytes[10]]); } // Lamp remaining else if (bytes[0] == 0x23 && bytes[1] == 0x96 && bytes[4] == 0x06 && bytes[6] == 0x04) { var newValue = bytes[7]; if (bytes[5] == 0x00) { if (newValue != _Lamp1RemainingPercent) { _Lamp1RemainingPercent = newValue; Lamp1RemainingPercent.FireUpdate(); } } else { if (newValue != _Lamp2RemainingPercent) { _Lamp2RemainingPercent = newValue; Lamp2RemainingPercent.FireUpdate(); } } Debug.Console(0, this, "Lamp {0}, {1}% remaining", (bytes[5] + 1), bytes[7]); } }
/// <summary> /// This method will run when the PortGather is satisfied. Parse responses here. /// </summary> /// <param name="dev"></param> /// <param name="args"></param> void Port_LineReceived(object dev, GenericCommMethodReceiveTextArgs args) { if (Debug.Level == 2) { Debug.Console(2, this, "Received: '{0}'", ComTextHelper.GetEscapedText(args.Text)); } char[] trimChars = { '\x02', '\x03' }; var FB = args.Text.Trim(trimChars); Debug.Console(2, this, "Received cmd: '{0}'", FB); switch (FB) { case "PON": { _PowerIsOn = true; PowerIsOnFeedback.FireUpdate(); InputNumberFeedback.FireUpdate(); break; } case "POF": { _PowerIsOn = false; PowerIsOnFeedback.FireUpdate(); InputNumber = 102; InputNumberFeedback.FireUpdate(); break; } case "QPW:1": { _PowerIsOn = true; PowerIsOnFeedback.FireUpdate(); InputNumberFeedback.FireUpdate(); break; } case "QPW:0": { _PowerIsOn = false; PowerIsOnFeedback.FireUpdate(); InputNumber = 102; InputNumberFeedback.FireUpdate(); break; } case "QMI:HM1": { if (_PowerIsOn) { InputNumber = 1; InputNumberFeedback.FireUpdate(); } break; } case "QMI:HM2": { if (_PowerIsOn) { InputNumber = 2; InputNumberFeedback.FireUpdate(); } break; } case "QMI:DV1": { if (_PowerIsOn) { InputNumber = 3; InputNumberFeedback.FireUpdate(); } break; } case "QMI:PC1": { if (_PowerIsOn) { InputNumber = 4; InputNumberFeedback.FireUpdate(); } break; } } }
public static void LinkToApi(this PepperDash.Essentials.Core.DisplayBase displayDevice, BasicTriList trilist, uint joinStart, string joinMapKey) { int inputNumber = 0; IntFeedback inputNumberFeedback; List <string> inputKeys = new List <string>(); DisplayControllerJoinMap joinMap = new DisplayControllerJoinMap(); var joinMapSerialized = JoinMapHelper.GetJoinMapForDevice(joinMapKey); if (!string.IsNullOrEmpty(joinMapSerialized)) { joinMap = JsonConvert.DeserializeObject <DisplayControllerJoinMap>(joinMapSerialized); } joinMap.OffsetJoinNumbers(joinStart); Debug.Console(1, "Linking to Trilist '{0}'", trilist.ID.ToString("X")); Debug.Console(0, "Linking to Display: {0}", displayDevice.Name); trilist.StringInput[joinMap.Name].StringValue = displayDevice.Name; var commMonitor = displayDevice as ICommunicationMonitor; if (commMonitor != null) { commMonitor.CommunicationMonitor.IsOnlineFeedback.LinkInputSig(trilist.BooleanInput[joinMap.IsOnline]); } inputNumberFeedback = new IntFeedback(() => { return(inputNumber); }); // Two way feedbacks var twoWayDisplay = displayDevice as PepperDash.Essentials.Core.TwoWayDisplayBase; if (twoWayDisplay != null) { trilist.SetBool(joinMap.IsTwoWayDisplay, true); twoWayDisplay.CurrentInputFeedback.OutputChange += new EventHandler <FeedbackEventArgs>(CurrentInputFeedback_OutputChange); inputNumberFeedback.LinkInputSig(trilist.UShortInput[joinMap.InputSelect]); } // Power Off trilist.SetSigTrueAction(joinMap.PowerOff, () => { inputNumber = 102; inputNumberFeedback.FireUpdate(); displayDevice.PowerOff(); }); displayDevice.PowerIsOnFeedback.OutputChange += new EventHandler <FeedbackEventArgs>((o, a) => { if (!a.BoolValue) { inputNumber = 102; inputNumberFeedback.FireUpdate(); } else { inputNumber = 0; inputNumberFeedback.FireUpdate(); } }); displayDevice.PowerIsOnFeedback.LinkComplementInputSig(trilist.BooleanInput[joinMap.PowerOff]); // PowerOn trilist.SetSigTrueAction(joinMap.PowerOn, () => { inputNumber = 0; inputNumberFeedback.FireUpdate(); displayDevice.PowerOn(); }); displayDevice.PowerIsOnFeedback.LinkInputSig(trilist.BooleanInput[joinMap.PowerOn]); int count = 1; foreach (var input in displayDevice.InputPorts) { inputKeys.Add(input.Key.ToString()); var tempKey = inputKeys.ElementAt(count - 1); trilist.SetSigTrueAction((ushort)(joinMap.InputSelectOffset + count), () => { displayDevice.ExecuteSwitch(displayDevice.InputPorts[tempKey].Selector); }); Debug.Console(2, displayDevice, "Setting Input Select Action on Digital Join {0} to Input: {1}", joinMap.InputSelectOffset + count, displayDevice.InputPorts[tempKey].Key.ToString()); trilist.StringInput[(ushort)(joinMap.InputNamesOffset + count)].StringValue = input.Key.ToString(); count++; } Debug.Console(2, displayDevice, "Setting Input Select Action on Analog Join {0}", joinMap.InputSelect); trilist.SetUShortSigAction(joinMap.InputSelect, (a) => { if (a == 0) { displayDevice.PowerOff(); inputNumber = 0; } else if (a > 0 && a < displayDevice.InputPorts.Count && a != inputNumber) { displayDevice.ExecuteSwitch(displayDevice.InputPorts.ElementAt(a - 1).Selector); inputNumber = a; } else if (a == 102) { displayDevice.PowerToggle(); } if (twoWayDisplay != null) { inputNumberFeedback.FireUpdate(); } }); var volumeDisplay = displayDevice as IBasicVolumeControls; if (volumeDisplay != null) { trilist.SetBoolSigAction(joinMap.VolumeUp, (b) => volumeDisplay.VolumeUp(b)); trilist.SetBoolSigAction(joinMap.VolumeDown, (b) => volumeDisplay.VolumeDown(b)); trilist.SetSigTrueAction(joinMap.VolumeMute, () => volumeDisplay.MuteToggle()); var volumeDisplayWithFeedback = volumeDisplay as IBasicVolumeWithFeedback; if (volumeDisplayWithFeedback != null) { trilist.SetUShortSigAction(joinMap.VolumeLevel, new Action <ushort>((u) => volumeDisplayWithFeedback.SetVolume(u))); volumeDisplayWithFeedback.VolumeLevelFeedback.LinkInputSig(trilist.UShortInput[joinMap.VolumeLevel]); volumeDisplayWithFeedback.MuteFeedback.LinkInputSig(trilist.BooleanInput[joinMap.VolumeMute]); } } }