/// <summary> /// Checks if a TableOverrideSetting is active, and returns a newly mirrored Output object with modified Value. If not found, returns same input back. /// NOTE: this will change sending output if there is an active schedule. /// If value of input is 0, ignore changing and return input unchanged. /// </summary> /// <param name="currentOutput">Output / port of device.</param> /// <param name="startingdeviceIndex">Specifies start index of device ID (1st UIO=27).</param> /// <param name="currentdeviceIndex">Specifies active index of device ID (for UIO this is zero-based, making the 1st UIO #27).</param> public IOutput getnewrecalculatedOutput(IOutput currentOutput, int startingdeviceIndex, int currentdeviceIndex) { if (currentOutput.Value != 0) { //create a new dummy output with no event mirroring input arg to avoid triggering a recursive OnOutputValueChanged (modifying Output directly would retrigger this method) Output newOutput = new Output(); newOutput.Value = currentOutput.Value; newOutput.Name = currentOutput.Name; newOutput.Number = currentOutput.Number; //Log.Write("ScheduledSettings.getnewrecalculatedOutput..name=" + newOutput.Name + ", number=" + newOutput.Number + ", currentdeviceIndex=" + currentdeviceIndex); TableOverrideSettingDevice activeDevice = getactiveDevice(newOutput, true, startingdeviceIndex, currentdeviceIndex); if (activeDevice != null) { return(newOutput); } else { return(currentOutput); } } else { return(currentOutput); } }
/// <summary> /// Checks if a TableOverrideSetting is active and enabled. Then among list of affected outputs, and of correct device ID. /// </summary> /// <param name="currentOutput">Output / port of device.</param> /// <param name="recalculateoutputValue">If true, recalculates output value directly.</param> /// <param name="startingdeviceIndex">Specifies start index of device ID (1st UIO=27).</param> /// <param name="currentdeviceIndex">Specifies active index of device ID (for UIO this is zero-based, making the 1st UIO #27).</param> public TableOverrideSettingDevice getactiveDevice(IOutput currentOutput, bool recalculateoutputValue, int startingdeviceIndex, int currentdeviceIndex) { TableOverrideSettingDevice foundactiveDevice = null; TableOverrideSetting foundactiveSequential = null; foreach (TableOverrideSetting tableOverrideSetting in this) { //first check if enabled and active if (tableOverrideSetting.Enabled == true && tableOverrideSetting.activeSetting == true) { //Log.Write("TableOverrideSettings.getactiveSequentialDevice, enabled: " + tableOverrideSetting.Name + ", checking output range..."); //find active sequence setting by checking if input output number / port matches first / primary index in outputs foreach (TableOverrideSettingDevice tableoverridesettingDevice in tableOverrideSetting.TableOverrideSettingDeviceList) { if ((currentdeviceIndex + startingdeviceIndex) == tableoverridesettingDevice.ConfigPostfixID && tableoverridesettingDevice.OutputList.Contains(currentOutput.Number) == true) { //Log.Write("TableOverrideSettings.TableOverrideSettingDevice... " + tableOverrideSetting.Name + " is active at channel #" + currentOutput.Number + " on device " + tableoverridesettingDevice.Name); foundactiveDevice = tableoverridesettingDevice; foundactiveSequential = tableOverrideSetting; break; } } } } //recalculate output value based on strength? if (foundactiveDevice != null && recalculateoutputValue == true) { double strengthFactor = foundactiveDevice.OutputPercent / 100f; byte newValue = Convert.ToByte(currentOutput.Value * strengthFactor); /*if (CacheList.Contains(foundactiveDevice) == false) { * CacheList.Add(foundactiveDevice); * * if (currentOutput.Value != 0) { * Log.Write("ScheduledSettings.GetActiveSchedule: found active schedule: " + foundactiveSchedule.Name + " [" + foundactiveSchedule.ClockStart + "-" + foundactiveSchedule.ClockEnd + "] at channel #" + currentOutput.Number + " on device config " + foundactiveDevice.Name + ", applying strength multiplier: " + strengthFactor + ", old value=" + currentOutput.Value + ", new value=" + newValue); * } * }*/ if (foundactiveDevice.OutputPercent == 0 && currentOutput.Value != 0) { currentOutput.Value = 0; } else if (foundactiveDevice.OutputPercent != 100) { currentOutput.Value = newValue; } } return(foundactiveDevice); }